.. _program_listing_file__tmp_ws_src_ecl_core_ecl_sigslots_include_ecl_sigslots_slot.hpp: Program Listing for File slot.hpp ================================= |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/ecl_core/ecl_sigslots/include/ecl/sigslots/slot.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /***************************************************************************** ** Ifdefs *****************************************************************************/ #ifndef ECL_SIGSLOTS_SLOT_HPP_ #define ECL_SIGSLOTS_SLOT_HPP_ /***************************************************************************** ** Includes *****************************************************************************/ #include "sigslot.hpp" #include #include /***************************************************************************** ** Namespaces *****************************************************************************/ namespace ecl { /***************************************************************************** ** Interface [General] *****************************************************************************/ template class ECL_PUBLIC Slot { public: Slot(void (*f)(Data)) : sigslot(NULL) { sigslot = new SigSlot(f); } Slot(void (*f)(Data), const std::string &topic) : sigslot(NULL) { sigslot = new SigSlot(f); connect(topic); } template Slot(void (C::*f)(Data), C &c) : sigslot(NULL) { sigslot = new SigSlot(f,c); } template Slot(void (C::*f)(Data), C &c, const std::string& topic) : sigslot(NULL) { sigslot = new SigSlot(f,c); connect(topic); } Slot(const Slot& slot) { *this = slot; sigslot->incrHandles(); } ~Slot() { sigslot->decrHandles(); if ( sigslot->handles() == 0 ) { delete sigslot; } } void operator=( const Slot& slot) { sigslot = slot.sigslot; } const std::set& connections() { return sigslot->subscribedTopics(); } void connect(const std::string& topic) { sigslot->connectSlot(topic); } void disconnect() { sigslot->disconnect(); } private: SigSlot* sigslot; }; /***************************************************************************** ** Interface [Void] *****************************************************************************/ template<> class ECL_PUBLIC Slot { public: Slot(VoidFunction f) : sigslot(NULL) { sigslot = new SigSlot(f); } Slot(VoidFunction f, const std::string &topic) : sigslot(NULL) { sigslot = new SigSlot(f); connect(topic); } template Slot(void (C::*f)(void), C &c) : sigslot(NULL) { sigslot = new SigSlot(f,c); } template Slot(void (C::*f)(void), C &c, const std::string &topic) : sigslot(NULL) { sigslot = new SigSlot(f,c); connect(topic); } Slot(const Slot& slot) { *this = slot; sigslot->incrHandles(); } ~Slot() { sigslot->decrHandles(); if ( sigslot->handles() == 0 ) { delete sigslot; } } void operator=( const Slot& slot) { sigslot = slot.sigslot; } void connect(const std::string& topic) { sigslot->connectSlot(topic); } void disconnect() { sigslot->disconnect(); } private: SigSlot* sigslot; // unused: // unsigned int copies() { return sigslot->handles(); } }; } // namespace ecl #endif /* ECL_SIGSLOTS_SLOT_HPP_ */