00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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