The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::State< EnumT, MetaDataT, MAX_MARKERS > Class Template Reference

The State class for watching transition between enum states. More...

#include <State.hpp>

Classes

class  Marker
 Class that will mark the state for transition. More...
 
class  Monitor
 Monitor a particular State value and allow the user to determine a full state change. More...
 

Public Types

typedef MetaDataT * MetaDataTPtr
 A peeter to the MetaData.
 
typedef std::conditional<!std::is_same< EnumT, bool >::value, typenameutils::Enum< EnumT >::Value, BoolEnum >::type EnumTValueType
 Convert the EnumT to a EnumT::Value or BoolEnum type.
 
typedef std::conditional<!std::is_same< EnumT, bool >::value, EnumT, BoolEnum::BoolValue >::type EnumType
 If EnumT is not an actual enum, we need to use.
 

Public Member Functions

 State (const EnumTValueType &initial_value=EnumType::__FIRST)
 Construct a State class.
 
 State (const State &other)
 Copy Constructor for State.
 
Stateoperator= (const State &)=delete
 Deleting default assignment operator to prevent copies.
 
virtual ~State ()
 Virtual destructor.
 
const EnumTValueTypegetValue () const
 Get the current value of the state.
 
const EnumTypegetEnumValue () const
 
Scheduler::Tick getTimeInState () const
 
void setValue (const EnumTValueType &val)
 Set a new enum value explicit and fire observers.
 
void reset ()
 Reset this State class.
 
void reset (const EnumTValueType &val)
 Reset this State class to the given value.
 
void operator= (const EnumTValueType &val)
 Assign a new state.
 
bool operator== (const EnumTValueType &rhs_val) const
 
bool operator!= (const EnumTValueType &rhs_val) const
 
MarkernewMarker (const EnumTValueType &val)
 Get a new marker for the enum type.
 
uint32_t numMarks (const EnumTValueType &val) const
 Get the number of marks for the enum type.
 
uint32_t numMarkers (const EnumTValueType &val) const
 Get the number of markers for the enum type.
 
bool complete (const EnumTValueType &val) const
 For a particular value, have all the marks been made.
 
void setMarkedThreshold (const EnumTValueType &val, uint32_t thresh)
 Set the marker set threshold for the given state value.
 
bool isSet (const EnumTValueType &val=BoolEnum::BoolValue::TRUE) const
 Determine if the State was ever set to value val.
 
bool isClear (const EnumTValueType &val=BoolEnum::BoolValue::TRUE) const
 Determine if the State value is clear (never set)
 
void observe (const EnumTValueType &val, const ScheduleableHandle &ev_hand)
 Observe this state, specifically, when it transitions to the given enum val.
 
void withdraw (const EnumTValueType &val, const ScheduleableHandle &ev_hand)
 withdraw event from this state
 
void release (const EnumTValueType &val)
 
void attachMonitor (const EnumTValueType &val, Monitor *mon)
 Attach a Monitor to a state value.
 
void detachMonitor (const EnumTValueType &val, Monitor *mon)
 Decouple a monitor from a state value.
 

Friends

class MarkerSet
 

Detailed Description

template<class EnumT, class MetaDataT = void, uint32_t MAX_MARKERS = 15>
class sparta::State< EnumT, MetaDataT, MAX_MARKERS >

The State class for watching transition between enum states.

The State classes are intended to encapsulate Object state values (typically in an enum) such that state changes can be observed by other objects – i.e. via the GoF observer design pattern.

State which must be jointly updated by several objects before changing is implemented via state markers. For instance, if a State consists of a READY state in its enum declaration, and there are two rules for a READY state transition, each rule is represented by a State<EnumT>::Marker, which must be set before the state can transition to READY.

The State class supports observation of an enum type from one value to another, but the State is exclusive – it can ONLY be only value at a time.

State classes take two template parameters: the Enum type (enum class or just standard enum) and the anticapted maximum number of markers that will be requested – default is 13. Because the State class is in the critical path for most performance modeling applications, use of STL types is discouraged.

Definition at line 122 of file State.hpp.

Member Typedef Documentation

◆ EnumTValueType

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
typedef std::conditional<!std::is_same<EnumT,bool>::value,typenameutils::Enum<EnumT>::Value,BoolEnum>::type sparta::State< EnumT, MetaDataT, MAX_MARKERS >::EnumTValueType

