Base module

State

State class for state machines.

#include <icy/stateful.h>

class State

Defined in src/base/include/icy/stateful.h:31

This class defines the state for a state machine, and should be extended and passed to implementations of the Stateful template.

For an example See also: PacketStreamState

Friends

NameDescription
operator<< inline

operator<<

inline

friend inline std::ostream & operator<<(std::ostream & os, const State & state)

Defined in src/base/include/icy/stateful.h:80

Public Methods

ReturnNameDescription
State
StateCopy constructor.
State &operator=Copy assignment.
~State virtualDefaulted destructor.
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 = 0)

Defined in src/base/include/icy/stateful.h:37

Parameters

ParameterTypeDescription
idIDInitial state ID. Defaults to 0.

State

State(const State & that)

Defined in src/base/include/icy/stateful.h:41

Copy constructor.

Parameters

ParameterTypeDescription
thatconst State &State to copy from.

operator=

State & operator=(const State & that)

Defined in src/base/include/icy/stateful.h:45

Copy assignment.

Parameters

ParameterTypeDescription
thatconst State &State to assign from.

~State

virtual

virtual ~State() = default

Defined in src/base/include/icy/stateful.h:46

Defaulted destructor.


id

const

ID id() const

Defined in src/base/include/icy/stateful.h:50

Returns the current state ID.

Returns

Atomic state ID value.


set

void set(ID id)

Defined in src/base/include/icy/stateful.h:54

Sets the state ID.

Parameters

ParameterTypeDescription
idIDNew state ID to assign.

str

virtual const

virtual std::string str(ID id) const

Defined in src/base/include/icy/stateful.h:60

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

Returns

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

Parameters

ParameterTypeDescription
idIDState ID to convert.

toString

virtual const

virtual std::string toString() const

Defined in src/base/include/icy/stateful.h:64

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

Returns

Result of str(id()).

Reimplemented by


equals

const

bool equals(ID id) const

Defined in src/base/include/icy/stateful.h:69

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

Returns

True if IDs match.

Parameters

ParameterTypeDescription
idIDState ID to compare against.

between

const

bool between(ID lid, ID rid) const

Defined in src/base/include/icy/stateful.h:75

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

Returns

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

Parameters

ParameterTypeDescription
lidIDLower bound state ID.
ridIDUpper bound state ID.

operator==

const inline

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

Defined in src/base/include/icy/stateful.h:77


operator==

const inline

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

Defined in src/base/include/icy/stateful.h:78

Protected Attributes

ReturnNameDescription
std::atomic< ID >_id

_id

std::atomic< ID > _id

Type: std::atomic< ID >

Defined in src/base/include/icy/stateful.h:87

Public Types

NameDescription
ID

ID

using ID = uint32_t

Defined in src/base/include/icy/stateful.h:34