Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

uobject.h

Go to the documentation of this file.
00001 /*
00002 ******************************************************************************
00003 *
00004 *   Copyright (C) 2002-2003, International Business Machines
00005 *   Corporation and others.  All Rights Reserved.
00006 *
00007 ******************************************************************************
00008 *   file name:  uobject.h
00009 *   encoding:   US-ASCII
00010 *   tab size:   8 (not used)
00011 *   indentation:4
00012 *
00013 *   created on: 2002jun26
00014 *   created by: Markus W. Scherer
00015 */
00016 
00017 #ifndef __UOBJECT_H__
00018 #define __UOBJECT_H__
00019 
00020 #include "unicode/utypes.h"
00021 
00022 U_NAMESPACE_BEGIN
00023 
00039 #ifndef U_OVERRIDE_CXX_ALLOCATION
00040 #define U_OVERRIDE_CXX_ALLOCATION 1
00041 #endif
00042 
00048 #ifndef U_HAVE_PLACEMENT_NEW
00049 #define U_HAVE_PLACEMENT_NEW 1
00050 #endif
00051 
00067 class U_COMMON_API UMemory {
00068 public:
00069 
00070 #if U_OVERRIDE_CXX_ALLOCATION
00071 
00079     static void *operator new(size_t size);
00080 
00086     static void *operator new[](size_t size);
00087 
00096     static void operator delete(void *p);
00097 
00103     static void operator delete[](void *p);
00104 
00105 #if U_HAVE_PLACEMENT_NEW
00106 
00111     static inline void * operator new(size_t, void *ptr) { return ptr; }
00112 
00118     static inline void operator delete(void *, void *) {}
00119 #endif /* U_HAVE_PLACEMENT_NEW */
00120 #endif /* U_OVERRIDE_CXX_ALLOCATION */
00121 
00122     /*
00123      * Assignment operator not declared. The compiler will provide one
00124      * which does nothing since this class does not contain any data members.
00125      * API/code coverage may show the assignment operator as present and
00126      * untested - ignore.
00127      * Subclasses need this assignment operator if they use compiler-provided
00128      * assignment operators of their own. An alternative to not declaring one
00129      * here would be to declare and empty-implement a protected or public one.
00130     UMemory &UMemory::operator=(const UMemory &);
00131      */
00132 };
00133 
00156 class U_COMMON_API UObject : public UMemory {
00157 public:
00163     virtual ~UObject();
00164 
00170     virtual UClassID getDynamicClassID() const = 0;
00171 
00172 protected:
00173     // the following functions are protected to prevent instantiation and
00174     // direct use of UObject itself
00175 
00176     // default constructor
00177     // commented out because UObject is abstract (see getDynamicClassID)
00178     // inline UObject() {}
00179 
00180     // copy constructor
00181     // commented out because UObject is abstract (see getDynamicClassID)
00182     // inline UObject(const UObject &other) {}
00183 
00184 #if U_ICU_VERSION_MAJOR_NUM>2
00185     // TODO post ICU 2.4  (This comment inserted in 2.2)
00186     // some or all of the following "boilerplate" functions may be made public
00187     // in a future ICU4C release when all subclasses implement them
00188 
00189     // assignment operator
00190     // (not virtual, see "Taligent's Guide to Designing Programs" pp.73..74)
00191     // commented out because the implementation is the same as a compiler's default
00192     // UObject &operator=(const UObject &other) { return *this; }
00193 
00194     // comparison operators
00195     virtual inline UBool operator==(const UObject &other) const { return this==&other; }
00196     inline UBool operator!=(const UObject &other) const { return !operator==(other); }
00197 
00198     // clone() commented out from the base class:
00199     // some compilers do not support co-variant return types
00200     // (i.e., subclasses would have to return UObject * as well, instead of SubClass *)
00201     // see also UObject class documentation.
00202     // virtual UObject *clone() const;
00203 #endif
00204 
00205     /*
00206      * Assignment operator not declared. The compiler will provide one
00207      * which does nothing since this class does not contain any data members.
00208      * API/code coverage may show the assignment operator as present and
00209      * untested - ignore.
00210      * Subclasses need this assignment operator if they use compiler-provided
00211      * assignment operators of their own. An alternative to not declaring one
00212      * here would be to declare and empty-implement a protected or public one.
00213     UObject &UObject::operator=(const UObject &);
00214      */
00215 };
00216 
00224 #define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass) \
00225     UClassID myClass::getStaticClassID() { \
00226         static const char classID = 0; \
00227         return (UClassID)&classID; \
00228     } \
00229     UClassID myClass::getDynamicClassID() const \
00230     { return myClass::getStaticClassID(); }
00231 
00232 
00233 
00234 U_NAMESPACE_END
00235 
00236 #endif

Generated on Mon Nov 24 14:35:44 2003 for ICU 2.8 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001