Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions

mitk::State Class Reference
[Interaction Classes]

represents one state with all its necessary information More...

#include <mitkState.h>

List of all members.

Public Types

typedef State Self
typedef itk::Object Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer
< const Self
ConstPointer
typedef std::map< int,
mitk::State::Pointer
StateMap
typedef std::map< int,
itk::WeakPointer
< mitk::Transition > > 
TransitionMap
typedef StateMap::iterator StateMapIter
typedef TransitionMap::iterator TransMapIter
typedef
TransitionMap::const_iterator 
TransMapConstIter

Public Member Functions

virtual const char * GetClassName () const
bool AddTransition (Transition *transition)
 Add a transition to the map of transitions.
const TransitionGetTransition (int eventId) const
 hashmap-lookup and returning the Transition. Returns NULL Pointer if not located
std::string GetName () const
 Returns the name.
int GetId () const
 Returns the Id.
std::set< int > GetAllNextStates () const
 Returns a set of all next States. E.g. to parse through all States.
bool IsValidEvent (int eventId) const
 Check, if this event (eventId) leads to a state.
bool ConnectTransitions (StateMap *allStates)
 Searches dedicated States of all Transitions and sets *nextState of these Transitions. Required for this is a List of all build States of that StateMachine (allStates). This way the StateMachine can be build up.

Static Public Member Functions

static Pointer New (std::string _arga, int _argb)
 static New method to use SmartPointer

Protected Member Functions

 State (std::string name, int id)
 Default Constructor. Use New instead! Set the name and the Id of the state. Name is to maintain readability during debug and Id is to identify this state inside the StateMachinePattern.
 ~State ()
 Default Destructor.

Detailed Description

represents one state with all its necessary information

Name and ID are stored. Also methods for building up, connecting and parsing for well formed statemachines are present. This class holds a map of transitions to next States.

Definition at line 41 of file mitkState.h.


Member Typedef Documentation

typedef itk::SmartPointer<const Self> mitk::State::ConstPointer

Definition at line 44 of file mitkState.h.

typedef itk::SmartPointer<Self> mitk::State::Pointer

Definition at line 44 of file mitkState.h.

Definition at line 44 of file mitkState.h.

Definition at line 49 of file mitkState.h.

typedef StateMap::iterator mitk::State::StateMapIter

Definition at line 54 of file mitkState.h.

typedef itk::Object mitk::State::Superclass

Definition at line 44 of file mitkState.h.

typedef std::map<int, itk::WeakPointer<mitk::Transition> > mitk::State::TransitionMap

Definition at line 52 of file mitkState.h.

typedef TransitionMap::const_iterator mitk::State::TransMapConstIter

Definition at line 57 of file mitkState.h.

typedef TransitionMap::iterator mitk::State::TransMapIter

Definition at line 55 of file mitkState.h.


Constructor & Destructor Documentation

mitk::State::State ( std::string  name,
int  id 
) [protected]

Default Constructor. Use New instead! Set the name and the Id of the state. Name is to maintain readability during debug and Id is to identify this state inside the StateMachinePattern.

Definition at line 22 of file mitkState.cpp.

: m_Name(stateName), m_Id(stateId)
{
}
mitk::State::~State (  ) [protected]

Default Destructor.

Definition at line 27 of file mitkState.cpp.

{
  //delete all transitions
  while (!m_Transitions.empty())
  {
    //copy first
    mitk::Transition* tempTransition = m_Transitions.begin()->second;
    //deleting it from map
    m_Transitions.erase(m_Transitions.begin());
    //deleting transition
    delete tempTransition;
  }
}

Member Function Documentation

bool mitk::State::AddTransition ( Transition transition )

Add a transition to the map of transitions.

Instances of all added transitions are freed in destructor of this class.

Definition at line 42 of file mitkState.cpp.

References mitk::Transition::GetEventId().

{
  std::pair<TransMapIter,bool> ok = m_Transitions.insert(TransitionMap::value_type( transition->GetEventId(), transition ));
  return (bool) ok.second;
}
bool mitk::State::ConnectTransitions ( StateMap allStates )

Searches dedicated States of all Transitions and sets *nextState of these Transitions. Required for this is a List of all build States of that StateMachine (allStates). This way the StateMachine can be build up.

searches dedicated States of all Transitions and sets *nextState of these Transitions. allStates is a List of all build States of that StateMachine

Definition at line 105 of file mitkState.cpp.

{
  for (TransMapIter i= m_Transitions.begin(); i != m_Transitions.end(); i++)
  {
    StateMapIter sIter = allStates->find(((*i).second)->GetNextStateId());
    if( sIter != allStates->end() )
      ((*i).second)->SetNextState((*sIter).second);
    else
      return false;//State not found!
  }
  return true;
}
std::set< int > mitk::State::GetAllNextStates (  ) const

Returns a set of all next States. E.g. to parse through all States.

gives all next States back. To parse through all States.

Definition at line 79 of file mitkState.cpp.

{
  std::set<int> tempset;

  for (TransMapConstIter i= m_Transitions.begin(); i != m_Transitions.end(); i++)
  {
    tempset.insert( (i->second)->GetNextStateId() );
  }
  return tempset;
}
virtual const char* mitk::State::GetClassName (  ) const [virtual]
int mitk::State::GetId (  ) const

Returns the Id.

Definition at line 71 of file mitkState.cpp.

Referenced by mitk::StateMachine::HandleEvent().

{
  return m_Id;
}
std::string mitk::State::GetName (  ) const

Returns the name.

Definition at line 65 of file mitkState.cpp.

Referenced by mitk::StateMachine::HandleEvent().

{
  return m_Name;
}
const mitk::Transition * mitk::State::GetTransition ( int  eventId ) const

hashmap-lookup and returning the Transition. Returns NULL Pointer if not located

Definition at line 48 of file mitkState.cpp.

Referenced by mitk::PointSetInteractor::CanHandleEvent(), and mitk::MouseMovePointSetInteractor::CanHandleEvent().

{
  TransitionMap::const_iterator tempTrans = m_Transitions.find(eventId);
  if( tempTrans != m_Transitions.end() )
    return (*tempTrans).second;
  else //can a Transition with ID 0 be found?
  {
    tempTrans = m_Transitions.find(0);
    if ( tempTrans != m_Transitions.end() )//found transition 0 (= transmitt all events to other local StateMachines)
    {
      return (*tempTrans).second.GetPointer();
    }
    else
      return NULL;
  }
}
bool mitk::State::IsValidEvent ( int  eventId ) const

Check, if this event (eventId) leads to a state.

to check, if this Event has a Transition. for menu Behavior e.g.

Definition at line 93 of file mitkState.cpp.

{
  if( m_Transitions.find(eventId) != m_Transitions.end() )
    return true;
  else
    return false;
}
static Pointer mitk::State::New ( std::string  _arga,
int  _argb 
) [inline, static]

static New method to use SmartPointer

Definition at line 49 of file mitkState.h.

Referenced by mitkStateMachineFactoryTest(), mitkStateTest(), mitkTransitionTest(), and mitk::StateMachineFactory::StartElement().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines