# 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  

module.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 #ifndef NL_MODULE_H
00026 #define NL_MODULE_H
00027 
00028 namespace NLAISCRIPT
00029 {
00031         typedef std::map<NLAISCRIPT::CStringType , NLAIAGENT::IObjectIA * > tDicoStr;
00032 
00043         class IBlock: public NLAIC::IBasicInterface
00044         {
00045         public:         
00046                 static const NLAIC::CIdentType IdBlock;
00047 
00048         protected:
00050                 typedef std::map<NLAISCRIPT::CStringType , NLAIAGENT::IObjectIA *>::iterator tDicoStrIter;
00051                 
00052         private:
00054                 CCodeBrancheRun*                        _Cbr;
00056                 tListCode                                       _ListCode;
00058                 tDicoStr                                        *_DicoLocVar;
00060                 bool                                            _HaveToDeleteDico;
00061 
00062                 bool                                            _Debug;                         
00063                 bool                                            _FirstOpCodeInLine;     
00064                 uint16                                          _CurrentLine;           
00065 
00066 
00067         public:
00068 
00070                 IBlock(bool debugMode,tDicoStr *dico)
00071                 {
00072                         _Debug = debugMode;
00073                         _Cbr = NULL;
00074                         _FirstOpCodeInLine = true;
00075                         _CurrentLine = 0;
00076                         _HaveToDeleteDico = false;
00077                         _DicoLocVar = dico;
00078                 }
00079 
00080                 IBlock(bool debugMode)          
00081                 {
00082                         _Debug = debugMode;
00083                         _Cbr = NULL;
00084                         _FirstOpCodeInLine = true;
00085                         _CurrentLine = 0;
00086                         _HaveToDeleteDico = true;
00087                         _DicoLocVar = new tDicoStr;
00088                 }               
00089 
00090 
00091                 virtual ~IBlock()
00092                 {
00093                         while(_ListCode.size() != 0)
00094                         {
00095                                 ((IOpCode *)*_ListCode.front())->release();
00096                                 delete _ListCode.front();
00097                                 _ListCode.pop_front();
00098                         }
00099                         
00100                         if(_Cbr)  _Cbr->release();
00101                         tDicoStrIter it = _DicoLocVar->begin();
00102                         while(it != _DicoLocVar->end())
00103                         {
00104 #ifdef NL_DEBUG                         
00105                                 const NLAIAGENT::IObjectIA *o = (*it).second;
00106 #endif                                                          
00107                                 (*it).second->release();
00108                                 it ++;
00109                         }               
00110                         if(_HaveToDeleteDico) delete _DicoLocVar;
00111                         
00112                 }
00113 
00115                 NLAIAGENT::IObjectIA *getVar(const char *Name)
00116                 {
00117                         tDicoStr::iterator Itr = _DicoLocVar->find(NLAISCRIPT::CStringType(Name));
00118 
00119                         if(Itr != _DicoLocVar->end())
00120                         {
00121                                 return (*Itr).second;
00122                         }
00123                         
00124                         return NULL;
00125                 }
00126 
00127                 NLAIAGENT::IObjectIA *eraseVar(const char *Name)
00128                 {
00129                         tDicoStr::iterator Itr = _DicoLocVar->find(NLAISCRIPT::CStringType(Name));
00130 
00131                         if(Itr != _DicoLocVar->end())
00132                         {
00133                                 _DicoLocVar->erase(Itr);
00134                         }
00135                         
00136                         return NULL;
00137                 }
00138                 
00139 
00141                 tDicoStr *lockDictionarry()
00142                 {
00143                         _HaveToDeleteDico = false;
00144                         return _DicoLocVar;
00145                 }
00146 
00148                 bool allocLocVar(const char *name, NLAIAGENT::IObjectIA *var)
00149                 {
00150                         if(getVar(name) != NULL) return false;
00151                         _DicoLocVar->insert(tDicoStr::value_type(NLAISCRIPT::CStringType(name),var));           
00152                         return true;
00153                 }
00154 
00156                 CCodeBrancheRun *getCode()
00157                 {
00158                         if(/*_Cbr == NULL && */_ListCode.size())
00159                         {
00160                                 sint32 k = _ListCode.size();
00161                                 CCodeBrancheRun *cbr;
00162                                 cbr = new CCodeBrancheRun(k);                                                   
00163                                 for(sint32 i = 0; i < k; i++)
00164                                 {
00165                                         CBagOfCode *x = _ListCode.front();
00166                                         (*cbr)[i] = (IOpCode *)*x;
00167                                         x->setConstraintIndex(i,cbr);
00168                                         delete x;
00169                                         _ListCode.pop_front();
00170                                 }
00171                                 return cbr;
00172 
00173                         }               
00174                         return NULL;
00175                 }
00176 
00178                 CCodeBrancheRunDebug* getCodeDebug(IScriptDebugSource* sourceCode)
00179                 {
00180                         if(/*_Cbr == NULL && */_ListCode.size())
00181                         {
00182                                 sint32 k = _ListCode.size();
00183                                 CCodeBrancheRunDebug *cbr;
00184                                 cbr = new CCodeBrancheRunDebug(k, sourceCode);
00185 
00186                                 for(sint32 i = 0; i < k; i++)
00187                                 {
00188                                         CBagOfCode *x = _ListCode.front();
00189                                         (*cbr)[i] = (IOpCode *)*x;
00190                                         x->setConstraintIndex(i,cbr);
00191                                         delete x;
00192                                         _ListCode.pop_front();
00193                                 }
00194                                 return cbr;
00195 
00196                         }               
00197                         return NULL;
00198                 }
00199 
00201                 sint32 isCodeMonted()
00202                 {               
00203                         return _Cbr != NULL;
00204                 }
00205 
00207 
00208                 const NLAIC::IBasicType *clone() const
00209                 {
00210                         NLAIC::IBasicType *x = new IBlock(_Debug);
00211                         return x;
00212                 }
00213 
00214                 const NLAIC::IBasicType *newInstance() const 
00215                 {
00216                         return clone();
00217                 }
00218 
00219                 const NLAIC::CIdentType &getType() const
00220                 {
00221                         return IdBlock;
00222                 }
00223 
00224                 void getDebugString(std::string &) const
00225                 {
00226                 }
00227 
00228                 void save(NLMISC::IStream &os)
00229                 {                       
00230                 }
00231 
00232                 void load(NLMISC::IStream &is) 
00233                 {                       
00234                 }
00235                 const NLAIAGENT::IObjectIA::CProcessResult &run();
00236                 bool isEqual(const NLAIAGENT::IBasicObjectIA &a) const{ return true;}
00238 
00240                 tListCode &listCode()
00241                 {
00242                         return _ListCode;
00243                 }
00244 
00246                 void addCode(IOpCode *op)
00247                 {                       
00248                         //op->incRef();
00249                         CBagOfCode *x = new CBagOfCode(op);
00250                         _ListCode.push_back(x);
00251 
00252                         // Debug part
00253                         CConstraintDebug* pcdb;
00254                         if (_Debug && _FirstOpCodeInLine)
00255                         {
00256                                 pcdb = new CConstraintDebug(_CurrentLine, 1);
00257                                 x->addConstraint(pcdb);
00258                                 _FirstOpCodeInLine = false;
00259                         }
00260                 }       
00261 
00263 
00264                 void pushCode(IOpCode *op)
00265                 {                                               
00266                         _ListCode.push_back(new CBagOfCode(op));
00267                 }       
00268                 
00269                 IOpCode *getBack()
00270                 {                       
00271                         return (IOpCode *)*_ListCode.back();
00272                 }       
00273 
00274                 IOpCode *getFront()
00275                 {                       
00276                         return (IOpCode *)*_ListCode.front();
00277                 }       
00278 
00279                 void pushBagCode(CBagOfCode *bOp)
00280                 {
00281                         _ListCode.push_back(bOp);
00282                 }
00283 
00284                 CBagOfCode *getBagOfCode()
00285                 {                       
00286                         return _ListCode.back();
00287                 }       
00289 
00291                 void setCurrentLine (uint16 line)
00292                 {
00293                         _CurrentLine = line;
00294                 }
00295 
00297                 void setFirstOpCodeInLine (bool b)
00298                 {
00299                         _FirstOpCodeInLine = b;
00300                 }
00301         };
00302 }
00303 #endif