CAutomataDesc Class Reference

#include <automata_desc.h>

Inheritance diagram for CAutomataDesc:

NLMISC::IStreamable NLMISC::IClassable

Detailed Description

A class which describe a simple success/fail automat. Each state is identified by an unique Id. The Id IDSUCCESS (-1) is the automat Success state Id. The Id IDFAIL (-2) is the automat Fail state Id.
Author:
Gabriel ROBERT

Nevrax France

Date:
2001

Definition at line 44 of file automata_desc.h.

Public Member Functions

 CAutomataDesc ()
 Constructor.

void generateScript ()
std::string getAutomatName () const
 Give the automat name.

const std::list< sint32 > & getEntryStates () const
const std::list< sint32 > & getFailStates (sint32 stateId) const
std::string getStateName (sint32 stateId) const
 Gives the name of a state.

const std::list< sint32 > & getSuccessStates (sint32 stateId) const
std::string removeSpaces (std::string &)
virtual ~CAutomataDesc ()
 Destructor.

Build Fonctions
Those functions are used for building a CAutomataDesc.

void addEntryState (sint32 entryId)
void addFailState (sint32 id, sint32 faileId)
void addState (sint32 id, std::string name)
void addSuccessState (sint32 id, sint32 successId)
void setAutomatName (std::string name)
void setExploredState (sint32 stateId)
void setVisitedState (sint32 stateId)
bool visitedState (sint32 stateId)
Derived from NLMISC::IStreamable
std::string getClassName ()
void serial (NLMISC::IStream &f) throw (NLMISC::EStream)

Static Public Attributes

const sint32 IDFAIL = -2
const sint32 IDSUCCESS = -1

Private Member Functions

bool exploredState (sint32 stateId)

Private Attributes

std::string _AutomatName
std::list< sint32_EntryStates
std::set< sint32_ExploredState
std::map< sint32, CState_States
std::set< sint32_VisitedState


Constructor & Destructor Documentation

CAutomataDesc::CAutomataDesc  ) 
 

Constructor.

Definition at line 35 of file automata_desc.cpp.

References addState(), IDFAIL, and IDSUCCESS.

00036         {
00037                 addState(IDSUCCESS, "AUTOMAT SUCCESS STATE");
00038                 addState(IDFAIL, "AUTOMAT FAIL STATE");
00039         }

virtual CAutomataDesc::~CAutomataDesc  )  [inline, virtual]
 

Destructor.

Definition at line 53 of file automata_desc.h.

00053 {}


Member Function Documentation

void CAutomataDesc::addEntryState sint32  entryId  ) 
 

Definition at line 108 of file automata_desc.cpp.

References _EntryStates, and sint32.

00109         {
00110                 _EntryStates.push_back(entryId);
00111         }

void CAutomataDesc::addFailState sint32  id,
sint32  faileId
 

Definition at line 100 of file automata_desc.cpp.

References _States, exploredState(), and sint32.

00101         {
00102                 if (!exploredState(id))
00103                 {
00104                         _States[id].FailStates.push_back(faileId);
00105                 }
00106         }

void CAutomataDesc::addState sint32  id,
std::string  name
 

Definition at line 84 of file automata_desc.cpp.

References _States, exploredState(), and sint32.

Referenced by CAutomataDesc().

00085         {
00086                 if (!exploredState(id))
00087                 {
00088                         _States[id].Name = name;
00089                 }
00090         }

void CAutomataDesc::addSuccessState sint32  id,
sint32  successId
 

Definition at line 92 of file automata_desc.cpp.

References _States, exploredState(), and sint32.

00093         {
00094                 if (!exploredState(id))
00095                 {
00096                         _States[id].SuccessStates.push_back(successId);
00097                 }
00098         }

bool CAutomataDesc::exploredState sint32  stateId  )  [private]
 

Definition at line 113 of file automata_desc.cpp.

References _ExploredState, and sint32.

Referenced by addFailState(), addState(), and addSuccessState().

00114         {
00115                 std::set<sint32>::const_iterator iSet = _ExploredState.find(stateId);
00116                 return (iSet != _ExploredState.end());
00117         }

void CAutomataDesc::generateScript  ) 
 

Definition at line 129 of file automata_desc.cpp.

References _States, getAutomatName(), getEntryStates(), getFailStates(), getStateName(), getSuccessStates(), IDFAIL, IDSUCCESS, removeSpaces(), and sint32.

