aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Signal.hh
diff options
context:
space:
mode:
authorMark Tiefenbruck <mark@fluxbox.org>2008-09-21 06:46:23 (GMT)
committerMark Tiefenbruck <mark@fluxbox.org>2008-09-21 06:46:23 (GMT)
commit4c11204716c3e31d853cb071239cafea52a92efc (patch)
tree9617ffbec230a7ede954cd5e90191174ad436143 /src/FbTk/Signal.hh
parentab8b21d18c16d9956b34bbbd7be8858aa048e500 (diff)
downloadfluxbox_pavel-4c11204716c3e31d853cb071239cafea52a92efc.zip
fluxbox_pavel-4c11204716c3e31d853cb071239cafea52a92efc.tar.bz2
fix a few things with new signal code
Diffstat (limited to 'src/FbTk/Signal.hh')
-rw-r--r--src/FbTk/Signal.hh27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/FbTk/Signal.hh b/src/FbTk/Signal.hh
index 768ca90..b25fe9a 100644
--- a/src/FbTk/Signal.hh
+++ b/src/FbTk/Signal.hh
@@ -24,6 +24,7 @@
24 24
25#include "Slot.hh" 25#include "Slot.hh"
26#include <list> 26#include <list>
27#include <map>
27#include <vector> 28#include <vector>
28 29
29namespace FbTk { 30namespace FbTk {
@@ -45,6 +46,8 @@ public:
45 typedef Iterator SlotID; 46 typedef Iterator SlotID;
46 typedef SlotList::const_iterator ConstIterator; 47 typedef SlotList::const_iterator ConstIterator;
47 48
49 virtual ~SignalHolder() { }
50
48 /// Remove a specific slot \c id from this signal 51 /// Remove a specific slot \c id from this signal
49 void disconnect(SlotID slotIt) { 52 void disconnect(SlotID slotIt) {
50 m_slots.erase( slotIt ); 53 m_slots.erase( slotIt );
@@ -78,6 +81,8 @@ class Signal0: public SignalHolder {
78public: 81public:
79 typedef Slot0<ReturnType> SlotType; 82 typedef Slot0<ReturnType> SlotType;
80 83
84 virtual ~Signal0() { }
85
81 void emit() { 86 void emit() {
82 for ( Iterator it = begin(); it != end(); ++it ) { 87 for ( Iterator it = begin(); it != end(); ++it ) {
83 static_cast<SlotType&>(*it)(); 88 static_cast<SlotType&>(*it)();
@@ -96,6 +101,8 @@ class Signal1: public SignalHolder {
96public: 101public:
97 typedef Slot1<ReturnType, Arg1> SlotType; 102 typedef Slot1<ReturnType, Arg1> SlotType;
98 103
104 virtual ~Signal1() { }
105
99 void emit(Arg1 arg) { 106 void emit(Arg1 arg) {
100 for ( Iterator it = begin(); it != end(); ++it ) { 107 for ( Iterator it = begin(); it != end(); ++it ) {
101 static_cast<SlotType&>(*it)(arg); 108 static_cast<SlotType&>(*it)(arg);
@@ -114,6 +121,8 @@ class Signal2: public SignalHolder {
114public: 121public:
115 typedef Slot2<ReturnType, Arg1, Arg2> SlotType; 122 typedef Slot2<ReturnType, Arg1, Arg2> SlotType;
116 123
124 virtual ~Signal2() { }
125
117 void emit(Arg1 arg1, Arg2 arg2) { 126 void emit(Arg1 arg1, Arg2 arg2) {
118 for ( Iterator it = begin(); it != end(); ++it ) { 127 for ( Iterator it = begin(); it != end(); ++it ) {
119 static_cast<SlotType&>(*it)(arg1, arg2); 128 static_cast<SlotType&>(*it)(arg1, arg2);
@@ -131,6 +140,8 @@ class Signal3: public SignalHolder {
131public: 140public:
132 typedef Slot3<ReturnType, Arg1, Arg2, Arg3> SlotType; 141 typedef Slot3<ReturnType, Arg1, Arg2, Arg3> SlotType;
133 142
143 virtual ~Signal3() { }
144
134 void emit(Arg1 arg1, Arg2 arg2, Arg3 arg3) { 145 void emit(Arg1 arg1, Arg2 arg2, Arg3 arg3) {
135 for ( Iterator it = begin(); it != end(); ++it ) { 146 for ( Iterator it = begin(); it != end(); ++it ) {
136 static_cast<SlotType&>(*it)(arg1, arg2, arg3); 147 static_cast<SlotType&>(*it)(arg1, arg2, arg3);
@@ -180,16 +191,15 @@ public:
180class SignalTracker { 191class SignalTracker {
181public: 192public:
182 /// Internal type, do not use. 193 /// Internal type, do not use.
183 typedef std::list< std::pair< SigImpl::SignalHolder*, SigImpl::SignalHolder::SlotID > > Connections; 194 typedef std::map<SigImpl::SignalHolder*, SigImpl::SignalHolder::SlotID> Connections;
184 typedef Connections::iterator TrackID; ///< \c ID type for join/leave. 195 typedef Connections::iterator TrackID; ///< \c ID type for join/leave.
185 196
186 ~SignalTracker() { 197 virtual ~SignalTracker() {
187 // disconnect all connections 198 // disconnect all connections
188 for ( Connections::iterator conIt = m_connections.begin(); 199 for ( Connections::iterator conIt = m_connections.begin();
189 conIt != m_connections.end(); ) { 200 conIt != m_connections.end(); ++conIt)
190 conIt->first->disconnect( conIt->second ); 201 conIt->first->disconnect( conIt->second );
191 conIt = m_connections.erase( conIt ); 202 m_connections.clear();
192 }
193 } 203 }
194 204
195 /// Starts tracking a signal. 205 /// Starts tracking a signal.
@@ -207,6 +217,13 @@ public:
207 m_connections.erase(id); 217 m_connections.erase(id);
208 } 218 }
209 219
220 /// Leave tracking for a signal
221 /// @param sig the signal to leave
222 template <typename Signal>
223 void leave(Signal &sig) {
224 m_connections.erase(&sig);
225 }
226
210private: 227private:
211 /// holds all connections to different signals and slots. 228 /// holds all connections to different signals and slots.
212 Connections m_connections; 229 Connections m_connections;