32 #include <itpp/itexports.h>
34 #if (defined(_MSC_VER) && defined(ITPP_SHARED_LIB) && !(defined(itpp_EXPORTS) || defined(itpp_debug_EXPORTS)))
36 #ifndef ITPP_PROTOCOL_EXCLUDED
37 #define ITPP_PROTOCOL_EXCLUDED
38 #pragma message( "PROTOCOL definitions are not available for MSVC shared builds" )
55 template<
class DataType>
class Signal;
56 template<
class DataType>
class Base_Slot;
57 template<
class ObjectType,
class DataType>
class Slot;
123 template<
class DataType>
130 Signal(
const std::string signal_name =
"Unamed Signal",
const bool single_shot =
false,
const bool enable_debug =
false);
153 void set_name(
const std::string &signal_name);
156 void set_debug(
const bool enable_debug =
true);
163 typedef typename std::list<Base_Slot<DataType>*, std::allocator< Base_Slot<DataType>* > >::iterator
Base_Slot_Iterator;
167 std::list<Base_Slot<DataType>*, std::allocator<Base_Slot<DataType>* > >
connected_slots;
183 template<
class DataType>
187 friend class Signal<DataType>;
190 Base_Slot(
const std::string slot_name =
"Unamed Base_Slot");
196 void set_name(
const std::string &slot_name);
204 typedef typename std::list<Signal<DataType>*, std::allocator< Signal<DataType>* > >::iterator
Signal_Iterator;
219 template<
class ObjectType,
class DataType>
224 Slot(
const std::string _name =
"Unamed Slot");
227 void forward(ObjectType *object_pointer,
void(ObjectType::*object_function_pointer)(DataType u));
239 void(ObjectType::*pm)(DataType signal);
246 template<
class ObjectType,
class DataType>
251 ATimer(
const std::string
Name =
"Unamed ATimer") {
254 time_out_signal->connect(time_out_slot);
259 void forward(ObjectType *po,
void(ObjectType::*pm)(DataType u)) { time_out_slot->forward(po, pm); }
262 void set(DataType u,
const Ttype delta_t) {
263 time_out_signal->operator()(u, delta_t);
267 void cancel() { time_out_signal->
cancel(); }
270 void set_name(
const std::string Name) {
272 time_out_signal->set_name(name);
281 Signal<DataType> *time_out_signal;
282 Slot<ObjectType, DataType> *time_out_slot;
295 template <
class THandler>
300 TTimer(THandler & handler,
void (THandler::*handlerFunction)(
Ttype time)) :
301 signal(
"timer_signal", true) {
305 registered_handler = &handler;
306 registered_handler_function = handlerFunction;
334 delta_time = time - current_time;
360 (*registered_handler.*registered_handler_function)(currentTime);
377 THandler *registered_handler;
378 void(THandler::*registered_handler_function)(
Ttype expiry_time);
391 template<
class DataType>
396 single = single_shot;
397 set_name(signal_name);
398 set_debug(enable_debug);
401 template<
class DataType>
405 begin = connected_slots.begin(),
406 end = connected_slots.end(),
409 for (i = begin; i != end; i++)
410 (*i)->_disconnect(
this);
412 connected_slots.clear();
418 template<
class DataType>
424 template<
class DataType>
427 debug = enable_debug;
430 template<
class DataType>
434 begin = connected_slots.begin(),
435 end = connected_slots.end(),
438 bool is_already_connected =
false;
440 for (i = begin; i != end; i++)
442 is_already_connected =
true;
444 if (!is_already_connected) {
445 connected_slots.push_back(slot);
449 std::cout <<
"Signal '" << name <<
"' and Slot '" << slot->
name <<
"' are already connected. Multiple connections have no effect!" << std::endl;
453 template<
class DataType>
457 begin = connected_slots.begin(),
458 end = connected_slots.end(),
461 for (i = begin; i != end; i++)
463 (*i)->_disconnect(
this);
464 connected_slots.erase(i);
469 template<
class DataType>
476 std::cout <<
"Warning: Changing time for Signal '" << name <<
"'." << std::endl;
478 operator()(signal, delta_time);
494 template<
class DataType>
497 if (armed && single) {
505 template<
class DataType>
511 begin = connected_slots.begin(),
512 end = connected_slots.end(),
515 for (i = begin; i != end; i++) {
517 std::cout <<
"Time = " <<
Event_Queue::now() <<
". Signal '" << name <<
"' was sent to Slot '" << (*i)->name <<
"'." << std::endl;
522 template<
class DataType>
526 begin = connected_slots.begin(),
527 end = connected_slots.end(),
530 for (i = begin; i != end; i++)
532 connected_slots.erase(i);
538 template<
class DataType>
544 template<
class DataType>
550 template<
class DataType>
555 begin = connected_signals.begin(),
556 end = connected_signals.end(),
559 for (i = begin; i != end; i++)
560 (*i)->_disconnect(
this);
562 connected_signals.clear();
565 template<
class DataType>
568 connected_signals.push_back(signal);
571 template<
class DataType>
576 begin = connected_signals.begin(),
577 end = connected_signals.end(),
580 for (i = begin; i != end; i++)
581 if ((*i) == signal) {
582 connected_signals.erase(i);
587 template<
class ObjectType,
class DataType>
594 template<
class ObjectType,
class DataType>
597 template<
class ObjectType,
class DataType>
600 pm = object_function_pointer;
610 template<
class ObjectType,
class DataType>
623 #endif // #ifndef SIGNAL_SLOT_H