aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Signal.hh
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-05-02 13:10:42 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-05-10 11:00:45 (GMT)
commit144d716a42072bd59f6c99e95e86be4486285782 (patch)
tree1be4796a961521c71d8a31597ac8b7fc1c140eb6 /src/FbTk/Signal.hh
parent4b47675441b76620519b0204497686b09113daaa (diff)
downloadfluxbox-144d716a42072bd59f6c99e95e86be4486285782.zip
fluxbox-144d716a42072bd59f6c99e95e86be4486285782.tar.bz2
Simplify Slot.hh
Replace CallbackHolder, FunctorHolder and SlotHolder with a (smaller) set of polymorphic classes. SignalHolder now stores a (smart) pointer to the class.
Diffstat (limited to 'src/FbTk/Signal.hh')
-rw-r--r--src/FbTk/Signal.hh49
1 files changed, 27 insertions, 22 deletions
diff --git a/src/FbTk/Signal.hh b/src/FbTk/Signal.hh
index 79d001f..71a4d6e 100644
--- a/src/FbTk/Signal.hh
+++ b/src/FbTk/Signal.hh
@@ -22,6 +22,7 @@
22#ifndef FBTK_SIGNAL_HH 22#ifndef FBTK_SIGNAL_HH
23#define FBTK_SIGNAL_HH 23#define FBTK_SIGNAL_HH
24 24
25#include "RefCount.hh"
25#include "Slot.hh" 26#include "Slot.hh"
26#include <list> 27#include <list>
27#include <map> 28#include <map>
@@ -49,7 +50,7 @@ public:
49 }; 50 };
50 51
51 /// Do not use this type outside this class 52 /// Do not use this type outside this class
52 typedef std::list<SlotHolder> SlotList; 53 typedef std::list<RefCount<SlotBase> > SlotList;
53 54
54 typedef SlotList::iterator Iterator; 55 typedef SlotList::iterator Iterator;
55 typedef Iterator SlotID; 56 typedef Iterator SlotID;
@@ -91,7 +92,7 @@ protected:
91 Iterator end() { return m_slots.end(); } 92 Iterator end() { return m_slots.end(); }
92 93
93 /// Connect a slot to this signal. Must only be called by child classes. 94 /// Connect a slot to this signal. Must only be called by child classes.
94 SlotID connect(const SlotHolder& slot) { 95 SlotID connect(const RefCount<SlotBase>& slot) {
95 return m_slots.insert(m_slots.end(), slot); 96 return m_slots.insert(m_slots.end(), slot);
96 } 97 }
97 98
@@ -111,16 +112,17 @@ template <typename ReturnType,
111 typename Arg1 = SigImpl::EmptyArg, typename Arg2 = SigImpl::EmptyArg, typename Arg3 = SigImpl::EmptyArg > 112 typename Arg1 = SigImpl::EmptyArg, typename Arg2 = SigImpl::EmptyArg, typename Arg3 = SigImpl::EmptyArg >
112class Signal: public SigImpl::SignalHolder { 113class Signal: public SigImpl::SignalHolder {
113public: 114public:
114 typedef SigImpl::Slot3<ReturnType, Arg1, Arg2, Arg3> SlotType;
115
116 void emit(Arg1 arg1, Arg2 arg2, Arg3 arg3) { 115 void emit(Arg1 arg1, Arg2 arg2, Arg3 arg3) {
117 for ( Iterator it = begin(); it != end(); ++it ) { 116 for ( Iterator it = begin(); it != end(); ++it ) {
118 static_cast<SlotType&>(*it)(arg1, arg2, arg3); 117 static_cast<SigImpl::SlotBase3<ReturnType, Arg1, Arg2, Arg3> &>(**it)(arg1, arg2, arg3);
119 } 118 }
120 } 119 }
121 120
122 SlotID connect(const SlotType& slot) { 121 template<typename Functor>
123 return SignalHolder::connect(slot); 122 SlotID connect(const Functor& functor) {
123 return SignalHolder::connect(FbTk::RefCount<SigImpl::SlotBase>(
124 new SigImpl::Slot3<ReturnType, Arg1, Arg2, Arg3, Functor>(functor)
125 ));
124 } 126 }
125}; 127};
126 128
@@ -128,16 +130,17 @@ public:
128template <typename ReturnType, typename Arg1, typename Arg2> 130template <typename ReturnType, typename Arg1, typename Arg2>
129class Signal<ReturnType, Arg1, Arg2, SigImpl::EmptyArg>: public SigImpl::SignalHolder { 131class Signal<ReturnType, Arg1, Arg2, SigImpl::EmptyArg>: public SigImpl::SignalHolder {
130public: 132public:
131 typedef SigImpl::Slot2<ReturnType, Arg1, Arg2> SlotType;
132
133 void emit(Arg1 arg1, Arg2 arg2) { 133 void emit(Arg1 arg1, Arg2 arg2) {
134 for ( Iterator it = begin(); it != end(); ++it ) { 134 for ( Iterator it = begin(); it != end(); ++it ) {
135 static_cast<SlotType&>(*it)(arg1, arg2); 135 static_cast<SigImpl::SlotBase2<ReturnType, Arg1, Arg2> &>(**it)(arg1, arg2);
136 } 136 }
137 } 137 }
138 138
139 SlotID connect(const SlotType& slot) { 139 template<typename Functor>
140 return SignalHolder::connect(slot); 140 SlotID connect(const Functor& functor) {
141 return SignalHolder::connect(FbTk::RefCount<SigImpl::SlotBase>(
142 new SigImpl::Slot2<ReturnType, Arg1, Arg2, Functor>(functor)
143 ));
141 } 144 }
142}; 145};
143 146
@@ -145,16 +148,17 @@ public:
145template <typename ReturnType, typename Arg1> 148template <typename ReturnType, typename Arg1>
146class Signal<ReturnType, Arg1, SigImpl::EmptyArg, SigImpl::EmptyArg>: public SigImpl::SignalHolder { 149class Signal<ReturnType, Arg1, SigImpl::EmptyArg, SigImpl::EmptyArg>: public SigImpl::SignalHolder {
147public: 150public:
148 typedef SigImpl::Slot1<ReturnType, Arg1> SlotType;
149
150 void emit(Arg1 arg) { 151 void emit(Arg1 arg) {
151 for ( Iterator it = begin(); it != end(); ++it ) { 152 for ( Iterator it = begin(); it != end(); ++it ) {
152 static_cast<SlotType&>(*it)(arg); 153 static_cast<SigImpl::SlotBase1<ReturnType, Arg1> &>(**it)(arg);
153 } 154 }
154 } 155 }
155 156
156 SlotID connect(const SlotType& slot) { 157 template<typename Functor>
157 return SignalHolder::connect(slot); 158 SlotID connect(const Functor& functor) {
159 return SignalHolder::connect(FbTk::RefCount<SigImpl::SlotBase>(
160 new SigImpl::Slot1<ReturnType, Arg1, Functor>(functor)
161 ));
158 } 162 }
159}; 163};
160 164
@@ -162,16 +166,17 @@ public:
162template <typename ReturnType> 166template <typename ReturnType>
163class Signal<ReturnType, SigImpl::EmptyArg, SigImpl::EmptyArg, SigImpl::EmptyArg>: public SigImpl::SignalHolder { 167class Signal<ReturnType, SigImpl::EmptyArg, SigImpl::EmptyArg, SigImpl::EmptyArg>: public SigImpl::SignalHolder {
164public: 168public:
165 typedef SigImpl::Slot0<ReturnType> SlotType;
166
167 void emit() { 169 void emit() {
168 for ( Iterator it = begin(); it != end(); ++it ) { 170 for ( Iterator it = begin(); it != end(); ++it ) {
169 static_cast<SlotType&>(*it)(); 171 static_cast<SigImpl::SlotBase0<ReturnType> &>(**it)();
170 } 172 }
171 } 173 }
172 174
173 SlotID connect(const SlotType& slot) { 175 template<typename Functor>
174 return SignalHolder::connect(slot); 176 SlotID connect(const Functor& functor) {
177 return SignalHolder::connect(FbTk::RefCount<SigImpl::SlotBase>(
178 new SigImpl::Slot0<ReturnType, Functor>(functor)
179 ));
175 } 180 }
176}; 181};
177 182