Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 23:31:22

0001 #ifndef SimG4Core_Notification_Signaler_h
0002 #define SimG4Core_Notification_Signaler_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Notification
0006 // Class  :     Signaler
0007 //
0008 /**\class Signaler Signaler.h SimG4Core/Notification/interface/Signaler.h
0009 
0010  Description: Manages a particular signal of the SimActivityRegistry
0011 
0012  Usage:
0013     This is an internal detail of how the SimActivityRegistry does its job.
0014 
0015     Having Signaler inherit frmo Observer<const T*> allows one Signaler to forward its signal
0016     to another Signaler.
0017 
0018     All connected Observers are required to have a lifetime greater than the Signaler to which they are 
0019     attached.
0020 */
0021 //
0022 // Original Author:
0023 //         Created:  Sat Dec  1 10:17:20 EST 2007
0024 //
0025 
0026 // system include files
0027 #include <vector>
0028 
0029 // user include files
0030 #include "SimG4Core/Notification/interface/Observer.h"
0031 
0032 // forward declarations
0033 
0034 namespace sim_act {
0035   template <typename T>
0036   class Signaler : public Observer<const T*> {
0037   public:
0038     typedef Observer<const T*>* slot_type;
0039     Signaler() {}
0040     ~Signaler() override {}
0041 
0042     // ---------- const member functions ---------------------
0043     void operator()(const T* iSignal) const {
0044       typedef typename std::vector<Observer<const T*>*>::const_iterator iterator;
0045       for (iterator it = observers_.begin(); it != observers_.end(); ++it) {
0046         (*it)->slotForUpdate(iSignal);
0047       }
0048     }
0049 
0050     // ---------- static member functions --------------------
0051 
0052     // ---------- member functions ---------------------------
0053 
0054     ///does not take ownership of memory
0055     void connect(Observer<const T*>* iObs) { observers_.push_back(iObs); }
0056 
0057     ///does not take ownership of memory
0058     void connect(Observer<const T*>& iObs) { observers_.push_back(&iObs); }
0059 
0060     Signaler(const Signaler&) = delete;                   // stop default
0061     const Signaler& operator=(const Signaler&) = delete;  // stop default
0062 
0063   private:
0064     void update(const T* iData) override { this->operator()(iData); }
0065     // ---------- member data --------------------------------
0066     std::vector<Observer<const T*>*> observers_;
0067   };
0068 
0069 }  // namespace sim_act
0070 #endif