00130         {
00131                 ofstream tmp_script( "fsm_script.ras");
00132                 
00133                 // Succes and failure states
00134 /*              tmp_script << "From Actor : Define SuccessState" << endl << "{" << endl;
00135                 tmp_script << "}" << endl << endl;
00136                 tmp_script << "From Actor : Define FailureState" << endl << "{" << endl;
00137                 tmp_script << "}" << endl << endl;
00138 */
00139 
00140                 tmp_script << "// " << getAutomatName() << " FSM definition generated script" << endl << endl;
00141                 std::string name;
00142                 // Generates states
00143                 std::map<sint32,CState>::const_iterator it_m = _States.begin();
00144                 while ( it_m != _States.end() )
00145                 {
00146                         sint32 state_id = (*it_m).first;
00147                         
00148                         name = getStateName( state_id );
00149                         // State name
00150                         std::string state_name = removeSpaces( name );
00151 
00152                         tmp_script << "From Actor : Define " << "Actor" << state_name << endl << "{" << endl;
00153 
00154                         if ( state_id != IDSUCCESS && state_id != IDFAIL )
00155                         {
00156 #ifdef NL_DEBUG
00157                                 tmp_script << "\tOnActivate()" << endl;
00158                                 tmp_script << "\t\tPrint('Etat " << state_name << " actif');" << endl;
00159                                 tmp_script << "\tEnd" << endl << endl;
00160 #endif
00161 
00162                                 // Success transitions
00163                                 tmp_script << "\tRunTell(SuccessMsg msg)" << endl;
00164                                 std::list<sint32>::const_iterator it_s = getSuccessStates( state_id ).begin();
00165                                 while ( it_s != getSuccessStates( state_id ).end() )
00166                                 {
00167                                         name = getStateName( *it_s );
00168                                         state_name = removeSpaces( name );
00169                                         tmp_script << "\t\tswitch('" << state_name << "');" << endl;
00170                                         it_s++;
00171                                 }
00172                                 tmp_script << "\t\tReturn msg;" << endl;
00173                                 tmp_script << "\tEnd" << endl << endl;
00174 
00175                                 // Failure transitions
00176                                 tmp_script << "\tRunTell(FailureMsg msg)" << endl;
00177                                 std::list<sint32>::const_iterator it_f = getFailStates( state_id ).begin();
00178                                 while ( it_f != getFailStates( state_id ).end() )
00179                                 {
00180                                         name = getStateName( *it_f );
00181                                         state_name = removeSpaces( name );
00182                                         tmp_script << "\t\tswitch('" << state_name << "');" << endl;
00183                                         it_f++;
00184                                 }
00185                                 tmp_script << "\t\tReturn msg;" << endl;
00186                                 tmp_script << "\tEnd" << endl;
00187                         }
00188                         else
00189                         {
00190                                 tmp_script << "\tRun()" << endl;
00191                                 if ( state_id == IDSUCCESS )
00192                                         tmp_script << "\t\tFather().Send(TELL, new SuccessMsg(0.0));" << endl;
00193                                 else
00194                                         tmp_script << "\t\tFather().Send(TELL, new FailureMsg(0.0));" << endl;
00195                                 tmp_script << "\tEnd" << endl;
00196                         }
00197 
00198                         // End of the State class
00199                         tmp_script << "}" << endl << endl;
00200 
00201                         it_m++;
00202                 }
00203 
00204                 // Generates FSM
00205                 std::string automateName = getAutomatName();
00206                 std::string fsm_name = removeSpaces( automateName );
00207                 tmp_script << "From Fsm : Define " << fsm_name << endl << "{" << endl;
00208 
00209                 // Generates states as static components of the FSM
00210                 tmp_script << "\tComponent:" << endl;
00211                 
00212                 it_m = _States.begin();
00213                 while ( it_m != _States.end() )
00214                 {
00215                         // State name
00216                         name = getStateName( (*it_m).first );
00217                         std::string state_name = removeSpaces( name );
00218                         tmp_script << "\t\tActor" << state_name << "<'" << state_name << "'>;" << endl;
00219                         it_m++;
00220                 }
00221                 tmp_script << "\tEnd" << endl << endl;
00222 
00223                 // Activates entry states
00224                 tmp_script << "\tConstructor()" << endl;
00225                 std::list<sint32>::const_iterator it_e = getEntryStates().begin();
00226                 while ( it_e != getEntryStates().end() )
00227                 {
00228                         name = getStateName( *it_e );
00229                         std::string state_name = removeSpaces( name );
00230                         tmp_script << "\t\t" << state_name << ".activate();" << endl;
00231                         it_e++;
00232                 }
00233                 tmp_script << "\tEnd" << endl;
00234 
00235                 // End of the Fsm Class
00236                 tmp_script << "}" << endl;
00237 
00238                 tmp_script.close();
00239         }

std::string CAutomataDesc::getAutomatName  )  const
 

Give the automat name.

Definition at line 41 of file automata_desc.cpp.

References _AutomatName.

Referenced by generateScript().

00042         {
00043                 return _AutomatName;
00044         }

std::string CAutomataDesc::getClassName  )  [virtual]
 

Implements NLMISC::IClassable.

Definition at line 124 of file automata_desc.cpp.

