SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
Event.h
Go to the documentation of this file.
1 /**
2  * \file Event.h
3  * \brief Event class used in the state machine
4  * \authors Michael Göttlicher
5  * \copyright http://opensource.org/licenses/GPL-3.0
6  * \remarks Please use clangformat to format the code. See more code style on
7  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
8  */
9 
10 #ifndef SM_EVENT_H
11 #define SM_EVENT_H
12 
13 #include <map>
14 #include <string>
15 #include <sm/EventData.h>
16 
17 /**
18  * @brief Collection of classes for a state machine implementation used in the Erleb-AR app.
19  * @author Micheal Göttlicher
20  * \copyright http://opensource.org/licenses/GPL-3.0
21  * \remarks Please use clangformat to format the code. See more code style on
22  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
23  */
24 namespace sm
25 {
26 
27 //-----------------------------------------------------------------------------
28 /**
29  * @brief Event class used in the state machine
30  */
31 class Event
32 {
33 public:
34  enum
35  {
36  EVENT_IGNORED = 0xFE,
37  };
38 
39  Event(std::string name, std::string senderInfo)
40  : _name(name),
42  {
43  }
44 
45  virtual ~Event(){};
46 
47  // enables a transition from one state to the other
48  void enableTransition(unsigned int from, unsigned int to)
49  {
50  _transitions[from] = to;
51  }
52 
53  //! Check if there is a transition to a new state. The current state is used to lookup the new state.
54  unsigned int getNewState(unsigned int currentState)
55  {
56  auto it = _transitions.find(currentState);
57  if (it != _transitions.end())
58  {
59  return it->second;
60  }
61  else
62  {
63  return EVENT_IGNORED;
64  }
65  }
66  /**
67  * @brief Get event data that was possibly send with this event.
68  * If the function returns nullptr, it contains no data.
69  *
70  * @return EventData*
71  */
73  {
74  return _eventData;
75  }
76 
77  const char* name() const { return _name.c_str(); }
78  const char* senderInfo() const { return _senderInfo.c_str(); }
79 
80 protected:
81  EventData* _eventData = nullptr;
82 
83 private:
84  std::map<unsigned int, unsigned int> _transitions;
85 
86  std::string _name;
87  std::string _senderInfo;
88 };
89 //-----------------------------------------------------------------------------
90 }
91 
92 #endif
Event class used in the state machine.
Event class used in the state machine.
Definition: Event.h:32
void enableTransition(unsigned int from, unsigned int to)
Definition: Event.h:48
Event(std::string name, std::string senderInfo)
Definition: Event.h:39
virtual ~Event()
Definition: Event.h:45
std::string _senderInfo
Definition: Event.h:87
EventData * getEventData()
Get event data that was possibly send with this event. If the function returns nullptr,...
Definition: Event.h:72
std::map< unsigned int, unsigned int > _transitions
Definition: Event.h:84
const char * name() const
Definition: Event.h:77
const char * senderInfo() const
Definition: Event.h:78
std::string _name
Definition: Event.h:86
unsigned int getNewState(unsigned int currentState)
Check if there is a transition to a new state. The current state is used to lookup the new state.
Definition: Event.h:54
EventData * _eventData
Definition: Event.h:81
@ EVENT_IGNORED
Definition: Event.h:36
Collection of classes for a state machine implementation used in the Erleb-AR app.
Definition: Event.h:25