signal.hpp
Go to the documentation of this file.
00001 
00010 /*****************************************************************************
00011 ** Ifdefs
00012 *****************************************************************************/
00013 
00014 #ifndef ECL_SIGSLOTS_SIGNAL_HPP_
00015 #define ECL_SIGSLOTS_SIGNAL_HPP_
00016 
00017 /*****************************************************************************
00018 ** Includes
00019 *****************************************************************************/
00020 
00021 #include "sigslot.hpp"
00022 #include <ecl/utilities/void.hpp>
00023 #include <ecl/config/macros.hpp>
00024 
00025 /*****************************************************************************
00026 ** Namespaces
00027 *****************************************************************************/
00028 
00029 namespace ecl {
00030 
00031 /*****************************************************************************
00032 ** Interface [General]
00033 *****************************************************************************/
00046 template <typename Data=Void>
00047 class ECL_PUBLIC Signal {
00048 public:
00055         Signal() : sigslot(NULL) {
00056                 sigslot = new SigSlot<Data>();
00057         }
00061         Signal(const std::string &topic) : sigslot(NULL) {
00062                 sigslot = new SigSlot<Data>();
00063                 connect(topic);
00064         }
00065 
00077         Signal(const Signal& signal) {
00078                 *this = signal;
00079                 sigslot->incrHandles();
00080         }
00081 
00089         ~Signal() {
00090                 sigslot->decrHandles();
00091                 if ( sigslot->handles() == 0 ) {
00092                         delete sigslot;
00093                 }
00094         }
00095 
00104         void connect(const std::string& topic) { sigslot->connectSignal(topic); }
00113         void connectAsSlot(const std::string& topic) { sigslot->connectSlot(topic); }
00119         void disconnect() { sigslot->disconnect(); }
00120 
00128         void emit(Data data) { sigslot->emit(data); }
00129 
00130 private:
00131         SigSlot<Data>* sigslot;
00132 };
00133 
00134 /*****************************************************************************
00135 ** Interface [Void]
00136 *****************************************************************************/
00148 template<>
00149 class ECL_PUBLIC Signal<Void> {
00150 public:
00157         Signal() : sigslot(NULL) {
00158                 sigslot = new SigSlot<Void>();
00159         }
00163         Signal(const std::string &topic) : sigslot(NULL) {
00164                 sigslot = new SigSlot<Void>();
00165                 connect(topic);
00166         }
00178         Signal(const Signal& signal) {
00179                 *this = signal;
00180                 sigslot->incrHandles();
00181         }
00189         ~Signal() {
00190                 sigslot->decrHandles();
00191                 if ( sigslot->handles() == 0 ) {
00192                         delete sigslot;
00193                 }
00194         }
00203         void connect(const std::string& topic) { sigslot->connectSignal(topic); }
00212         void connectAsSlot(const std::string& topic) { sigslot->connectSlot(topic); }
00218         void disconnect() { sigslot->disconnect(); }
00219 
00225         void emit() { sigslot->emit(); }
00226 
00227 private:
00228         SigSlot<Void>* sigslot;
00229 
00230 };
00231 
00232 } // namespace ecl
00233 
00234 #endif /* ECL_SIGSLOTS_SIGNAL_HPP_ */


ecl_sigslots
Author(s): Daniel Stonier
autogenerated on Wed Aug 26 2015 11:27:23