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  public:
37  typedef std::function<T> slot_type;
38  typedef std::vector<slot_type> slot_list_type;
39 
40  Signal() = default;
41  ~Signal() = default;
42  Signal(Signal&&) = default;
43 
44  // ---------- const member functions ---------------------
45  template <typename... Args>
46  void emit(Args&&... args) const {
47  for (auto& slot : m_slots) {
48  slot(std::forward<Args>(args)...);
49  }
50  }
51 
52  template <typename... Args>
53  void operator()(Args&&... args) const {
54  emit(std::forward<Args>(args)...);
55  }
56 
57  slot_list_type const& slots() const { return m_slots; }
58  // ---------- static member functions --------------------
59 
60  // ---------- member functions ---------------------------
61  template <typename U>
62  void connect(U iFunc) {
63  m_slots.push_back(std::function<T>(iFunc));
64  }
65 
66  template <typename U>
67  void connect_front(U iFunc) {
68  m_slots.insert(m_slots.begin(), std::function<T>(iFunc));
69  }
70 
71  private:
72  Signal(const Signal&) = delete; // stop default
73 
74  const Signal& operator=(const Signal&) = delete; // stop default
75 
76  // ---------- member data --------------------------------
77  slot_list_type m_slots;
78  };
79  } // namespace signalslot
80 } // namespace edm
81 
82 #endif
void connect_front(U iFunc)
Definition: Signal.h:67
void operator()(Args &&...args) const
Definition: Signal.h:53
slot_list_type const & slots() const
Definition: Signal.h:57
std::vector< slot_type > slot_list_type
Definition: Signal.h:38
const Signal & operator=(const Signal &)=delete
std::function< T > slot_type
Definition: Signal.h:37
slot_list_type m_slots
Definition: Signal.h:77
HLT enums.
void connect(U iFunc)
Definition: Signal.h:62
void emit(Args &&...args) const
Definition: Signal.h:46
Definition: vlib.h:28