Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "mitkState.h"
00020
00021
00022 mitk::State::State(std::string stateName, int stateId)
00023 : m_Name(stateName), m_Id(stateId)
00024 {
00025 }
00026
00027 mitk::State::~State()
00028 {
00029
00030 while (!m_Transitions.empty())
00031 {
00032
00033 mitk::Transition* tempTransition = m_Transitions.begin()->second;
00034
00035 m_Transitions.erase(m_Transitions.begin());
00036
00037 delete tempTransition;
00038 }
00039 }
00040
00041
00042 bool mitk::State::AddTransition( Transition* transition )
00043 {
00044 std::pair<TransMapIter,bool> ok = m_Transitions.insert(TransitionMap::value_type( transition->GetEventId(), transition ));
00045 return (bool) ok.second;
00046 }
00047
00048 const mitk::Transition* mitk::State::GetTransition(int eventId) const
00049 {
00050 TransitionMap::const_iterator tempTrans = m_Transitions.find(eventId);
00051 if( tempTrans != m_Transitions.end() )
00052 return (*tempTrans).second;
00053 else
00054 {
00055 tempTrans = m_Transitions.find(0);
00056 if ( tempTrans != m_Transitions.end() )
00057 {
00058 return (*tempTrans).second.GetPointer();
00059 }
00060 else
00061 return NULL;
00062 }
00063 }
00064
00065 std::string mitk::State::GetName() const
00066 {
00067 return m_Name;
00068 }
00069
00070
00071 int mitk::State::GetId() const
00072 {
00073 return m_Id;
00074 }
00075
00076
00077
00078
00079 std::set<int> mitk::State::GetAllNextStates() const
00080 {
00081 std::set<int> tempset;
00082
00083 for (TransMapConstIter i= m_Transitions.begin(); i != m_Transitions.end(); i++)
00084 {
00085 tempset.insert( (i->second)->GetNextStateId() );
00086 }
00087 return tempset;
00088 }
00089
00090
00091
00092
00093 bool mitk::State::IsValidEvent(int eventId) const
00094 {
00095 if( m_Transitions.find(eventId) != m_Transitions.end() )
00096 return true;
00097 else
00098 return false;
00099 }
00100
00101
00102
00103
00104
00105 bool mitk::State::ConnectTransitions(StateMap *allStates)
00106 {
00107 for (TransMapIter i= m_Transitions.begin(); i != m_Transitions.end(); i++)
00108 {
00109 StateMapIter sIter = allStates->find(((*i).second)->GetNextStateId());
00110 if( sIter != allStates->end() )
00111 ((*i).second)->SetNextState((*sIter).second);
00112 else
00113 return false;
00114 }
00115 return true;
00116 }