State Machine  0.5.0
This repository contains packages for creating and running general purpose state machines.
state_machine::Container Class Reference

#include <Container.hpp>

Inheritance diagram for state_machine::Container:
Inheritance graph

Public Member Functions

void addState (const StatePtr &state)
 
virtual void removeStateByName (const std::string &name)
 
bool stateExists (const std::string &name) const
 
StatePtr getState (const std::string &name) const
 
std::map< std::string, StatePtrgetStates () const
 
std::set< std::string > getStateNames () const
 
size_t getNumberOfStates () const
 
virtual void clear ()
 
bool isConsistent (std::vector< std::string > &inconsistencies) const override
 
void recallPauseAfterExecution () override
 
bool pauseAfterExecutionRequested () override
 
void requestPreempt () override
 
void recallPreempt () override
 
void printStateHierarchy (const bool useNestedNames, const bool useIndentation, const unsigned int indentation) const override
 
- Public Member Functions inherited from state_machine::State
 State (ContextPtr context, std::string name, std::set< std::string > outcomes)
 
virtual ~State ()=default
 
ContextPtr getContext () const
 
void setName (const std::string &name)
 
const std::string & getName () const
 
NestedName getNestedName () const
 
const std::set< std::string > & getOutcomes () const
 
const std::string & getType () const
 
void resetIds ()
 
const std::string & getKeyPrefix () const
 
void setParent (State *parent)
 
StategetParent ()
 
void resetParent ()
 
virtual void loadSettings (const Settings &settings)
 
virtual void saveSettings (Settings &settings) const
 
virtual void getAvailableInitialStateNestedNames (std::set< NestedName > &nestedNames) const
 
virtual bool setInitialStateByNestedName (const NestedName &nestedName)
 
std::string execute ()
 
virtual std::string midExecution ()=0
 
bool isRunning () const
 
void requestPause ()
 
virtual bool requestPauseAfterExecution ()
 
void requestResume ()
 
bool isPaused ()
 
void servicePreempt ()
 
bool preemptRequested () const
 
void sleepOnce ()
 
void sleepWhilePaused ()
 
virtual Progress getProgress ()
 
virtual std::map< NestedName, ProgressgetRunningStates (const bool ignoreBackgroundStates)
 
void printStateHierarchy ()
 

Protected Member Functions

 Container (ContextPtr context, std::string name, std::set< std::string > outcomes)
 
 ~Container () override=default
 
- Protected Member Functions inherited from state_machine::State
void setId ()
 
virtual void preExecution ()
 
virtual void postExecution ()
 
void sleep (const double duration)
 

Protected Attributes

std::map< std::string, StatePtrstates_
 
- Protected Attributes inherited from state_machine::State
ContextPtr context_
 
std::string name_
 
std::string type_
 
std::set< std::string > outcomes_
 
unsigned int id_ = -1
 
std::string keyPrefix_
 
Stateparent_ = nullptr
 
std::atomic< bool > isRunning_
 
std::atomic< bool > preemptRequested_
 
Progress progress_
 

Additional Inherited Members

- Static Public Member Functions inherited from state_machine::State
static double getTimeStep ()
 
- Static Protected Attributes inherited from state_machine::State
static std::mutex freeIdMutex_
 
static int freeId_ = 0
 
static double timeStep_ = 0.1
 
static std::atomic< bool > isPaused_
 

Detailed Description

A container is a state containing child states. It is the base class of a state machine and a concurrency, and does not implement any execution.

Constructor & Destructor Documentation

◆ Container()

state_machine::Container::Container ( ContextPtr  context,
std::string  name,
std::set< std::string >  outcomes 
)
protected

General methods. Constructor.

Parameters
contextShared state machine context.
nameName of the container.
outcomesList of possible outcomes.

◆ ~Container()

state_machine::Container::~Container ( )
overrideprotecteddefault

Destructor.

Member Function Documentation

◆ addState()

void state_machine::Container::addState ( const StatePtr state)

Setup methods. Add a child state.

Parameters
stateState to add.

◆ clear()

void state_machine::Container::clear ( )
virtual

Clear the container, removing all contained child states.

Reimplemented in state_machine::Concurrency, and state_machine::StateMachine.

◆ getNumberOfStates()

size_t state_machine::Container::getNumberOfStates ( ) const

Get the number of states.

Returns
Number of states.

◆ getState()

StatePtr state_machine::Container::getState ( const std::string &  name) const

Get a child state.

Parameters
nameName of the child state.
Returns
Child state, empty pointer if not existing.

◆ getStateNames()

std::set< std::string > state_machine::Container::getStateNames ( ) const

Get all child state names.

Returns
Names of child states.

◆ getStates()

std::map< std::string, StatePtr > state_machine::Container::getStates ( ) const

Get all child states.

Returns
Map of names and child states.

◆ isConsistent()

bool state_machine::Container::isConsistent ( std::vector< std::string > &  inconsistencies) const
overridevirtual

Check if the container is consistent.

Parameters
inconsistenciesReturn argument, will contain a list of inconsistencies for printing.
Returns
True if consistent.

Reimplemented from state_machine::State.

Reimplemented in state_machine::StateMachine, and state_machine_planning::StatePlanner.

◆ pauseAfterExecutionRequested()

bool state_machine::Container::pauseAfterExecutionRequested ( )
overridevirtual

Request to pause after executing the currently running state.

Returns
True if successful.

Reimplemented from state_machine::State.

Reimplemented in state_machine::StateMachine.

◆ printStateHierarchy()

void state_machine::Container::printStateHierarchy ( const bool  useNestedNames,
const bool  useIndentation,
const unsigned int  indentation 
) const
overridevirtual

Analysis and debugging methods. Print the state hierarchy to the console.

Parameters
useNestedNamesPrint names as nested names.
useIndentationPrint indentations.
indentationIndentation for printing.

Reimplemented from state_machine::State.

◆ recallPauseAfterExecution()

void state_machine::Container::recallPauseAfterExecution ( )
overridevirtual

Execution methods. Recall the request to pause after executing the currently running state.

Reimplemented from state_machine::State.

Reimplemented in state_machine::StateMachine.

◆ recallPreempt()

void state_machine::Container::recallPreempt ( )
overridevirtual

Recall the request to preempt the state.

Reimplemented from state_machine::State.

◆ removeStateByName()

void state_machine::Container::removeStateByName ( const std::string &  name)
virtual

Remove a child state

Parameters
nameName of the child state.

Reimplemented in state_machine::Concurrency, and state_machine::StateMachine.

◆ requestPreempt()

void state_machine::Container::requestPreempt ( )
overridevirtual

Request to preempt the state.

Reimplemented from state_machine::State.

◆ stateExists()

bool state_machine::Container::stateExists ( const std::string &  name) const

Check if a child state exists.

Parameters
nameName of the child state.
Returns
True if existing.

Member Data Documentation

◆ states_

std::map<std::string, StatePtr> state_machine::Container::states_
protected

Members set during setup.


The documentation for this class was generated from the following files: