slot.hpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Ifdefs
00010 *****************************************************************************/
00011 
00012 #ifndef ECL_SIGSLOTS_LITE_SLOT_HPP_
00013 #define ECL_SIGSLOTS_LITE_SLOT_HPP_
00014 
00015 /*****************************************************************************
00016 ** Includes
00017 *****************************************************************************/
00018 
00019 #include <cstddef> // defines NULL
00020 
00021 /*****************************************************************************
00022 ** Namespaces
00023 *****************************************************************************/
00024 
00025 namespace ecl {
00026 namespace lite {
00027 
00028 /*****************************************************************************
00029 ** Slots
00030 *****************************************************************************/
00031 
00032 namespace sigslots {
00040 template <typename Data>
00041 class SlotBase {
00042 public:
00043         virtual void execute(Data data) = 0;
00044 };
00051 template <typename Data, typename FunctionClass>
00052 class MemberSlot : public SlotBase<Data> {
00053 public:
00054         MemberSlot() {}
00055         MemberSlot(void (FunctionClass::*func)(Data), FunctionClass &instance) :
00056                 object(&instance),
00057                 member_function(func)
00058         {}
00059 
00060         void execute(Data data) {
00061                 (*object.*member_function)(data);
00062         }
00063         FunctionClass *object;
00064         void (FunctionClass::*member_function)(Data);
00065 private:
00066 };
00067 
00068 
00074 template <typename Data>
00075 class GlobalSlot : public SlotBase<Data> {
00076 public:
00077         GlobalSlot() : global_function(NULL) {}
00078         GlobalSlot(void (*func)(Data)) : global_function(func) {}
00079 
00080         void execute(Data data) {
00081                 if ( global_function != NULL ) {
00082                         (*global_function)(data);
00083                 }
00084         }
00085         void (*global_function)(Data); 
00086 };
00087 
00088 /*****************************************************************************
00089 ** Slot Specialisations
00090 *****************************************************************************/
00091 
00097 template <>
00098 class SlotBase<void> {
00099 public:
00100         virtual void execute() = 0;
00101 };
00102 
00109 template <typename FunctionClass>
00110 class MemberSlot<void,FunctionClass> : public SlotBase<void> {
00111 public:
00112         MemberSlot() {}
00113         MemberSlot(void (FunctionClass::*func)(void), FunctionClass &instance) :
00114                 object(&instance),
00115                 member_function(func)
00116         {}
00117 
00118         void execute() {
00119                 (*object.*member_function)();
00120         }
00121         FunctionClass *object;
00122         void (FunctionClass::*member_function)(void);
00123 private:
00124 };
00125 
00131 template <>
00132 class GlobalSlot<void> : public SlotBase<void> {
00133 public:
00134         GlobalSlot() : global_function(NULL) {}
00135         GlobalSlot(void (*func)(void)) : global_function(func) {}
00136 
00137         void execute() {
00138                 if ( global_function != NULL ) {
00139                         (*global_function)();
00140                 }
00141         }
00142         void (*global_function)(void); 
00143 };
00144 
00145 } // namespace sigslots
00146 } // namespace lite
00147 } // namespace ecl
00148 
00149 #endif /* ECL_SIGSLOTS_LITE_SLOT_HPP_ */


ecl_sigslots_lite
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 18:53:25