Zth (libzth)
|
Basic FSM base class. More...
#include <fsm14.h>
Public Types | |
enum class | Flag : size_t { entry , selfloop , blocked , transition , pushed , popped , stop , input , flags } |
Flags that indicate properties of the current state. More... | |
using | index_type = TransitionsBase::index_type |
Public Member Functions | |
BasicFsm (cow_string const &name="FSM") | |
Ctor. More... | |
BasicFsm (BasicFsm &&f) | |
Move ctor. More... | |
BasicFsm & | operator= (BasicFsm &&f) noexcept |
Move assignment. More... | |
virtual | ~BasicFsm ()=default |
Dtor. More... | |
State const & | state () const noexcept |
Return the current state. More... | |
bool | valid () const noexcept |
Checks if the FSM was initialized. More... | |
void | reserveStack (size_t capacity) |
Reserve memory to push() a amount of states. More... | |
virtual void | reset () noexcept |
Reset the state machine. More... | |
State const & | prev () const noexcept |
Return the previous state. More... | |
GuardPollInterval | step () |
Try to take one step in the state machine. More... | |
void | push () |
Push the current state onto the state stack. More... | |
virtual void | pop () |
Pop the previous state from the state stack. More... | |
bool | popped () const noexcept |
Check if the current state was reached via pop(). More... | |
bool | flag (Flag f) const noexcept |
Check if the given flag is set. More... | |
bool | entry () noexcept |
Check if the state was just entered. More... | |
Symbol | input () const noexcept |
Return the input symbol that triggered the transition to the current state. More... | |
virtual void | input (Symbol i) |
Register the given input symbol. More... | |
bool | clearInput (Symbol i) noexcept |
Remove the given input symbol. More... | |
void | clearInput () noexcept |
Clear the input symbol that triggered the current state. More... | |
void | clearInputs () noexcept |
Clear all inputs. More... | |
void | reserveInputs (size_t capacity) |
Reserve memory for the given amount of input symbols. More... | |
bool | hasInput (Symbol i) const noexcept |
Checks if the given input symbol was registered before. More... | |
Public Member Functions inherited from zth::UniqueID< BasicFsm > | |
UniqueID (UniqueID const &)=delete | |
UniqueID (UniqueID &&u) noexcept | |
UniqueID (string const &name) | |
UniqueID (string &&name) | |
UniqueID (char const *name=nullptr) | |
UniqueID & | operator= (UniqueID const &)=delete |
UniqueID & | operator= (UniqueID &&u) noexcept |
virtual | ~UniqueID ()=default |
void const * | normptr () const noexcept |
uint64_t | id () const noexcept |
string const & | name () const noexcept |
void | setName (string const &name) |
void | setName (char const *name) |
void | setName (string &&name) |
virtual char const * | id_str () const override |
Protected Member Functions | |
bool | setFlag (Flag f, bool value=true) noexcept |
Set or clear the given flag. More... | |
void | clearFlag (Flag f) noexcept |
Set the given flag. More... | |
virtual void | leave () |
Called when the current state is about to be left. More... | |
virtual void | enter () |
Called when the current state was just entered. More... | |
Protected Member Functions inherited from zth::UniqueIDBase | |
virtual | ~UniqueIDBase ()=default |
Additional Inherited Members | |
Static Public Member Functions inherited from zth::UniqueID< BasicFsm > | |
static uint64_t | getID () noexcept |
Basic FSM base class.
This basic class only executes the FSM, without references to Timestamp and fibers. It is suitable to be executed from an interrupt context, where the current time is not available. Just call step() regularly to run the FSM.
|
strong |
Flags that indicate properties of the current state.
Enumerator | |
---|---|
entry | Just entered the current state. |
selfloop | Took transition to the same state. |
blocked | The FSM is blocked, as no guards are enabled. |
transition | A transition is taken. |
pushed | The current state was entered using push(). |
popped | The current state was entered using pop(). |
stop | stop() was requested. run() will terminate. |
input | The current state was entered via an input symbol. |
flags | Not a flag, just a count of the other flags. |
|
inline |
|
inline |
|
virtualdefault |
Dtor.
|
inlineprotectednoexcept |
|
inlinenoexcept |
Clear the input symbol that triggered the current state.
This is the callback function for the zth::fsm::consume action.
|
inlinenoexcept |
Remove the given input symbol.
false
if the given symbol was not registered
|
inlinenoexcept |
|
inlineprotectedvirtual |
Called when the current state was just entered.
This function calls the action. When overriding this function in a subclass, usually call this function first before adding custom logic.
Reimplemented in zth::fsm::Fsm.
|
inlinenoexcept |
Check if the state was just entered.
This is the callback function for the zth::fsm::entry() guard.
|
inlinenoexcept |
|
inlinenoexcept |
Checks if the given input symbol was registered before.
|
inlinenoexcept |
|
inlinevirtual |
Register the given input symbol.
Reimplemented in zth::fsm::Fsm.
|
inlineprotectedvirtual |
|
inlinevirtual |
|
inlinenoexcept |
Check if the current state was reached via pop().
This is the callback function for the zth::fsm::popped() guard.
|
inlinenoexcept |
|
inline |
Push the current state onto the state stack.
This is the callback function for the zth::fsm::push() action.
The FSM must be valid().
|
inline |
Reserve memory for the given amount of input symbols.
std::bad_alloc | when allocation fails |
|
inline |
|
inlinevirtualnoexcept |
|
inlineprotectednoexcept |
|
inlinenoexcept |
|
inline |
Try to take one step in the state machine.
This basically does:
|
inlinenoexcept |