19 #ifndef __Callback_Sender_h
20 #define __Callback_Sender_h
44 void send (
const Type& data)
47 for (
unsigned irecv=0; irecv < recipients.size(); irecv++) {
48 if (
verbose) std::cerr <<
"Callback::send " << irecv
49 <<
"/" << recipients.size() << std::endl;
50 recipients[irecv] -> call (data);
55 template<
class Class,
typename Method>
56 void connect (Class* instance, Method method)
58 change (instance, method,
true);
62 template<
class Class,
typename Method>
63 void disconnect (Class* instance, Method method)
65 change (instance, method,
false);
69 template<
typename Function>
70 void connect (Function
function)
72 change (
function,
true);
76 template<
typename Function>
79 change (
function,
false);
82 template<
class Class,
typename Method>
88 template<
class Class,
typename Method>
99 template<
class Class,
typename Method>
100 void change (Class* instance, Method method,
bool add)
102 if (!instance || !method)
105 typedef typename Functor<void(Type)>::template
106 Method<Class, Method> ReceiverBase;
108 ReceiverBase* receiver = 0;
110 for (
unsigned i=0; i < recipients.size(); i++) {
112 receiver =
dynamic_cast<ReceiverBase*
>(recipients[i].ptr());
114 if (receiver && receiver -> matches (instance, method)) {
116 recipients.erase(recipients.begin()+i);
123 receiver =
new ReceiverBase (instance, method);
124 recipients.push_back (receiver);
129 template<
typename Function>
130 void change (Function
function,
bool add)
135 typedef typename Functor<void(Type)>::template
136 Function<Function> ReceiverBase;
138 ReceiverBase* receiver = 0;
140 for (
unsigned i=0; i < recipients.size(); i++) {
142 receiver =
dynamic_cast<ReceiverBase*
>(recipients[i].ptr());
144 if (receiver && receiver -> matches (
function)) {
146 recipients.erase(recipients.begin()+i);
153 receiver =
new ReceiverBase (
function);
154 recipients.push_back (receiver);
161 for (
unsigned i=0; i < recipients.size(); )
162 if (!recipients[i]->is_valid())
163 recipients.erase(recipients.begin()+i);
170 #endif // #ifndef __Callback_Callback_h