rtop
Public Member Functions | Private Attributes | Friends | List of all members
rtop::StateMachine Class Reference

statemachine that uses integer corresponding to object uuids to represent states More...

#include <sm.h>

Public Member Functions

 StateMachine (std::map< int, std::map< int, int >> &trans)
 StateMachine constructor. Instantiates state machine with provided state transition table. More...
 
 StateMachine ()
 StateMachine constructor. More...
 
 ~StateMachine ()
 
void addTransition (int, int, int)
 add a single transition i.e. tuple (key_input, curr_state, next_state) More...
 
void next (int)
 updates current state with next state based on key input and encoded state transition table More...
 
void next ()
 same as StateMachine::next(int) except that reads key input from global More...
 
void reset ()
 resets state machine into base state as specified in transition table tuple entry (base_state, -1, base_state) More...
 
void setCurrState (int state)
 sets current state More...
 
int currState () const
 returns current state More...
 
int prevState () const
 returns previous state More...
 
bool isChanged () const
 returns true if prev_state and curr_state are different More...
 
void stale ()
 sets changed to false More...
 

Private Attributes

std::map< int, std::map< int, int > > state_transitions
 state transition table More...
 
int curr_state
 state variable holding current state value More...
 
int prev_state
 state variable holding previous state value More...
 
bool changed = false
 indicates whether state has changed More...
 

Friends

class XMLTree
 

Detailed Description

statemachine that uses integer corresponding to object uuids to represent states

provides API to change state, based on key input
and reading state information

Definition at line 20 of file sm.h.

Constructor & Destructor Documentation

◆ StateMachine() [1/2]

rtop::StateMachine::StateMachine ( std::map< int, std::map< int, int >> &  trans)
inline

StateMachine constructor. Instantiates state machine with provided state transition table.

Definition at line 33 of file sm.h.

◆ StateMachine() [2/2]

rtop::StateMachine::StateMachine ( )
inline

StateMachine constructor.

Definition at line 35 of file sm.h.

◆ ~StateMachine()

rtop::StateMachine::~StateMachine ( )
inline

Definition at line 36 of file sm.h.

Member Function Documentation

◆ addTransition()

void rtop::StateMachine::addTransition ( int  key,
int  curr_st,
int  next_st 
)

add a single transition i.e. tuple (key_input, curr_state, next_state)

Definition at line 150 of file sm.h.

◆ currState()

int rtop::StateMachine::currState ( ) const
inline

returns current state

Definition at line 48 of file sm.h.

◆ isChanged()

bool rtop::StateMachine::isChanged ( ) const
inline

returns true if prev_state and curr_state are different

Definition at line 52 of file sm.h.

◆ next() [1/2]

void rtop::StateMachine::next ( int  ch)

updates current state with next state based on key input and encoded state transition table

Todo:
: this is absurd as curr_state should always be one option in transition table. investigate, remove

Definition at line 78 of file sm.h.

◆ next() [2/2]

void rtop::StateMachine::next ( )

same as StateMachine::next(int) except that reads key input from global

Definition at line 114 of file sm.h.

◆ prevState()

int rtop::StateMachine::prevState ( ) const
inline

returns previous state

Definition at line 50 of file sm.h.

◆ reset()

void rtop::StateMachine::reset ( )

resets state machine into base state as specified in transition table tuple entry (base_state, -1, base_state)

Definition at line 68 of file sm.h.

◆ setCurrState()

void rtop::StateMachine::setCurrState ( int  state)
inline

sets current state

Definition at line 46 of file sm.h.

◆ stale()

void rtop::StateMachine::stale ( )

sets changed to false

Definition at line 59 of file sm.h.

Friends And Related Function Documentation

◆ XMLTree

friend class XMLTree
friend

Definition at line 55 of file sm.h.

Member Data Documentation

◆ changed

bool rtop::StateMachine::changed = false
private

indicates whether state has changed

Definition at line 30 of file sm.h.

◆ curr_state

int rtop::StateMachine::curr_state
private

state variable holding current state value

Definition at line 26 of file sm.h.

◆ prev_state

int rtop::StateMachine::prev_state
private

state variable holding previous state value

Definition at line 28 of file sm.h.

◆ state_transitions

std::map<int, std::map<int, int> > rtop::StateMachine::state_transitions
private

state transition table

Definition at line 24 of file sm.h.


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