contain.h

Go to the documentation of this file.
00001 /*
00002  * contain.h
00003  *
00004  * Umbrella include for Container Classes.
00005  *
00006  * Portable Windows Library
00007  *
00008  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Portable Windows Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
00025  * All Rights Reserved.
00026  *
00027  * Contributor(s): ______________________________________.
00028  *
00029  * $Revision: 25387 $
00030  * $Author: rjongbloed $
00031  * $Date: 2011-03-22 22:51:09 -0500 (Tue, 22 Mar 2011) $
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 // Abstract container class
00049 
00050 // The type below cannot be nested into PContainer as DevStudio 2005 AUTOEXP.DAT doesn't like it
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;          // Size of what the container contains
00071     PAtomicInteger count;         // reference count to the container content - guaranteed to be atomic
00072     bool           deleteObjects; // Used by PCollection but put here for efficiency
00073     bool           constObject;   // Indicates object is constant/static, copy on write.
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 // Abstract collection of objects class
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 // The abstract array class
00607 
00608 #include <ptlib/array.h>
00609 
00611 // The abstract array class
00612 
00613 #include <ptlib/lists.h>
00614 
00616 // PString class (specialised version of PBASEARRAY(char))
00617 
00618 #include <ptlib/dict.h>
00619 
00620 
00622 // PString class
00623 
00624 #include <ptlib/pstring.h>
00625 
00626 
00627 
00629 // Fill in all the inline functions
00630 
00631 #if P_USE_INLINES
00632 #include <ptlib/contain.inl>
00633 #endif
00634 
00635 
00636 #endif // PTLIB_CONTAIN_H
00637 
00638 
00639 // End Of File ///////////////////////////////////////////////////////////////

Generated on Fri Feb 15 20:58:31 2013 for PTLib by  doxygen 1.4.7