# 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  

agent_object.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_AGENT_OBJECT_DEF_H
00026 #define NL_AGENT_OBJECT_DEF_H
00027 
00028 
00029 #include "nel/ai/agent/agent_string.h"
00030 #include "nel/ai/agent/agent_operator.h"
00031 
00032 
00033 namespace NLAIAGENT
00034 {                       
00035 
00043         class CStringType: public IObjetOp
00044         {
00045         private:                
00046                 IVarName *_Str;                                 
00047 
00048         public:
00049                 static const NLAIC::CIdentType IdStringType;
00050         public:
00051                 CStringType(const IVarName &str): _Str((IVarName *)str.clone())
00052                 {                       
00053                 }
00054 
00055                 CStringType(const CStringType &a): _Str((IVarName *)a._Str->clone())
00056                 {                       
00057                 }               
00058 
00059                 CStringType(NLMISC::IStream &is)
00060                 {
00061                         load(is);
00062                 }
00063                 
00064                 virtual const NLAIC::IBasicType *clone() const
00065                 {
00066                         NLAIC::IBasicInterface *m = new CStringType(*this);
00067                         return m;
00068                 }               
00069 
00070                 virtual const NLAIC::IBasicType *newInstance() const
00071                 {
00072                         return clone();
00073                 }
00074                 
00075                 virtual const NLAIC::CIdentType &getType() const;               
00076 
00077                 virtual void save(NLMISC::IStream &os)
00078                 {                       
00079                         os.serial( (NLAIC::CIdentType &) ( _Str->getType() ) );
00080                         _Str->save(os);
00081                 }
00082 
00083                 virtual void load(NLMISC::IStream &is)
00084                 {                       
00085                         NLAIC::CIdentTypeAlloc id;
00086                         is.serial( id );
00087                         _Str->release();
00088                         _Str = (IVarName *)id.allocClass();                     
00089                         _Str->load(is);                 
00090                 }
00091 
00092                 virtual void getDebugString(char *text) const
00093                 {
00094                         sprintf(text,"%s",_Str->getString());
00095                 }
00096 
00097                 const IVarName & getStr() const
00098                 {
00099                         return *_Str;
00100                 }
00101 
00103 
00104                 virtual IObjetOp &operator += (const IObjetOp &a);              
00105                 virtual IObjetOp &operator -= (const IObjetOp &a);              
00106                 virtual IObjetOp *operator < (IObjetOp &a) const;
00107                 virtual IObjetOp *operator > (IObjetOp &a) const;
00108                 virtual IObjetOp *operator <= (IObjetOp &a) const;      
00109                 virtual IObjetOp *operator >= (IObjetOp &a) const;      
00110                 virtual IObjetOp *operator != (IObjetOp &a) const;
00112 
00113 
00114                 virtual bool operator < (const CStringType &a) const;
00115 
00116 
00117                 virtual bool isTrue() const
00118                 {
00119                         return IObjetOp::isTrue();
00120                 }
00121                 
00122                 virtual ~CStringType()
00123                 {       
00124                         _Str->release();
00125                 }       
00126                 
00127                 virtual bool isEqual(const IBasicObjectIA &a) const
00128                 {
00129                         const CStringType &t = (const CStringType &)a;
00130                         return *t._Str == *_Str;
00131                 }
00132                         
00133 
00134                 virtual const CProcessResult &run();            
00135         };
00136 
00137                 
00138 
00139         /*
00140         class CPaireType: public IObjetOp
00141         {
00142         private:                
00143                 CStringType     _ValueName;
00144                 IObjectIA *_Value;              
00145 
00146         public:
00147                 static const NLAIC::CIdentType IdPaireType;
00148                 
00149         public:
00150                 CPaireType(const CStringType &valueName,const IObjectIA &value): 
00151                   _ValueName(valueName),_Value((IObjectIA *)value.clone())
00152                 {                       
00153                 }
00154 
00155                 CPaireType(const CPaireType &a): _ValueName(a._ValueName),_Value((IObjectIA *)a._Value->clone())
00156                 {
00157                 }                               
00158 
00159                 virtual const NLAIC::IBasicType *clone() const
00160                 {
00161                         NLAIC::IBasicInterface *m = new CPaireType(*this);
00162                         return m;
00163                 }
00164 
00165                 virtual const NLAIC::IBasicType *newInstance() const
00166                 {
00167                         return clone();
00168                 }
00169                 
00170                 virtual const NLAIC::CIdentType &getType() const;
00171                 
00172 
00173                 virtual void save(NLMISC::IStream &os)
00174                 {                                               
00175                         _ValueName.save(os);
00176                         os.serial( (NLAIC::CIdentType &) (_Value->getType()) );
00177                         _Value->save(os);                       
00178                 }
00179 
00180                 virtual void load(NLMISC::IStream &is)
00181                 {                                               
00182                         _ValueName.load(is);
00183                         _Value->release();
00184                         NLAIC::CIdentTypeAlloc id;
00185                         is.serial(id);
00186                         _Value = (IObjectIA *)id.allocClass();
00187                         _Value->load(is);                       
00188                 }
00189 
00190                 virtual const CProcessResult &run();
00191 
00192                 virtual void getDebugString(char *text) const;          
00193 
00194                 virtual bool isTrue() const
00195                 {
00196                         return IObjetOp::isTrue();
00197                 }
00198                 
00199 
00200                 operator const IObjectIA *() const
00201                 {
00202                         return _Value;
00203                 }
00204 
00205                 operator const CStringType& ()
00206                 {
00207                         return _ValueName;
00208 
00209                 }
00210                 virtual ~CPaireType()
00211                 {                       
00212                         _Value->release();
00213                 }       
00214 
00215                 virtual bool isEqual(const IBasicObjectIA &a) const
00216                 {
00217                         const CPaireType &t = (const CPaireType &)a;
00218                         if(((IObjectIA &)t._ValueName) == ((IObjectIA &)_ValueName)) return t._Value == _Value;
00219                         return false;
00220                 }
00221         };
00222         */
00223 
00234         class IBasicIterator
00235         {
00236         public:
00237                 virtual const IObjetOp* operator ++ (int) = 0;
00238                 virtual const IObjetOp* operator -- (int) = 0;
00239                 virtual operator const IObjetOp*() const = 0;           
00240                 virtual bool isInEnd() const = 0;
00241                 virtual bool isInBegin() const = 0;
00242         };
00243 
00251         template<class typeClass>
00252         class CTemplateIterator: public IBasicIterator
00253         {
00254         private:
00255                 typename typeClass::const_iterator _I;
00256                 const typeClass &_ListType;
00257                 
00258         public:
00259                 CTemplateIterator(const typeClass &l):_I(l.begin()),_ListType(l)
00260                 {
00261                 }
00262                 ~CTemplateIterator()
00263                 {
00264                 }
00265 
00266                 virtual const IObjetOp* operator ++ (int) 
00267                 {
00268                         return (const IObjetOp*)*_I++;
00269                 }
00270                 virtual const IObjetOp* operator -- (int)
00271                 {
00272                         return (const IObjetOp*)*_I--;
00273                 }
00274 
00275                 virtual operator const IObjetOp *() const
00276                 {
00277                         return (const IObjetOp *)*_I;
00278                 }               
00279 
00280                 virtual bool isInEnd() const
00281                 {
00282                         
00283                         return _I == _ListType.end();
00284                 
00285                 }
00286                 virtual bool isInBegin() const
00287                 {
00288                         return _I == _ListType.begin();
00289                 }
00290         };
00291 
00300         class CListIterator: public CTemplateIterator<std::list<const IObjectIA *> >
00301         {
00302         public:
00303                 CListIterator(const std::list<const IObjectIA *> &l):
00304                   CTemplateIterator<std::list<const IObjectIA *> >(l)
00305                   {
00306                   }
00307 
00308         };
00309         
00317         class CVectorIterator: public CTemplateIterator<std::vector<const IObjectIA *> >
00318         {
00319         public:
00320                 CVectorIterator(const std::vector<const IObjectIA *>&l):
00321                   CTemplateIterator<std::vector<const IObjectIA *> >(l)
00322                   {
00323                   }
00324 
00325         };
00326 
00335         class CIteratorContener: public IBasicIterator
00336         {
00337         private:
00338                 IBasicIterator *_I;
00339         public:
00340                 CIteratorContener(IBasicIterator *i):_I(i)
00341                 {
00342                 }
00343                 ~CIteratorContener()
00344                 {
00345                         delete _I;
00346                 }
00347 
00348                 virtual const IObjetOp*operator ++ (int) 
00349                 {
00350                         const IObjetOp *a = (*_I)++;                       
00351                         return a;
00352                 }
00353                 virtual const IObjetOp*operator -- (int)
00354                 {
00355                         const IObjetOp *a = (*_I) --;                      
00356                         return a;
00357                 }
00358 
00359                 virtual operator const IObjetOp*() const
00360                 {
00361                         return (const IObjetOp *)*_I;
00362                 }               
00363                 
00364                 virtual bool isInEnd() const 
00365                 {                       
00366                         return _I->isInEnd();
00367                 }
00368                 virtual bool isInBegin() const
00369                 {
00370                         return _I->isInBegin();
00371                 }
00372         };
00373         
00382         class IBaseGroupType: public IObjetOp
00383         {
00384 
00385         public:
00386                 struct CMethodCall
00387                 {
00388                         CMethodCall(const char *name, int i): MethodName (name)
00389                         {                               
00390                                 Index = i;
00391                         }
00392                         CStringVarName MethodName;
00393                         sint32 Index;
00394                 };
00395                 static CMethodCall _Method[];   
00396 
00397         public:         
00398 
00399                 IBaseGroupType(const IBaseGroupType &c):IObjetOp(c){}           
00400                 IBaseGroupType();
00401                 virtual ~IBaseGroupType();
00402                 
00404 
00405                 virtual IObjetOp &operator += (const IObjetOp &a) = 0;
00406                 virtual IObjetOp &operator -= (const IObjetOp &a) = 0;
00407                 virtual IObjetOp *operator + (const IObjetOp &a)  const
00408                 {
00409                         IObjetOp *o = (IObjetOp *)clone();                      
00410                         *o += a;
00411                         return o;
00412                 }
00413                 virtual IObjetOp *operator - (const IObjetOp &a)  const
00414                 {
00415                         IObjetOp *o = (IObjetOp *)clone();
00416                         *o -= a;
00417                         return o;
00418                 }
00419                 virtual IObjetOp *operator ! () const = 0;
00420                 virtual bool isTrue() const;
00422 
00424 
00425                 virtual sint32 getMethodIndexSize() const;
00426                 virtual sint32 isClassInheritedFrom(const IVarName &) const;
00427                 virtual tQueue isMember(const IVarName *,const IVarName *,const IObjectIA &) const;
00428                 virtual CProcessResult runMethodeMember(sint32, sint32, IObjectIA *);
00429                 virtual CProcessResult runMethodeMember(sint32 index,IObjectIA *);
00431                 
00433 
00434                 virtual IObjectIA &operator = (const IObjectIA &a) = 0;
00435                 virtual const IObjectIA *operator[] (sint32) const= 0;
00436                 
00438                 virtual void set(int,IObjectIA *) = 0;          
00439                 
00441                 virtual void push(const IObjectIA *o) = 0;
00443                 virtual void pushFront(const IObjectIA *o) = 0;
00445                 virtual void cpy(const IObjectIA &o) = 0;
00447                 virtual CIteratorContener getIterator() const = 0;
00448 
00450                 virtual const IObjectIA *pop() = 0;
00452                 virtual const IObjectIA *popFront() = 0;
00454                 virtual const IObjectIA *get() const = 0;               
00456                 virtual const IObjectIA *getFront() const = 0;
00458                 virtual sint32 size() const = 0;
00459 
00461                 virtual const IObjectIA *find(const IObjectIA &obj) const = 0;
00462                 
00463                 //virtual void eraseFirst(const IObjectIA &) = 0;
00465                 virtual void eraseAll(const IObjectIA &) = 0; 
00467                 virtual void erase(const IObjectIA *) = 0; 
00469                 virtual void erase(const IObjectIA &) = 0;
00471                 virtual void erase(std::list<const IObjectIA *> &) = 0;
00473                 virtual void clear() = 0;
00475         };
00484         class CGroupType: public IBaseGroupType
00485         {
00486 
00487         public:
00488                 static const NLAIC::CIdentType IdGroupType;
00489                 
00490         public:
00491                 //typedef of the std::list constainer
00492                 typedef std::list<const IObjectIA *> tListType;
00493         public:                         
00495                 tListType _List;
00496 
00497         protected:
00498 
00499                 tListType &getList();
00500 
00501         public:
00502                 CGroupType();
00503                 CGroupType(const CGroupType &g);
00504 
00505                 virtual void getDebugString(char *text) const;
00506 
00507                 virtual const CProcessResult &run();
00508 
00509                 virtual IObjetOp &operator += (const IObjetOp &a);
00510                 virtual IObjetOp &operator -= (const IObjetOp &a);
00511                 virtual IObjectIA &operator = (const IObjectIA &a);
00512 
00513                 virtual const IObjectIA *operator[] (sint32) const;
00514 
00515                 virtual void set(int,IObjectIA *);
00516 
00517                 virtual CIteratorContener getIterator() const
00518                 {
00519                         return CIteratorContener(new CListIterator(_List));
00520                 }
00521 
00522 //              virtual bool isTrue() const;
00523 
00524                 IObjetOp *CGroupType::operator ! () const;
00525                 void push(const IObjectIA *o);
00526                 void pushFront(const IObjectIA *o);
00527                 void cpy(const IObjectIA &o);
00528                 const IObjectIA *pop();
00529                 const IObjectIA *get() const;
00530                 const IObjectIA *popFront();
00531                 const IObjectIA *getFront() const;
00532                 sint32 size() const;
00533                 tListType findList(const IObjectIA &obj) const;
00534                 tListType::const_iterator getBegin() const;
00535                 tListType::const_iterator getEnd() const;
00536                 tListType::iterator getBegin();
00537                 tListType::iterator getEnd();
00538                 const IObjectIA *find(const IObjectIA &obj) const;              
00539                 void eraseAll(const IObjectIA &obj); 
00540                 void erase(const IObjectIA *o); 
00541                 void erase(const IObjectIA &obj);
00542                 void erase(std::list<const IObjectIA *> &l);
00543                 virtual bool isEqual(const IBasicObjectIA &a) const;
00544                 virtual const NLAIC::IBasicType *clone() const;
00545                 virtual const NLAIC::IBasicType *newInstance() const;
00546                 virtual const NLAIC::CIdentType &getType() const;               
00547                 virtual void save(NLMISC::IStream &os);
00548                 virtual IObjetOp &neg();
00549                 virtual void load(NLMISC::IStream &is);
00550                 void clear();
00551 
00552                 virtual ~CGroupType();
00553         };
00554 
00563         class CVectorGroupType: public IBaseGroupType
00564         {
00565 
00566         public:
00567                 static const NLAIC::CIdentType IdVectorGroupType;
00568                 
00569         public:
00570                 //typedef of the std::vector constainer
00571                 typedef std::vector<const IObjectIA *> tVectorType;
00572         private:                                
00574                 tVectorType _Vector;            
00575 
00576         protected:
00577                 tVectorType &getVector();
00578 
00579         public:
00580                 CVectorGroupType(sint32 );
00581                 CVectorGroupType();
00582                 CVectorGroupType(const CVectorGroupType &g);
00583 
00584                 virtual void getDebugString(char *text) const;
00585 
00586                 virtual const CProcessResult &run();
00587 
00588                 virtual IObjetOp &operator += (const IObjetOp &a);
00589                 virtual IObjetOp &operator -= (const IObjetOp &a);
00590                 virtual IObjectIA &operator = (const IObjectIA &a);
00591 
00592                 virtual const IObjectIA *operator[] (sint32) const;
00593 
00594                 virtual void set(int,IObjectIA *);
00595 
00596                 // virtual bool isTrue() const;
00597 
00598                 IObjetOp *CVectorGroupType::operator ! () const;
00599                 void push(const IObjectIA *o);
00600                 void pushFront(const IObjectIA *o);
00601                 virtual CIteratorContener getIterator() const
00602                 {
00603                         return CIteratorContener(new CVectorIterator(_Vector));
00604                 }
00605 
00606                 void setObject(sint32 i,IObjectIA *a)
00607                 {
00608                         _Vector[i] = a;
00609                 }
00610 
00611                 void cpy(const IObjectIA &o);
00612                 const IObjectIA *pop();
00613                 const IObjectIA *get() const;
00614                 const IObjectIA *popFront();
00615                 const IObjectIA *getFront() const;
00616                 sint32 size() const;
00617                 tVectorType findList(const IObjectIA &obj) const;
00618                 tVectorType::const_iterator getBegin() const;
00619                 tVectorType::const_iterator getEnd() const;
00620                 tVectorType::iterator getBegin();
00621                 tVectorType::iterator getEnd();
00622                 const IObjectIA *find(const IObjectIA &obj) const;              
00623                 void eraseAll(const IObjectIA &obj); 
00624                 void erase(const IObjectIA *o); 
00625                 void erase(const IObjectIA &obj);
00626                 void erase(std::list<const IObjectIA *> &l);
00627                 virtual bool isEqual(const IBasicObjectIA &a) const;
00628                 virtual const NLAIC::IBasicType *clone() const;
00629                 virtual const NLAIC::IBasicType *newInstance() const;
00630                 virtual const NLAIC::CIdentType &getType() const;               
00631                 virtual void save(NLMISC::IStream &os);
00632                 virtual IObjetOp &neg();
00633                 virtual void load(NLMISC::IStream &is);
00634                 void clear();
00635 
00636                 virtual sint32 getMethodIndexSize() const;
00637                 virtual tQueue isMember(const IVarName *,const IVarName *,const IObjectIA &) const;
00638                 virtual CProcessResult runMethodeMember(sint32, sint32, IObjectIA *);
00639                 virtual CProcessResult runMethodeMember(sint32 index,IObjectIA *);
00640 
00641                 virtual ~CVectorGroupType();
00642         };
00643 }
00644 #endif