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  * $Log: contain.h,v $
00030  * Revision 1.67  2007/08/01 05:20:48  rjongbloed
00031  * Changes to container classes to become compatible with advanced DevStudio 2005 "Visualizers".
00032  *
00033  * Revision 1.66  2006/04/10 23:57:27  csoutheren
00034  * Checked in changes to remove some warnings with gcc effc++ flag
00035  *
00036  * Revision 1.65  2005/11/25 03:43:47  csoutheren
00037  * Fixed function argument comments to be compatible with Doxygen
00038  *
00039  * Revision 1.64  2004/04/15 22:44:52  csoutheren
00040  * Re-applied gcc 2.95 patch as CVS screwed up
00041  *
00042  * Revision 1.63  2004/04/14 23:34:52  csoutheren
00043  * Added plugin for data access
00044  *
00045  * Revision 1.61  2004/04/12 00:36:04  csoutheren
00046  * Added new class PAtomicInteger and added Windows implementation
00047  *
00048  * Revision 1.60  2004/04/11 06:15:27  csoutheren
00049  * Modified to use Atomic_word if available
00050  *
00051  * Revision 1.59  2004/04/11 02:55:17  csoutheren
00052  * Added PCriticalSection for Windows
00053  * Added compile time option for PContainer to use critical sections to provide thread safety under some circumstances
00054  *
00055  * Revision 1.58  2004/04/09 03:42:34  csoutheren
00056  * Removed all usages of "virtual inline" and "inline virtual"
00057  *
00058  * Revision 1.57  2003/09/17 05:41:58  csoutheren
00059  * Removed recursive includes
00060  *
00061  * Revision 1.56  2003/09/17 01:18:02  csoutheren
00062  * Removed recursive include file system and removed all references
00063  * to deprecated coooperative threading support
00064  *
00065  * Revision 1.55  2003/03/31 01:23:56  robertj
00066  * Added ReadFrom functions for standard container classes such as
00067  *   PIntArray and PStringList etc
00068  *
00069  * Revision 1.54  2002/09/16 01:08:59  robertj
00070  * Added #define so can select if #pragma interface/implementation is used on
00071  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00072  *
00073  * Revision 1.53  2001/02/13 04:39:08  robertj
00074  * Fixed problem with operator= in container classes. Some containers will
00075  *   break unless the copy is virtual (eg PStringStream's buffer pointers) so
00076  *   needed to add a new AssignContents() function to all containers.
00077  *
00078  * Revision 1.52  1999/11/30 00:22:54  robertj
00079  * Updated documentation for doc++
00080  *
00081  * Revision 1.51  1999/08/22 12:13:42  robertj
00082  * Fixed warning when using inlines on older GNU compiler
00083  *
00084  * Revision 1.50  1999/08/17 03:46:40  robertj
00085  * Fixed usage of inlines in optimised version.
00086  *
00087  * Revision 1.49  1999/03/09 02:59:49  robertj
00088  * Changed comments to doc++ compatible documentation.
00089  *
00090  * Revision 1.48  1999/02/16 08:07:11  robertj
00091  * MSVC 6.0 compatibility changes.
00092  *
00093  * Revision 1.47  1998/09/23 06:20:23  robertj
00094  * Added open source copyright license.
00095  *
00096  * Revision 1.46  1997/07/08 13:15:04  robertj
00097  * DLL support.
00098  *
00099  * Revision 1.45  1996/08/17 10:00:20  robertj
00100  * Changes for Windows DLL support.
00101  *
00102  * Revision 1.44  1996/08/08 10:08:41  robertj
00103  * Directory structure changes for common files.
00104  *
00105  * Revision 1.43  1995/06/17 11:12:26  robertj
00106  * Documentation update.
00107  *
00108  * Revision 1.42  1995/03/14 12:41:13  robertj
00109  * Updated documentation to use HTML codes.
00110  *
00111  * Revision 1.41  1995/01/09  12:36:18  robertj
00112  * Removed unnecesary return value from I/O functions.
00113  * Changes due to Mac port.
00114  *
00115  * Revision 1.40  1994/12/13  11:50:45  robertj
00116  * Added MakeUnique() function to all container classes.
00117  *
00118  * Revision 1.39  1994/12/12  10:16:18  robertj
00119  * Restructuring and documentation of container classes.
00120  * Renaming of some macros for declaring container classes.
00121  * Added some extra functionality to PString.
00122  * Added start to 2 byte characters in PString.
00123  * Fixed incorrect overrides in PCaselessString.
00124  *
00125  * Revision 1.38  1994/12/05  11:18:58  robertj
00126  * Moved SetMinSize from PAbstractArray to PContainer.
00127  *
00128  * Revision 1.37  1994/11/28  12:33:44  robertj
00129  * Added dummy parameter for cls* constructor in containers. This prevents some very
00130  * strange an undesirable default construction of clones.
00131  *
00132  * Revision 1.36  1994/10/30  11:50:09  robertj
00133  * Split into Object classes and Container classes.
00134  * Changed mechanism for doing notification callback functions.
00135  *
00136  * Revision 1.35  1994/10/23  04:40:50  robertj
00137  * Made container * constractor protected.
00138  * Shorted OS Error assert.
00139  * Added printf constructor to PString.
00140  *
00141  * Revision 1.34  1994/09/25  10:36:41  robertj
00142  * Improved const behavious of container class macros.
00143  *
00144  * Revision 1.33  1994/08/23  11:32:52  robertj
00145  * Oops
00146  *
00147  * Revision 1.32  1994/08/22  00:46:48  robertj
00148  * Added pragma fro GNU C++ compiler.
00149  *
00150  * Revision 1.31  1994/08/21  23:43:02  robertj
00151  * Changed parameter before variable argument list to NOT be a reference.
00152  * Added object serialisation classes.
00153  *
00154  * Revision 1.30  1994/08/04  11:51:39  robertj
00155  * Rewrite of memory check functions.
00156  *
00157  * Revision 1.29  1994/07/27  05:58:07  robertj
00158  * Synchronisation.
00159  *
00160  * Revision 1.28  1994/07/25  03:33:50  robertj
00161  * Extra memory tests.
00162  *
00163  * Revision 1.27  1994/07/17  10:46:06  robertj
00164  * Added functions to strings in containers.
00165  *
00166  * Revision 1.26  1994/07/02  03:03:49  robertj
00167  * Addition of container searching facilities.
00168  *
00169  * Revision 1.25  1994/06/25  11:55:15  robertj
00170  * Unix version synchronisation.
00171  *
00172  * Revision 1.24  1994/04/20  12:17:44  robertj
00173  * Added code to assert
00174  *
00175  * Revision 1.23  1994/04/11  14:17:27  robertj
00176  * Made standard operators new and delete only declared for GNU C++
00177  *
00178  * Revision 1.22  1994/04/01  14:09:46  robertj
00179  * Removed PDECLARE_ABSTRACT_CONTAINER.
00180  * Added string stream class.
00181  * Added string containers.
00182  *
00183  * Revision 1.21  1994/03/07  07:38:19  robertj
00184  * Major enhancementsacross the board.
00185  *
00186  * Revision 1.20  1994/01/13  08:42:29  robertj
00187  * Fixed missing copy constuctor and assignment operator for PString.
00188  *
00189  * Revision 1.19  1994/01/13  05:33:41  robertj
00190  * Added contructor to get caseless string from ordinary string.
00191  *
00192  * Revision 1.18  1994/01/03  04:42:23  robertj
00193  * Mass changes to common container classes and interactors etc etc etc.
00194  *
00195  * Revision 1.17  1993/12/31  06:40:34  robertj
00196  * Made inlines optional for debugging purposes.
00197  * Added default to DeleteObjects() function.
00198  *
00199  * Revision 1.16  1993/12/24  04:20:52  robertj
00200  * Mac CFront port.
00201  *
00202  * Revision 1.15  1993/12/16  00:51:46  robertj
00203  * Made some container functions const.
00204  *
00205  * Revision 1.14  1993/12/15  21:10:10  robertj
00206  * Changes to fix inadequate reference system for containers.
00207  *
00208  * Revision 1.13  1993/12/14  18:44:56  robertj
00209  * Added RemoveAll() to collection classes.
00210  * Fixed incorrect destruction of objects in containers.
00211  *
00212  * Revision 1.12  1993/12/04  05:23:58  robertj
00213  * Added more string functions
00214  *
00215  * Revision 1.11  1993/09/27  16:35:25  robertj
00216  * Fixed bug in sorted lists.
00217  * Changed simple function for array of strings to a constructor.
00218  * Capitalised all macros.
00219  *
00220  * Revision 1.10  1993/08/27  18:17:47  robertj
00221  * Fixed bug with default number of elements in a collection.
00222  * Added missing Compare function to PAbstractSortedList
00223  * Added inline keywords for CFront compatibility.
00224  *
00225  * Revision 1.9  1993/08/21  01:50:33  robertj
00226  * Made Clone() function optional, default will assert if called.
00227  *
00228  * Revision 1.8  1993/08/19  18:00:32  robertj
00229  * Added two more standard base array classes
00230  *
00231  * Revision 1.7  1993/08/01  14:05:27  robertj
00232  * Added const to ToLower() and ToUpper() in the PString class.
00233  *
00234  * Revision 1.6  1993/07/16  14:40:55  robertj
00235  * Added PString constructor for individual characters.
00236  * Added string to C style literal format.
00237  *
00238  * Revision 1.5  1993/07/15  05:02:57  robertj
00239  * Removed redundant word in PString enum for string types.
00240  *
00241  * Revision 1.4  1993/07/15  04:23:39  robertj
00242  * Added constructor to PString to allow conversion from other string formats.
00243  * Fixed problem with variable parameter lists in sprintf() functions.
00244  *
00245  * Revision 1.3  1993/07/14  12:49:16  robertj
00246  * Fixed RCS keywords.
00247  *
00248  */
00249 
00250 #ifndef _CONTAIN_H
00251 #define _CONTAIN_H
00252 
00253 #ifdef P_USE_PRAGMA
00254 #pragma interface
00255 #endif
00256 
00257 #include <ptlib/object.h>
00258 #include <ptlib/critsec.h>
00259 
00261 // Abstract container class
00262 
00263 // The type below cannot be nested into PContainer as DevStudio 2005 AUTOEXP.DAT doesn't like it
00264 class PContainerReference {
00265   public:
00266     inline PContainerReference(PINDEX initialSize)
00267       : size(initialSize), count(1), deleteObjects(TRUE)
00268     {
00269     }
00270 
00271     inline PContainerReference(const PContainerReference & ref)
00272       : size(ref.size), count(1), deleteObjects(ref.deleteObjects)
00273     {  
00274     }
00275 
00276     PINDEX   size;         // Size of what the container contains
00277     PAtomicInteger count;  // reference count to the container content - guaranteed to be atomic
00278     BOOL deleteObjects;    // Used by PCollection but put here for efficiency
00279 
00280   private:
00281     PContainerReference & operator=(const PContainerReference &) 
00282     { return *this; }
00283 };
00284 
00307 class PContainer : public PObject
00308 {
00309   PCLASSINFO(PContainer, PObject);
00310 
00311   public:
00316     PContainer(
00317       PINDEX initialSize = 0  
00318     );
00319 
00324     PContainer(
00325       const PContainer & cont  
00326     );
00327 
00335     PContainer & operator=(
00336       const PContainer & cont  
00337     );
00338 
00343     virtual ~PContainer()
00344     { Destruct(); }
00345 
00347 
00356     virtual PINDEX GetSize() const;
00357 
00371     virtual BOOL SetSize(
00372       PINDEX newSize  
00373     ) = 0;
00374 
00380     BOOL SetMinSize(
00381       PINDEX minSize  
00382     );
00383 
00390     virtual BOOL IsEmpty() const;
00391 
00398     BOOL IsUnique() const;
00399 
00408     virtual BOOL MakeUnique();
00410 
00411   protected:
00422     PContainer(
00423       int dummy,        
00424       const PContainer * cont  
00425     );
00426 
00437     virtual void DestroyContents() = 0;
00438 
00448     virtual void AssignContents(const PContainer & c);
00449 
00461     void CopyContents(const PContainer & c);
00462 
00479     void CloneContents(const PContainer * src);
00480 
00484     void Destruct();
00485 
00486 
00487     PContainerReference * reference;
00488 };
00489 
00490 
00491 
00539 #define PCONTAINERINFO(cls, par) \
00540     PCLASSINFO(cls, par) \
00541   public: \
00542     cls(const cls & c) : par(c) { CopyContents(c); } \
00543     cls & operator=(const cls & c) \
00544       { AssignContents(c); return *this; } \
00545     virtual ~cls() { Destruct(); } \
00546     virtual BOOL MakeUnique() \
00547       { if(par::MakeUnique())return TRUE; CloneContents(this);return FALSE; } \
00548   protected: \
00549     cls(int dummy, const cls * c) : par(dummy, c) { CloneContents(c); } \
00550     virtual void DestroyContents(); \
00551     void CloneContents(const cls * c); \
00552     void CopyContents(const cls & c); \
00553     virtual void AssignContents(const PContainer & c) \
00554       { par::AssignContents(c); CopyContents((const cls &)c); }
00555 
00556 
00558 // Abstract collection of objects class
00559 
00591 class PCollection : public PContainer
00592 {
00593   PCLASSINFO(PCollection, PContainer);
00594 
00595   public:
00600     PCollection(
00601       PINDEX initialSize = 0  
00602     );
00604 
00620     virtual void PrintOn(
00621       ostream &strm   
00622     ) const;
00624 
00636     virtual PINDEX Append(
00637       PObject * obj   
00638     ) = 0;
00639 
00656     virtual PINDEX Insert(
00657       const PObject & before,   
00658       PObject * obj             
00659     ) = 0;
00660 
00672     virtual PINDEX InsertAt(
00673       PINDEX index,   
00674       PObject * obj   
00675     ) = 0;
00676 
00686     virtual BOOL Remove(
00687       const PObject * obj   
00688     ) = 0;
00689 
00698     virtual PObject * RemoveAt(
00699       PINDEX index   
00700     ) = 0;
00701 
00708     virtual void RemoveAll();
00709 
00723     virtual BOOL SetAt(
00724       PINDEX index,   
00725       PObject * val   
00726     ) = 0;
00727 
00733     virtual PObject * GetAt(
00734       PINDEX index  
00735     ) const = 0;
00736 
00743     virtual PINDEX GetObjectsIndex(
00744       const PObject * obj  
00745     ) const = 0;
00746 
00755     virtual PINDEX GetValuesIndex(
00756       const PObject & obj  
00757     ) const = 0;
00758 
00772     PINLINE void AllowDeleteObjects(
00773       BOOL yes = TRUE   
00774     );
00775 
00779     void DisallowDeleteObjects();
00781 
00782   protected:
00793     PINLINE PCollection(
00794       int dummy,        
00795       const PCollection * coll  
00796     );
00797 };
00798 
00799 
00800 
00802 // The abstract array class
00803 
00804 #include <ptlib/array.h>
00805 
00807 // The abstract array class
00808 
00809 #include <ptlib/lists.h>
00810 
00812 // PString class (specialised version of PBASEARRAY(char))
00813 
00814 #include <ptlib/dict.h>
00815 
00816 
00818 // PString class
00819 
00820 #include <ptlib/pstring.h>
00821 
00822 
00823 
00825 // Fill in all the inline functions
00826 
00827 #if P_USE_INLINES
00828 #include <ptlib/contain.inl>
00829 #endif
00830 
00831 #endif // _CONTAIN_H
00832 
00833 
00834 // End Of File ///////////////////////////////////////////////////////////////

Generated on Fri Mar 7 06:25:02 2008 for PTLib by  doxygen 1.5.1