6#ifndef INFINITE_STATE_MACHINE_HPP_
7#define INFINITE_STATE_MACHINE_HPP_
24template <
typename Topology>
struct state {
66 std::deque<state<Topology> *>
exits;
70 std::deque<state<Topology> *>
enters;
88 std::deque<state<Topology> *> exits, enters;
90 exits.assign(states.rbegin(), states.rend());
98 to && std::find(enters.rbegin(), enters.rend(), to) == enters.rend();
100 enters.push_front(to);
103 while (!exits.empty() && !enters.empty() &&
104 exits.back() == enters.front()) {
105 states.push_back(exits.back());
109 states.insert(states.end(), enters.begin(), enters.end());
111 return {exits, enters};
120 return states.empty() ? nullptr : states.back();
127 return std::find(states.cbegin(), states.cend(),
state) != states.cend();
140 std::deque<state<Topology> *> states;
A state machine topology navigation class.
bool in(state< Topology > *state) const
Check if a state is active.
state< Topology > * at() const
Get the current state.
virtual ~state_machine()
Destructor for the state machine.
struct transition go(state< Topology > *to)
Transition to a new state.
A struct representing the states exited and entered during a transition.
std::deque< state< Topology > * > exits
The states that were exited during the transition.
std::deque< state< Topology > * > enters
The states that were entered during the transition.
A default abstract state representation.
topology_ptr super
Pointer to the super-state.
Topology * topology_ptr
Pointer type for the topology.
topology_ptr self()
Returns a pointer to the current state.