Base module

State

[State]({#ref classicy_1_1State #}) class for state machines.

State

#include <icy/stateful.h>

Subclassed by: DiagnosticState, PacketStreamState, TransactionState, EncoderState, InstallationState, ClientState, ClientState

State class for state machines.

This class defines the state for a state machine, and should be extended and passed to implementations of the [Stateful](icy-Stateful.html#stateful) template.

For an example See also: PacketStreamState

Public Methods

ReturnNameDescription
State#### Parameters
StateCopy constructor.
State &operator=Copy assignment.
IDid constReturns the current state ID.
voidsetSets the state ID.
std::stringstr virtual constReturns a human-readable string for the given state ID. Override in derived classes to provide meaningful names.
std::stringtoString virtual constReturns a human-readable string for the current state ID.
boolequals constReturns true if the current state ID equals the given ID.
boolbetween constReturns true if the current state ID is in the inclusive range [lid, rid].
booloperator== const inline
booloperator== const inline

State

State(ID id)

Parameters

  • id Initial state ID. Defaults to 0.

State

State(const State & that)

Copy constructor.

Parameters

  • that State to copy from.

operator=

State & operator=(const State & that)

Copy assignment.

Parameters

  • that State to assign from.

id

const

ID id() const

Returns the current state ID.

Returns

Atomic state ID value.


set

void set(ID id)

Sets the state ID.

Parameters

  • id New state ID to assign.

str

virtual const

virtual std::string str(ID id) const

Returns a human-readable string for the given state ID. Override in derived classes to provide meaningful names.

Parameters

  • id State ID to convert.

Returns

String representation of the state, or "undefined" by default.


toString

virtual const

virtual std::string toString() const

Returns a human-readable string for the current state ID.

Returns

Result of str(id()).


equals

const

bool equals(ID id) const

Returns true if the current state ID equals the given ID.

Parameters

  • id State ID to compare against.

Returns

True if IDs match.


between

const

bool between(ID lid, ID rid) const

Returns true if the current state ID is in the inclusive range [lid, rid].

Parameters

  • lid Lower bound state ID.

  • rid Upper bound state ID.

Returns

True if lid <= id() <= rid.


operator==

const inline

inline bool operator==(const State & that) const

operator==

const inline

inline bool operator==(const State::ID & that) const

Protected Attributes

ReturnNameDescription
std::atomic< ID >_id

_id

std::atomic< ID > _id

Public Types

NameDescription
ID

ID

uint32_t ID()