ifw  0.0.1-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Event.hpp
Go to the documentation of this file.
1 
9 #ifndef RAD_EVENT_HPP_
10 #define RAD_EVENT_HPP_
11 #include <memory>
12 #include "rad/detail/Holder.hpp"
13 #include "rad/AnyEvent.hpp"
14 
15 namespace rad {
16 
20  template<typename EVENT,
21  typename = void>
22  class Event {
23  public:
24  char const* getId() const {
25  return EVENT::id;
26  }
27  };
28 
33  template<typename EVENT>
34  class Event<EVENT,
35  typename std::enable_if<!std::is_void<typename EVENT::payload_t>::value>::type> {
36  using payload_t = typename EVENT::payload_t;
37  public:
38 
39 
41 
42  Event(Event const& e) = default;
43  Event(Event& e) = default;
44  Event(Event&& e) = default;
45  Event& operator=(Event const& e) = default;
47 
51  template<class... Args>
52 // typename std::enable_if<!std::is_same<Event<EVENT>, Args...>::value>::type>
53  Event(Args&&... args):
54  m_ptr{new detail::HolderTImpl<EVENT>{std::forward<Args>(args)...}}
55  {
56  }
57 
58  char const* getId() const {
59  return EVENT::id;
60  }
61 
62  payload_t& getPayload() {
63  return static_cast<detail::HolderTImpl<EVENT>*>(m_ptr.get())->m_payload;
64  }
65 
66  payload_t const& getPayload() const {
67  return const_cast<Event<EVENT>*>(this)->getPayload();
68  }
69 
70  AnyEvent makeAny() {
71  // @todo: Move to a free function make_any(Event<EVENT>);
72  return AnyEvent(m_ptr);
73  }
74 
75  private:
76  // Use Holder to allow easy conversion to AnyEvent and vice-versa
77  std::shared_ptr<detail::Holder> m_ptr;
78  };
79 
80 }
81 #endif // #ifndef EVENT_EVENT_HPP_
EVENT::payload_t & getPayload(AnyEvent &ev)
Definition: GetPayload.hpp:29
string id
Definition: requests.proto:15
tuple Args
Definition: test_command.py:17
Definition: Event.hpp:22
Definition: AnyEvent.hpp:55
char const * getId() const
Definition: Event.hpp:24