#include <logic_state_machine.h>
Nevrax France
Definition at line 56 of file logic_state_machine.h.
Public Member Functions | |
void | addCondition (CLogicCondition condition) |
void | addCounter (CLogicCounter counter) |
void | addSIdMap (const TSIdMap &sIdMap) |
void | addState (CLogicState logicState) |
void | addVariable (CLogicVariable var) |
CLogicStateMachine () | |
void | displayStates () |
void | displayVariables () |
bool | getCondition (const std::string &condName, CLogicCondition &cond) |
const std::map< std::string, CLogicCondition > & | getConditions () |
const std::map< std::string, CLogicCounter > & | getCounters () |
void | getMessagesToSend (std::multimap< NLMISC::CEntityId, NLNET::CMessage > &msgs) |
std::string | getName () const |
void | getSelfAddressedMessages (std::list< NLNET::CMessage > &msgs) |
const std::map< std::string, CLogicState > & | getStates () |
bool | getVariable (std::string &varName, CLogicVariable &var) |
const std::map< std::string, CLogicVariable > & | getVariables () |
void | modifyVariable (std::string varName, std::string modifOperator, sint64 value) |
void | processLogic () |
void | read (xmlNodePtr node) |
void | setCurrentState (std::string stateName) |
void | setName (const std::string &name) |
void | setVerbose (std::string varName, bool b) |
void | write (xmlDocPtr doc) const |
Private Attributes | |
std::map< std::string, CLogicCondition > | _Conditions |
conditions used in this state machine | |
std::map< std::string, CLogicCounter > | _Counters |
counters | |
std::string | _CurrentState |
name of the current state | |
std::string | _Name |
name of this sate machine | |
std::map< std::string, CLogicState > | _States |
states | |
std::map< std::string, CLogicVariable > | _Variables |
variables |
|
Default constructor Definition at line 87 of file logic_state_machine.h.
00087 { _Name = "no_name"; } |
|
Add a condition in the state machine
Definition at line 124 of file logic_state_machine.cpp. References _Conditions, and condition.
00125 { 00126 condition.setLogicStateMachine(this); 00127 _Conditions.insert(make_pair(condition.getName(),condition)); 00128 00129 } // addCondition // |
|
Add a counter in the state machine
Definition at line 150 of file logic_state_machine.h. References _Counters, and NLLOGIC::CLogicVariable::getName().
00150 { _Counters.insert( std::make_pair(counter.getName(),counter) ); } |
|
call the addSIdMap() method for each sate machines
Definition at line 151 of file logic_state_machine.cpp. References NLLOGIC::TSIdMap.
|
|
Add a state to the state machine
Definition at line 137 of file logic_state_machine.cpp. References NLLOGIC::CLogicState::getName(), and NLLOGIC::CLogicState::setLogicStateMachine().
00138 { 00139 logicState.setLogicStateMachine( this ); 00140 _States.insert( std::make_pair(logicState.getName(),logicState) ); 00141 00142 } // addState // |
|
Add a variable in the state machine
Definition at line 134 of file logic_state_machine.h. References _Variables, and NLLOGIC::CLogicVariable::getName().
00134 { _Variables.insert( std::make_pair(var.getName(),var) ); } |
|
Display the states Definition at line 381 of file logic_state_machine.cpp. References nlinfo.
00382 { 00383 nlinfo("There are %d STATES in the state machine \"%s\": ",_States.size(),_Name.c_str()); 00384 map<string, CLogicState>::const_iterator itS; 00385 for( itS = _States.begin(); itS != _States.end(); ++itS ) 00386 { 00387 nlinfo("%s",(*itS).first.c_str()); 00388 } 00389 nlinfo("The current state is : \"%s\"",_CurrentState.c_str()); 00390 00391 } // displayStates // |
|
Display the variables Definition at line 316 of file logic_state_machine.cpp. References _Variables, nlinfo, NLMISC::CEntityId::setCreatorId(), NLMISC::CEntityId::setDynamicId(), NLMISC::CEntityId::setType(), and uint8.
00317 { 00318 multimap<CEntityId,string> allVariables; 00319 00320 // // get vars referenced in the states 00321 map<string, CLogicState>::iterator itS; 00322 for( itS = _States.begin(); itS != _States.end(); ++itS ) 00323 { 00324 (*itS).second.fillVarMap( allVariables ); 00325 } 00326 00327 // extract the unclaimed variables from all the variables 00328 vector<string> unclaimedVariables; 00329 CEntityId unknown; 00330 unknown.setType( 0xfe ); 00331 unknown.setCreatorId( 0 ); 00332 unknown.setDynamicId( 0 ); 00333 pair<multimap<CEntityId,string>::iterator,multimap<CEntityId,string>::iterator> itVarsRng = allVariables.equal_range(unknown); 00334 multimap<CEntityId,string>::iterator itVars; 00335 00336 for( itVars = itVarsRng.first; itVars != itVarsRng.second; ) 00337 { 00338 multimap<CEntityId,string>::iterator itDel = itVars++; 00339 unclaimedVariables.push_back( (*itDel).second ); 00340 allVariables.erase( itDel ); 00341 } 00342 /* 00343 if( itVarsRng.first != allVariables.end() ) 00344 { 00345 itVars = itVarsRng.first; 00346 do 00347 { 00348 multimap<CEntityId,string>::iterator itDel = itVars++; 00349 unclaimedVariables.push_back( (*itDel).second ); 00350 allVariables.erase( itDel ); 00351 } 00352 while( itVars != itVarsRng.second ); 00353 } 00354 */ 00355 00356 00357 nlinfo("VARIABLES/COUNTERS in %s : %d/%d are registered : ",_Name.c_str(),allVariables.size(),allVariables.size()+unclaimedVariables.size()); 00358 // display the registered variables 00359 for( itVars = allVariables.begin(); itVars != allVariables.end(); ++itVars ) 00360 { 00361 map<string, CLogicVariable>::const_iterator itV = _Variables.find( (*itVars).second ); 00362 nlinfo("[%d] %s = %f",(uint8)(*itVars).first.getDynamicId(),(*itV).first.c_str(),(double)(*itV).second.getValue()); 00363 } 00364 00365 // display the unclaimed variables 00366 sort( unclaimedVariables.begin(), unclaimedVariables.end() ); 00367 vector<string>::iterator itUV; 00368 for( itUV = unclaimedVariables.begin(); itUV != unclaimedVariables.end(); ++itUV ) 00369 { 00370 map<string, CLogicVariable>::const_iterator itV = _Variables.find( *itUV ); 00371 nlinfo("(-)%s = %f",(*itV).first.c_str(),(double)(*itV).second.getValue()); 00372 } 00373 00374 } // displayVariables // |
|
Get the condition
Definition at line 233 of file logic_state_machine.cpp. References _Conditions. Referenced by NLLOGIC::CLogicState::fillVarMap(), NLLOGIC::CLogicConditionLogicBlock::fillVarSet(), NLLOGIC::CLogicEvent::testCondition(), and NLLOGIC::CLogicConditionLogicBlock::testLogic().
00234 { 00235 map<string,CLogicCondition>::iterator itCond = _Conditions.find( condName ); 00236 if( itCond != _Conditions.end() ) 00237 { 00238 cond = (*itCond).second; 00239 return true; 00240 } 00241 else 00242 { 00243 return false; 00244 } 00245 00246 } // getCondition // |
|
Definition at line 80 of file logic_state_machine.h. References _Conditions.
00080 { return _Conditions; } |
|
Definition at line 79 of file logic_state_machine.h. References _Counters.
00079 { return _Counters; } |
|
Get the messages to send
Definition at line 190 of file logic_state_machine.cpp.
|
|
Get the state machine name
Definition at line 101 of file logic_state_machine.h. Referenced by NLLOGIC::CLogicConditionLogicBlock::testLogic().
00101 { return _Name; } |
|
Get the self-addressed message
|
|
Definition at line 81 of file logic_state_machine.h.
00081 { return _States; } |
|
Get the variable
Definition at line 207 of file logic_state_machine.cpp. References _Counters, and _Variables. Referenced by NLLOGIC::CLogicComparisonBlock::testLogic().
00208 { 00209 map<string,CLogicVariable>::iterator itVar = _Variables.find( varName ); 00210 if( itVar != _Variables.end() ) 00211 { 00212 var = (*itVar).second; 00213 return true; 00214 } 00215 00216 map<string,CLogicCounter>::iterator itCount = _Counters.find( varName ); 00217 if( itCount != _Counters.end() ) 00218 { 00219 var = (*itCount).second; 00220 return true; 00221 } 00222 00223 return false; 00224 00225 } // getVariable // |
|
Definition at line 78 of file logic_state_machine.h. References _Variables.
00078 { return _Variables; } |
|
modify a variable
Definition at line 253 of file logic_state_machine.cpp. References _Counters, _Variables, nlwarning, sint64, and value.
00254 { 00255 map<string,CLogicVariable>::iterator itVar = _Variables.find( varName ); 00256 if( itVar != _Variables.end() ) 00257 { 00258 (*itVar).second.applyModification( modifOperator, value ); 00259 return; 00260 } 00261 map<string,CLogicCounter>::iterator itCount = _Counters.find( varName ); 00262 if( itCount != _Counters.end() ) 00263 { 00264 (*itCount).second.applyModification( modifOperator, value ); 00265 return; 00266 } 00267 00268 nlwarning("(LOGIC)<CLogicStateMachine::modifyVariable> The variable \"%s\" is not in the state machine \"%s\"",varName.c_str(),_Name.c_str()); 00269 00270 } // modifyVariable // |
|
call the processLogic method for each sate machines Definition at line 168 of file logic_state_machine.cpp. References _Counters, and nlassert.
00169 { 00170 // call processLogic for the current state 00171 map<string,CLogicState>::iterator itStates = _States.find( _CurrentState ); 00172 nlassert( itStates != _States.end() ); 00173 (*itStates).second.processLogic(); 00174 00175 // update the counters 00176 map<string,CLogicCounter>::iterator itCount; 00177 for( itCount = _Counters.begin(); itCount != _Counters.end(); ++itCount ) 00178 { 00179 (*itCount).second.update(); 00180 } 00181 00182 } // processLogic // |
|
Definition at line 571 of file logic_state_machine.cpp. References _Conditions, _Counters, _Variables, NLLOGIC::getXMLProp(), setCurrentState(), setName(), uint, v, and NLLOGIC::xmlCheckNodeName().
00572 { 00573 xmlCheckNodeName (node, "STATE_MACHINE"); 00574 00575 setName (getXMLProp (node, "Name")); 00576 00577 { 00578 // Count the parent 00579 uint nb = CIXml::countChildren (node, "VARIABLE"); 00580 uint i = 0; 00581 xmlNodePtr parent = CIXml::getFirstChildNode (node, "VARIABLE"); 00582 while (i<nb) 00583 { 00584 CLogicVariable v; 00585 v.read(parent); 00586 _Variables.insert (make_pair(v.getName(), v)); 00587 00588 // Next parent 00589 parent = CIXml::getNextChildNode (parent, "VARIABLE"); 00590 i++; 00591 } 00592 } 00593 00594 { 00595 // Count the parent 00596 uint nb = CIXml::countChildren (node, "COUNTER"); 00597 uint i = 0; 00598 xmlNodePtr parent = CIXml::getFirstChildNode (node, "COUNTER"); 00599 while (i<nb) 00600 { 00601 CLogicCounter v; 00602 v.read(parent); 00603 _Counters.insert (make_pair(v.getName(), v)); 00604 00605 // Next parent 00606 parent = CIXml::getNextChildNode (parent, "COUNTER"); 00607 i++; 00608 } 00609 } 00610 00611 { 00612 // Count the parent 00613 uint nb = CIXml::countChildren (node, "CONDITION"); 00614 uint i = 0; 00615 xmlNodePtr parent = CIXml::getFirstChildNode (node, "CONDITION"); 00616 while (i<nb) 00617 { 00618 CLogicCondition v; 00619 v.read(parent); 00620 _Conditions.insert (make_pair(v.getName(), v)); 00621 00622 // Next parent 00623 parent = CIXml::getNextChildNode (parent, "CONDITION"); 00624 i++; 00625 } 00626 } 00627 00628 { 00629 // Count the parent 00630 uint nb = CIXml::countChildren (node, "STATE"); 00631 uint i = 0; 00632 xmlNodePtr parent = CIXml::getFirstChildNode (node, "STATE"); 00633 while (i<nb) 00634 { 00635 CLogicState v; 00636 v.read(parent); 00637 _States.insert (make_pair(v.getName(), v)); 00638 00639 // Next parent 00640 parent = CIXml::getNextChildNode (parent, "STATE"); 00641 i++; 00642 } 00643 } 00644 00645 setCurrentState (getXMLProp (node, "CurrentState")); 00646 } |
|
Set the current state
Definition at line 98 of file logic_state_machine.cpp. References nlinfo, and nlwarning. Referenced by NLLOGIC::CLogicState::processLogic(), and read().
00099 { 00100 map<string,CLogicState>::iterator itStates = _States.find( stateName ); 00101 if( itStates != _States.end() ) 00102 { 00103 (*itStates).second.exitState(); 00104 00105 _CurrentState = stateName; 00106 00107 (*itStates).second.enterState(); 00108 00109 nlinfo("Switching to state \"%s\"",_CurrentState.c_str()); 00110 } 00111 else 00112 { 00113 nlwarning("(LOGIC)<CLogicStateMachine::setCurrentState> The state \"%s\" is not in the state machine \"%s\"",stateName.c_str(),_Name.c_str()); 00114 } 00115 00116 } // setCurrentState // |
|
Set the state machine name
Definition at line 94 of file logic_state_machine.h. Referenced by read().
00094 { _Name = name; } |
|
Set the verbose mode for a variable
Definition at line 398 of file logic_state_machine.cpp. References _Counters, _Variables, nlinfo, sint8, and NLLOGIC::testNameWithFilter().
00399 { 00400 if( varName == "all" ) 00401 { 00402 map<string, CLogicVariable>::iterator itV; 00403 for( itV = _Variables.begin(); itV != _Variables.end(); ++itV ) 00404 { 00405 (*itV).second.setVerbose( b ); 00406 } 00407 map<string, CLogicCounter>::iterator itC; 00408 for( itC = _Counters.begin(); itC != _Counters.end(); ++itC ) 00409 { 00410 (*itC).second.setVerbose( b ); 00411 } 00412 if(b) 00413 { 00414 nlinfo("the verbose mode has been activated for all the variables",varName.c_str()); 00415 } 00416 else 00417 { 00418 nlinfo("the verbose mode has been desactivated for all the variables",varName.c_str()); 00419 } 00420 return; 00421 } 00422 00423 sint8 filter = -1; 00424 string motif; 00425 // *xxx* => we look for a string with xxx inside 00426 if( varName[0]=='*' && varName[varName.size()-1]=='*') 00427 { 00428 motif = varName.substr(1,varName.size()-2); 00429 filter = 0; 00430 } 00431 else 00432 // *xxx => we look for a string with xxx at the end 00433 if( varName[0]=='*' ) 00434 { 00435 motif = varName.substr(1,varName.size()-1); 00436 filter = 1; 00437 } 00438 else 00439 // xxx* => we look for a string with xxx at the begining 00440 if( varName[varName.size()-1]=='*' ) 00441 { 00442 motif = varName.substr(0,varName.size()-1); 00443 filter = 2; 00444 } 00445 00446 // if no filter 00447 if( filter == -1 ) 00448 { 00449 map<string, CLogicVariable>::iterator itV = _Variables.find( varName ); 00450 if( itV != _Variables.end() ) 00451 { 00452 (*itV).second.setVerbose( b ); 00453 } 00454 map<string, CLogicCounter>::iterator itC = _Counters.find( varName ); 00455 if( itC != _Counters.end() || varName =="all" ) 00456 { 00457 (*itC).second.setVerbose( b ); 00458 } 00459 } 00460 // if filter 00461 else 00462 { 00463 map<string, CLogicVariable>::iterator itV; 00464 for( itV = _Variables.begin(); itV != _Variables.end(); ++itV ) 00465 { 00466 if( testNameWithFilter( filter, motif,(*itV).second.getName()) ) 00467 { 00468 (*itV).second.setVerbose( b ); 00469 } 00470 } 00471 map<string, CLogicCounter>::iterator itC; 00472 for( itC = _Counters.begin(); itC != _Counters.end(); ++itC ) 00473 { 00474 if( testNameWithFilter( filter, motif,(*itC).second.getName()) ) 00475 { 00476 (*itC).second.setVerbose( b ); 00477 } 00478 } 00479 } 00480 if(b) 00481 { 00482 nlinfo("the verbose mode for variable \"%s\" has been activated",varName.c_str()); 00483 } 00484 else 00485 { 00486 nlinfo("the verbose mode for variable \"%s\" has been desactivated",varName.c_str()); 00487 } 00488 00489 } // setVerbose // |
|
Definition at line 542 of file logic_state_machine.cpp. References _Conditions, _Counters, and _Variables.
00543 { 00544 // Create the first node 00545 xmlNodePtr node = xmlNewDocNode (doc, NULL, (const xmlChar*)"STATE_MACHINE", NULL); 00546 xmlDocSetRootElement (doc, node); 00547 xmlSetProp (node, (const xmlChar*)"Name", (const xmlChar*)_Name.c_str()); 00548 xmlSetProp (node, (const xmlChar*)"CurrentState", (const xmlChar*)_CurrentState.c_str()); 00549 00550 for (std::map<std::string, CLogicVariable>::const_iterator vit = _Variables.begin(); vit != _Variables.end(); vit++) 00551 { 00552 (*vit).second.write(node); 00553 } 00554 00555 for (std::map<std::string, CLogicCounter>::const_iterator cit = _Counters.begin(); cit != _Counters.end(); cit++) 00556 { 00557 (*cit).second.write(node); 00558 } 00559 00560 for (std::map<std::string, CLogicCondition>::const_iterator c2it = _Conditions.begin(); c2it != _Conditions.end(); c2it++) 00561 { 00562 (*c2it).second.write(node); 00563 } 00564 00565 for (std::map<std::string, CLogicState>::const_iterator sit = _States.begin(); sit != _States.end(); sit++) 00566 { 00567 (*sit).second.write(node); 00568 } 00569 } |
|
conditions used in this state machine
Definition at line 65 of file logic_state_machine.h. Referenced by addCondition(), getCondition(), getConditions(), read(), and write(). |
|
counters
Definition at line 62 of file logic_state_machine.h. Referenced by addCounter(), getCounters(), getVariable(), modifyVariable(), processLogic(), read(), setVerbose(), and write(). |
|
name of the current state
Definition at line 71 of file logic_state_machine.h. |
|
name of this sate machine
Definition at line 74 of file logic_state_machine.h. |
|
states
Definition at line 68 of file logic_state_machine.h. |
|
variables
Definition at line 59 of file logic_state_machine.h. Referenced by addVariable(), displayVariables(), getVariable(), getVariables(), modifyVariable(), read(), setVerbose(), and write(). |