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: 22375 $
00030  * $Author: rjongbloed $
00031  * $Date: 2009-04-06 21:47:23 -0500 (Mon, 06 Apr 2009) $
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(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;         // 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   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 // Abstract collection of objects class
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 // The abstract array class
00590 
00591 #include <ptlib/array.h>
00592 
00594 // The abstract array class
00595 
00596 #include <ptlib/lists.h>
00597 
00599 // PString class (specialised version of PBASEARRAY(char))
00600 
00601 #include <ptlib/dict.h>
00602 
00603 
00605 // PString class
00606 
00607 #include <ptlib/pstring.h>
00608 
00609 
00610 
00612 // Fill in all the inline functions
00613 
00614 #if P_USE_INLINES
00615 #include <ptlib/contain.inl>
00616 #endif
00617 
00618 
00619 #endif // PTLIB_CONTAIN_H
00620 
00621 
00622 // End Of File ///////////////////////////////////////////////////////////////

Generated on Thu May 27 01:36:47 2010 for PTLib by  doxygen 1.4.7