object.h

Go to the documentation of this file.
00001 /*
00002  * object.h
00003  *
00004  * Mother of all ancestor 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: object.h,v $
00030  * Revision 1.131  2007/10/03 01:18:44  rjongbloed
00031  * Fixed build for Windows Mobile 5 and added Windows Mobile 6
00032  *
00033  * Revision 1.130  2007/09/17 11:14:42  rjongbloed
00034  * Added "No Trace" build configuration.
00035  *
00036  * Revision 1.129  2007/09/15 21:46:50  dsandras
00037  * Applied patch from Matthias Schneider to fix WIN32 build. Many thanks!
00038  *
00039  * Revision 1.128  2007/09/12 18:43:43  ykiryanov
00040  * Added !defined(_WIN32_WCE)  to new memory leakage dectection code. Memory organized other way on WCE based devices and crtdbg.h API  is not present
00041  *
00042  * Revision 1.127  2007/09/12 00:55:41  rjongbloed
00043  * Improved memory leak detection, reduce false positives.
00044  *
00045  * Revision 1.126  2007/09/09 10:29:49  rjongbloed
00046  * Fixed DevStudio 2003 build with memory check code.
00047  *
00048  * Revision 1.125  2007/09/09 09:42:48  rjongbloed
00049  * Fixed DevStudio 2003 build with memory check code.
00050  *
00051  * Revision 1.124  2007/09/08 11:34:28  rjongbloed
00052  * Improved memory checking (leaks etc), especially when using MSVC debug library.
00053  *
00054  * Revision 1.123  2007/08/17 08:46:01  csoutheren
00055  * Remove unnecessary inclusions of <iostream>
00056  *
00057  * Revision 1.122  2007/07/16 05:38:20  csoutheren
00058  * Fix compile problem when enabling memory checking on Windows
00059  *
00060  * Revision 1.121  2007/07/06 02:11:48  csoutheren
00061  * Add extra memory leak debugging on Linux
00062  * Remove compile warnings
00063  *
00064  * Revision 1.120  2007/05/16 07:54:21  csoutheren
00065  * Fix problems created by gcc 4.2.0
00066  *
00067  * Revision 1.119  2006/07/14 04:55:09  csoutheren
00068  * Applied 1520151 - Adds PID to tracefile + Rolling Date pattern
00069  * Thanks to Paul Nader
00070  *
00071  * Revision 1.118  2006/06/20 09:49:16  csoutheren
00072  * Applied 1489468
00073  * Fix stlport on old gcc/non-gcc compilers
00074  * Thanks to Adam Butcher
00075  *
00076  * Revision 1.117  2006/04/10 23:57:27  csoutheren
00077  * Checked in changes to remove some warnings with gcc effc++ flag
00078  *
00079  * Revision 1.116  2006/03/20 00:24:56  csoutheren
00080  * Applied patch #1446482
00081  * Thanks to Adam Butcher
00082  *
00083  * Revision 1.115  2005/11/30 12:47:37  csoutheren
00084  * Removed tabs, reformatted some code, and changed tags for Doxygen
00085  *
00086  * Revision 1.114  2005/11/25 03:43:47  csoutheren
00087  * Fixed function argument comments to be compatible with Doxygen
00088  *
00089  * Revision 1.113  2005/09/18 11:05:36  dominance
00090  * include/ptlib/channel.h, include/ptlib/pstring.h, src/ptlib/common/contain.cxx,
00091  * src/ptlib/common/pchannel.cxx:
00092  *   correct the STL defined checking to use proper syntax.
00093  *
00094  * include/ptlib/object.h:
00095  *   re-add typedef to compile on mingw
00096  *
00097  * make/ptlib-config.in:
00098  *   import a long-standing fix from the Debian packs which allows usage of
00099  *   ptlib-config without manually adding -lpt for each of the subsequent
00100  *   projects
00101  *
00102  * Revision 1.112  2005/08/30 06:36:39  csoutheren
00103  * Added ability to rotate output logs on a daily basis
00104  *
00105  * Revision 1.111  2005/03/10 06:37:20  csoutheren
00106  * Removed use of typeid on WIndows to get class name because it is not threadsafe
00107  * In fact, lets just use #classname everywhere because that will always work
00108  * Thanks to Vyacheslav Frolov
00109  *
00110  * Revision 1.110  2004/08/14 14:17:29  csoutheren
00111  * Fixed problem with PAssert and associated functions caused by using expressions
00112  * as statements. inline functions are your friend :)
00113  *
00114  * Revision 1.109  2004/08/05 12:09:35  rjongbloed
00115  * Added macros for "remove const" and "down cast" funcions with and without RTTI.
00116  * Added ability to disable Asserts.
00117  * Change PAssert macros so pass through the boolean result so that they can be used
00118  *   in if statements, allowing a chance to continue if ignore assert.
00119  *
00120  * Revision 1.108  2004/07/11 07:56:35  csoutheren
00121  * Applied jumbo VxWorks patch, thanks to Eize Slange
00122  *
00123  * Revision 1.107  2004/07/03 06:49:49  rjongbloed
00124  * Added PTRACE_PARAM() macro to fix warnings on parameters used in PTRACE
00125  *  macros only.
00126  *
00127  * Revision 1.106  2004/06/01 07:42:19  csoutheren
00128  * Restored memory allocation checking
00129  * Added configure flag to enable, thanks to Derek Smithies
00130  *
00131  * Revision 1.105  2004/06/01 05:22:43  csoutheren
00132  * Restored memory check functionality
00133  *
00134  * Revision 1.104  2004/05/12 04:36:17  csoutheren
00135  * Fixed problems with using sem_wait and friends on systems that do not
00136  * support atomic integers
00137  *
00138  * Revision 1.103  2004/04/18 04:33:36  rjongbloed
00139  * Changed all operators that return BOOL to return standard type bool. This is primarily
00140  *   for improved compatibility with std STL usage removing many warnings.
00141  *
00142  * Revision 1.102  2004/04/11 13:26:25  csoutheren
00143  * Removed namespace problems and removed warnings for Windows <string>
00144  *
00145  * Revision 1.101  2004/04/11 03:20:41  csoutheren
00146  * Added Unix implementation of PCriticalSection
00147  *
00148  * Revision 1.100  2004/04/11 02:55:17  csoutheren
00149  * Added PCriticalSection for Windows
00150  * Added compile time option for PContainer to use critical sections to provide thread safety under some circumstances
00151  *
00152  * Revision 1.99  2004/04/09 11:54:46  csoutheren
00153  * Added configure.in check for STL streams, and tested with gcc 2.95.3,
00154  * gcc 3.3.1, and gcc 3.3.3
00155  *
00156  * Revision 1.98  2004/04/09 07:53:51  rjongbloed
00157  * Fixed backward compatibility after STL streams change
00158  *
00159  * Revision 1.97  2004/04/09 00:56:35  csoutheren
00160  * Fixed problem with new class name code
00161  *
00162  * Revision 1.96  2004/04/09 00:42:58  csoutheren
00163  * Changed Unix build to use slightly different method for
00164  * keep class names, as GCC does not use actual class names for typeinfo
00165  *
00166  * Revision 1.95  2004/04/04 13:24:18  rjongbloed
00167  * Changes to support native C++ Run Time Type Information
00168  *
00169  * Revision 1.94  2004/04/03 08:57:31  csoutheren
00170  * Replaced pseudo-RTTI with real RTTI
00171  *
00172  * Revision 1.93  2004/04/03 08:22:20  csoutheren
00173  * Remove pseudo-RTTI and replaced with real RTTI
00174  *
00175  * Revision 1.92  2004/04/03 07:41:00  csoutheren
00176  * Fixed compile problem with ostringstream/ostrstream
00177  *
00178  * Revision 1.91  2004/04/03 07:16:05  rjongbloed
00179  * Fixed backward compatibility with MSVC 6
00180  *
00181  * Revision 1.90  2004/04/03 06:54:22  rjongbloed
00182  * Many and various changes to support new Visual C++ 2003
00183  *
00184  * Revision 1.89  2003/09/17 09:00:59  csoutheren
00185  * Moved PSmartPointer and PNotifier into seperate files
00186  * Added detection for system regex libraries on all platforms
00187  *
00188  * Revision 1.88  2003/09/17 05:41:58  csoutheren
00189  * Removed recursive includes
00190  *
00191  * Revision 1.87  2003/09/17 01:18:02  csoutheren
00192  * Removed recursive include file system and removed all references
00193  * to deprecated coooperative threading support
00194  *
00195  * Revision 1.86  2002/10/14 21:42:37  rogerh
00196  * Only use malloc.h on Windows
00197  *
00198  * Revision 1.85  2002/10/10 04:43:43  robertj
00199  * VxWorks port, thanks Martijn Roest
00200  *
00201  * Revision 1.84  2002/10/08 12:41:51  robertj
00202  * Changed for IPv6 support, thanks Sébastien Josset.
00203  *
00204  * Revision 1.83  2002/09/16 01:08:59  robertj
00205  * Added #define so can select if #pragma interface/implementation is used on
00206  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00207  *
00208  * Revision 1.82  2002/08/06 02:27:58  robertj
00209  * GNU C++ v3 compatibility.
00210  *
00211  * Revision 1.81  2002/06/25 02:22:47  robertj
00212  * Improved assertion system to allow C++ class name to be displayed if
00213  *   desired, especially relevant to container classes.
00214  *
00215  * Revision 1.80  2002/06/14 10:29:43  rogerh
00216  * STL + gcc 3.1 compile fix. Submitted by Klaus Kaempf <kkaempf@suse.de>
00217  *
00218  * Revision 1.79  2002/06/13 08:34:05  rogerh
00219  * gcc 3.1 needs iostream instead of iostream.h
00220  *
00221  * Revision 1.78  2002/05/22 00:23:31  craigs
00222  * Added GMTTime flag to tracing options
00223  *
00224  * Revision 1.77  2002/04/19 00:20:51  craigs
00225  * Added option to append to log file rather than create anew each time
00226  *
00227  * Revision 1.76  2002/01/26 23:55:55  craigs
00228  * Changed for GCC 3.0 compatibility, thanks to manty@manty.net
00229  *
00230  * Revision 1.75  2001/10/18 19:56:26  yurik
00231  * Fixed WinCE x86 compilation problems with memory check off
00232  *
00233  * Revision 1.74  2001/08/12 11:26:07  robertj
00234  * Put back PMEMORY_CHECK taken out by the Carbon port.
00235  *
00236  * Revision 1.73  2001/08/11 07:57:30  rogerh
00237  * Add Mac OS Carbon changes from John Woods <jfw@jfwhome.funhouse.com>
00238  *
00239  * Revision 1.72  2001/05/03 06:27:29  robertj
00240  * Added return value to PMemoryCheck::SetIgnoreAllocations() so get previous state.
00241  *
00242  * Revision 1.71  2001/03/24 01:11:10  robertj
00243  * Added missing PTRACE_IF define in non PTRACING mode.
00244  *
00245  * Revision 1.70  2001/03/23 05:34:09  robertj
00246  * Added PTRACE_IF to output trace if a conditional is TRUE.
00247  *
00248  * Revision 1.69  2001/03/01 02:15:16  robertj
00249  * Fixed PTRACE_LINE() so drops filename and line which may not be in trace otherwise.
00250  *
00251  * Revision 1.68  2001/02/22 08:16:41  robertj
00252  * Added standard trace file setup subroutine.
00253  *
00254  * Revision 1.67  2001/02/13 03:27:24  robertj
00255  * Added function to do heap validation.
00256  *
00257  * Revision 1.66  2001/02/09 04:41:27  robertj
00258  * Removed added non memrycheck implementations of new/delete when using GNU C++.
00259  *
00260  * Revision 1.65  2001/02/07 04:47:49  robertj
00261  * Added changes for possible random crashes in multi DLL environment
00262  *   due to memory allocation wierdness, thanks Milan Dimitrijevic.
00263  *
00264  * Revision 1.64  2001/01/24 06:15:44  yurik
00265  * Windows CE port-related declarations
00266  *
00267  * Revision 1.63  2000/07/28 05:13:47  robertj
00268  * Fixed silly mistake in runtime_malloc() function, should return a pointer!
00269  *
00270  * Revision 1.62  2000/07/20 05:46:34  robertj
00271  * Added runtime_malloc() function for cases where memory check code must be bypassed.
00272  *
00273  * Revision 1.61  2000/07/13 15:45:35  robertj
00274  * Removed #define std that causes everyone so much grief!
00275  *
00276  * Revision 1.60  2000/06/26 11:17:19  robertj
00277  * Nucleus++ port (incomplete).
00278  *
00279  * Revision 1.59  2000/02/29 12:26:14  robertj
00280  * Added named threads to tracing, thanks to Dave Harvey
00281  *
00282  * Revision 1.58  2000/01/07 12:31:12  robertj
00283  * Fixed 8 byte alignment on memory heap checking.
00284  *
00285  * Revision 1.57  2000/01/05 00:29:12  robertj
00286  * Fixed alignment problems in memory checking debug functions.
00287  *
00288  * Revision 1.56  1999/11/30 00:22:54  robertj
00289  * Updated documentation for doc++
00290  *
00291  * Revision 1.55  1999/11/01 00:10:27  robertj
00292  * Added override of new functions for MSVC memory check code.
00293  *
00294  * Revision 1.54  1999/10/19 09:21:30  robertj
00295  * Added functions to get current trace options and level.
00296  *
00297  * Revision 1.53  1999/09/13 13:15:06  robertj
00298  * Changed PTRACE so will output to system log in PServiceProcess applications.
00299  *
00300  * Revision 1.52  1999/08/24 08:15:23  robertj
00301  * Added missing operator on smart pointer to return the pointer!
00302  *
00303  * Revision 1.51  1999/08/24 06:54:36  robertj
00304  * Cleaned up the smart pointer code (macros).
00305  *
00306  * Revision 1.50  1999/08/22 13:38:39  robertj
00307  * Fixed termination hang up problem with memory check code under unix pthreads.
00308  *
00309  * Revision 1.49  1999/08/17 03:46:40  robertj
00310  * Fixed usage of inlines in optimised version.
00311  *
00312  * Revision 1.48  1999/08/10 10:45:09  robertj
00313  * Added mutex in memory check detection code.
00314  *
00315  * Revision 1.47  1999/07/18 15:08:24  robertj
00316  * Fixed 64 bit compatibility
00317  *
00318  * Revision 1.46  1999/06/14 07:59:37  robertj
00319  * Enhanced tracing again to add options to trace output (timestamps etc).
00320  *
00321  * Revision 1.45  1999/05/01 11:29:19  robertj
00322  * Alpha linux port changes.
00323  *
00324  * Revision 1.44  1999/04/18 12:58:39  robertj
00325  * MSVC 5 backward compatibility
00326  *
00327  * Revision 1.43  1999/03/09 10:30:17  robertj
00328  * Fixed ability to have PMEMORY_CHECK on/off on both debug/release versions.
00329  *
00330  * Revision 1.42  1999/03/09 02:59:50  robertj
00331  * Changed comments to doc++ compatible documentation.
00332  *
00333  * Revision 1.41  1999/02/23 07:11:26  robertj
00334  * Improved trace facility adding trace levels and #define to remove all trace code.
00335  *
00336  * Revision 1.40  1999/02/22 10:48:14  robertj
00337  * Fixed delete operator prototypes for MSVC6 and GNU compatibility.
00338  *
00339  * Revision 1.39  1999/02/19 11:33:02  robertj
00340  * Fixed compatibility problems with GNU/MSVC6
00341  *
00342  * Revision 1.38  1999/02/16 08:12:22  robertj
00343  * MSVC 6.0 compatibility changes.
00344  *
00345  * Revision 1.37  1999/01/07 03:35:35  robertj
00346  * Added default for PCHAR8 to ANSI, removes need for compiler option.
00347  *
00348  * Revision 1.36  1998/12/15 09:00:29  robertj
00349  * Fixed 8 byte alignment problem in memory leak check code for sparc.
00350  *
00351  * Revision 1.35  1998/11/03 00:57:19  robertj
00352  * Added allocation breakpoint variable.
00353  *
00354  * Revision 1.34  1998/10/26 11:05:26  robertj
00355  * Added raw free for things allocated within the runtime library.
00356  *
00357  * Revision 1.33  1998/10/18 14:26:55  robertj
00358  * Improved tracing functions.
00359  *
00360  * Revision 1.32  1998/10/15 07:47:21  robertj
00361  * Added ability to ignore G++lib memory leaks.
00362  *
00363  * Revision 1.31  1998/10/15 01:53:58  robertj
00364  * GNU compatibility.
00365  *
00366  * Revision 1.30  1998/10/13 14:23:29  robertj
00367  * Complete rewrite of memory leak detection.
00368  *
00369  * Revision 1.29  1998/09/23 06:20:57  robertj
00370  * Added open source copyright license.
00371  *
00372  * Revision 1.28  1998/09/14 12:29:11  robertj
00373  * Fixed memory leak dump under windows to not include static globals.
00374  * Fixed problem with notifier declaration not allowing implementation inline after macro.
00375  *
00376  * Revision 1.27  1997/07/08 13:13:45  robertj
00377  * DLL support.
00378  *
00379  * Revision 1.26  1997/04/27 05:50:11  robertj
00380  * DLL support.
00381  *
00382  * Revision 1.25  1997/02/05 11:54:10  robertj
00383  * Fixed problems with memory check and leak detection.
00384  *
00385  * Revision 1.24  1996/09/16 12:57:23  robertj
00386  * DLL support
00387  *
00388  * Revision 1.23  1996/08/17 10:00:23  robertj
00389  * Changes for Windows DLL support.
00390  *
00391  * Revision 1.22  1996/07/15 10:27:51  robertj
00392  * Changed endian classes to be memory mapped.
00393  *
00394  * Revision 1.21  1996/05/09 12:14:48  robertj
00395  * Fixed up 64 bit integer class for Mac platform.
00396  *
00397  * Revision 1.20  1996/02/24 14:19:29  robertj
00398  * Fixed bug in endian independent integer code for memory transfers.
00399  *
00400  * Revision 1.19  1996/01/28 02:46:43  robertj
00401  * Removal of MemoryPointer classes as usage didn't work for GNU.
00402  * Added missing bit shift operators to 64 bit integer class.
00403  *
00404  * Revision 1.18  1996/01/23 13:14:32  robertj
00405  * Added const version of PMemoryPointer.
00406  * Added constructor to endian classes for the base type.
00407  *
00408  * Revision 1.17  1996/01/02 11:54:11  robertj
00409  * Mac OS compatibility changes.
00410  *
00411  * Revision 1.16  1995/11/09 12:17:10  robertj
00412  * Added platform independent base type access classes.
00413  *
00414  * Revision 1.15  1995/06/17 11:12:47  robertj
00415  * Documentation update.
00416  *
00417  * Revision 1.14  1995/06/04 12:34:19  robertj
00418  * Added trace functions.
00419  *
00420  * Revision 1.13  1995/04/25 12:04:35  robertj
00421  * Fixed borland compatibility.
00422  * Fixed function hiding ancestor virtuals.
00423  *
00424  * Revision 1.12  1995/03/14 12:41:54  robertj
00425  * Updated documentation to use HTML codes.
00426  *
00427  * Revision 1.11  1995/03/12  04:40:55  robertj
00428  * Changed standard error code for not open from file to channel.
00429  *
00430  * Revision 1.10  1995/02/19  04:19:14  robertj
00431  * Added dynamically linked command processing.
00432  *
00433  * Revision 1.9  1995/02/05  00:48:07  robertj
00434  * Fixed template version.
00435  *
00436  * Revision 1.8  1995/01/15  04:51:31  robertj
00437  * Mac compatibility.
00438  * Added levels of memory checking.
00439  *
00440  * Revision 1.7  1995/01/09  12:38:31  robertj
00441  * Changed variable names around during documentation run.
00442  * Fixed smart pointer comparison.
00443  * Fixed serialisation stuff.
00444  * Documentation.
00445  *
00446  * Revision 1.6  1995/01/03  09:39:06  robertj
00447  * Put standard malloc style memory allocation etc into memory check system.
00448  *
00449  * Revision 1.5  1994/12/12  10:08:30  robertj
00450  * Renamed PWrapper to PSmartPointer..
00451  *
00452  * Revision 1.4  1994/12/05  11:23:28  robertj
00453  * Fixed PWrapper macros.
00454  *
00455  * Revision 1.3  1994/11/19  00:22:55  robertj
00456  * Changed PInteger to be INT, ie standard type like BOOL/WORD etc.
00457  * Moved null object check in notifier to construction rather than use.
00458  * Added virtual to the callback function in notifier destination class.
00459  *
00460  * Revision 1.2  1994/11/03  09:25:30  robertj
00461  * Made notifier destination object not to be descendent of PObject.
00462  *
00463  * Revision 1.1  1994/10/30  12:01:37  robertj
00464  * Initial revision
00465  *
00466  */
00467 
00468 #ifndef _POBJECT_H
00469 #define _POBJECT_H
00470 
00471 #ifdef P_USE_PRAGMA
00472 #pragma interface
00473 #endif
00474 
00475 #ifdef _WIN32
00476 #include "msos/ptlib/contain.h"
00477 #else
00478 #include "unix/ptlib/contain.h"
00479 #endif
00480 
00481 #if defined(P_VXWORKS)
00482 #include <private/stdiop.h>
00483 #endif
00484 
00485 #include <stdio.h>
00486 #include <stdarg.h>
00487 #include <stdlib.h>
00488 
00489 #include <string.h>
00490 
00491 #ifdef __USE_STL__
00492   #include <string>
00493   #include <iomanip>
00494   #include <iostream>
00495   #if (__GNUC__ >= 3)
00496     #include <sstream>
00497     typedef std::ostringstream ostrstream;
00498   #else
00499     #include <strstream>
00500   #endif
00501   //using namespace std;
00502   #ifdef _STLP_IOS_BASE_H
00503   typedef std::ios_base::fmtflags _Ios_Fmtflags;
00504   #endif
00505 #else
00506   #if (__GNUC__ >= 3)
00507     #include <iosfwd>
00508     #ifndef __MWERKS__
00509       #include <iomanip>
00510     #endif
00511   #else
00512     #include <iosfwd>
00513     #ifdef __GNUC__
00514       #include <strstream.h>
00515     #else
00516       #include <strstrea.h>
00517     #endif
00518     #ifndef __MWERKS__
00519       #include <iomanip.h>
00520     #endif
00521   #endif
00522 #endif
00523 
00524 #if (__GNUC__ < 3) && !defined(_STLP_IOS_BASE_H)
00525 typedef long _Ios_Fmtflags;
00526 #endif
00527 
00528 #if _MSC_VER<1300
00529 #define _BADOFF -1
00530 #endif
00531 
00533 // Disable inlines when debugging for faster compiles (the compiler doesn't
00534 // actually inline the function with debug on any way).
00535 
00536 #ifndef P_USE_INLINES
00537 #ifdef _DEBUG
00538 #define P_USE_INLINES 0
00539 #else
00540 #define P_USE_INLINES 0
00541 #endif
00542 #endif
00543 
00544 #if P_USE_INLINES
00545 #define PINLINE inline
00546 #else
00547 #define PINLINE
00548 #endif
00549 
00550 
00552 // Declare the debugging support
00553 
00554 #ifndef P_USE_ASSERTS
00555 #define P_USE_ASSERTS 1
00556 #endif
00557 
00558 #if !P_USE_ASSERTS
00559 
00560 #define PAssert(b, m) (b)
00561 #define PAssert2(b, c, m) (b)
00562 #define PAssertOS(b) (b)
00563 #define PAssertNULL(p) (p)
00564 #define PAssertAlways(m)
00565 #define PAssertAlways2(c, m)
00566 
00567 #else // P_USE_ASSERTS
00568 
00570 enum PStandardAssertMessage {
00571   PLogicError,              // A logic error occurred.
00572   POutOfMemory,             // A new or malloc failed.
00573   PNullPointerReference,    // A reference was made through a NULL pointer.
00574   PInvalidCast,             // An invalid cast to descendant is required.
00575   PInvalidArrayIndex,       // An index into an array was negative.
00576   PInvalidArrayElement,     // A NULL array element object was accessed.
00577   PStackEmpty,              // A Pop() was made of a stack with no elements.
00578   PUnimplementedFunction,   // Funtion is not implemented.
00579   PInvalidParameter,        // Invalid parameter was passed to a function.
00580   POperatingSystemError,    // Error was returned by Operating System.
00581   PChannelNotOpen,          // Operation attempted when channel not open.
00582   PUnsupportedFeature,      // Feature is not supported.
00583   PInvalidWindow,           // Access through invalid window.
00584   PMaxStandardAssertMessage
00585 };
00586 
00587 #define __CLASS__ NULL
00588 
00589 void PAssertFunc(const char * file, int line, const char * className, PStandardAssertMessage msg);
00590 void PAssertFunc(const char * file, int line, const char * className, const char * msg);
00591 void PAssertFunc(const char * full_msg);
00592 
00593 inline bool PAssertFuncInline(bool b, const char * file, int line, const char * className, PStandardAssertMessage msg)
00594 {
00595   if (!b) 
00596     PAssertFunc(file, line, className, msg);
00597   return b;
00598 }
00599 inline bool PAssertFuncInline(bool b, const char * file, int line, const char * className, const char * msg)
00600 {
00601   if (!b) 
00602     PAssertFunc(file, line, className, msg);
00603   return b;
00604 }
00605 
00612 #define PAssert(b, m) PAssertFuncInline((b), __FILE__,__LINE__,__CLASS__,(m))
00613 
00621 #define PAssert2(b, c, m) PAssertFuncInline((b), __FILE__,__LINE__,(c),(m))
00622 
00629 #define PAssertOS(b) PAssertFuncInline((b), __FILE__,__LINE__,__CLASS__,POperatingSystemError)
00630 
00640 #define PAssertNULL(p) (((p)!=NULL)?(p): \
00641                      (PAssertFunc(__FILE__,__LINE__, __CLASS__, PNullPointerReference),(p)))
00642 
00649 #define PAssertAlways(m) PAssertFunc(__FILE__,__LINE__,__CLASS__,(m))
00650 
00657 #define PAssertAlways2(c, m) PAssertFunc(__FILE__,__LINE__,(c),(m))
00658 
00659 #endif // P_USE_ASSERTS
00660 
00661 
00666 ostream & PGetErrorStream();
00667 
00671 void PSetErrorStream(ostream * strm  );
00672 
00687 #define PError (PGetErrorStream())
00688 
00689 
00690 
00692 // Debug and tracing
00693 
00694 #ifndef PTRACING
00695 #define PTRACING 1
00696 #endif
00697 
00698 #if PTRACING
00699 
00704 class PTrace
00705 {
00706 public:
00708   enum Options {
00714     Blocks = 1,
00716     DateAndTime = 2,
00718     Timestamp = 4,
00720     Thread = 8,
00722     TraceLevel = 16,
00724     FileAndLine = 32,
00726     ThreadAddress = 64,
00728     AppendToFile = 128,
00731     GMTTime = 256,
00734     RotateDaily = 512,
00738     SystemLogStream = 32768
00739   };
00740 
00748   static void Initialise(
00749     unsigned level,
00750     const char * filename = NULL,
00751     unsigned options = Timestamp | Thread | Blocks
00752   );
00753 
00764   static void Initialise(
00765     unsigned level,
00766     const char * filename,
00767     const char * rolloverPattern,
00768     unsigned options = Timestamp | Thread | Blocks
00769   );
00770 
00777   static void SetOptions(unsigned options  );
00778 
00786   static void ClearOptions(unsigned options  );
00787 
00792   static unsigned GetOptions();
00793 
00799   static void SetLevel(unsigned level  );
00800 
00806   static unsigned GetLevel();
00807 
00812   static BOOL CanTrace(unsigned level );
00813 
00818   static void SetStream(ostream * out  );
00819 
00835   static ostream & Begin(
00836     unsigned level,         
00837     const char * fileName,  
00838     int lineNum             
00839   );
00840 
00857   static ostream & End(ostream & strm );
00858 
00859 
00865   class Block {
00866     public:
00868       Block(
00869         const char * fileName, 
00870         int lineNum,           
00871         const char * traceName
00873        );
00874       Block(const Block & obj)
00875         : file(obj.file), line(obj.line), name(obj.name) { }
00877       ~Block();
00878     private:
00879       Block & operator=(const Block &)
00880       { return *this; }
00881       const char * file;
00882       int          line;
00883       const char * name;
00884   };
00885 };
00886 
00887 /* Macro to conditionally declare a parameter to a function to avoid compiler
00888    warning due that parameter only being used in a PTRACE */
00889 #define PTRACE_PARAM(param) param
00890 
00897 #define PTRACE_BLOCK(name) PTrace::Block __trace_block_instance(__FILE__, __LINE__, name)
00898 
00902 #define PTRACE_LINE() \
00903     if (!PTrace::CanTrace(1)) ; else \
00904       PTrace::Begin(1, __FILE__, __LINE__) << __FILE__ << '(' << __LINE__ << ')' << PTrace::End
00905 
00911 #define PTRACE(level, args) \
00912     if (!PTrace::CanTrace(level)) ; else \
00913       PTrace::Begin(level, __FILE__, __LINE__) << args << PTrace::End
00914 
00922 #define PTRACE_IF(level, cond, args) \
00923     if (!(PTrace::CanTrace(level)  && (cond))) ; else \
00924       PTrace::Begin(level, __FILE__, __LINE__) << args << PTrace::End
00925 
00926 #else // PTRACING
00927 
00928 #define PTRACE_PARAM(param)
00929 #define PTRACE_BLOCK(n)
00930 #define PTRACE_LINE()
00931 #define PTRACE(level, arg)
00932 #define PTRACE_IF(level, cond, args)
00933 
00934 #endif // PTRACING
00935 
00936 
00937 
00938 #if PMEMORY_CHECK || (defined(_MSC_VER) && defined(_DEBUG) && !defined(_WIN32_WCE)) 
00939 
00940 #define PMEMORY_HEAP 1
00941 
00948 class PMemoryHeap {
00949   public:
00951     PMemoryHeap();
00952 
00953     // Clear up the memory checking subsystem, dumping memory leaks.
00954     ~PMemoryHeap();
00955 
00962     static void * Allocate(
00963       size_t nSize,           
00964       const char * file,      
00965       int line,               
00966       const char * className  
00967     );
00974     static void * Allocate(
00975       size_t count,       
00976       size_t iSize,       
00977       const char * file,  
00978       int line            
00979     );
00980 
00988     static void * Reallocate(
00989       void * ptr,         
00990       size_t nSize,       
00991       const char * file,  
00992       int line            
00993     );
00994 
01000     static void Deallocate(
01001       void * ptr,             
01002       const char * className  
01003     );
01004 
01007     enum Validation {
01008       Ok, Bad, Trashed
01009     };
01017     static Validation Validate(
01018       const void * ptr,       
01019       const char * className, 
01020       ostream * error         
01021     );
01022 
01027     static BOOL ValidateHeap(
01028       ostream * error = NULL  
01029     );
01030 
01036     static BOOL SetIgnoreAllocations(
01037       BOOL ignore  
01038     );
01039 
01043     static void DumpStatistics();
01047     static void DumpStatistics(ostream & strm );
01048 
01049 #if PMEMORY_CHECK
01050     struct State {
01051       DWORD allocationNumber;
01052     };
01053 #else
01054         typedef _CrtMemState State;
01055 #endif
01056 
01057     /* Get memory state.
01058       This returns a state that may be used to determine where to start dumping
01059       objects from.
01060      */
01061     static void GetState(
01062       State & state  
01063     );
01064 
01072     static void DumpObjectsSince(
01073       const State & when    
01074     );
01075 
01081     static void DumpObjectsSince(
01082       const State & when,   
01083       ostream & strm        
01084     );
01085 
01091     static void SetAllocationBreakpoint(
01092       DWORD point   
01093     );
01094 
01095 #if PMEMORY_CHECK
01096 
01097   protected:
01098     void * InternalAllocate(
01099       size_t nSize,           // Number of bytes to allocate.
01100       const char * file,      // Source file name for allocating function.
01101       int line,               // Source file line for allocating function.
01102       const char * className  // Class name for allocating function.
01103     );
01104     Validation InternalValidate(
01105       const void * ptr,       // Pointer to memory block to check
01106       const char * className, // Class name it should be.
01107       ostream * error         // Stream to receive error message (may be NULL)
01108     );
01109     void InternalDumpStatistics(ostream & strm);
01110     void InternalDumpObjectsSince(DWORD objectNumber, ostream & strm);
01111 
01112     class Wrapper {
01113       public:
01114         Wrapper();
01115         ~Wrapper();
01116         PMemoryHeap * operator->() const { return instance; }
01117       private:
01118         PMemoryHeap * instance;
01119     };
01120     friend class Wrapper;
01121 
01122     enum Flags {
01123       NoLeakPrint = 1
01124     };
01125 
01126 #pragma pack(1)
01127     struct Header {
01128       enum {
01129         // Assure that the Header struct is aligned to 8 byte boundary
01130         NumGuardBytes = 16 - (sizeof(Header *) +
01131                               sizeof(Header *) +
01132                               sizeof(const char *) +
01133                               sizeof(const char *) +
01134                               sizeof(size_t) +
01135                               sizeof(DWORD) +
01136                               sizeof(WORD) +
01137                               sizeof(BYTE)
01138 #ifdef P_LINUX
01139                               + sizeof(pthread_t)
01140 #endif
01141                               )%8
01142       };
01143 
01144       Header     * prev;
01145       Header     * next;
01146       const char * className;
01147       const char * fileName;
01148       size_t       size;
01149       DWORD        request;
01150       WORD         line;
01151       BYTE         flags;
01152 #ifdef P_LINUX
01153       pthread_t    thread;
01154 #endif
01155       char         guard[NumGuardBytes];
01156 
01157       static char GuardBytes[NumGuardBytes];
01158     };
01159 #pragma pack()
01160 
01161     BOOL isDestroyed;
01162 
01163     Header * listHead;
01164     Header * listTail;
01165 
01166     static DWORD allocationBreakpoint;
01167     DWORD allocationRequest;
01168     DWORD firstRealObject;
01169     BYTE  flags;
01170 
01171     char  allocFillChar;
01172     char  freeFillChar;
01173 
01174     DWORD currentMemoryUsage;
01175     DWORD peakMemoryUsage;
01176     DWORD currentObjects;
01177     DWORD peakObjects;
01178     DWORD totalObjects;
01179 
01180     ostream * leakDumpStream;
01181 
01182 #if defined(_WIN32)
01183     CRITICAL_SECTION mutex;
01184 #elif defined(P_PTHREADS)
01185     pthread_mutex_t mutex;
01186 #elif defined(P_VXWORKS)
01187     void * mutex;
01188 #endif
01189 
01190 #else
01191 
01192 #define P_CLIENT_BLOCK (_CLIENT_BLOCK|(0x61<<16)) // This identifies a PObject derived class
01193     _CrtMemState initialState;
01194 
01195 #endif // PMEMORY_CHECK
01196 };
01197 
01198 
01203 inline void * runtime_malloc(size_t bytes  ) { return malloc(bytes); }
01204 
01209 inline void runtime_free(void * ptr  ) { free(ptr); }
01210 
01211 
01218 #define malloc(s) PMemoryHeap::Allocate(s, __FILE__, __LINE__, NULL)
01219 
01226 #define calloc(n,s) PMemoryHeap::Allocate(n, s, __FILE__, __LINE__)
01227 
01234 #define realloc(p,s) PMemoryHeap::Reallocate(p, s, __FILE__, __LINE__)
01235 
01236 
01243 #define free(p) PMemoryHeap::Deallocate(p, NULL)
01244 
01245 
01252 #define cfree(p) PMemoryHeap::Deallocate(p, NULL)
01253 
01254 
01269 #define PNEW  new (__FILE__, __LINE__)
01270 
01271 #if !defined(_MSC_VER) || _MSC_VER<1200
01272 #define PSPECIAL_DELETE_FUNCTION
01273 #else
01274 #define PSPECIAL_DELETE_FUNCTION \
01275     void operator delete(void * ptr, const char *, int) \
01276       { PMemoryHeap::Deallocate(ptr, Class()); } \
01277     void operator delete[](void * ptr, const char *, int) \
01278       { PMemoryHeap::Deallocate(ptr, Class()); }
01279 #endif
01280 
01281 #define PNEW_AND_DELETE_FUNCTIONS \
01282     void * operator new(size_t nSize, const char * file, int line) \
01283       { return PMemoryHeap::Allocate(nSize, file, line, Class()); } \
01284     void * operator new(size_t nSize) \
01285       { return PMemoryHeap::Allocate(nSize, NULL, 0, Class()); } \
01286     void operator delete(void * ptr) \
01287       { PMemoryHeap::Deallocate(ptr, Class()); } \
01288     void * operator new(size_t, void * placement) \
01289       { return placement; } \
01290     void operator delete(void *, void *) \
01291       { } \
01292     void * operator new[](size_t nSize, const char * file, int line) \
01293       { return PMemoryHeap::Allocate(nSize, file, line, Class()); } \
01294     void * operator new[](size_t nSize) \
01295       { return PMemoryHeap::Allocate(nSize, NULL, 0, Class()); } \
01296     void operator delete[](void * ptr) \
01297       { PMemoryHeap::Deallocate(ptr, Class()); } \
01298     PSPECIAL_DELETE_FUNCTION
01299 
01300 
01301 inline void * operator new(size_t nSize, const char * file, int line)
01302   { return PMemoryHeap::Allocate(nSize, file, line, NULL); }
01303 
01304 inline void * operator new[](size_t nSize, const char * file, int line)
01305   { return PMemoryHeap::Allocate(nSize, file, line, NULL); }
01306 
01307 #ifndef __GNUC__
01308 void * operator new(size_t nSize);
01309 void * operator new[](size_t nSize);
01310 
01311 void operator delete(void * ptr);
01312 void operator delete[](void * ptr);
01313 
01314 #if defined(_MSC_VER) && _MSC_VER>=1200
01315 inline void operator delete(void * ptr, const char *, int)
01316   { PMemoryHeap::Deallocate(ptr, NULL); }
01317 
01318 inline void operator delete[](void * ptr, const char *, int)
01319   { PMemoryHeap::Deallocate(ptr, NULL); }
01320 #endif
01321 #endif
01322 
01323 
01324 class PMemoryHeapIgnoreAllocationsForScope {
01325 public:
01326   PMemoryHeapIgnoreAllocationsForScope() : previousIgnoreAllocations(PMemoryHeap::SetIgnoreAllocations(TRUE)) { }
01327   ~PMemoryHeapIgnoreAllocationsForScope() { PMemoryHeap::SetIgnoreAllocations(previousIgnoreAllocations); }
01328 private:
01329   BOOL previousIgnoreAllocations;
01330 };
01331 
01332 #define PMEMORY_IGNORE_ALLOCATIONS_FOR_SCOPE PMemoryHeapIgnoreAllocationsForScope instance_PMemoryHeapIgnoreAllocationsForScope
01333 
01334 class PMemoryAllocationBreakpoint {
01335 public:
01336   PMemoryAllocationBreakpoint(DWORD point)
01337   {
01338     PMemoryHeap::SetAllocationBreakpoint(point);
01339   }
01340 };
01341 
01342 #define PMEMORY_ALLOCATION_BREAKPOINT(point) PMemoryAllocationBreakpoint PMemoryAllocationBreakpointInstance(point)
01343 
01344 
01345 #else // PMEMORY_CHECK || (defined(_MSC_VER) && defined(_DEBUG))
01346 
01347 #define PMEMORY_HEAP 0
01348 
01349 #define PNEW new
01350 
01351 #define PNEW_AND_DELETE_FUNCTIONS
01352 
01353 #define runtime_malloc(s) malloc(s)
01354 #define runtime_free(p) free(p)
01355 
01356 #define PMEMORY_IGNORE_ALLOCATIONS_FOR_SCOPE
01357 #define PMEMORY_ALLOCATION_BREAKPOINT(point)
01358 
01359 #endif // PMEMORY_CHECK || (defined(_MSC_VER) && defined(_DEBUG))
01360 
01361 
01372 #define PCLASSINFO(cls, par) \
01373   public: \
01374     static inline const char * Class() \
01375       { return #cls; } \
01376     virtual BOOL InternalIsDescendant(const char * clsName) const \
01377       { return strcmp(clsName, cls::Class()) == 0 || par::InternalIsDescendant(clsName); } \
01378     virtual const char * GetClass(unsigned ancestor = 0) const \
01379       { return ancestor > 0 ? par::GetClass(ancestor-1) : cls::Class(); } \
01380     virtual Comparison CompareObjectMemoryDirect(const PObject & obj) const \
01381       { return (Comparison)memcmp(this, &obj, sizeof(cls)); } \
01382     PNEW_AND_DELETE_FUNCTIONS
01383 
01384 
01385 #if P_HAS_TYPEINFO
01386 
01387 #define PIsDescendant(ptr, cls)    (dynamic_cast<const cls *>(ptr) != NULL) 
01388 #define PIsDescendantStr(ptr, str) ((ptr)->InternalIsDescendant(str)) 
01389 
01390 #define PRemoveConst(cls, ptr)  (const_cast<cls*>(ptr))
01391 
01392 #if P_USE_ASSERTS
01393 template<class BaseClass> inline BaseClass * PAssertCast(BaseClass * obj, const char * file, int line) 
01394   { if (obj == NULL) PAssertFunc(file, line, BaseClass::Class(), PInvalidCast); return obj; }
01395 #define PDownCast(cls, ptr) PAssertCast<cls>(dynamic_cast<cls*>(ptr),__FILE__,__LINE__)
01396 #else
01397 #define PDownCast(cls, ptr) (dynamic_cast<cls*>(ptr))
01398 #endif
01399 
01400 #include <typeinfo>
01401 
01402 #else // P_HAS_TYPEINFO
01403 
01404 #define PIsDescendant(ptr, cls)    ((ptr)->InternalIsDescendant(cls::Class()))
01405 #define PIsDescendantStr(ptr, str) ((ptr)->InternalIsDescendant(str))
01406 
01407 #define PRemoveConst(cls, ptr)  ((cls*)(ptr))
01408 
01409 #if P_USE_ASSERTS
01410 template<class BaseClass> inline BaseClass * PAssertCast(PObject * obj, const char * file, int line) 
01411   { if (obj->InternalIsDescendant(BaseClass::Class()) return (BaseClass *)obj; PAssertFunc(file, line, BaseClass::Class(), PInvalidCast); return NULL; }
01412 #define PDownCast(cls, ptr) PAssertCast<cls>((ptr),__FILE__,__LINE__)
01413 #else
01414 #define PDownCast(cls, ptr) ((cls*)(ptr))
01415 #endif
01416 
01417 #endif // P_HAS_TYPEINFO
01418 
01419 
01428 #define PDECLARE_CLASS(cls, par) class cls : public par { PCLASSINFO(cls, par)
01429 #ifdef DOC_PLUS_PLUS
01430 } Match previous opening brace in doc++
01431 #endif
01432 
01434 // The root of all evil ... umm classes
01435 
01440 class PObject {
01441 
01442   protected:
01446     PObject() { }
01447 
01448   public:
01449     /* Destructor required to get the "virtual". A PObject really has nothing
01450        to destroy.
01451      */
01452     virtual ~PObject() { }
01453 
01466     static inline const char * Class()    { return "PObject"; }
01467 
01480     virtual const char * GetClass(unsigned /*ancestor*/ = 0) const { return Class(); }
01481 
01482     BOOL IsClass(const char * cls) const 
01483     { return strcmp(cls, GetClass()) == 0; }
01484 
01494     virtual BOOL InternalIsDescendant(
01495       const char * clsName    // Ancestor class name to compare against.
01496     ) const
01497     { return IsClass(clsName); }
01498 
01500 
01506     enum Comparison {
01507       LessThan = -1,
01508       EqualTo = 0,
01509       GreaterThan = 1
01510     };
01511 
01523     virtual Comparison Compare(
01524       const PObject & obj   // Object to compare against.
01525     ) const;
01526     
01538     virtual Comparison CompareObjectMemoryDirect(
01539       const PObject & obj   // Object to compare against.
01540     ) const;
01541 
01547     bool operator==(
01548       const PObject & obj   // Object to compare against.
01549     ) const { return Compare(obj) == EqualTo; }
01550 
01556     bool operator!=(
01557       const PObject & obj   // Object to compare against.
01558     ) const { return Compare(obj) != EqualTo; }
01559 
01565     bool operator<(
01566       const PObject & obj   // Object to compare against.
01567     ) const { return Compare(obj) == LessThan; }
01568 
01574     bool operator>(
01575       const PObject & obj   // Object to compare against.
01576     ) const { return Compare(obj) == GreaterThan; }
01577 
01583     bool operator<=(
01584       const PObject & obj   // Object to compare against.
01585     ) const { return Compare(obj) != GreaterThan; }
01586 
01592     bool operator>=(
01593       const PObject & obj   // Object to compare against.
01594     ) const { return Compare(obj) != LessThan; }
01596 
01605     virtual void PrintOn(
01606       ostream &strm   // Stream to print the object into.
01607     ) const;
01608 
01615     virtual void ReadFrom(
01616       istream &strm   // Stream to read the objects contents from.
01617     );
01618 
01619 
01625     inline friend ostream & operator<<(
01626       ostream &strm,       // Stream to print the object into.
01627       const PObject & obj  // Object to print to the stream.
01628     ) { obj.PrintOn(strm); return strm; }
01629 
01635     inline friend istream & operator>>(
01636       istream &strm,   // Stream to read the objects contents from.
01637       PObject & obj    // Object to read inormation into.
01638     ) { obj.ReadFrom(strm); return strm; }
01639 
01640 
01655     virtual PObject * Clone() const;
01656 
01668     virtual PINDEX HashFunction() const;
01670 };
01671 
01673 // Platform independent types
01674 
01675 // All these classes encapsulate primitive types such that they may be
01676 // transfered in a platform independent manner. In particular it is used to
01677 // do byte swapping for little endien and big endien processor architectures
01678 // as well as accommodating structure packing rules for memory structures.
01679 
01680 #define PANSI_CHAR 1
01681 #define PLITTLE_ENDIAN 2
01682 #define PBIG_ENDIAN 3
01683 
01684 
01685 #if 0
01686 class PStandardType
01687 /* Encapsulate a standard 8 bit character into a portable format. This would
01688    rarely need to do translation, only if the target platform uses EBCDIC
01689    would it do anything.
01690 
01691    The platform independent form here is always 8 bit ANSI.
01692  */
01693 {
01694   public:
01695     PStandardType(
01696       type newVal   // Value to initialise data in platform dependent form.
01697     ) { data = newVal; }
01698     /* Create a new instance of the platform independent type using platform
01699        dependent data, or platform independent streams.
01700      */
01701 
01702     operator type() { return data; }
01703     /* Get the platform dependent value for the type.
01704 
01705        @return
01706        data for instance.
01707      */
01708 
01709     friend ostream & operator<<(ostream & strm, const PStandardType & val)
01710       { return strm << (type)val; }
01711     /* Output the platform dependent value for the type to the stream.
01712 
01713        @return
01714        the stream output was made to.
01715      */
01716 
01717     friend istream & operator>>(istream & strm, PStandardType & val)
01718       { type data; strm >> data; val = PStandardType(data); return strm; }
01719     /* Input the platform dependent value for the type from the stream.
01720 
01721        @return
01722        the stream input was made from.
01723      */
01724 
01725 
01726   private:
01727     type data;
01728 };
01729 #endif
01730 
01731 
01732 #define PI_SAME(name, type) \
01733   struct name { \
01734     name() : data(0) { } \
01735     name(type value) : data(value) { } \
01736     name(const name & value) : data(value.data) { } \
01737     name & operator =(type value) { data = value; return *this; } \
01738     name & operator =(const name & value) { data = value.data; return *this; } \
01739     operator type() const { return data; } \
01740     friend ostream & operator<<(ostream & s, const name & v) { return s << v.data; } \
01741     friend istream & operator>>(istream & s, name & v) { return s >> v.data; } \
01742     private: type data; \
01743   }
01744 
01745 #define PI_LOOP(src, dst) \
01746     BYTE *s = ((BYTE *)&src)+sizeof(src); BYTE *d = (BYTE *)&dst; \
01747     while (s != (BYTE *)&src) *d++ = *--s;
01748 
01749 #define PI_DIFF(name, type) \
01750   struct name { \
01751     name() : data(0) { } \
01752     name(type value) : data(0) { operator=(value); } \
01753     name(const name & value) : data(value.data) { } \
01754     name & operator =(type value) { PI_LOOP(value, data); return *this; } \
01755     name & operator =(const name & value) { data = value.data; return *this; } \
01756     operator type() const { type value; PI_LOOP(data, value); return value; } \
01757     friend ostream & operator<<(ostream & s, const name & value) { return s << (type)value; } \
01758     friend istream & operator>>(istream & s, name & v) { type val; s >> val; v = val; return s; } \
01759     private: type data; \
01760   }
01761 
01762 #ifndef PCHAR8
01763 #define PCHAR8 PANSI_CHAR
01764 #endif
01765 
01766 #if PCHAR8==PANSI_CHAR
01767 PI_SAME(PChar8, char);
01768 #endif
01769 
01770 PI_SAME(PInt8, signed char);
01771 
01772 PI_SAME(PUInt8, unsigned char);
01773 
01774 #if PBYTE_ORDER==PLITTLE_ENDIAN
01775 PI_SAME(PInt16l, PInt16);
01776 #elif PBYTE_ORDER==PBIG_ENDIAN
01777 PI_DIFF(PInt16l, PInt16);
01778 #endif
01779 
01780 #if PBYTE_ORDER==PLITTLE_ENDIAN
01781 PI_DIFF(PInt16b, PInt16);
01782 #elif PBYTE_ORDER==PBIG_ENDIAN
01783 PI_SAME(PInt16b, PInt16);
01784 #endif
01785 
01786 #if PBYTE_ORDER==PLITTLE_ENDIAN
01787 PI_SAME(PUInt16l, WORD);
01788 #elif PBYTE_ORDER==PBIG_ENDIAN
01789 PI_DIFF(PUInt16l, WORD);
01790 #endif
01791 
01792 #if PBYTE_ORDER==PLITTLE_ENDIAN
01793 PI_DIFF(PUInt16b, WORD);
01794 #elif PBYTE_ORDER==PBIG_ENDIAN
01795 PI_SAME(PUInt16b, WORD);
01796 #endif
01797 
01798 #if PBYTE_ORDER==PLITTLE_ENDIAN
01799 PI_SAME(PInt32l, PInt32);
01800 #elif PBYTE_ORDER==PBIG_ENDIAN
01801 PI_DIFF(PInt32l, PInt32);
01802 #endif
01803 
01804 #if PBYTE_ORDER==PLITTLE_ENDIAN
01805 PI_DIFF(PInt32b, PInt32);
01806 #elif PBYTE_ORDER==PBIG_ENDIAN
01807 PI_SAME(PInt32b, PInt32);
01808 #endif
01809 
01810 #if PBYTE_ORDER==PLITTLE_ENDIAN
01811 PI_SAME(PUInt32l, DWORD);
01812 #elif PBYTE_ORDER==PBIG_ENDIAN
01813 PI_DIFF(PUInt32l, DWORD);
01814 #endif
01815 
01816 #if PBYTE_ORDER==PLITTLE_ENDIAN
01817 PI_DIFF(PUInt32b, DWORD);
01818 #elif PBYTE_ORDER==PBIG_ENDIAN
01819 PI_SAME(PUInt32b, DWORD);
01820 #endif
01821 
01822 #if PBYTE_ORDER==PLITTLE_ENDIAN
01823 PI_SAME(PInt64l, PInt64);
01824 #elif PBYTE_ORDER==PBIG_ENDIAN
01825 PI_DIFF(PInt64l, PInt64);
01826 #endif
01827 
01828 #if PBYTE_ORDER==PLITTLE_ENDIAN
01829 PI_DIFF(PInt64b, PInt64);
01830 #elif PBYTE_ORDER==PBIG_ENDIAN
01831 PI_SAME(PInt64b, PInt64);
01832 #endif
01833 
01834 #if PBYTE_ORDER==PLITTLE_ENDIAN
01835 PI_SAME(PUInt64l, PUInt64);
01836 #elif PBYTE_ORDER==PBIG_ENDIAN
01837 PI_DIFF(PUInt64l, PUInt64);
01838 #endif
01839 
01840 #if PBYTE_ORDER==PLITTLE_ENDIAN
01841 PI_DIFF(PUInt64b, PUInt64);
01842 #elif PBYTE_ORDER==PBIG_ENDIAN
01843 PI_SAME(PUInt64b, PUInt64);
01844 #endif
01845 
01846 #if PBYTE_ORDER==PLITTLE_ENDIAN
01847 PI_SAME(PFloat32l, float);
01848 #elif PBYTE_ORDER==PBIG_ENDIAN
01849 PI_DIFF(PFloat32l, float);
01850 #endif
01851 
01852 #if PBYTE_ORDER==PLITTLE_ENDIAN
01853 PI_DIFF(PFloat32b, float);
01854 #elif PBYTE_ORDER==PBIG_ENDIAN
01855 PI_SAME(PFloat32b, float);
01856 #endif
01857 
01858 #if PBYTE_ORDER==PLITTLE_ENDIAN
01859 PI_SAME(PFloat64l, double);
01860 #elif PBYTE_ORDER==PBIG_ENDIAN
01861 PI_DIFF(PFloat64l, double);
01862 #endif
01863 
01864 #if PBYTE_ORDER==PLITTLE_ENDIAN
01865 PI_DIFF(PFloat64b, double);
01866 #elif PBYTE_ORDER==PBIG_ENDIAN
01867 PI_SAME(PFloat64b, double);
01868 #endif
01869 
01870 #ifndef NO_LONG_DOUBLE // stupid OSX compiler
01871 #if PBYTE_ORDER==PLITTLE_ENDIAN
01872 PI_SAME(PFloat80l, long double);
01873 #elif PBYTE_ORDER==PBIG_ENDIAN
01874 PI_DIFF(PFloat80l, long double);
01875 #endif
01876 
01877 #if PBYTE_ORDER==PLITTLE_ENDIAN
01878 PI_DIFF(PFloat80b, long double);
01879 #elif PBYTE_ORDER==PBIG_ENDIAN
01880 PI_SAME(PFloat80b, long double);
01881 #endif
01882 #endif
01883 
01884 #undef PI_LOOP
01885 #undef PI_SAME
01886 #undef PI_DIFF
01887 
01888 
01890 // Miscellaneous
01891 
01892 /*$MACRO PARRAYSIZE(array)
01893    This macro is used to calculate the number of array elements in a static
01894    array.
01895  */
01896 #define PARRAYSIZE(array) ((PINDEX)(sizeof(array)/sizeof(array[0])))
01897 
01898 /*$MACRO PMIN(v1, v2)
01899    This macro is used to calculate the minimum of two values. As this is a
01900    macro the expression in #v1# or #v2# is executed
01901    twice so extreme care should be made in its use.
01902  */
01903 #define PMIN(v1, v2) ((v1) < (v2) ? (v1) : (v2))
01904 
01905 /*$MACRO PMAX(v1, v2)
01906    This macro is used to calculate the maximum of two values. As this is a
01907    macro the expression in #v1# or #v2# is executed
01908    twice so extreme care should be made in its use.
01909  */
01910 #define PMAX(v1, v2) ((v1) > (v2) ? (v1) : (v2))
01911 
01912 /*$MACRO PABS(val)
01913    This macro is used to calculate an absolute value. As this is a macro the
01914    expression in #val# is executed twice so extreme care should be
01915    made in its use.
01916  */
01917 #define PABS(v) ((v) < 0 ? -(v) : (v))
01918 
01919 #endif // _POBJECT_H
01920 
01921 // End Of File ///////////////////////////////////////////////////////////////

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