# smach< CON, K, M >::state< T > Class Template Reference

State class. More...

`#include <_smach.h>`

Inheritance diagram for smach< CON, K, M >::state< T >:

List of all members.

## Public Types

typedef event_def_internal< T > | event_def
typedef T | state_context_type

## Public Member Functions

| state (const char *n, smach *nest=0)
| Default handler for unknown key.
virtual | ~state ()
void | set_nested_machine (smach *sm)
| Setup a nested state machine.
void | set_default_handler (const typename event_def::funcptr &x)
| Sets the default handler.
virtual const char * | get_name () const
| Returns given the name of the state.
state_context_type & | get_context (smach &machine)
void | insert (const event_def &x)
| Adds an event_def onto the list and then make sure it is sorted correctly.
std::vector< event_def >::iterator | find (const event_key &x)
std::vector< event_def > ::const_iterator | find (const event_key &x) const

## Protected Member Functions

virtual void * | enter_state (context_type *machine_context) const
virtual bool | leave_state (void *x) const
virtual event_result | process_event (void *x, const event &id) const

## Private Attributes

std::vector< event_def > | event_list
smach * | nested
event_key | low
| Nested machine.
event_key | high
const char * | name
| Lowest and Highest event values.
event_def::funcptr | default_handler
| Name of the state.

## Friends

class | smach

## Detailed Description

### template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>
class smach< CON, K, M >::state< T >

State class.

Definition at line 166 of file _smach.h.

## Member Typedef Documentation

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

typedef event_def_internal<T> smach< CON, K, M >::state< T >::event_def

Definition at line 172 of file _smach.h.

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

typedef T smach< CON, K, M >::state< T >::state_context_type

Definition at line 173 of file _smach.h.

## Constructor & Destructor Documentation

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

smach< CON, K, M >::state< T >::state | ( | const char * | n,
|  | smach * | nest = `0` |
| ) |  |  | `[inline]`

Default handler for unknown key.

Constructor

Definition at line 188 of file _smach.h.

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

virtual smach< CON, K, M >::state< T >::~state | ( |  | ) | `[inline, virtual]`

Definition at line 192 of file _smach.h.

## Member Function Documentation

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

void smach< CON, K, M >::state< T >::set_nested_machine | ( | smach * | sm | ) | `[inline]`

Setup a nested state machine.

A more detailed explanation needs to be written

Definition at line 196 of file _smach.h.

References smach< CON, K, M >::state< T >::nested.

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

void smach< CON, K, M >::state< T >::set_default_handler | ( | const typename event_def::funcptr & | x | ) | `[inline]`

Sets the default handler.

Definition at line 199 of file _smach.h.

References smach< CON, K, M >::state< T >::default_handler.

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

virtual const char* smach< CON, K, M >::state< T >::get_name | ( |  | ) | const`[inline, virtual]`

Returns given the name of the state.

Implements smach< CON, K, M >::state_base.

Definition at line 202 of file _smach.h.

References smach< CON, K, M >::state< T >::name.

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

state_context_type& smach< CON, K, M >::state< T >::get_context | ( | smach & | machine | ) | `[inline]`

Definition at line 204 of file _smach.h.

References smach< CON, K, M >::state_context.

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

void smach< CON, K, M >::state< T >::insert | ( | const event_def & | x | ) | `[inline]`

Adds an event_def onto the list and then make sure it is sorted correctly.

Definition at line 214 of file _smach.h.

References smach< CON, K, M >::state< T >::event_list, smach< CON, K, M >::state< T >::high, smach< CON, K, M >::event_def_internal< T >::id, and smach< CON, K, M >::state< T >::low.

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

std::vector<event_def>::iterator smach< CON, K, M >::state< T >::find | ( | const event_key & | x | ) | `[inline]`

Definition at line 232 of file _smach.h.

References binary_find(), and smach< CON, K, M >::state< T >::event_list.

Referenced by smach< CON, K, M >::state< T >::process_event().

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

std::vector<event_def>::const_iterator smach< CON, K, M >::state< T >::find | ( | const event_key & | x | ) | const`[inline]`

Definition at line 233 of file _smach.h.

References binary_find(), and smach< CON, K, M >::state< T >::event_list.

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

virtual void* smach< CON, K, M >::state< T >::enter_state | ( | context_type * | machine_context | ) | const`[inline, protected, virtual]`

Implements smach< CON, K, M >::state_base.

Definition at line 237 of file _smach.h.

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

virtual bool smach< CON, K, M >::state< T >::leave_state | ( | void * | x | ) | const`[inline, protected, virtual]`

Implements smach< CON, K, M >::state_base.

Definition at line 242 of file _smach.h.

References smach< CON, K, M >::state_context.

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

virtual event_result smach< CON, K, M >::state< T >::process_event | ( | void * | x,
|  | const event & | id |
| ) |  |  | const`[inline, protected, virtual]`

Implements smach< CON, K, M >::state_base.

Definition at line 250 of file _smach.h.

References smach< CON, K, M >::state< T >::default_handler, smach< CON, K, M >::state< T >::find(), smach< CON, K, M >::state< T >::high, smach< CON, K, M >::state< T >::low, smach< CON, K, M >::state< T >::nested, smach< CON, K, M >::process_event(), smach< CON, K, M >::RESULT_OK, and smach< CON, K, M >::state_context.

## Friends And Related Function Documentation

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

friend class smach `[friend]`

Reimplemented from smach< CON, K, M >::state_base.

Definition at line 169 of file _smach.h.

## Member Data Documentation

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

std::vector<event_def> smach< CON, K, M >::state< T >::event_list `[private]`

Definition at line 178 of file _smach.h.

Referenced by smach< CON, K, M >::state< T >::find(), and smach< CON, K, M >::state< T >::insert().

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

smach* smach< CON, K, M >::state< T >::nested `[private]`

Definition at line 180 of file _smach.h.

Referenced by smach< CON, K, M >::state< T >::process_event(), and smach< CON, K, M >::state< T >::set_nested_machine().

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

event_key smach< CON, K, M >::state< T >::low `[private]`

Nested machine.

Definition at line 181 of file _smach.h.

Referenced by smach< CON, K, M >::state< T >::insert(), and smach< CON, K, M >::state< T >::process_event().

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

event_key smach< CON, K, M >::state< T >::high `[private]`

Definition at line 181 of file _smach.h.

Referenced by smach< CON, K, M >::state< T >::insert(), and smach< CON, K, M >::state< T >::process_event().

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

const char* smach< CON, K, M >::state< T >::name `[private]`

Lowest and Highest event values.

Definition at line 182 of file _smach.h.

Referenced by smach< CON, K, M >::state< T >::get_name().

template<typename CON, typename K = int, typename M = mutex_null>
template<typename T>

event_def::funcptr smach< CON, K, M >::state< T >::default_handler `[private]`

Name of the state.

Definition at line 183 of file _smach.h.

Referenced by smach< CON, K, M >::state< T >::process_event(), and smach< CON, K, M >::state< T >::set_default_handler().

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

- _smach.h