rad  5.1.0
smEvent.hpp
Go to the documentation of this file.
1 
10 #ifndef RAD_SM_EVENT_HPP
11 #define RAD_SM_EVENT_HPP
12 
13 #include <rad/anyEvent.hpp>
14 #include <rad/exceptions.hpp>
15 #include <rad/getPayload.hpp>
16 
17 #include <scxml4cpp/Context.h>
18 #include <scxml4cpp/Event.h>
19 
20 namespace rad {
21 
25 class SMEvent : public scxml4cpp::Event {
26  public:
27  SMEvent();
28  explicit SMEvent(const AnyEvent& ev);
29  SMEvent(const SMEvent& e);
30  virtual ~SMEvent();
31  SMEvent& operator=(const SMEvent& e);
32 
33  AnyEvent const& GetEv() const;
34  void SetEv(AnyEvent const& ev);
35 
36  private:
37  UniqueEvent m_ev;
38 };
39 
40 template <typename EVENT>
41 const EVENT& GetLastEvent(scxml4cpp::Context* c) {
42  if (c == nullptr) {
43  throw rad::Exception("SCXML4CPP Context is NULL.");
44  }
45  SMEvent* e = dynamic_cast<SMEvent*>(c->getLastEvent());
46  if (e == nullptr) {
47  throw rad::Exception("SCXML4CPP Context is NULL.");
48  }
49  return static_cast<const EVENT&>(*e->getPayload());
50 }
51 
53 
54 template <typename EVENT>
55 typename EVENT::payload_t& GetLastEventPayload(scxml4cpp::Context* c) {
56  const EVENT& ev = GetLastEvent<EVENT>(c);
57  if (typeid(ev) != typeid(EVENT)) {
58  throw IncorrectEventType("Wrong event type");
59  }
60  return static_cast<EVENT&>(ev).GetPayload();
61 }
62 
63 template <typename EVENT>
64 typename EVENT::payload_t const* GetLastEventPayloadNothrow(scxml4cpp::Context* c) {
65  if (c == nullptr) {
66  return nullptr;
67  }
68  if (c->getLastEvent() == nullptr) {
69  return nullptr;
70  }
71  SMEvent* e = dynamic_cast<SMEvent*>(c->getLastEvent());
72  if (e == nullptr) {
73  return nullptr;
74  }
75  return rad::GetPayloadNothrow<EVENT>(e->GetEv());
76 }
77 
78 } // namespace rad
79 
80 #endif // RAD_SM_EVENT_HPP
Context header.
Event header.
AnyEvent class header file.
Definition: anyEvent.hpp:52
Base class for the exceptions thrown by RAD and its users.
Definition: exceptions.hpp:53
Definition: smEvent.hpp:25
SMEvent()
Definition: smEvent.cpp:17
virtual ~SMEvent()
Definition: smEvent.cpp:38
SMEvent & operator=(const SMEvent &e)
Definition: smEvent.cpp:46
void SetEv(AnyEvent const &ev)
Definition: smEvent.cpp:62
AnyEvent const & GetEv() const
Definition: smEvent.cpp:57
Definition: Context.h:58
Event * getLastEvent() const
Definition: Context.cpp:80
Definition: Event.h:66
void * getPayload() const
Definition: Event.cpp:106
Exception classes header file.
getPayload functions source file.
Definition: actionsApp.cpp:20
EVENT::payload_t & GetLastEventPayload(scxml4cpp::Context *c)
Definition: smEvent.hpp:55
EVENT::payload_t const * GetLastEventPayloadNothrow(scxml4cpp::Context *c)
Definition: smEvent.hpp:64
EVENT::payload_t & GetPayload(AnyEvent &ev)
Definition: getPayload.hpp:29
std::unique_ptr< AnyEvent > UniqueEvent
Definition: anyEvent.hpp:45
const EVENT & GetLastEvent(scxml4cpp::Context *c)
Definition: smEvent.hpp:41
const rad::AnyEvent & GetLastAnyEvent(scxml4cpp::Context *c)
Definition: smEvent.cpp:69
Definition: anyEvent.hpp:19