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 _CONTAIN_H
00035 #define _CONTAIN_H
00036
00037 #ifdef P_USE_PRAGMA
00038 #pragma interface
00039 #endif
00040
00041 #include <ptlib/object.h>
00042 #include <ptlib/critsec.h>
00043
00045
00046
00047
00048 class PContainerReference {
00049 public:
00050 inline PContainerReference(PINDEX initialSize)
00051 : size(initialSize), count(1), deleteObjects(PTrue)
00052 {
00053 }
00054
00055 inline PContainerReference(const PContainerReference & ref)
00056 : size(ref.size), count(1), deleteObjects(ref.deleteObjects)
00057 {
00058 }
00059
00060 PINDEX size;
00061 PAtomicInteger count;
00062 PBoolean deleteObjects;
00063
00064 private:
00065 PContainerReference & operator=(const PContainerReference &)
00066 { return *this; }
00067 };
00068
00091 class PContainer : public PObject
00092 {
00093 PCLASSINFO(PContainer, PObject);
00094
00095 public:
00100 PContainer(
00101 PINDEX initialSize = 0
00102 );
00103
00108 PContainer(
00109 const PContainer & cont
00110 );
00111
00119 PContainer & operator=(
00120 const PContainer & cont
00121 );
00122
00127 virtual ~PContainer()
00128 { Destruct(); }
00129
00131
00140 virtual PINDEX GetSize() const;
00141
00155 virtual PBoolean SetSize(
00156 PINDEX newSize
00157 ) = 0;
00158
00164 PBoolean SetMinSize(
00165 PINDEX minSize
00166 );
00167
00174 virtual PBoolean IsEmpty() const;
00175
00182 PBoolean IsUnique() const;
00183
00192 virtual PBoolean MakeUnique();
00194
00195 protected:
00206 PContainer(
00207 int dummy,
00208 const PContainer * cont
00209 );
00210
00221 virtual void DestroyContents() = 0;
00222
00232 virtual void AssignContents(const PContainer & c);
00233
00245 void CopyContents(const PContainer & c);
00246
00263 void CloneContents(const PContainer * src);
00264
00268 void Destruct();
00269
00270
00271 PContainerReference * reference;
00272 };
00273
00274
00275
00323 #define PCONTAINERINFO(cls, par) \
00324 PCLASSINFO(cls, par) \
00325 public: \
00326 cls(const cls & c) : par(c) { CopyContents(c); } \
00327 cls & operator=(const cls & c) \
00328 { AssignContents(c); return *this; } \
00329 virtual ~cls() { Destruct(); } \
00330 virtual PBoolean MakeUnique() \
00331 { if(par::MakeUnique())return PTrue; CloneContents(this);return PFalse; } \
00332 protected: \
00333 cls(int dummy, const cls * c) : par(dummy, c) { CloneContents(c); } \
00334 virtual void DestroyContents(); \
00335 void CloneContents(const cls * c); \
00336 void CopyContents(const cls & c); \
00337 virtual void AssignContents(const PContainer & c) \
00338 { par::AssignContents(c); CopyContents((const cls &)c); }
00339
00340
00342
00343
00375 class PCollection : public PContainer
00376 {
00377 PCLASSINFO(PCollection, PContainer);
00378
00379 public:
00384 PCollection(
00385 PINDEX initialSize = 0
00386 );
00388
00404 virtual void PrintOn(
00405 ostream &strm
00406 ) const;
00408
00420 virtual PINDEX Append(
00421 PObject * obj
00422 ) = 0;
00423
00440 virtual PINDEX Insert(
00441 const PObject & before,
00442 PObject * obj
00443 ) = 0;
00444
00456 virtual PINDEX InsertAt(
00457 PINDEX index,
00458 PObject * obj
00459 ) = 0;
00460
00470 virtual PBoolean Remove(
00471 const PObject * obj
00472 ) = 0;
00473
00482 virtual PObject * RemoveAt(
00483 PINDEX index
00484 ) = 0;
00485
00492 virtual void RemoveAll();
00493
00507 virtual PBoolean SetAt(
00508 PINDEX index,
00509 PObject * val
00510 ) = 0;
00511
00517 virtual PObject * GetAt(
00518 PINDEX index
00519 ) const = 0;
00520
00527 virtual PINDEX GetObjectsIndex(
00528 const PObject * obj
00529 ) const = 0;
00530
00539 virtual PINDEX GetValuesIndex(
00540 const PObject & obj
00541 ) const = 0;
00542
00556 PINLINE void AllowDeleteObjects(
00557 PBoolean yes = PTrue
00558 );
00559
00563 void DisallowDeleteObjects();
00565
00566 protected:
00577 PINLINE PCollection(
00578 int dummy,
00579 const PCollection * coll
00580 );
00581 };
00582
00583
00584
00586
00587
00588 #include <ptlib/array.h>
00589
00591
00592
00593 #include <ptlib/lists.h>
00594
00596
00597
00598 #include <ptlib/dict.h>
00599
00600
00602
00603
00604 #include <ptlib/pstring.h>
00605
00606
00607
00609
00610
00611 #if P_USE_INLINES
00612 #include <ptlib/contain.inl>
00613 #endif
00614
00615 #endif // _CONTAIN_H
00616
00617
00618