rad 6.2.0
Loading...
Searching...
No Matches
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
20namespace rad {
21
25class 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
40template <typename EVENT>
42 if (c == nullptr) {
43 throw rad::Exception("SCXML4CPP Context is NULL.");
44 }
45
46 SMEvent* e = dynamic_cast<SMEvent*>(c->getLastEvent());
47 if (e == nullptr) {
48 throw rad::Exception("Last event in SCXML4CPP context is NULL.");
49 }
50
51 EVENT* ev = static_cast<EVENT*>(e->getPayload());
52 if (ev == nullptr) {
53 throw rad::Exception("Cannot cast from SCXML4CPP last event to specific EVENT type.");
54 }
55
56 return *ev;
57}
58
60
61template <typename EVENT>
62typename EVENT::payload_t& GetLastEventPayload(scxml4cpp::Context* c) {
63 const EVENT& ev = GetLastEvent<EVENT>(c);
64 if (typeid(ev) != typeid(EVENT)) {
65 throw IncorrectEventType("Wrong event type");
66 }
67 return static_cast<EVENT&>(ev).GetPayload();
68}
69
70template <typename EVENT>
71typename EVENT::payload_t const* GetLastEventPayloadNothrow(scxml4cpp::Context* c) {
72 if (c == nullptr) {
73 return nullptr;
74 }
75 if (c->getLastEvent() == nullptr) {
76 return nullptr;
77 }
78 SMEvent* e = dynamic_cast<SMEvent*>(c->getLastEvent());
79 if (e == nullptr) {
80 return nullptr;
81 }
82 return rad::GetPayloadNothrow<EVENT>(e->GetEv());
83}
84
85} // namespace rad
86
87#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:23
const EVENT & GetLastEvent(scxml4cpp::Context *c)
Definition smEvent.hpp:41
std::unique_ptr< AnyEvent > UniqueEvent
Definition anyEvent.hpp:45
EVENT::payload_t const * GetLastEventPayloadNothrow(scxml4cpp::Context *c)
Definition smEvent.hpp:71
EVENT::payload_t & GetLastEventPayload(scxml4cpp::Context *c)
Definition smEvent.hpp:62
const rad::AnyEvent & GetLastAnyEvent(scxml4cpp::Context *c)
Definition smEvent.cpp:69
EVENT::payload_t & GetPayload(AnyEvent &ev)
Definition getPayload.hpp:29
Definition anyEvent.hpp:19