$search
00001 00008 /***************************************************************************** 00009 ** Ifdefs 00010 *****************************************************************************/ 00011 00012 #ifndef ECL_SIGSLOTS_LITE_CONNECT_HPP_ 00013 #define ECL_SIGSLOTS_LITE_CONNECT_HPP_ 00014 00015 /***************************************************************************** 00016 ** Includes 00017 *****************************************************************************/ 00018 00019 #include "slot.hpp" 00020 #include "signal.hpp" 00021 #include "errors.hpp" 00022 00023 /***************************************************************************** 00024 ** Namespaces 00025 *****************************************************************************/ 00026 00027 namespace ecl { 00028 namespace lite { 00029 00030 /***************************************************************************** 00031 ** Privately Used Connects 00032 *****************************************************************************/ 00033 00034 namespace sigslots { 00046 template <typename Data, unsigned int Capacity, typename FunctionClass> 00047 ecl::lite::sigslots::Error connect(ecl::lite::Signal<Data, Capacity> &signal, MemberSlot<Data,FunctionClass> &slot) { 00048 return signal.connect(slot); 00049 } 00050 00062 template <typename Data, unsigned int Capacity> 00063 ecl::lite::sigslots::Error connect(ecl::lite::Signal<Data, Capacity> &signal, GlobalSlot<Data> &slot) { 00064 return signal.connect(slot); 00065 } 00066 00067 } // namespace sigslots 00068 00069 /***************************************************************************** 00070 ** Publicly Used Connects 00071 *****************************************************************************/ 00072 00088 template <typename Data, unsigned int Capacity, typename FunctionClass> 00089 sigslots::Error connect(Signal<Data,Capacity> &signal, void(FunctionClass::*f)(Data), FunctionClass &o) { 00090 // Need to do this just in case o has member slot interfaces for multiple Data types. 00091 // If we don't it can't resolve the footprint that seems to get lost when passing 00092 // the function pointers down the line - another way to resolve maybe? 00093 sigslots::MemberSlotsBase<Data,FunctionClass> &member_slots = o; 00094 sigslots::MemberSlot<Data,FunctionClass> *slot = member_slots.addSlot(f,o); 00095 if ( slot != NULL ) { 00096 return sigslots::connect(signal,*slot); // koenig lookup also works 00097 } else { 00098 return sigslots::Error(sigslots::OutOfResourcesError); 00099 } 00100 } 00115 template <typename Data, unsigned int Capacity> 00116 sigslots::Error connect(Signal<Data, Capacity> &signal, void (*function)(Data)) { 00117 sigslots::GlobalSlot<Data> *slot = GlobalSlots<Data>::addSlot(function); 00118 if ( slot != NULL ) { 00119 return sigslots::connect(signal,*slot); 00120 } else { 00121 return sigslots::Error(sigslots::OutOfResourcesError); 00122 } 00123 00124 } 00125 00126 /***************************************************************************** 00127 ** Publicly Used Connect Overloads 00128 *****************************************************************************/ 00129 00140 template <unsigned int Capacity, typename FunctionClass> 00141 sigslots::Error connect(Signal<void, Capacity> &signal, void(FunctionClass::*function)(void), FunctionClass &o) { 00142 // Need to do this just in case o has member slot interfaces for multiple Data types. 00143 // If we don't it can't resolve the footprint that seems to get lost when passing 00144 // the function pointers down the line - another way to resolve maybe? 00145 sigslots::MemberSlotsBase<void,FunctionClass> &member_slots = o; 00146 sigslots::MemberSlot<void,FunctionClass> *slot = member_slots.addSlot(function,o); 00147 if ( slot != NULL ) { 00148 return sigslots::connect(signal,*slot); // koenig lookup also works 00149 } else { 00150 return sigslots::Error(sigslots::OutOfResourcesError); 00151 } 00152 } 00162 template <unsigned int Capacity> 00163 sigslots::Error connect(Signal<void, Capacity> &signal, void (*function)(void)) { 00164 sigslots::GlobalSlot<void> *slot = GlobalSlots<void>::addSlot(function); 00165 if ( slot != NULL ) { 00166 return sigslots::connect(signal,*slot); 00167 } else { 00168 return sigslots::Error(sigslots::OutOfResourcesError); 00169 } 00170 00171 } 00172 00173 } // namespace lite 00174 } // namespace ecl 00175 00176 #endif /* ECL_SIGSLOTS_LITE_CONNECT_HPP_ */