Zth (libzth)
|
FSM base class. More...
#include <fsm14.h>
Public Types | |
using | base = BasicFsm |
Public Types inherited from zth::fsm::BasicFsm | |
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 | |
Fsm (cow_string const &name="FSM") | |
Ctor. More... | |
Fsm (Fsm &&f) | |
Move ctor. More... | |
Fsm & | operator= (Fsm &&f) noexcept |
Move assignment. More... | |
virtual | ~Fsm () override=default |
Dtor. More... | |
virtual void | reset () noexcept override |
Reset the state machine. More... | |
GuardPollInterval | run (Timestamp const &until) |
Run the state machine until the given time stamp. More... | |
GuardPollInterval | run (bool returnWhenBlocked=false) |
Run the state machine. More... | |
void | trigger () noexcept |
Trigger a currently running FSM to reevaluate the guards immediately. More... | |
void | stop () noexcept |
Interrupt a running FSM. More... | |
virtual void | input (Symbol i) override |
Register the given input symbol. More... | |
Timestamp const & | t () const noexcept |
Returns the time stamp when the current state was entered. More... | |
TimeInterval | dt () const |
Returns the time since the current state was entered. More... | |
Public Member Functions inherited from zth::fsm::BasicFsm | |
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... | |
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... | |
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 |
Static Public Member Functions | |
template<time_t s> | |
static GuardPollInterval | timeoutGuard_s (Fsm &fsm) |
Callback function for the zth::fsm::timeout_s guard. More... | |
template<uint64_t ms> | |
static GuardPollInterval | timeoutGuard_ms (Fsm &fsm) |
Callback function for the zth::fsm::timeout_ms guard. More... | |
template<uint64_t us> | |
static GuardPollInterval | timeoutGuard_us (Fsm &fsm) |
Callback function for the zth::fsm::timeout_us guard. More... | |
Static Public Member Functions inherited from zth::UniqueID< BasicFsm > | |
static uint64_t | getID () noexcept |
Protected Member Functions | |
virtual void | enter () override |
Called when the current state was just entered. More... | |
Protected Member Functions inherited from zth::fsm::BasicFsm | |
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... | |
Protected Member Functions inherited from zth::UniqueIDBase | |
virtual | ~UniqueIDBase ()=default |
FSM base class.
If you want to hold some state in the FSM, inherit this class. A reference to your inherited class can be passed to the guard and action functions.
using zth::fsm::Fsm::base = BasicFsm |
|
inline |
|
overridevirtualdefault |
Dtor.
|
inline |
|
inlineoverrideprotectedvirtual |
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 from zth::fsm::BasicFsm.
|
inlineoverridevirtual |
Register the given input symbol.
trigger() is called to trigger immediate reevaluation of the guards.
Reimplemented from zth::fsm::BasicFsm.
|
inlineoverridevirtualnoexcept |
Reset the state machine.
Reimplemented from zth::fsm::BasicFsm.
|
inline |
|
inline |
|
inlinenoexcept |
Interrupt a running FSM.
This is the callback function for the zth::fsm::stop action. When the FSM is not running (by run()), calling stop() does nothing.
|
inlinenoexcept |
|
inlinestatic |
Callback function for the zth::fsm::timeout_ms guard.
|
inlinestatic |
Callback function for the zth::fsm::timeout_s guard.
|
inlinestatic |
Callback function for the zth::fsm::timeout_us guard.
|
inlinenoexcept |