-
Notifications
You must be signed in to change notification settings - Fork 0
/
State.h
55 lines (43 loc) · 975 Bytes
/
State.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* @file State.h
* @author Jan Wielgus
* @brief Base class for all concrete states.
* @date 2021-01-26
*
*/
#ifndef STATE_H
#define STATE_H
class Context;
class State
{
protected:
Context* const context;
State(Context* _context)
: context(_context)
{
}
virtual ~State() {}
/**
* @brief Update current state and decide if remain in this one
* or change the state.
* Have to be overriden in derivative class.
* @return State* new dynamically allocated object or nullptr
* if this state should remain.
*/
virtual void updateState() = 0;
/**
* @brief Can be overriden. Called once
* before the first call of updateState() method.
*/
virtual void entryEvent() {}
/**
* @brief Optional state name getter.
* Can be overriden in derivative class.
*/
virtual const char* stateName()
{
return "";
}
friend class Context;
};
#endif