aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/Signal.hh35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/FbTk/Signal.hh b/src/FbTk/Signal.hh
index b25fe9a..18b03b3 100644
--- a/src/FbTk/Signal.hh
+++ b/src/FbTk/Signal.hh
@@ -46,7 +46,7 @@ public:
46 typedef Iterator SlotID; 46 typedef Iterator SlotID;
47 typedef SlotList::const_iterator ConstIterator; 47 typedef SlotList::const_iterator ConstIterator;
48 48
49 virtual ~SignalHolder() { } 49 ~SignalHolder() { }
50 50
51 /// Remove a specific slot \c id from this signal 51 /// Remove a specific slot \c id from this signal
52 void disconnect(SlotID slotIt) { 52 void disconnect(SlotID slotIt) {
@@ -81,7 +81,7 @@ class Signal0: public SignalHolder {
81public: 81public:
82 typedef Slot0<ReturnType> SlotType; 82 typedef Slot0<ReturnType> SlotType;
83 83
84 virtual ~Signal0() { } 84 ~Signal0() { }
85 85
86 void emit() { 86 void emit() {
87 for ( Iterator it = begin(); it != end(); ++it ) { 87 for ( Iterator it = begin(); it != end(); ++it ) {
@@ -101,7 +101,7 @@ class Signal1: public SignalHolder {
101public: 101public:
102 typedef Slot1<ReturnType, Arg1> SlotType; 102 typedef Slot1<ReturnType, Arg1> SlotType;
103 103
104 virtual ~Signal1() { } 104 ~Signal1() { }
105 105
106 void emit(Arg1 arg) { 106 void emit(Arg1 arg) {
107 for ( Iterator it = begin(); it != end(); ++it ) { 107 for ( Iterator it = begin(); it != end(); ++it ) {
@@ -121,7 +121,7 @@ class Signal2: public SignalHolder {
121public: 121public:
122 typedef Slot2<ReturnType, Arg1, Arg2> SlotType; 122 typedef Slot2<ReturnType, Arg1, Arg2> SlotType;
123 123
124 virtual ~Signal2() { } 124 ~Signal2() { }
125 125
126 void emit(Arg1 arg1, Arg2 arg2) { 126 void emit(Arg1 arg1, Arg2 arg2) {
127 for ( Iterator it = begin(); it != end(); ++it ) { 127 for ( Iterator it = begin(); it != end(); ++it ) {
@@ -140,7 +140,7 @@ class Signal3: public SignalHolder {
140public: 140public:
141 typedef Slot3<ReturnType, Arg1, Arg2, Arg3> SlotType; 141 typedef Slot3<ReturnType, Arg1, Arg2, Arg3> SlotType;
142 142
143 virtual ~Signal3() { } 143 ~Signal3() { }
144 144
145 void emit(Arg1 arg1, Arg2 arg2, Arg3 arg3) { 145 void emit(Arg1 arg1, Arg2 arg2, Arg3 arg3) {
146 for ( Iterator it = begin(); it != end(); ++it ) { 146 for ( Iterator it = begin(); it != end(); ++it ) {
@@ -191,15 +191,12 @@ public:
191class SignalTracker { 191class SignalTracker {
192public: 192public:
193 /// Internal type, do not use. 193 /// Internal type, do not use.
194 typedef std::map<SigImpl::SignalHolder*, SigImpl::SignalHolder::SlotID> Connections; 194 typedef std::list< std::pair<SigImpl::SignalHolder*,
195 SigImpl::SignalHolder::SlotID> > Connections;
195 typedef Connections::iterator TrackID; ///< \c ID type for join/leave. 196 typedef Connections::iterator TrackID; ///< \c ID type for join/leave.
196 197
197 virtual ~SignalTracker() { 198 ~SignalTracker() {
198 // disconnect all connections 199 leaveAll();
199 for ( Connections::iterator conIt = m_connections.begin();
200 conIt != m_connections.end(); ++conIt)
201 conIt->first->disconnect( conIt->second );
202 m_connections.clear();
203 } 200 }
204 201
205 /// Starts tracking a signal. 202 /// Starts tracking a signal.
@@ -220,10 +217,22 @@ public:
220 /// Leave tracking for a signal 217 /// Leave tracking for a signal
221 /// @param sig the signal to leave 218 /// @param sig the signal to leave
222 template <typename Signal> 219 template <typename Signal>
223 void leave(Signal &sig) { 220 void leave(const Signal &sig) {
224 m_connections.erase(&sig); 221 m_connections.erase(&sig);
225 } 222 }
226 223
224
225 void leaveAll() {
226 // disconnect all connections
227 for ( Connections::iterator conIt = m_connections.begin();
228 conIt != m_connections.end(); ) {
229 // keep temporary, while disconnecting we can
230 // in some strange cases get a call to this again
231 Connections::value_type tmp = *conIt;
232 conIt = m_connections.erase(conIt);
233 tmp.first->disconnect(tmp.second);
234 }
235 }
227private: 236private:
228 /// holds all connections to different signals and slots. 237 /// holds all connections to different signals and slots.
229 Connections m_connections; 238 Connections m_connections;