-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStateAction.h
executable file
·192 lines (159 loc) · 4.2 KB
/
StateAction.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#pragma once
#include"RxFSM/IncludeExtLibs.h"
namespace Reactor
{
/**
* Do I need an interface for state machine contexts?
*/
template <typename Context>
class StateMachineContext
{
public:
StateMachineContext(std::shared_ptr<Context> context)
: context_(context)
{}
virtual ~StateMachineContext()
{}
const Context& context() const
{
return context_.context().operator *();
}
Context& context()
{
return context_.context().operator *();
}
private:
Templates::ContextDataShared<Context> context_;
};
//template<typename Return, typename T>
//class StateAction : public StrategyContextAction1<Return, T>
//{
//public:
// StateAction(ActionContextPtr context, typename Strategy1<Return, T>::Ptr action)
// : Templates::StrategyContextAction1<Return, T>(context, action, T())
// { }
//};
/**
* I want every action in a state machine to have access to a user defined context.
*/
template<typename Context, typename Return>
class StateMachineAction0
: public Templates::Action0<Return>
, public StateMachineContext<Context>
{
public:
StateMachineAction0(std::shared_ptr<Context> context) : StateMachineContext<Context>(context)
{ }
virtual ~StateMachineAction0()
{ }
CLASS_TRAITS(StateMachineAction0)
virtual void Entry()
{
this->context().Entry();
}
virtual void Exit()
{
this->context().Exit();
}
};
template<typename Context, typename Return, typename Arg1>
class StateMachineAction1
: public Templates::Action1<Return, Arg1>
, public StateMachineContext<Context>
{
public:
StateMachineAction1(std::shared_ptr<Context> context) : StateMachineContext<Context>(context)
{ }
virtual ~StateMachineAction1()
{ }
CLASS_TRAITS(StateMachineAction1)
virtual void Entry()
{
this->context().Entry();
}
virtual void Exit()
{
this->context().Exit();
}
};
template<typename Context, typename Return, typename Arg1, typename Arg2>
class StateMachineAction2
: public Templates::Action2<Return, Arg1, Arg2>
, public StateMachineContext<Context>
{
public:
StateMachineAction2(std::shared_ptr<Context> context) : StateMachineContext<Context>(context)
{ }
virtual ~StateMachineAction2()
{ }
CLASS_TRAITS(StateMachineAction2)
virtual void Entry()
{
this->context().Entry();
}
virtual void Exit()
{
this->context().Exit();
}
};
template<typename Context, typename Return, typename Arg1, typename Arg2, typename Arg3>
class StateMachineAction3
: public Templates::Action3<Return, Arg1, Arg2, Arg3>
, public StateMachineContext<Context>
{
public:
StateMachineAction3(std::shared_ptr<Context> context) : StateMachineContext<Context>(context)
{ }
virtual ~StateMachineAction3()
{ }
CLASS_TRAITS(StateMachineAction3)
virtual void Entry()
{
this->context().Entry();
}
virtual void Exit()
{
this->context().Exit();
}
};
template<typename Context, typename Return, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
class StateMachineAction4
: public Templates::Action4<Return, Arg1, Arg2, Arg3, Arg4>
, public StateMachineContext<Context>
{
public:
StateMachineAction4(std::shared_ptr<Context> context) : StateMachineContext<Context>(context)
{ }
virtual ~StateMachineAction4()
{ }
CLASS_TRAITS(StateMachineAction4)
virtual void Entry()
{
this->context().Entry();
}
virtual void Exit()
{
this->context().Exit();
}
};
template<typename Context, typename Return, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5>
class StateMachineAction5
: public Templates::Action5<Return, Arg1, Arg2, Arg3, Arg4, Arg5>
, public StateMachineContext<Context>
{
public:
StateMachineAction5(std::shared_ptr<Context> context) : StateMachineContext<Context>(context)
{ }
virtual ~StateMachineAction5()
{ }
CLASS_TRAITS(StateMachineAction5)
virtual void Entry()
{
this->context().Entry();
}
virtual void Exit()
{
this->context().Exit();
}
};
}