.. _program_listing_file__tmp_ws_src_ecl_lite_ecl_sigslots_lite_include_ecl_sigslots_lite_slot.hpp: Program Listing for File slot.hpp ================================= |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/ecl_lite/ecl_sigslots_lite/include/ecl/sigslots_lite/slot.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /***************************************************************************** ** Ifdefs *****************************************************************************/ #ifndef ECL_SIGSLOTS_LITE_SLOT_HPP_ #define ECL_SIGSLOTS_LITE_SLOT_HPP_ /***************************************************************************** ** Includes *****************************************************************************/ #include // defines NULL /***************************************************************************** ** Namespaces *****************************************************************************/ namespace ecl { namespace lite { /***************************************************************************** ** Slots *****************************************************************************/ namespace sigslots { template class SlotBase { public: virtual void execute(Data data) = 0; }; template class MemberSlot : public SlotBase { public: MemberSlot() {} MemberSlot(void (FunctionClass::*func)(Data), FunctionClass &instance) : object(&instance), member_function(func) {} void execute(Data data) { (*object.*member_function)(data); } FunctionClass *object; void (FunctionClass::*member_function)(Data); private: }; template class GlobalSlot : public SlotBase { public: GlobalSlot() : global_function(NULL) {} GlobalSlot(void (*func)(Data)) : global_function(func) {} void execute(Data data) { if ( global_function != NULL ) { (*global_function)(data); } } void (*global_function)(Data); }; /***************************************************************************** ** Slot Specialisations *****************************************************************************/ template <> class SlotBase { public: virtual void execute() = 0; }; template class MemberSlot : public SlotBase { public: MemberSlot() {} MemberSlot(void (FunctionClass::*func)(void), FunctionClass &instance) : object(&instance), member_function(func) {} void execute() { (*object.*member_function)(); } FunctionClass *object; void (FunctionClass::*member_function)(void); private: }; template <> class GlobalSlot : public SlotBase { public: GlobalSlot() : global_function(NULL) {} GlobalSlot(void (*func)(void)) : global_function(func) {} void execute() { if ( global_function != NULL ) { (*global_function)(); } } void (*global_function)(void); }; } // namespace sigslots } // namespace lite } // namespace ecl #endif /* ECL_SIGSLOTS_LITE_SLOT_HPP_ */