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(PTrue)
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 private:
00068 PContainerReference & operator=(const PContainerReference &)
00069 { return *this; }
00070 };
00071
00094 class PContainer : public PObject
00095 {
00096 PCLASSINFO(PContainer, PObject);
00097
00098 public:
00103 PContainer(
00104 PINDEX initialSize = 0
00105 );
00106
00111 PContainer(
00112 const PContainer & cont
00113 );
00114
00122 PContainer & operator=(
00123 const PContainer & cont
00124 );
00125
00130 virtual ~PContainer()
00131 { Destruct(); }
00132
00134
00143 virtual PINDEX GetSize() const;
00144
00158 virtual PBoolean SetSize(
00159 PINDEX newSize
00160 ) = 0;
00161
00167 PBoolean SetMinSize(
00168 PINDEX minSize
00169 );
00170
00177 virtual PBoolean IsEmpty() const;
00178
00185 PBoolean IsUnique() const;
00186
00195 virtual PBoolean MakeUnique();
00197
00198 protected:
00209 PContainer(
00210 int dummy,
00211 const PContainer * cont
00212 );
00213
00224 virtual void DestroyContents() = 0;
00225
00235 virtual void AssignContents(const PContainer & c);
00236
00248 void CopyContents(const PContainer & c);
00249
00266 void CloneContents(const PContainer * src);
00267
00271 void Destruct();
00272
00273
00274 PContainerReference * reference;
00275 };
00276
00277
00278
00326 #define PCONTAINERINFO(cls, par) \
00327 PCLASSINFO(cls, par) \
00328 public: \
00329 cls(const cls & c) : par(c) { CopyContents(c); } \
00330 cls & operator=(const cls & c) \
00331 { AssignContents(c); return *this; } \
00332 virtual ~cls() { Destruct(); } \
00333 virtual PBoolean MakeUnique() \
00334 { if(par::MakeUnique())return PTrue; CloneContents(this);return PFalse; } \
00335 protected: \
00336 cls(int dummy, const cls * c) : par(dummy, c) { CloneContents(c); } \
00337 virtual void DestroyContents(); \
00338 void CloneContents(const cls * c); \
00339 void CopyContents(const cls & c); \
00340 virtual void AssignContents(const PContainer & c) \
00341 { par::AssignContents(c); CopyContents((const cls &)c); }
00342
00343
00345
00346
00378 class PCollection : public PContainer
00379 {
00380 PCLASSINFO(PCollection, PContainer);
00381
00382 public:
00387 PCollection(
00388 PINDEX initialSize = 0
00389 );
00391
00407 virtual void PrintOn(
00408 ostream &strm
00409 ) const;
00411
00423 virtual PINDEX Append(
00424 PObject * obj
00425 ) = 0;
00426
00443 virtual PINDEX Insert(
00444 const PObject & before,
00445 PObject * obj
00446 ) = 0;
00447
00459 virtual PINDEX InsertAt(
00460 PINDEX index,
00461 PObject * obj
00462 ) = 0;
00463
00473 virtual PBoolean Remove(
00474 const PObject * obj
00475 ) = 0;
00476
00485 virtual PObject * RemoveAt(
00486 PINDEX index
00487 ) = 0;
00488
00495 virtual void RemoveAll();
00496
00510 virtual PBoolean SetAt(
00511 PINDEX index,
00512 PObject * val
00513 ) = 0;
00514
00520 virtual PObject * GetAt(
00521 PINDEX index
00522 ) const = 0;
00523
00530 virtual PINDEX GetObjectsIndex(
00531 const PObject * obj
00532 ) const = 0;
00533
00542 virtual PINDEX GetValuesIndex(
00543 const PObject & obj
00544 ) const = 0;
00545
00559 PINLINE void AllowDeleteObjects(
00560 PBoolean yes = PTrue
00561 );
00562
00566 void DisallowDeleteObjects();
00568
00569 protected:
00580 PINLINE PCollection(
00581 int dummy,
00582 const PCollection * coll
00583 );
00584 };
00585
00586
00587
00589
00590
00591 #include <ptlib/array.h>
00592
00594
00595
00596 #include <ptlib/lists.h>
00597
00599
00600
00601 #include <ptlib/dict.h>
00602
00603
00605
00606
00607 #include <ptlib/pstring.h>
00608
00609
00610
00612
00613
00614 #if P_USE_INLINES
00615 #include <ptlib/contain.inl>
00616 #endif
00617
00618
00619 #endif // PTLIB_CONTAIN_H
00620
00621
00622