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: 24177 $
00030  * $Author: rjongbloed $
00031  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
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   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;         // Size of what the container contains
00064     PAtomicInteger count;  // reference count to the container content - guaranteed to be atomic
00065     PBoolean deleteObjects;    // Used by PCollection but put here for efficiency
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 // Abstract collection of objects class
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 // The abstract array class
00592 
00593 #include <ptlib/array.h>
00594 
00596 // The abstract array class
00597 
00598 #include <ptlib/lists.h>
00599 
00601 // PString class (specialised version of PBASEARRAY(char))
00602 
00603 #include <ptlib/dict.h>
00604 
00605 
00607 // PString class
00608 
00609 #include <ptlib/pstring.h>
00610 
00611 
00612 
00614 // Fill in all the inline functions
00615 
00616 #if P_USE_INLINES
00617 #include <ptlib/contain.inl>
00618 #endif
00619 
00620 
00621 #endif // PTLIB_CONTAIN_H
00622 
00623 
00624 // End Of File ///////////////////////////////////////////////////////////////

Generated on Fri Oct 14 01:44:09 2011 for PTLib by  doxygen 1.4.7