Convert the EnumT to a EnumT::Value or BoolEnum type.

Definition at line 136 of file State.hpp.

◆ EnumType

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
typedef std::conditional<!std::is_same<EnumT,bool>::value,EnumT,BoolEnum::BoolValue>::type sparta::State< EnumT, MetaDataT, MAX_MARKERS >::EnumType

If EnumT is not an actual enum, we need to use.

Definition at line 144 of file State.hpp.

◆ MetaDataTPtr

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
typedef MetaDataT* sparta::State< EnumT, MetaDataT, MAX_MARKERS >::MetaDataTPtr

A peeter to the MetaData.

Definition at line 129 of file State.hpp.

Constructor & Destructor Documentation

◆ State() [1/2]

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
sparta::State< EnumT, MetaDataT, MAX_MARKERS >::State ( const EnumTValueType initial_value = EnumType::__FIRST)
inline

Construct a State class.

Parameters
initial_valueThe initial value; __FIRST is not given
Note
Ensures that the EnumTValueType is a true enum or class enum. During construction of a State instance, we construct its internal state tracker unit. If tracking is disabled, a nullptr is returned, whereas, when it is enabled, a live state tracker pointer is given, ready to start tracking states.

Definition at line 438 of file State.hpp.

◆ State() [2/2]

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
sparta::State< EnumT, MetaDataT, MAX_MARKERS >::State ( const State< EnumT, MetaDataT, MAX_MARKERS > &  other)
inline

Copy Constructor for State.

Definition at line 482 of file State.hpp.

◆ ~State()

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
virtual sparta::State< EnumT, MetaDataT, MAX_MARKERS >::~State ( )
inlinevirtual

Virtual destructor.

Definition at line 494 of file State.hpp.

Member Function Documentation

◆ attachMonitor()

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
void sparta::State< EnumT, MetaDataT, MAX_MARKERS >::attachMonitor ( const EnumTValueType val,
Monitor mon 
)
inline

Attach a Monitor to a state value.

Parameters
valThe value to associate with the Monitor
monThe monitor to attach

Attach a Monitor that will be called when the state value (val) is up for selection

Definition at line 717 of file State.hpp.

◆ complete()

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
bool sparta::State< EnumT, MetaDataT, MAX_MARKERS >::complete ( const EnumTValueType val) const
inline

For a particular value, have all the marks been made.

Parameters
valThe value to query
Returns
true if all markers have returned and marked

Definition at line 627 of file State.hpp.

Here is the call graph for this function:

◆ detachMonitor()

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
void sparta::State< EnumT, MetaDataT, MAX_MARKERS >::detachMonitor ( const EnumTValueType val,
Monitor mon 
)
inline

Decouple a monitor from a state value.

Parameters
valThe Enum value to detach from
monThe monitor to remove

Definition at line 726 of file State.hpp.

◆ getEnumValue()

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
const EnumType & sparta::State< EnumT, MetaDataT, MAX_MARKERS >::getEnumValue ( ) const
inline

Definition at line 501 of file State.hpp.

◆ getTimeInState()

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
Scheduler::Tick sparta::State< EnumT, MetaDataT, MAX_MARKERS >::getTimeInState ( ) const
inline

This methods returns the amount of time in Scheduler Ticks, this sparta::State instance has been residing in its current state. Requires StateTracking to be enabled.

Definition at line 508 of file State.hpp.

◆ getValue()

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
const EnumTValueType & sparta::State< EnumT, MetaDataT, MAX_MARKERS >::getValue ( ) const
inline

Get the current value of the state.

Definition at line 497 of file State.hpp.

◆ isClear()

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
bool sparta::State< EnumT, MetaDataT, MAX_MARKERS >::isClear ( const EnumTValueType val = BoolEnum::BoolValue::TRUE) const
inline

Determine if the State value is clear (never set)

Parameters
valThe value to query
Returns
true if the state never reached this value

Definition at line 664 of file State.hpp.

Here is the call graph for this function:

◆ isSet()

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
bool sparta::State< EnumT, MetaDataT, MAX_MARKERS >::isSet ( const EnumTValueType val = BoolEnum::BoolValue::TRUE) const
inline

Determine if the State was ever set to value val.

Parameters
valThe value to query
Returns
true if was set to that value

Definition at line 654 of file State.hpp.

Here is the call graph for this function:

