# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

logic_state_machine.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef LOGIC_STATE_MACHINE_H
00027 #define LOGIC_STATE_MACHINE_H
00028 
00029 #include "logic_state.h"
00030 #include "logic_variable.h"
00031 #include "logic_condition.h"
00032 
00033 #include "nel/misc/o_xml.h"
00034 #include "nel/misc/i_xml.h"
00035 
00036 #include "nel/net/service.h"
00037 
00038 #include <vector>
00039 #include <map>
00040 #include <string>
00041 
00042 
00043 namespace NLLOGIC
00044 {
00045 
00046 void xmlCheckNodeName (xmlNodePtr &node, const char *nodeName);
00047 std::string getXMLProp (xmlNodePtr node, const char *propName);
00048 
00056 class CLogicStateMachine
00057 {
00059         std::map<std::string, CLogicVariable> _Variables;
00060 
00062         std::map<std::string, CLogicCounter> _Counters;
00063 
00065         std::map<std::string, CLogicCondition> _Conditions;
00066 
00068         std::map<std::string, CLogicState> _States;
00069 
00071         std::string _CurrentState;
00072 
00074         std::string _Name;
00075         
00076 public:
00077         
00078         const std::map<std::string, CLogicVariable> &getVariables () { return _Variables; }
00079         const std::map<std::string, CLogicCounter> &getCounters () { return _Counters; }
00080         const std::map<std::string, CLogicCondition> &getConditions () { return _Conditions; }
00081         const std::map<std::string, CLogicState> &getStates () { return _States; }
00082 
00083 
00087         CLogicStateMachine() { _Name = "no_name"; }
00088 
00094         void setName( const std::string& name ) { _Name = name; }
00095 
00101         std::string getName() const { return _Name; }
00102 
00108         void setCurrentState( std::string stateName );
00109 
00115         void addSIdMap( const TSIdMap& sIdMap );
00116 
00120         void processLogic();
00121 
00127         void getSelfAddressedMessages( std::list<NLNET::CMessage>& msgs );
00128 
00134         void addVariable( CLogicVariable var ) { _Variables.insert( std::make_pair(var.getName(),var) ); }
00135 
00143         bool getVariable( std::string& varName, CLogicVariable& var );
00144 
00150         void addCounter( CLogicCounter counter ) { _Counters.insert( std::make_pair(counter.getName(),counter) ); }
00151 
00157         void addCondition( CLogicCondition condition );
00158 
00166         bool getCondition( const std::string& condName, CLogicCondition& cond );
00167 
00173         void getMessagesToSend( std::multimap<NLMISC::CEntityId,NLNET::CMessage>& msgs );
00174 
00180         void addState( CLogicState logicState );
00181 
00189         void modifyVariable( std::string varName, std::string modifOperator, sint64 value ); 
00190 
00194         //void serial( NLMISC::IStream &f ) throw(NLMISC::EStream);
00195 
00199         void displayVariables();
00200 
00204         void displayStates();
00205 
00212         void setVerbose( std::string varName, bool b );
00213 
00214         void write (xmlDocPtr doc) const;
00215         void read (xmlNodePtr node);
00216 };
00217 
00218 } // NLLOGIC
00219 
00220 #endif //LOGIC_SYSTEM
00221 
00222 
00223