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 <exception>
26 #include <vector>
27 #include <functional>
28 
29 // user include files
31 
32 // forward declarations
33 
34 namespace edm {
35  namespace signalslot {
36  template <typename T>
37  class Signal {
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  Signal(const Signal&) = delete;
46  Signal& operator=(const Signal&) = delete;
47 
48  // ---------- const member functions ---------------------
49  template <typename... Args>
50  void emit(Args&&... args) const {
51  std::exception_ptr exceptionPtr;
52  for (auto& slot : m_slots) {
53  CMS_SA_ALLOW try { slot(std::forward<Args>(args)...); } catch (...) {
54  if (!exceptionPtr) {
55  exceptionPtr = std::current_exception();
56  }
57  }
58  }
59  if (exceptionPtr) {
60  std::rethrow_exception(exceptionPtr);
61  }
62  }
63 
64  template <typename... Args>
65  void operator()(Args&&... args) const {
66  emit(std::forward<Args>(args)...);
67  }
68 
69  slot_list_type const& slots() const { return m_slots; }
70  // ---------- static member functions --------------------
71 
72  // ---------- member functions ---------------------------
73  template <typename U>
74  void connect(U iFunc) {
75  m_slots.push_back(std::function<T>(iFunc));
76  }
77 
78  template <typename U>
79  void connect_front(U iFunc) {
80  m_slots.insert(m_slots.begin(), std::function<T>(iFunc));
81  }
82 
83  private:
84  // ---------- member data --------------------------------
86  };
87  } // namespace signalslot
88 } // namespace edm
89 
90 #endif
#define CMS_SA_ALLOW
void operator()(Args &&... args) const
Definition: Signal.h:65
void connect_front(U iFunc)
Definition: Signal.h:79
slot_list_type const & slots() const
Definition: Signal.h:69
std::vector< slot_type > slot_list_type
Definition: Signal.h:40
void emit(Args &&... args) const
Definition: Signal.h:50
std::function< T > slot_type
Definition: Signal.h:39
slot_list_type m_slots
Definition: Signal.h:85
HLT enums.
Signal & operator=(const Signal &)=delete
void connect(U iFunc)
Definition: Signal.h:74