00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef PTLIB_CONTAIN_H
00035 #define PTLIB_CONTAIN_H
00036
00037 #ifdef P_USE_PRAGMA
00038 #pragma interface
00039 #endif
00040
00041
00042 #include <ptlib/critsec.h>
00043 #include <ptlib/object.h>
00044
00045
00046
00048
00049
00050
00051 class PContainerReference {
00052 public:
00053 inline PContainerReference(PINDEX initialSize)
00054 : size(initialSize), count(1), deleteObjects(true)
00055 {
00056 }
00057
00058 inline PContainerReference(const PContainerReference & ref)
00059 : size(ref.size), count(1), deleteObjects(ref.deleteObjects)
00060 {
00061 }
00062
00063 PINDEX size;
00064 PAtomicInteger count;
00065 PBoolean deleteObjects;
00066
00067 PDECLARE_POOL_ALLOCATOR();
00068
00069 private:
00070 PContainerReference & operator=(const PContainerReference &)
00071 { return *this; }
00072 };
00073
00096 class PContainer : public PObject
00097 {
00098 PCLASSINFO(PContainer, PObject);
00099
00100 public:
00105 PContainer(
00106 PINDEX initialSize = 0
00107 );
00108
00113 PContainer(
00114 const PContainer & cont
00115 );
00116
00124 PContainer & operator=(
00125 const PContainer & cont
00126 );
00127
00132 virtual ~PContainer()
00133 { Destruct(); }
00134
00136
00145 virtual PINDEX GetSize() const;
00146
00160 virtual PBoolean SetSize(
00161 PINDEX newSize
00162 ) = 0;
00163
00169 PBoolean SetMinSize(
00170 PINDEX minSize
00171 );
00172
00179 virtual PBoolean IsEmpty() const;
00180
00187 PBoolean IsUnique() const;
00188
00197 virtual PBoolean MakeUnique();
00199
00200 protected:
00211 PContainer(
00212 int dummy,
00213 const PContainer * cont
00214 );
00215
00226 virtual void DestroyContents() = 0;
00227
00237 virtual void AssignContents(const PContainer & c);
00238
00250 void CopyContents(const PContainer & c);
00251
00268 void CloneContents(const PContainer * src);
00269
00273 void Destruct();
00274
00275
00276 PContainerReference * reference;
00277 };
00278
00279
00280
00328 #define PCONTAINERINFO(cls, par) \
00329 PCLASSINFO(cls, par) \
00330 public: \
00331 cls(const cls & c) : par(c) { CopyContents(c); } \
00332 cls & operator=(const cls & c) \
00333 { AssignContents(c); return *this; } \
00334 virtual ~cls() { Destruct(); } \
00335 virtual PBoolean MakeUnique() \
00336 { if(par::MakeUnique())return true; CloneContents(this);return false; } \
00337 protected: \
00338 cls(int dummy, const cls * c) : par(dummy, c) { CloneContents(c); } \
00339 virtual void DestroyContents(); \
00340 void CloneContents(const cls * c); \
00341 void CopyContents(const cls & c); \
00342 virtual void AssignContents(const PContainer & c) \
00343 { par::AssignContents(c); CopyContents((const cls &)c); }
00344
00345
00347
00348
00380 class PCollection : public PContainer
00381 {
00382 PCLASSINFO(PCollection, PContainer);
00383
00384 public:
00389 PCollection(
00390 PINDEX initialSize = 0
00391 );
00393
00409 virtual void PrintOn(
00410 ostream &strm
00411 ) const;
00413
00425 virtual PINDEX Append(
00426 PObject * obj
00427 ) = 0;
00428
00445 virtual PINDEX Insert(
00446 const PObject & before,
00447 PObject * obj
00448 ) = 0;
00449
00461 virtual PINDEX InsertAt(
00462 PINDEX index,
00463 PObject * obj
00464 ) = 0;
00465
00475 virtual PBoolean Remove(
00476 const PObject * obj
00477 ) = 0;
00478
00487 virtual PObject * RemoveAt(
00488 PINDEX index
00489 ) = 0;
00490
00497 virtual void RemoveAll();
00498
00512 virtual PBoolean SetAt(
00513 PINDEX index,
00514 PObject * val
00515 ) = 0;
00516
00522 virtual PObject * GetAt(
00523 PINDEX index
00524 ) const = 0;
00525
00532 virtual PINDEX GetObjectsIndex(
00533 const PObject * obj
00534 ) const = 0;
00535
00544 virtual PINDEX GetValuesIndex(
00545 const PObject & obj
00546 ) const = 0;
00547
00561 PINLINE void AllowDeleteObjects(
00562 PBoolean yes = true
00563 );
00564
00568 void DisallowDeleteObjects();
00570
00571 protected:
00582 PINLINE PCollection(
00583 int dummy,
00584 const PCollection * coll
00585 );
00586 };
00587
00588
00589
00591
00592
00593 #include <ptlib/array.h>
00594
00596
00597
00598 #include <ptlib/lists.h>
00599
00601
00602
00603 #include <ptlib/dict.h>
00604
00605
00607
00608
00609 #include <ptlib/pstring.h>
00610
00611
00612
00614
00615
00616 #if P_USE_INLINES
00617 #include <ptlib/contain.inl>
00618 #endif
00619
00620
00621 #endif // PTLIB_CONTAIN_H
00622
00623
00624