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 {
00053 public:
00054 __inline PContainerReference(PINDEX initialSize, bool isConst = false)
00055 : size(initialSize)
00056 , count(1)
00057 , deleteObjects(true)
00058 , constObject(isConst)
00059 {
00060 }
00061
00062 __inline PContainerReference(const PContainerReference & ref)
00063 : size(ref.size)
00064 , count(1)
00065 , deleteObjects(ref.deleteObjects)
00066 , constObject(false)
00067 {
00068 }
00069
00070 PINDEX size;
00071 PAtomicInteger count;
00072 bool deleteObjects;
00073 bool constObject;
00074
00075 PDECLARE_POOL_ALLOCATOR();
00076
00077 private:
00078 void operator=(const PContainerReference &) { }
00079 };
00080
00081
00104 class PContainer : public PObject
00105 {
00106 PCLASSINFO(PContainer, PObject);
00107
00108 public:
00113 PContainer(
00114 PINDEX initialSize = 0
00115 );
00116
00121 PContainer(
00122 const PContainer & cont
00123 );
00124
00132 PContainer & operator=(
00133 const PContainer & cont
00134 );
00135
00140 virtual ~PContainer()
00141 { Destruct(); }
00142
00144
00153 virtual PINDEX GetSize() const;
00154
00168 virtual PBoolean SetSize(
00169 PINDEX newSize
00170 ) = 0;
00171
00177 PBoolean SetMinSize(
00178 PINDEX minSize
00179 );
00180
00187 virtual PBoolean IsEmpty() const;
00188
00195 PBoolean IsUnique() const;
00196
00205 virtual PBoolean MakeUnique();
00207
00208 protected:
00219 PContainer(
00220 int dummy,
00221 const PContainer * cont
00222 );
00223
00225 PContainer(PContainerReference & reference);
00226
00237 virtual void DestroyContents() = 0;
00238
00248 virtual void AssignContents(const PContainer & c);
00249
00261 void CopyContents(const PContainer & c);
00262
00279 void CloneContents(const PContainer * src);
00280
00284 void Destruct();
00285
00289 virtual void DestroyReference();
00290
00291 PContainerReference * reference;
00292 };
00293
00294
00295
00343 #define PCONTAINERINFO(cls, par) \
00344 PCLASSINFO(cls, par) \
00345 public: \
00346 cls(const cls & c) : par(c) { CopyContents(c); } \
00347 cls & operator=(const cls & c) \
00348 { AssignContents(c); return *this; } \
00349 virtual ~cls() { Destruct(); } \
00350 virtual PBoolean MakeUnique() \
00351 { if(par::MakeUnique())return true; CloneContents(this);return false; } \
00352 protected: \
00353 cls(int dummy, const cls * c) : par(dummy, c) { CloneContents(c); } \
00354 virtual void DestroyContents(); \
00355 void CloneContents(const cls * c); \
00356 void CopyContents(const cls & c); \
00357 virtual void AssignContents(const PContainer & c) \
00358 { par::AssignContents(c); CopyContents((const cls &)c); }
00359
00360
00362
00363
00395 class PCollection : public PContainer
00396 {
00397 PCLASSINFO(PCollection, PContainer);
00398
00399 public:
00404 PCollection(
00405 PINDEX initialSize = 0
00406 );
00408
00424 virtual void PrintOn(
00425 ostream &strm
00426 ) const;
00428
00440 virtual PINDEX Append(
00441 PObject * obj
00442 ) = 0;
00443
00460 virtual PINDEX Insert(
00461 const PObject & before,
00462 PObject * obj
00463 ) = 0;
00464
00476 virtual PINDEX InsertAt(
00477 PINDEX index,
00478 PObject * obj
00479 ) = 0;
00480
00490 virtual PBoolean Remove(
00491 const PObject * obj
00492 ) = 0;
00493
00502 virtual PObject * RemoveAt(
00503 PINDEX index
00504 ) = 0;
00505
00512 virtual void RemoveAll();
00513
00527 virtual PBoolean SetAt(
00528 PINDEX index,
00529 PObject * val
00530 ) = 0;
00531
00537 virtual PObject * GetAt(
00538 PINDEX index
00539 ) const = 0;
00540
00547 virtual PINDEX GetObjectsIndex(
00548 const PObject * obj
00549 ) const = 0;
00550
00559 virtual PINDEX GetValuesIndex(
00560 const PObject & obj
00561 ) const = 0;
00562
00576 PINLINE void AllowDeleteObjects(
00577 PBoolean yes = true
00578 );
00579
00583 void DisallowDeleteObjects();
00585
00586 protected:
00597 PINLINE PCollection(
00598 int dummy,
00599 const PCollection * coll
00600 );
00601 };
00602
00603
00604
00606
00607
00608 #include <ptlib/array.h>
00609
00611
00612
00613 #include <ptlib/lists.h>
00614
00616
00617
00618 #include <ptlib/dict.h>
00619
00620
00622
00623
00624 #include <ptlib/pstring.h>
00625
00626
00627
00629
00630
00631 #if P_USE_INLINES
00632 #include <ptlib/contain.inl>
00633 #endif
00634
00635
00636 #endif // PTLIB_CONTAIN_H
00637
00638
00639