00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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 std::string &str): _Str(new CStringVarName(str.c_str()))
00052 {
00053 }
00054
00055 CStringType(const IVarName &str): _Str((IVarName *)str.clone())
00056 {
00057 }
00058
00059 CStringType(const CStringType &a): _Str((IVarName *)a._Str->clone())
00060 {
00061 }
00062
00063 CStringType(NLMISC::IStream &is)
00064 {
00065 load(is);
00066 }
00067
00068 virtual const NLAIC::IBasicType *clone() const
00069 {
00070 NLAIC::IBasicInterface *m = new CStringType(*this);
00071 return m;
00072 }
00073
00074 virtual const NLAIC::IBasicType *newInstance() const
00075 {
00076 return clone();
00077 }
00078
00079 virtual const NLAIC::CIdentType &getType() const;
00080
00081 virtual void save(NLMISC::IStream &os)
00082 {
00083 os.serial( (NLAIC::CIdentType &) ( _Str->getType() ) );
00084 _Str->save(os);
00085 }
00086
00087 virtual void load(NLMISC::IStream &is)
00088 {
00089 NLAIC::CIdentTypeAlloc id;
00090 is.serial( id );
00091 _Str->release();
00092 _Str = (IVarName *)id.allocClass();
00093 _Str->load(is);
00094 }
00095
00096
00097 virtual void getDebugString(std::string &text) const
00098 {
00099 text += NLAIC::stringGetBuild("%s",_Str->getString());
00100 }
00101
00102 const IVarName & getStr() const
00103 {
00104 return *_Str;
00105 }
00106
00108
00109 virtual IObjetOp &operator += (const IObjetOp &a);
00110 virtual IObjetOp &operator -= (const IObjetOp &a);
00111 virtual IObjetOp *operator < (IObjetOp &a) const;
00112 virtual IObjetOp *operator > (IObjetOp &a) const;
00113 virtual IObjetOp *operator <= (IObjetOp &a) const;
00114 virtual IObjetOp *operator >= (IObjetOp &a) const;
00115 virtual IObjetOp *operator != (IObjetOp &a) const;
00116 virtual IObjetOp *operator == (IObjetOp &a) const;
00118
00119
00120 virtual bool operator < (const CStringType &a) const;
00121
00122
00123 virtual bool isTrue() const
00124 {
00125 return IObjetOp::isTrue();
00126 }
00127
00128 virtual ~CStringType()
00129 {
00130 _Str->release();
00131 }
00132
00133 virtual bool isEqual(const IBasicObjectIA &a) const
00134 {
00135 const CStringType &t = (const CStringType &)a;
00136 return *t._Str == *_Str;
00137 }
00138
00139
00140 virtual const CProcessResult &run();
00141 };
00142
00143
00144
00151 class CPairType: public IObjetOp
00152 {
00153 public:
00154 struct CMethodCall
00155 {
00156 CMethodCall(const char *name, int i): MethodName (name)
00157 {
00158 Index = i;
00159 }
00160 CStringVarName MethodName;
00161 sint32 Index;
00162 };
00163 static CMethodCall _Method[];
00164
00165 private:
00166 IObjectIA *_First;
00167 IObjectIA *_Second;
00168
00169 public:
00170 static const NLAIC::CIdentType IdPaireType;
00171
00172 public:
00173 CPairType(IObjectIA *first,IObjectIA *second):
00174 _First(first),_Second(second)
00175 {
00176 }
00177
00178 CPairType(const CPairType &a): _First(a._First),_Second(a._Second)
00179 {
00180 _First->incRef();
00181 _Second->incRef();
00182 }
00183
00184 virtual const NLAIC::IBasicType *clone() const
00185 {
00186 NLAIC::IBasicInterface *m = new CPairType(*this);
00187 return m;
00188 }
00189
00190 virtual const NLAIC::IBasicType *newInstance() const
00191 {
00192 return clone();
00193 }
00194
00195 virtual const NLAIC::CIdentType &getType() const
00196 {
00197 return IdPaireType;
00198 }
00199
00200
00201 virtual void save(NLMISC::IStream &os)
00202 {
00203 }
00204
00205 virtual void load(NLMISC::IStream &is)
00206 {
00207 }
00208
00209 virtual const CProcessResult &run()
00210 {
00211 return IObjectIA::ProcessRun;
00212 }
00213
00214 virtual void getDebugString(std::string &text) const
00215 {
00216 std::string f,s;
00217
00218 _First->getDebugString(f);
00219 _Second->getDebugString(s);
00220 text += "First:<";
00221 text += f;
00222 text += ">";
00223 text += "Second:<";
00224 text += s;
00225 text += ">";
00226 }
00227
00228 virtual bool isTrue() const
00229 {
00230 return IObjetOp::isTrue();
00231 }
00232
00233 IObjectIA *first() const
00234 {
00235 return _First;
00236 }
00237
00238 IObjectIA *second() const
00239 {
00240 return _Second;
00241 }
00242
00243 virtual ~CPairType()
00244 {
00245 _First->release();
00246 _Second->release();
00247 }
00248
00249 virtual bool isEqual(const IBasicObjectIA &a) const
00250 {
00251 const CPairType &t = (const CPairType &)a;
00252 if((t._First) == (_First)) return t._Second == _Second;
00253 return false;
00254 }
00255
00256 virtual sint32 getMethodIndexSize() const;
00257 virtual tQueue isMember(const IVarName *,const IVarName *,const IObjectIA &) const;
00258 virtual CProcessResult runMethodeMember(sint32, sint32, IObjectIA *);
00259 virtual CProcessResult runMethodeMember(sint32 index,IObjectIA *);
00260 };
00261
00272 class IConstBasicIterator
00273 {
00274 public:
00275 IConstBasicIterator() {}
00276 virtual const IObjetOp* operator ++ (int) = 0;
00277 virtual const IObjetOp* operator -- (int) = 0;
00278 virtual operator const IObjetOp*() const = 0;
00279 virtual bool isInEnd() const = 0;
00280 virtual bool isInBegin() const = 0;
00281 virtual ~IConstBasicIterator() {}
00282 };
00283
00284 class IBasicIterator: public IConstBasicIterator
00285 {
00286 public:
00287 IBasicIterator() {}
00288 virtual void erase() = 0;
00289 virtual ~IBasicIterator() {}
00290 };
00291
00299 template<class typeClass>
00300 class CTemplateIterator: public IBasicIterator
00301 {
00302 private:
00303 typename typeClass::iterator _I;
00304 typeClass &_ListType;
00305
00306 public:
00307 CTemplateIterator(typeClass &l):_I(l.begin()),_ListType(l)
00308 {
00309 }
00310 virtual ~CTemplateIterator()
00311 {
00312 }
00313
00314 virtual const IObjetOp* operator ++ (int)
00315 {
00316 return (const IObjetOp*)*_I++;
00317 }
00318 virtual const IObjetOp* operator -- (int)
00319 {
00320 return (const IObjetOp*)*_I--;
00321 }
00322
00323 virtual operator const IObjetOp *() const
00324 {
00325 return (const IObjetOp *)*_I;
00326 }
00327
00328 virtual void erase()
00329 {
00330 typename typeClass::iterator temp = _I;
00331 _I++;
00332 _ListType.erase(temp);
00333 }
00334
00335 virtual bool isInEnd() const
00336 {
00337 return _I == _ListType.end();
00338 }
00339
00340 virtual bool isInBegin() const
00341 {
00342 return _I == _ListType.begin();
00343 }
00344 };
00345
00346 template<class typeClass>
00347 class CConstTemplateIterator: public IConstBasicIterator
00348 {
00349 private:
00350 typename typeClass::const_iterator _I;
00351 const typeClass &_ListType;
00352
00353 public:
00354 CConstTemplateIterator(const typeClass &l):_I(l.begin()),_ListType(l)
00355 {
00356 }
00357 virtual ~CConstTemplateIterator()
00358 {
00359 }
00360
00361 virtual const IObjetOp* operator ++ (int)
00362 {
00363 return (const IObjetOp*)*_I++;
00364 }
00365 virtual const IObjetOp* operator -- (int)
00366 {
00367 return (const IObjetOp*)*_I--;
00368 }
00369
00370 virtual operator const IObjetOp *() const
00371 {
00372 return (const IObjetOp *)*_I;
00373 }
00374
00375 virtual bool isInEnd() const
00376 {
00377 return _I == _ListType.end();
00378 }
00379
00380 virtual bool isInBegin() const
00381 {
00382 return _I == _ListType.begin();
00383 }
00384 };
00385
00386
00395 class CListIterator: public CTemplateIterator<std::list<const IObjectIA *> >
00396 {
00397 public:
00398 CListIterator(std::list<const IObjectIA *> &l): CTemplateIterator<std::list<const IObjectIA *> >(l)
00399 {
00400 }
00401
00402 virtual ~CListIterator()
00403 {
00404 }
00405
00406 };
00407
00408 class CConstListIterator: public CConstTemplateIterator<std::list<const IObjectIA *> >
00409 {
00410 public:
00411 CConstListIterator(const std::list<const IObjectIA *> &l): CConstTemplateIterator<std::list<const IObjectIA *> >(l)
00412 {
00413 }
00414
00415 virtual ~CConstListIterator()
00416 {
00417 }
00418
00419 };
00420
00428 class CVectorIterator: public CTemplateIterator<std::vector<const IObjectIA *> >
00429 {
00430 public:
00431 CVectorIterator(std::vector<const IObjectIA *>&l): CTemplateIterator<std::vector<const IObjectIA *> >(l)
00432 {
00433 }
00434
00435 virtual ~CVectorIterator()
00436 {
00437 }
00438
00439 };
00440
00441 class CConstVectorIterator: public CConstTemplateIterator<std::vector<const IObjectIA *> >
00442 {
00443 public:
00444 CConstVectorIterator(const std::vector<const IObjectIA *>&l): CConstTemplateIterator<std::vector<const IObjectIA *> >(l)
00445 {
00446 }
00447
00448 virtual ~CConstVectorIterator()
00449 {
00450 }
00451
00452 };
00453
00462 class CConstIteratorContener: public IConstBasicIterator
00463 {
00464 protected:
00465 IBasicIterator *_I;
00466 public:
00467 CConstIteratorContener(const CConstIteratorContener &i):_I(i._I)
00468 {
00469 }
00470
00471 CConstIteratorContener(IBasicIterator *i):_I(i)
00472 {
00473 }
00474
00475 virtual ~CConstIteratorContener()
00476 {
00477 delete _I;
00478 }
00479
00480 virtual const IObjetOp*operator ++ (int)
00481 {
00482 const IObjetOp *a = (*_I)++;
00483 return a;
00484 }
00485 virtual const IObjetOp*operator -- (int)
00486 {
00487 const IObjetOp *a = (*_I) --;
00488 return a;
00489 }
00490 virtual operator const IObjetOp*() const
00491 {
00492 return (const IObjetOp *)*_I;
00493 }
00494
00495 virtual bool isInEnd() const
00496 {
00497 return _I->isInEnd();
00498 }
00499 virtual bool isInBegin() const
00500 {
00501 return _I->isInBegin();
00502 }
00503 };
00504
00505 class CIteratorContener: public CConstIteratorContener
00506 {
00507 public:
00508 CIteratorContener(const CIteratorContener &i):CConstIteratorContener(i._I)
00509 {
00510 }
00511
00512 CIteratorContener(const CConstIteratorContener &i):CConstIteratorContener(i)
00513 {
00514 }
00515
00516 CIteratorContener(IBasicIterator *i):CConstIteratorContener(i)
00517 {
00518 }
00519
00520 virtual ~CIteratorContener()
00521 {
00522 }
00523
00524 virtual void erase()
00525 {
00526 _I->erase();
00527 }
00528
00529 };
00530
00539 class IBaseGroupType: public IObjetOp
00540 {
00541
00542 public:
00543 struct CMethodCall
00544 {
00545 CMethodCall(const char *name, int i): MethodName (name)
00546 {
00547 Index = i;
00548 }
00549 CStringVarName MethodName;
00550 sint32 Index;
00551 };
00552 static CMethodCall _Method[];
00553
00554 public:
00555
00556 IBaseGroupType(const IBaseGroupType &c):IObjetOp(c){}
00557 IBaseGroupType();
00558 virtual ~IBaseGroupType();
00559
00561
00562 virtual IObjetOp &operator += (IObjetOp *a);
00563 virtual IObjetOp &operator -= (IObjetOp *a);
00564 virtual IObjetOp &operator += (const IObjetOp &a);
00565 virtual IObjetOp &operator -= (const IObjetOp &a);
00566
00567 virtual IObjetOp *operator ! () const = 0;
00568 virtual bool isTrue() const;
00570
00572
00573 virtual sint32 getMethodIndexSize() const;
00574 virtual sint32 isClassInheritedFrom(const IVarName &) const;
00575 virtual tQueue isMember(const IVarName *,const IVarName *,const IObjectIA &) const;
00576 virtual CProcessResult runMethodeMember(sint32, sint32, IObjectIA *);
00577 virtual CProcessResult runMethodeMember(sint32 index,IObjectIA *);
00579
00581
00582 virtual IObjectIA &operator = (const IObjectIA &a) = 0;
00583 virtual const IObjectIA *operator[] (sint32) const= 0;
00584
00586 virtual void set(int,IObjectIA *) = 0;
00587
00589 virtual void push(const IObjectIA *o) = 0;
00591 virtual void pushFront(const IObjectIA *o) = 0;
00593 virtual void cpy(const IObjectIA &o) = 0;
00595 virtual CIteratorContener getIterator() = 0;
00596 virtual CConstIteratorContener getConstIterator() const = 0;
00597
00599 virtual const IObjectIA *pop() = 0;
00601 virtual const IObjectIA *popFront() = 0;
00603 virtual const IObjectIA *get() const = 0;
00605 virtual const IObjectIA *getFront() const = 0;
00607 virtual sint32 size() const = 0;
00608
00610 virtual const IObjectIA *find(const IObjectIA &obj) const = 0;
00611
00612
00614
00616
00618
00620
00622
00624
00633 class CGroupType: public IBaseGroupType
00634 {
00635
00636 public:
00637 static const NLAIC::CIdentType IdGroupType;
00638
00639 public:
00640
00641 typedef std::list<const IObjectIA *> tListType;
00642 public:
00644 tListType _List;
00645
00646 protected:
00647
00648 tListType &getList();
00649
00650 public:
00651 CGroupType();
00652 CGroupType(const CGroupType &g);
00653
00654 virtual void getDebugString(std::string &text) const;
00655
00656 virtual const CProcessResult &run();
00657
00658 virtual IObjectIA &operator = (const IObjectIA &a);
00659 virtual IObjetOp *operator + (const IObjetOp &a);
00660 virtual IObjetOp *operator - (const IObjetOp &a);
00661
00662 virtual IObjetOp *operator + (IObjetOp *a);
00663 virtual IObjetOp *operator - (IObjetOp *a);
00664
00665 virtual const IObjectIA *operator[] (sint32) const;
00666
00667 virtual void set(int,IObjectIA *);
00668
00669 virtual CIteratorContener getIterator()
00670 {
00671 return CIteratorContener(new CListIterator(_List));
00672 }
00673
00674 virtual CConstIteratorContener getConstIterator() const
00675 {
00676 return CConstIteratorContener((IBasicIterator *)(new CConstListIterator(_List)));
00677 }
00678
00679
00680
00681 IObjetOp *CGroupType::operator ! () const;
00682 void push(const IObjectIA *o);
00683 void pushFront(const IObjectIA *o);
00684 void cpy(const IObjectIA &o);
00685 const IObjectIA *pop();
00686 const IObjectIA *get() const;
00687 const IObjectIA *popFront();
00688 const IObjectIA *getFront() const;
00689 sint32 size() const;
00690 tListType findList(const IObjectIA &obj) const;
00691 tListType::const_iterator getBegin() const;
00692 tListType::const_iterator getEnd() const;
00693 tListType::iterator getBegin();
00694 tListType::iterator getEnd();
00695 const IObjectIA *find(const IObjectIA &obj) const;
00696 void eraseAll(const IObjectIA &obj);
00697 void erase(const IObjectIA *o);
00698 void erase(const IObjectIA &obj);
00699 void erase(std::list<const IObjectIA *> &l);
00700 virtual bool isEqual(const IBasicObjectIA &a) const;
00701 virtual const NLAIC::IBasicType *clone() const;
00702 virtual const NLAIC::IBasicType *newInstance() const;
00703 virtual const NLAIC::CIdentType &getType() const;
00704 virtual void save(NLMISC::IStream &os);
00705 virtual IObjetOp &neg();
00706 virtual void load(NLMISC::IStream &is);
00707 void clear();
00708
00709 virtual ~CGroupType();
00710 };
00711
00720 class CVectorGroupType: public IBaseGroupType
00721 {
00722
00723 public:
00724 static const NLAIC::CIdentType IdVectorGroupType;
00725
00726 public:
00727
00728 typedef std::vector<const IObjectIA *> tVectorType;
00729 private:
00731 tVectorType _Vector;
00732
00733 protected:
00734 tVectorType &getVector();
00735
00736 public:
00738 CVectorGroupType(sint32 );
00739 CVectorGroupType();
00740 CVectorGroupType(const CVectorGroupType &g);
00741
00742 virtual void getDebugString(std::string &text) const;
00743
00744 virtual const CProcessResult &run();
00745
00746 virtual IObjetOp *operator + (const IObjetOp &a) ;
00747 virtual IObjetOp *operator - (const IObjetOp &a) ;
00748
00749 virtual IObjetOp *operator + (IObjetOp *a);
00750 virtual IObjetOp *operator - (IObjetOp *a);
00751
00752 virtual IObjectIA &operator = (const IObjectIA &a);
00753
00754 virtual const IObjectIA *operator[] (sint32) const;
00755
00756 virtual void set(int,IObjectIA *);
00757
00758
00759
00760 IObjetOp *CVectorGroupType::operator ! () const;
00761 void push(const IObjectIA *o);
00762 void pushFront(const IObjectIA *o);
00763 virtual CIteratorContener getIterator()
00764 {
00765 return CIteratorContener(new CVectorIterator(_Vector));
00766 }
00767
00768 virtual CConstIteratorContener getConstIterator() const
00769 {
00770 return CConstIteratorContener((IBasicIterator *)(new CConstVectorIterator(_Vector)));
00771 }
00772
00773 void setObject(sint32 i,IObjectIA *a)
00774 {
00775 _Vector[i] = a;
00776 }
00777
00778 void cpy(const IObjectIA &o);
00779 const IObjectIA *pop();
00780 const IObjectIA *get() const;
00781 const IObjectIA *popFront();
00782 const IObjectIA *getFront() const;
00783 sint32 size() const;
00784 tVectorType findList(const IObjectIA &obj) const;
00785 tVectorType::const_iterator getBegin() const;
00786 tVectorType::const_iterator getEnd() const;
00787 tVectorType::iterator getBegin();
00788 tVectorType::iterator getEnd();
00789 const IObjectIA *find(const IObjectIA &obj) const;
00790 void eraseAll(const IObjectIA &obj);
00791 void erase(const IObjectIA *o);
00792 void erase(const IObjectIA &obj);
00793 void erase(std::list<const IObjectIA *> &l);
00794 virtual bool isEqual(const IBasicObjectIA &a) const;
00795 virtual const NLAIC::IBasicType *clone() const;
00796 virtual const NLAIC::IBasicType *newInstance() const;
00797 virtual const NLAIC::CIdentType &getType() const;
00798 virtual void save(NLMISC::IStream &os);
00799 virtual IObjetOp &neg();
00800 virtual void load(NLMISC::IStream &is);
00801 void clear();
00802
00803 virtual sint32 getMethodIndexSize() const;
00804 virtual tQueue isMember(const IVarName *,const IVarName *,const IObjectIA &) const;
00805 virtual CProcessResult runMethodeMember(sint32, sint32, IObjectIA *);
00806 virtual CProcessResult runMethodeMember(sint32 index,IObjectIA *);
00807
00808 virtual ~CVectorGroupType();
00809 };
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00821
00822
00823
00824
00825
00826
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898 }
00899 #endif