CMS 3D CMS Logo

Signaler.h
Go to the documentation of this file.
1 #ifndef SimG4Core_Notification_Signaler_h
2 #define SimG4Core_Notification_Signaler_h
3 // -*- C++ -*-
4 //
5 // Package: Notification
6 // Class : Signaler
7 //
21 //
22 // Original Author:
23 // Created: Sat Dec 1 10:17:20 EST 2007
24 //
25 
26 // system include files
27 #include <vector>
28 
29 // user include files
31 
32 // forward declarations
33 
34 namespace sim_act {
35  template <typename T>
36  class Signaler : public Observer<const T*> {
37  public:
39  Signaler() {}
40  ~Signaler() override {}
41 
42  // ---------- const member functions ---------------------
43  void operator()(const T* iSignal) const {
44  typedef typename std::vector<Observer<const T*>*>::const_iterator iterator;
45  for (iterator it = observers_.begin(); it != observers_.end(); ++it) {
46  (*it)->slotForUpdate(iSignal);
47  }
48  }
49 
50  // ---------- static member functions --------------------
51 
52  // ---------- member functions ---------------------------
53 
55  void connect(Observer<const T*>* iObs) { observers_.push_back(iObs); }
56 
58  void connect(Observer<const T*>& iObs) { observers_.push_back(&iObs); }
59 
60  private:
61  Signaler(const Signaler&) = delete; // stop default
62 
63  const Signaler& operator=(const Signaler&) = delete; // stop default
64 
65  void update(const T* iData) override { this->operator()(iData); }
66  // ---------- member data --------------------------------
67  std::vector<Observer<const T*>*> observers_;
68  };
69 
70 } // namespace sim_act
71 #endif
Observer
Definition: Observer.h:23
sim_act::Signaler::operator()
void operator()(const T *iSignal) const
Definition: Signaler.h:43
Observer.h
sim_act::Signaler::~Signaler
~Signaler() override
Definition: Signaler.h:40
sim_act::Signaler
Definition: Signaler.h:36
sim_act::Signaler::connect
void connect(Observer< const T * > *iObs)
does not take ownership of memory
Definition: Signaler.h:55
sim_act::Signaler::connect
void connect(Observer< const T * > &iObs)
does not take ownership of memory
Definition: Signaler.h:58
sim_act::Signaler::update
void update(const T *iData) override
This routine will be called when the appropriate signal arrives.
Definition: Signaler.h:65
sim_act::Signaler::operator=
const Signaler & operator=(const Signaler &)=delete
sim_act::Signaler::observers_
std::vector< Observer< const T * > * > observers_
Definition: Signaler.h:67
sim_act::Signaler::slot_type
Observer< const T * > * slot_type
Definition: Signaler.h:38
T
long double T
Definition: Basic3DVectorLD.h:48
sim_act
Definition: Signaler.h:34
sim_act::Signaler::Signaler
Signaler()
Definition: Signaler.h:39