Skip to content

Commit bb14a93

Browse files
1.8.0 (#33)
+ sprinkled noexcept everywhere + added support for pointer and reference contexts + added version info ^ updated .natvis ^ improved TaskListT<>
1 parent f0632bf commit bb14a93

File tree

92 files changed

+5320
-3866
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+5320
-3866
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Header-only heriarchical FSM framework in C++11, with fully statically-defined s
3535

3636
## Feature Highlights
3737

38-
- Permissive **[MIT License](https://github.com/andrew-gresyk/FFSM2/blob/master/LICENSE)**
38+
- Permissive **[MIT License](https://github.com/andrew-gresyk/HFSM2/blob/master/LICENSE)**
3939
- Written in widely-supported modern(ish) C++11
4040
- Header-only
4141
- Convenient, minimal boilerplate

examples/advanced_event_handling/main.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// HFSM (hierarchical state machine for games and interactive applications)
1+
// HFSM2 (hierarchical state machine for games and interactive applications)
22
// Created by Andrew Gresyk
33
//
44
// Event handling example
@@ -94,7 +94,7 @@ struct Reactive
9494
: FSM::State
9595
{
9696
// handle a single event type - TransitionEvent
97-
void react(const TransitionEvent&, FullControl& control) {
97+
void react(const TransitionEvent&, FullControl& control) noexcept {
9898
std::cout << " Reactive: reacting to TransitionEvent\n";
9999

100100
control.changeTo<Target>();
@@ -118,12 +118,12 @@ struct ConcreteHandler
118118
: FSM::State
119119
{
120120
// handle two event types - PrimaryEvent
121-
void react(const PrimaryEvent&, FullControl&) {
121+
void react(const PrimaryEvent&, FullControl&) noexcept {
122122
std::cout << " ConcreteHandler: reacting to PrimaryEvent\n";
123123
}
124124

125125
// and SecondaryEvent
126-
void react(const SecondaryEvent&, FullControl&) {
126+
void react(const SecondaryEvent&, FullControl&) noexcept {
127127
std::cout << " ConcreteHandler: reacting to SecondaryEvent\n";
128128
}
129129

@@ -138,7 +138,7 @@ struct TemplateHandler
138138
{
139139
// handle all possible event types
140140
template <typename TEvent>
141-
void react(const TEvent&, FullControl&) {
141+
void react(const TEvent&, FullControl&) noexcept {
142142
std::cout << " TemplateHandler: reacting to TEvent\n";
143143
}
144144
};
@@ -151,14 +151,14 @@ struct EnableIfHandler
151151
// use std::enable_if to build more complex conditional event handling
152152
template <typename TEvent>
153153
typename std::enable_if<std::is_class<TEvent>::value>::type
154-
react(const TEvent&, FullControl&) {
154+
react(const TEvent&, FullControl&) noexcept {
155155
std::cout << " EnableIfHandler: reacting to a <class event>\n";
156156
}
157157

158158
// but remember to cover all the remaining cases
159159
template <typename TEvent>
160160
typename std::enable_if<!std::is_class<TEvent>::value>::type
161-
react(const TEvent&, FullControl&) {
161+
react(const TEvent&, FullControl&) noexcept {
162162
std::cout << " EnableIfHandler: reacting to a <non-class event>\n";
163163
}
164164
};
@@ -168,15 +168,15 @@ struct EnableIfHandler
168168
struct Target
169169
: FSM::State
170170
{
171-
void enter(Control&) {
171+
void enter(Control&) noexcept {
172172
std::cout << " changed to Target\n";
173173
}
174174
};
175175

176176
////////////////////////////////////////////////////////////////////////////////
177177

178178
int
179-
main() {
179+
main() noexcept {
180180
FSM::Instance machine;
181181

182182
std::cout << "sending PrimaryEvent:\n";

examples/basic_audio_player/main.cpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// HFSM (hierarchical state machine for games and interactive applications)
1+
// HFSM2 (hierarchical state machine for games and interactive applications)
22
// Created by Andrew Gresyk
33
//
44
// An HFSM2 port of https://gist.github.com/martinmoene/797b1923f9c6c1ae355bb2d6870be25e
@@ -64,7 +64,7 @@ static_assert(FSM::stateId<Paused>() == 3, "");
6464
struct Logger
6565
: M::LoggerInterface
6666
{
67-
static const char* stateName(const StateID stateId) {
67+
static const char* stateName(const StateID stateId) noexcept {
6868
switch (stateId) {
6969
case 1:
7070
return "Idle";
@@ -81,7 +81,7 @@ struct Logger
8181
void recordTransition(Context& /*context*/,
8282
const StateID origin,
8383
const TransitionType /*transition*/,
84-
const StateID target) override
84+
const StateID target) noexcept override
8585
{
8686
std::cout << stateName(origin) << " -> " << stateName(target) << "\n";
8787
}
@@ -94,7 +94,7 @@ struct Base
9494
: FSM::State
9595
{
9696
template <typename Event>
97-
void react(const Event&, FullControl&) {
97+
void react(const Event&, FullControl&) noexcept {
9898
std::cout << "[unsupported transition]\n";
9999
}
100100
};
@@ -105,7 +105,7 @@ struct Idle
105105
{
106106
using Base::react;
107107

108-
void react(const Play& event, FullControl& control) {
108+
void react(const Play& event, FullControl& control) noexcept {
109109
control.context() = event.title;
110110
control.changeTo<Playing>();
111111
}
@@ -116,11 +116,11 @@ struct Playing
116116
{
117117
using Base::react;
118118

119-
void react(const Pause&, FullControl& control) {
119+
void react(const Pause&, FullControl& control) noexcept {
120120
control.changeTo<Paused>();
121121
}
122122

123-
void react(const Stop&, FullControl& control) {
123+
void react(const Stop&, FullControl& control) noexcept {
124124
control.changeTo<Idle>();
125125
}
126126
};
@@ -130,39 +130,40 @@ struct Paused
130130
{
131131
using Base::react;
132132

133-
void react(const Resume&, FullControl& control) {
133+
void react(const Resume&, FullControl& control) noexcept {
134134
control.changeTo<Playing>();
135135
}
136136

137-
void react(const Stop&, FullControl& control) {
137+
void react(const Stop&, FullControl& control) noexcept {
138138
control.changeTo<Idle>();
139139
}
140140
};
141141

142142
//------------------------------------------------------------------------------
143143

144-
int main() {
144+
int
145+
main() noexcept {
145146
// construct everything
146147
Context title;
147148
Logger logger;
148149
FSM::Instance machine(title, &logger);
149150

150151
// do the work :)
151-
machine.react(Play{"any"});
152-
machine.react(Stop{});
152+
machine.react(Play{"any"}); // Idle -> Playing
153+
machine.react(Stop{}); // Playing -> Idle
153154

154-
machine.react(Play{"optional"});
155-
machine.react(Pause{});
156-
machine.react(Stop{});
155+
machine.react(Play{"optional"}); // Idle -> Playing
156+
machine.react(Pause{}); // Playing -> Paused
157+
machine.react(Stop{}); // Paused -> Idle
157158

158-
machine.react(Play{"variant"});
159-
machine.react(Pause{}); //-V760
160-
machine.react(Resume{});
161-
machine.react(Stop{});
159+
machine.react(Play{"variant"}); // Idle -> Playing
160+
machine.react(Pause{}); //-V760 // Playing -> Paused
161+
machine.react(Resume{}); // Paused -> Playing
162+
machine.react(Stop{}); // Playing -> Idle
162163

163-
machine.react(Pause{});
164-
machine.react(Resume{});
165-
machine.react(Stop{});
164+
machine.react(Pause{}); // [unsupported transition]
165+
machine.react(Resume{}); // [unsupported transition]
166+
machine.react(Stop{}); // [unsupported transition]
166167

167168
return 0;
168169
}

examples/basic_traffic_light/main.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// HFSM (hierarchical state machine for games and interactive applications)
1+
// HFSM2 (hierarchical state machine for games and interactive applications)
22
// Created by Andrew Gresyk
33
//
44
// Traffic light example:
@@ -42,7 +42,7 @@
4242

4343
// data shared between FSM states and outside code
4444
struct Context {
45-
unsigned cycleCount;
45+
unsigned cycleCount = 0;
4646
};
4747

4848
// convenience typedef
@@ -110,7 +110,7 @@ struct On
110110
: FSM::State // necessary boilerplate!
111111
{
112112
// called on state entry
113-
void enter(Control& control) {
113+
void enter(Control& control) noexcept {
114114
control.context().cycleCount = 0;
115115
std::cout << "On" << std::endl;
116116
}
@@ -122,13 +122,13 @@ struct On
122122
struct Red
123123
: FSM::State
124124
{
125-
void enter(Control& control) {
125+
void enter(Control& control) noexcept {
126126
++control.context().cycleCount;
127127
std::cout << " Red" << std::endl;
128128
}
129129

130130
// state can initiate transitions to _any_ other state
131-
void update(FullControl& control) {
131+
void update(FullControl& control) noexcept {
132132
// multiple transitions can be initiated, can be useful in a hierarchy
133133
if (control.context().cycleCount > 3)
134134
control.changeTo<Off>();
@@ -142,11 +142,11 @@ struct Red
142142
struct YellowDownwards
143143
: FSM::State
144144
{
145-
void enter(Control&) {
145+
void enter(Control&) noexcept {
146146
std::cout << " Yellow v" << std::endl;
147147
}
148148

149-
void update(FullControl& control) {
149+
void update(FullControl& control) noexcept {
150150
control.changeTo<Green>();
151151
}
152152
};
@@ -156,11 +156,11 @@ struct YellowDownwards
156156
struct YellowUpwards
157157
: FSM::State
158158
{
159-
void enter(Control&) {
159+
void enter(Control&) noexcept {
160160
std::cout << " Yellow ^" << std::endl;
161161
}
162162

163-
void update(FullControl& control) {
163+
void update(FullControl& control) noexcept {
164164
control.changeTo<Red>();
165165
}
166166
};
@@ -170,11 +170,11 @@ struct YellowUpwards
170170
struct Green
171171
: FSM::State
172172
{
173-
void enter(Control&) {
173+
void enter(Control&) noexcept {
174174
std::cout << " Green" << std::endl;
175175
}
176176

177-
void update(FullControl& control) {
177+
void update(FullControl& control) noexcept {
178178
control.changeTo<YellowUpwards>();
179179
}
180180
};
@@ -185,15 +185,15 @@ struct Green
185185
struct Off
186186
: FSM::State
187187
{
188-
void enter(Control&) {
188+
void enter(Control&) noexcept {
189189
std::cout << "Off" << std::endl;
190190
}
191191
};
192192

193193
////////////////////////////////////////////////////////////////////////////////
194194

195195
int
196-
main() {
196+
main() noexcept {
197197
// shared data storage instance
198198
Context context;
199199

examples/debug_logger_interface/main.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// HFSM (hierarchical state machine for games and interactive applications)
1+
// HFSM2 (hierarchical state machine for games and interactive applications)
22
// Created by Andrew Gresyk
33
//
44
// Attachable logger example:
@@ -90,7 +90,7 @@ struct Logger
9090
{
9191
void recordMethod(Context& /*context*/,
9292
const hfsm2::StateID /*origin*/,
93-
const Method method) override
93+
const Method method) noexcept override
9494
{
9595
std::cout //<< hfsm2::stateName(origin) << "::"
9696
<< hfsm2::methodName(method) << "()\n";
@@ -99,7 +99,7 @@ struct Logger
9999
void recordTransition(Context& /*context*/,
100100
const hfsm2::StateID /*origin*/,
101101
const TransitionType transitionType,
102-
const hfsm2::StateID /*target*/) override
102+
const hfsm2::StateID /*target*/) noexcept override
103103
{
104104
std::cout //<< hfsm2::stateName(origin) << ": "
105105
<< hfsm2::transitionName(transitionType) << "<"
@@ -115,12 +115,12 @@ struct Top
115115
: FSM::State // necessary boilerplate!
116116
{
117117
// all state methods:
118-
void entryGuard(GuardControl&) {} // not going to be called in this example
119-
void enter(Control&) {}
120-
void update(FullControl&) {}
118+
void entryGuard(GuardControl&) noexcept {} // not going to be called in this example
119+
void enter(Control&) noexcept {}
120+
void update(FullControl&) noexcept {}
121121
template <typename TEvent>
122-
void react(const TEvent&, FullControl&) {}
123-
void exit(Control&) {}
122+
void react(const TEvent&, FullControl&) noexcept {}
123+
void exit(Control&) noexcept {}
124124
};
125125

126126
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -130,12 +130,12 @@ struct From
130130
: FSM::State
131131
{
132132
// all state methods:
133-
void entryGuard(GuardControl&) {} // not going to be called in this example
134-
void enter(Control&) {}
135-
void update(FullControl&) {}
133+
void entryGuard(GuardControl&) noexcept {} // not going to be called in this example
134+
void enter(Control&) noexcept {}
135+
void update(FullControl&) noexcept {}
136136
template <typename TEvent>
137-
void react(const TEvent&, FullControl& control) { control.changeTo<To>(); }
138-
void exit(Control&) {}
137+
void react(const TEvent&, FullControl& control) noexcept { control.changeTo<To>(); }
138+
void exit(Control&) noexcept {}
139139
};
140140

141141
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -145,17 +145,18 @@ struct To
145145
: FSM::State
146146
{
147147
// all state methods:
148-
void entryGuard(GuardControl&) {}
149-
void enter(Control&) {}
150-
void update(FullControl&) {}
148+
void entryGuard(GuardControl&) noexcept {}
149+
void enter(Control&) noexcept {}
150+
void update(FullControl&) noexcept {}
151151
template <typename TEvent>
152-
void react(const TEvent&, FullControl&) {} // not going to be called in this example
153-
void exit(Control&) {}
152+
void react(const TEvent&, FullControl&) noexcept {} // not going to be called in this example
153+
void exit(Control&) noexcept {}
154154
};
155155

156156
////////////////////////////////////////////////////////////////////////////////
157157

158-
int main() {
158+
int
159+
main() noexcept {
159160
{
160161
// logger
161162
Logger logger;

0 commit comments

Comments
 (0)