CMS 3D CMS Logo

Signal.h
Go to the documentation of this file.
1 #ifndef FWCore_ServiceRegistry_Signal_h
2 #define FWCore_ServiceRegistry_Signal_h
3 // -*- C++ -*-
4 //
5 // Package: ServiceRegistry
6 // Class : Signal
7 //
19 //
20 // Original Author: Chris Jones
21 // Created: Thu Jan 17 16:03:51 CST 2013
22 //
23 
24 // system include files
25 #include <vector>
26 #include <functional>
27 
28 // user include files
29 
30 // forward declarations
31 
32 namespace edm {
33  namespace signalslot {
34  template <typename T>
35  class Signal
36  {
37 
38  public:
39  typedef std::function<T> slot_type;
40  typedef std::vector<slot_type> slot_list_type;
41 
42  Signal() = default;
43  ~Signal() = default;
44  Signal(Signal&&) = default;
45 
46  // ---------- const member functions ---------------------
47  template<typename... Args>
48  void emit(Args&&... args) const {
49  for(auto& slot:m_slots) {
50  slot(std::forward<Args>(args)...);
51  }
52  }
53 
54  template<typename... Args>
55  void operator()(Args&&... args) const {
56  emit(std::forward<Args>(args)...);
57  }
58 
59  slot_list_type const& slots() const {return m_slots;}
60  // ---------- static member functions --------------------
61 
62  // ---------- member functions ---------------------------
63  template<typename U>
64  void connect(U iFunc) {
65  m_slots.push_back(std::function<T>(iFunc));
66  }
67 
68  template<typename U>
69  void connect_front(U iFunc) {
70  m_slots.insert(m_slots.begin(),std::function<T>(iFunc));
71  }
72 
73  private:
74  Signal(const Signal&) = delete; // stop default
75 
76  const Signal& operator=(const Signal&) = delete; // stop default
77 
78  // ---------- member data --------------------------------
79  slot_list_type m_slots;
80 
81  };
82  }
83 }
84 
85 #endif
void connect_front(U iFunc)
Definition: Signal.h:69
void operator()(Args &&...args) const
Definition: Signal.h:55
slot_list_type const & slots() const
Definition: Signal.h:59
std::vector< slot_type > slot_list_type
Definition: Signal.h:40
const Signal & operator=(const Signal &)=delete
std::function< T > slot_type
Definition: Signal.h:39
slot_list_type m_slots
Definition: Signal.h:79
HLT enums.
void connect(U iFunc)
Definition: Signal.h:64
void emit(Args &&...args) const
Definition: Signal.h:48
Definition: vlib.h:39