# 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  

baseai.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 NL_BASEIA_H
00027 #define NL_BASEIA_H
00028 #include <iostream.h>
00029 #include <fstream.h>
00030 #include <vector>
00031 
00032 #include <queue>
00033 
00034 #include "nel/ai/agent/ident.h"
00035 
00036 
00040 namespace NLAIAGENT
00041 {
00042 
00043 
00050         enum TProcessStatement {
00051                 processIdle,    
00052                 processLocked,  
00053                 processBuzzy,   
00054                 processEnd,             
00055                 processToKill,  
00056                 processPresKill, 
00057                 processNotComplete,
00058                 processError    
00059         };
00060 
00068         template <class T>
00069         bool eraseFromList(std::list<T> *l,T a)
00070         {
00071                 typedef typename std::list<T>::iterator TIterator;
00072                 TIterator i = l->begin();
00073                 while(i != l->end())
00074                 {               
00075                         TIterator j = i++;
00076                         if(*j == a)
00077                         {
00078                                 l->erase(j);
00079                                 return true;
00080                         }                       
00081                 }
00082                 return false;
00083         }
00084         
00092         class IBasicObjectIA : public NLAIC::IBasicInterface
00093         {
00094                 public:
00095                         IBasicObjectIA();
00096                         IBasicObjectIA(const IBasicObjectIA &a);
00097                 
00102                         bool operator == (const IBasicObjectIA &classType) const;
00103 
00108                         virtual bool isEqual(const IBasicObjectIA &a) const = 0;
00109                         virtual ~IBasicObjectIA();
00110         };
00111         
00112         class IBaseGroupType;
00113         class IBasicType;
00114         class IObjectIA;
00115         class IMessageBase;
00116         
00117         struct CIdMethod
00118         {
00120                 sint32 Index;
00122                 double Weight;
00124                 IObjectIA *Method;
00126                 IObjectIA *ReturnType;
00127 
00128                 CIdMethod(const CIdMethod &a);          
00129                 
00130                 CIdMethod(sint32 i, double w,IObjectIA *m,IObjectIA *r);                
00131 
00132                 CIdMethod();            
00133 
00134                 virtual ~CIdMethod();           
00135 
00136                 bool operator < (const CIdMethod &) const;              
00137                 const CIdMethod &operator = (const CIdMethod &);
00138         };
00139         
00140 
00141         typedef std::priority_queue<CIdMethod> tQueue;
00142 
00154         class IObjectIA: public IBasicObjectIA
00155         {       
00156         protected:
00161                 IObjectIA(const IObjectIA &a);
00162 
00163         public:
00167                 struct CProcessResult
00168                 {
00169                         CProcessResult()
00170                         {                               
00171                                 ResultState = processIdle;
00172                                 Result = NULL;
00173                         }
00174 
00175                         CProcessResult(TProcessStatement state)
00176                         {                               
00177                                 ResultState = state;
00178                                 Result = NULL;
00179                         }
00180 
00184                         TProcessStatement ResultState;
00188                         IObjectIA *Result;
00189                 };              
00190 
00191         public:
00192 
00193                 static CProcessResult ProcessRun;
00194                 static CProcessResult ProcessNotComplit;                
00195                 
00199                 static TProcessStatement ProcessIdle;
00200 
00204                 static TProcessStatement ProcessLocked;
00205 
00209                 static TProcessStatement ProcessBuzzy;
00210 
00214                 static TProcessStatement ProcessEnd;
00215 
00219                 static TProcessStatement ProcessError;
00220                 
00221 
00222         public:
00223                 IObjectIA();
00224 
00228                 virtual void init(IObjectIA *);
00229 
00233                 virtual IObjectIA &operator = (const IObjectIA &a);
00234 
00238                 virtual const CProcessResult &run() = 0;                
00239 
00243                 virtual const CProcessResult &runStep();
00244 
00248                 virtual sint32 getStaticMemberSize() const;
00252                 virtual sint32 getStaticMemberIndex(const IVarName &) const;
00256                 virtual const IObjectIA *getStaticMember(sint32) const;
00257 
00261                 const IObjectIA *getStaticMember(const IVarName &compName) const
00262                 {
00263                         return getStaticMember(getStaticMemberIndex(compName));
00264                 }
00268                 bool setStaticMember(const IVarName &compName,IObjectIA *change)
00269                 {
00270                         return setStaticMember(getStaticMemberIndex(compName),change);
00271                 }
00272 
00276                 virtual bool setStaticMember(sint32,IObjectIA *);
00277 
00281                 virtual sint32 getMethodIndexSize() const;
00293                 virtual tQueue isMember(const IVarName *,const IVarName *,const IObjectIA &) const;
00300                 virtual sint32 isClassInheritedFrom(const IVarName &) const;
00301 
00309                 virtual CProcessResult runMethodeMember(sint32, sint32, IObjectIA *);
00310 
00315                 virtual std::string getMethodeMemberDebugString(sint32, sint32) const;
00316 
00323                 virtual CProcessResult runMethodeMember(sint32 index,IObjectIA *);
00324 
00328                 virtual CProcessResult sendMessage(IObjectIA *);
00329 
00333                 virtual CProcessResult sendMessage(const IVarName &,IObjectIA *);
00334                 
00340                 virtual tQueue canProcessMessage(const IVarName &);
00341 
00343                 virtual bool isLocal();
00344 
00345                 virtual ~IObjectIA();
00346         };      
00347         
00354         class IRefrence: public IObjectIA
00355         {       
00356         private:
00358                 IWordNumRef *_NumRef;
00360                 IWordNumRef *_Parent;
00361 
00362         protected:
00363                 IRefrence(const IRefrence &A);
00365                 void refLoadStream(NLMISC::IStream &is);
00366                 void setNumRef(const IWordNumRef &ref);
00367 
00368         public:
00370                 IRefrence();
00372                 IRefrence(const IWordNumRef *parent);
00374                 IRefrence(NLMISC::IStream &is);
00375 
00377                 operator const IWordNumRef &() const;
00379                 operator const IWordNumRef *() const ;
00380 
00381                 virtual const CIdent getIdentType() const;
00382 
00384                 IRefrence *getParent() const;
00385 
00387                 virtual void setParent(const IWordNumRef *parent);
00389                 virtual const IRefrence *getOwner() const;
00390                 
00392 
00396                 virtual void save(NLMISC::IStream &os) = 0;
00397                 virtual void load(NLMISC::IStream &is) = 0;
00399 
00400 
00402                 void setTypeAt(uint64 t);               
00403 
00404                 virtual ~IRefrence();
00405         };
00406 
00418         class IConnectIA: public IRefrence
00419         {
00420         private:
00421                 typedef std::set<const IConnectIA *> tListiBasic;
00422                 typedef std::set<const IConnectIA *>::iterator tListiBasicItr;
00423                 typedef std::set<const IConnectIA *>::const_iterator tListiBasicCstItr;
00424 
00425         protected:
00426                 tListiBasic _Connection;
00427                 tListiBasic _Connected;         
00428 
00429         protected:
00430                 IConnectIA(const IConnectIA &A);
00431                 void connectLoadStream(NLMISC::IStream &is);
00432 
00433         public:
00434 
00435                 IConnectIA();
00436                 IConnectIA(const IWordNumRef *parent);
00437                 IConnectIA(NLMISC::IStream &is);
00438                 IConnectIA *getParent() const;
00439                                 
00441                 virtual void onKill(IConnectIA *);      
00444 
00445                 virtual const CProcessResult &getState() const = 0;
00446                 virtual void setState(TProcessStatement s, IObjectIA *result) = 0;              
00448 
00451                 virtual IObjectIA::CProcessResult sendMessage(IObjectIA *m)
00452                 {
00453                         return sendMessage((IMessageBase *)m);
00454                 }
00455                 virtual IObjectIA::CProcessResult sendMessage(IMessageBase *msg) = 0;
00456                 
00458 
00462                 virtual void save(NLMISC::IStream &os) = 0;
00463                 virtual void load(NLMISC::IStream &is) = 0;
00465 
00468                 void connect(IConnectIA *b);
00470                 void removeConnection(IConnectIA *Agent);
00471 
00472                 virtual void setParent(const IWordNumRef *parent);
00473 
00475                 virtual void Kill(); 
00476 
00477                 virtual ~IConnectIA();
00478 
00479         protected:              
00480                 
00482 
00483                 void addInConnectionList(const IConnectIA *a);
00484                 void removeInConnectionList(IConnectIA *a);
00485                 void addInConnectedList(const IConnectIA *a);
00486                 void removeInConnectedList(const IConnectIA *a);
00488 
00489         };
00490 }
00491 #endif