CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/SimG4Core/Notification/interface/Signaler.h

Go to the documentation of this file.
00001 #ifndef SimG4Core_Notification_Signaler_h
00002 #define SimG4Core_Notification_Signaler_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     Notification
00006 // Class  :     Signaler
00007 // 
00021 //
00022 // Original Author:  
00023 //         Created:  Sat Dec  1 10:17:20 EST 2007
00024 // $Id: Signaler.h,v 1.1 2007/12/02 05:17:47 chrjones Exp $
00025 //
00026 
00027 // system include files
00028 #include <vector>
00029 
00030 // user include files
00031 #include "SimG4Core/Notification/interface/Observer.h"
00032 
00033 // forward declarations
00034 
00035 namespace sim_act {
00036    template <typename T>
00037    class Signaler : public Observer<const T*>
00038    {
00039          
00040       public:
00041          typedef Observer<const T*>* slot_type; 
00042          Signaler() {}
00043          virtual ~Signaler() {}
00044          
00045          // ---------- const member functions ---------------------
00046          void operator()(const T* iSignal) const {
00047             typedef typename std::vector<Observer<const T*>* >::const_iterator iterator; 
00048             for( iterator it = observers_.begin();
00049                 it != observers_.end();
00050                 ++it) {
00051                (*it)->slotForUpdate(iSignal);
00052             }
00053          }
00054 
00055          // ---------- static member functions --------------------
00056          
00057          // ---------- member functions ---------------------------
00058 
00060          void connect(Observer<const T*>* iObs) {
00061             observers_.push_back(iObs);
00062          }
00063 
00065          void connect(Observer<const T*>& iObs) {
00066             observers_.push_back(&iObs);
00067          }
00068 
00069       private:
00070          Signaler(const Signaler&); // stop default
00071          
00072          const Signaler& operator=(const Signaler&); // stop default
00073          
00074          void update(const T* iData) {
00075             this->operator()(iData);
00076          }
00077          // ---------- member data --------------------------------
00078          std::vector<Observer<const T*>* > observers_;
00079    };
00080    
00081 }
00082 #endif