DART 6.10.1
Loading...
Searching...
No Matches
ConnectionBody.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2021, The DART development contributors
3 * All rights reserved.
4 *
5 * The list of contributors can be found at:
6 * https://github.com/dartsim/dart/blob/master/LICENSE
7 *
8 * This file is provided under the following "BSD-style" License:
9 * Redistribution and use in source and binary forms, with or
10 * without modification, are permitted provided that the following
11 * conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifndef DART_COMMON_DETAIL_CONNECTIONBODY_HPP_
34#define DART_COMMON_DETAIL_CONNECTIONBODY_HPP_
35
36#include <memory>
37
38namespace dart {
39namespace common {
40
41namespace signal {
42namespace detail {
43
46{
47public:
49 ConnectionBodyBase() = default;
50
52 virtual ~ConnectionBodyBase();
53
55 virtual void disconnect() = 0;
56};
57
59template <typename SignalType>
60class ConnectionBody final
61 : public ConnectionBodyBase,
62 public std::enable_shared_from_this<ConnectionBody<SignalType>>
63{
64public:
65 using SlotType = typename SignalType::SlotType;
66
68 ConnectionBody(SignalType& signal, const SlotType& _slot);
69
71 ConnectionBody(SignalType& signal, SlotType&& _slot);
72
74 virtual ~ConnectionBody();
75
77 void disconnect() override;
78
80 const SlotType& getSlot() const;
81
82private:
84 SignalType& mSignal;
85 // Holding the reference of the Signal is safe because the lifetime of this
86 // ConnectionBody is always shorter than the Signal since the Signal has the
87 // ownership of this ConnectionBody.
88
91};
92
93//==============================================================================
94template <typename SignalType>
96 SignalType& signal, const SlotType& _slot)
97 : ConnectionBodyBase(), mSignal(signal), mSlot(_slot)
98{
99 // Do nothing
100}
101
102//==============================================================================
103template <typename SignalType>
105 : ConnectionBodyBase(), mSignal(signal), mSlot(std::forward<SlotType>(_slot))
106{
107 // Do nothing
108}
109
110//==============================================================================
111template <typename SignalType>
116
117//==============================================================================
118template <typename SignalType>
120{
121 mSignal.disconnect(this->shared_from_this());
122}
123
124//==============================================================================
125template <typename SignalType>
128{
129 return mSlot;
130}
131
133template <typename T>
135{
136 typedef T result_type;
137
138 template <typename InputIterator>
139 static T process(InputIterator first, InputIterator last)
140 {
141 // If there are no slots to call, just return the
142 // default-constructed value
143 if (first == last)
144 return T();
145
146 return *(--last);
147 }
148};
149
150} // namespace detail
151} // namespace signal
152
153} // namespace common
154} // namespace dart
155
156#endif // DART_COMMON_DETAIL_CONNECTIONBODY_HPP_
class ConnectionBodyBase
Definition ConnectionBody.hpp:46
virtual ~ConnectionBodyBase()
Destructor.
Definition ConnectionBody.cpp:42
class ConnectionBody
Definition ConnectionBody.hpp:63
virtual ~ConnectionBody()
Destructor.
Definition ConnectionBody.hpp:112
SlotType mSlot
Slot.
Definition ConnectionBody.hpp:90
typename SignalType::SlotType SlotType
Definition ConnectionBody.hpp:65
ConnectionBody(SignalType &signal, const SlotType &_slot)
Constructor given slot.
Definition ConnectionBody.hpp:95
const SlotType & getSlot() const
Get slot.
Definition ConnectionBody.hpp:127
SignalType & mSignal
Signal of this connection.
Definition ConnectionBody.hpp:84
void disconnect() override
Disconnect.
Definition ConnectionBody.hpp:119
Definition BulletCollisionDetector.cpp:65
Definition SharedLibraryManager.hpp:46
DefaultCombiner – return the last result.
Definition ConnectionBody.hpp:135
static T process(InputIterator first, InputIterator last)
Definition ConnectionBody.hpp:139
T result_type
Definition ConnectionBody.hpp:136