◆ newMarker()

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
Marker * sparta::State< EnumT, MetaDataT, MAX_MARKERS >::newMarker ( const EnumTValueType val)
inline

Get a new marker for the enum type.

Parameters
valThe enum type to get a marker for
Returns
A new marker

Definition at line 600 of file State.hpp.

◆ numMarkers()

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
uint32_t sparta::State< EnumT, MetaDataT, MAX_MARKERS >::numMarkers ( const EnumTValueType val) const
inline

Get the number of markers for the enum type.

Parameters
valThe enum type to query
Returns
The number of marks set for the enum type

Definition at line 618 of file State.hpp.

◆ numMarks()

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
uint32_t sparta::State< EnumT, MetaDataT, MAX_MARKERS >::numMarks ( const EnumTValueType val) const
inline

Get the number of marks for the enum type.

Parameters
valThe enum type to query
Returns
The number of marks set for the enum type

Definition at line 609 of file State.hpp.

◆ observe()

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
void sparta::State< EnumT, MetaDataT, MAX_MARKERS >::observe ( const EnumTValueType val,
const ScheduleableHandle ev_hand 
)
inline

Observe this state, specifically, when it transitions to the given enum val.

Parameters
valThe value to observe
ev_handThe Scheduleable to schedule when the observation is made

Definition at line 681 of file State.hpp.

◆ operator!=()

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
bool sparta::State< EnumT, MetaDataT, MAX_MARKERS >::operator!= ( const EnumTValueType rhs_val) const
inline
Parameters
rhs_valThe right hand side
Returns
True if equal

Definition at line 585 of file State.hpp.

Here is the call graph for this function:

◆ operator=()

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
void sparta::State< EnumT, MetaDataT, MAX_MARKERS >::operator= ( const EnumTValueType val)
inline

Assign a new state.

Parameters
valThe enum to assign to this state

Definition at line 569 of file State.hpp.

Here is the call graph for this function:

◆ operator==()

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
bool sparta::State< EnumT, MetaDataT, MAX_MARKERS >::operator== ( const EnumTValueType rhs_val) const
inline
Parameters
rhs_valThe right hand side
Returns
True if equal

Definition at line 577 of file State.hpp.

Here is the call graph for this function:

◆ release()

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
void sparta::State< EnumT, MetaDataT, MAX_MARKERS >::release ( const EnumTValueType val)
inline

Definition at line 698 of file State.hpp.

◆ reset() [1/2]

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
void sparta::State< EnumT, MetaDataT, MAX_MARKERS >::reset ( )
inline

Reset this State class.

Clears all markers and puts the current_state_ to the initial_value given in the constructor

Definition at line 540 of file State.hpp.

◆ reset() [2/2]

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
void sparta::State< EnumT, MetaDataT, MAX_MARKERS >::reset ( const EnumTValueType val)
inline

Reset this State class to the given value.

Parameters
valThe value to reset the State to

Clears all markers and puts the current_state_ to the given value

Definition at line 555 of file State.hpp.

◆ setMarkedThreshold()

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
void sparta::State< EnumT, MetaDataT, MAX_MARKERS >::setMarkedThreshold ( const EnumTValueType val,
uint32_t  thresh 
)
inline

Set the marker set threshold for the given state value.

Parameters
valThe value to set the threshold on
threshThe threshold amount

Sets the minimum number of markers that must "call in" before the state transitions to that new value.

Definition at line 639 of file State.hpp.

◆ setValue()

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
void sparta::State< EnumT, MetaDataT, MAX_MARKERS >::setValue ( const EnumTValueType val)
inline

Set a new enum value explicit and fire observers.

Parameters
valThe value to set

If tracking is disabled, this internal

Definition at line 518 of file State.hpp.

◆ withdraw()

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
void sparta::State< EnumT, MetaDataT, MAX_MARKERS >::withdraw ( const EnumTValueType val,
const ScheduleableHandle ev_hand 
)
inline

withdraw event from this state

Parameters
valThe value to observe
ev_handThe Scheduleable that needs to be withdrawn

Definition at line 692 of file State.hpp.

Friends And Related Symbol Documentation

◆ MarkerSet

template<class EnumT , class MetaDataT = void, uint32_t MAX_MARKERS = 15>
friend class MarkerSet
friend

Friend the MarkerSet to set the value on the State when all markers have been set

Definition at line 397 of file State.hpp.


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