test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
45  // ---------- const member functions ---------------------
46  template<typename... Args>
47  void emit(Args&&... args) const {
48  for(auto& slot:m_slots) {
49  slot(std::forward<Args>(args)...);
50  }
51  }
52 
53  template<typename... Args>
54  void operator()(Args&&... args) const {
55  emit(std::forward<Args>(args)...);
56  }
57 
58  slot_list_type const& slots() const {return m_slots;}
59  // ---------- static member functions --------------------
60 
61  // ---------- member functions ---------------------------
62  template<typename U>
63  void connect(U iFunc) {
64  m_slots.push_back(std::function<T>(iFunc));
65  }
66 
67  template<typename U>
68  void connect_front(U iFunc) {
69  m_slots.insert(m_slots.begin(),std::function<T>(iFunc));
70  }
71 
72  private:
73  Signal(const Signal&) = delete; // stop default
74 
75  const Signal& operator=(const Signal&) = delete; // stop default
76 
77  // ---------- member data --------------------------------
79 
80  };
81  }
82 }
83 
84 #endif
void connect_front(U iFunc)
Definition: Signal.h:68
void operator()(Args &&...args) const
Definition: Signal.h:54
slot_list_type const & slots() const
Definition: Signal.h:58
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:78
void connect(U iFunc)
Definition: Signal.h:63
void emit(Args &&...args) const
Definition: Signal.h:47
Definition: vlib.h:39