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 // $Id: Signal.h,v 1.1 2013/01/20 16:56:21 chrjones Exp $
23 //
24 
25 // system include files
26 #include <vector>
27 #include <functional>
28 
29 // user include files
30 
31 // forward declarations
32 
33 namespace edm {
34  namespace signalslot {
35  template <typename T>
36  class Signal
37  {
38 
39  public:
40  typedef std::function<T> slot_type;
41  typedef std::vector<slot_type> slot_list_type;
42 
43  Signal() = default;
44  ~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 --------------------------------
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:41
const Signal & operator=(const Signal &)=delete
std::function< T > slot_type
Definition: Signal.h:40
slot_list_type m_slots
Definition: Signal.h:79
dictionary args
void connect(U iFunc)
Definition: Signal.h:64
void emit(Args &&...args) const
Definition: Signal.h:48