slot.hpp
Go to the documentation of this file.
00001 
00010 /*****************************************************************************
00011 ** Ifdefs
00012 *****************************************************************************/
00013 
00014 #ifndef ECL_SIGSLOTS_SLOT_HPP_
00015 #define ECL_SIGSLOTS_SLOT_HPP_
00016 
00017 /*****************************************************************************
00018 ** Includes
00019 *****************************************************************************/
00020 
00021 #include "sigslot.hpp"
00022 #include <ecl/config/macros.hpp>
00023 #include <ecl/utilities/void.hpp>
00024 
00025 /*****************************************************************************
00026 ** Namespaces
00027 *****************************************************************************/
00028 
00029 namespace ecl {
00030 
00031 /*****************************************************************************
00032 ** Interface [General]
00033 *****************************************************************************/
00034 
00047 template <typename Data=Void>
00048 class ECL_PUBLIC Slot {
00049 public:
00058         Slot(void (*f)(Data)) : sigslot(NULL) {
00059                 sigslot = new SigSlot<Data>(f);
00060         }
00072         Slot(void (*f)(Data), const std::string &topic) : sigslot(NULL) {
00073                 sigslot = new SigSlot<Data>(f);
00074                 connect(topic);
00075         }
00076 
00086         template <typename C>
00087         Slot(void (C::*f)(Data), C &c) : sigslot(NULL) {
00088                 sigslot = new SigSlot<Data>(f,c);
00089         }
00102         template <typename C>
00103         Slot(void (C::*f)(Data), C &c, const std::string& topic) : sigslot(NULL) {
00104                 sigslot = new SigSlot<Data>(f,c);
00105                 connect(topic);
00106         }
00107 
00119         Slot(const Slot& slot) {
00120                 *this = slot;
00121                 sigslot->incrHandles();
00122         }
00123 
00131         ~Slot() {
00132                 sigslot->decrHandles();
00133                 if ( sigslot->handles() == 0 ) {
00134                         delete sigslot;
00135                 }
00136         }
00143         const std::set<std::string>& connections() { return sigslot->subscribedTopics(); }
00152         void connect(const std::string& topic) {        sigslot->connectSlot(topic); }
00158         void disconnect() { sigslot->disconnect(); }
00159 
00160 private:
00161         SigSlot<Data>* sigslot;
00162 };
00163 
00164 /*****************************************************************************
00165 ** Interface [Void]
00166 *****************************************************************************/
00176 template<>
00177 class ECL_PUBLIC Slot<Void> {
00178 public:
00187         Slot(VoidFunction f) : sigslot(NULL) {
00188                 sigslot = new SigSlot<Void>(f);
00189         }
00199         Slot(VoidFunction f, const std::string &topic) : sigslot(NULL) {
00200                 sigslot = new SigSlot<Void>(f);
00201                 connect(topic);
00202         }
00212         template <typename C>
00213         Slot(void (C::*f)(void), C &c) : sigslot(NULL) {
00214                 sigslot = new SigSlot<Void>(f,c);
00215         }
00226         template <typename C>
00227         Slot(void (C::*f)(void), C &c, const std::string &topic) : sigslot(NULL) {
00228                 sigslot = new SigSlot<Void>(f,c);
00229                 connect(topic);
00230         }
00242         Slot(const Slot& slot) {
00243                 *this = slot;
00244                 sigslot->incrHandles();
00245         }
00253         ~Slot() {
00254                 sigslot->decrHandles();
00255                 if ( sigslot->handles() == 0 ) {
00256                         delete sigslot;
00257                 }
00258         }
00267         void connect(const std::string& topic) {        sigslot->connectSlot(topic); }
00273         void disconnect() { sigslot->disconnect(); }
00274 
00275 private:
00276         SigSlot<Void>* sigslot;
00277 
00278 // unused:
00279 //        unsigned int copies() { return sigslot->handles(); }
00280 };
00281 
00282 } // namespace ecl
00283 
00284 #endif /* ECL_SIGSLOTS_SLOT_HPP_ */


ecl_sigslots
Author(s): Daniel Stonier
autogenerated on Mon Jul 3 2017 02:22:06