00125         {
00126                 return "CAutomataDesc";
00127         }

const std::list< sint32 > & CAutomataDesc::getEntryStates  )  const
 

Gives the States linked to the automat entry.

Returns:
A list of state Id.

Definition at line 46 of file automata_desc.cpp.

References _EntryStates.

Referenced by generateScript().

00047         {
00048                 return _EntryStates;
00049         }

const std::list< sint32 > & CAutomataDesc::getFailStates sint32  stateId  )  const
 

Gives the States linked to the stateId fail output.

Returns:
A list of state Id.

Definition at line 58 of file automata_desc.cpp.

References _States, and sint32.

Referenced by generateScript().

00059         {
00060                 std::map<sint32,CState>::const_iterator iStates;
00061                 iStates = _States.find(stateId);
00062                 return (*iStates).second.FailStates;
00063         }

std::string CAutomataDesc::getStateName sint32  stateId  )  const
 

Gives the name of a state.

Definition at line 65 of file automata_desc.cpp.

References _States, and sint32.

Referenced by generateScript().

00066         {
00067                 std::map<sint32,CState>::const_iterator iStates;
00068                 iStates = _States.find(stateId);
00069                 if (iStates != _States.end())
00070                 {
00071                         return (*iStates).second.Name;
00072                 }
00073                 else
00074                 {
00075                         return "ERROR : Invalid State ID";
00076                 }
00077         }

const std::list< sint32 > & CAutomataDesc::getSuccessStates sint32  stateId  )  const
 

Gives the States linked to the stateId success output.

Returns:
A list of state Id.

Definition at line 51 of file automata_desc.cpp.

References _States, and sint32.

Referenced by generateScript().

00052         {
00053                 std::map<sint32,CState>::const_iterator iStates;
00054                 iStates = _States.find(stateId);
00055                 return (*iStates).second.SuccessStates;
00056         }

std::string CAutomataDesc::removeSpaces std::string &   ) 
 

Definition at line 241 of file automata_desc.cpp.

References buffer.

Referenced by generateScript().

00242         {
00243                 int i = 0;
00244                 char buffer[1024];
00245                 while ( i != (int)txt.size() )
00246                 {
00247                         if ( txt[i] == ' ')
00248                                 buffer[i] = '_';
00249                         else
00250                                 buffer[i] = txt[i];
00251                         i++;
00252                 }
00253                 buffer[i] = 0;
00254                 return std::string( buffer );
00255         }

void CAutomataDesc::serial NLMISC::IStream f  )  throw (NLMISC::EStream) [inline, virtual]
 

Implements NLMISC::IStreamable.

Definition at line 95 of file automata_desc.h.

References _AutomatName, _EntryStates, and _States.

00096         {
00097                 f.serialCont(_States);
00098                 f.serialCont(_EntryStates);
00099                 f.serial(_AutomatName);
00100         }

void CAutomataDesc::setAutomatName std::string  name  ) 
 

Definition at line 79 of file automata_desc.cpp.

References _AutomatName.

00080         {
00081                 _AutomatName = name;
00082         }

void CAutomataDesc::setExploredState sint32  stateId  ) 
 

Definition at line 119 of file automata_desc.cpp.

References _ExploredState, and sint32.

00120         {
00121                 _ExploredState.insert(stateId);
00122         }       

void CAutomataDesc::setVisitedState sint32  stateId  ) 
 

bool CAutomataDesc::visitedState sint32  stateId  ) 
 


Field Documentation

std::string CAutomataDesc::_AutomatName [private]
 

Definition at line 127 of file automata_desc.h.

Referenced by getAutomatName(), serial(), and setAutomatName().

std::list<sint32> CAutomataDesc::_EntryStates [private]
 

Definition at line 124 of file automata_desc.h.

Referenced by addEntryState(), getEntryStates(), and serial().

std::set<sint32> CAutomataDesc::_ExploredState [private]
 

Definition at line 126 of file automata_desc.h.

Referenced by exploredState(), and setExploredState().

std::map<sint32,CState> CAutomataDesc::_States [private]
 

Definition at line 123 of file automata_desc.h.

Referenced by addFailState(), addState(), addSuccessState(), generateScript(), getFailStates(), getStateName(), getSuccessStates(), and serial().

std::set<sint32> CAutomataDesc::_VisitedState [private]
 

Definition at line 125 of file automata_desc.h.

const sint32 CAutomataDesc::IDFAIL = -2 [static]
 

Definition at line 30 of file automata_desc.cpp.

Referenced by CAutomataDesc(), and generateScript().

const sint32 CAutomataDesc::IDSUCCESS = -1 [static]
 

Definition at line 29 of file automata_desc.cpp.

Referenced by CAutomataDesc(), and generateScript().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 06:43:53 2004 for NeL by doxygen 1.3.6