- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

# uobject.h

Go to the documentation of this file.

    00001 /*
    00002 ******************************************************************************
    00003 *
    00004 *   Copyright (C) 2002-2010, 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
    00050 #ifndef U_HAVE_PLACEMENT_NEW
    00051 #define U_HAVE_PLACEMENT_NEW 1
    00052 #endif
    00053
    00054
    00062 #ifndef U_HAVE_DEBUG_LOCATION_NEW
    00063 #define U_HAVE_DEBUG_LOCATION_NEW 0
    00064 #endif
    00065
    00080 #ifndef U_NO_THROW
    00081 #define U_NO_THROW throw()
    00082 #endif
    00083
    00101 class U_COMMON_API UMemory {
    00102 public:
    00103
    00104 /* test versions for debugging shaper heap memory problems */
    00105 #ifdef SHAPER_MEMORY_DEBUG
    00106     static void * NewArray(int size, int count);
    00107     static void * GrowArray(void * array, int newSize );
    00108     static void   FreeArray(void * array );
    00109 #endif
    00110
    00111 #if U_OVERRIDE_CXX_ALLOCATION
    00112
    00120     static void * U_EXPORT2 operator new(size_t size) U_NO_THROW;
    00121
    00127     static void * U_EXPORT2 operator new[](size_t size) U_NO_THROW;
    00128
    00137     static void U_EXPORT2 operator delete(void *p) U_NO_THROW;
    00138
    00144     static void U_EXPORT2 operator delete[](void *p) U_NO_THROW;
    00145
    00146 #if U_HAVE_PLACEMENT_NEW
    00147
    00152     static inline void * U_EXPORT2 operator new(size_t, void *ptr) U_NO_THROW { return ptr; }
    00153
    00159     static inline void U_EXPORT2 operator delete(void *, void *) U_NO_THROW {}
    00160 #endif /* U_HAVE_PLACEMENT_NEW */
    00161 #if U_HAVE_DEBUG_LOCATION_NEW
    00162
    00169     static void * U_EXPORT2 operator new(size_t size, const char* file, int line) U_NO_THROW;
    00177     static void U_EXPORT2 operator delete(void* p, const char* file, int line) U_NO_THROW;
    00178 #endif /* U_HAVE_DEBUG_LOCATION_NEW */
    00179 #endif /* U_OVERRIDE_CXX_ALLOCATION */
    00180
    00181     /*
    00182      * Assignment operator not declared. The compiler will provide one
    00183      * which does nothing since this class does not contain any data members.
    00184      * API/code coverage may show the assignment operator as present and
    00185      * untested - ignore.
    00186      * Subclasses need this assignment operator if they use compiler-provided
    00187      * assignment operators of their own. An alternative to not declaring one
    00188      * here would be to declare and empty-implement a protected or public one.
    00189     UMemory &UMemory::operator=(const UMemory &);
    00190      */
    00191 };
    00192
    00215 class U_COMMON_API UObject : public UMemory {
    00216 public:
    00222     virtual ~UObject();
    00223
    00229     virtual UClassID getDynamicClassID() const = 0;
    00230
    00231 protected:
    00232     // the following functions are protected to prevent instantiation and
    00233     // direct use of UObject itself
    00234
    00235     // default constructor
    00236     // commented out because UObject is abstract (see getDynamicClassID)
    00237     // inline UObject() {}
    00238
    00239     // copy constructor
    00240     // commented out because UObject is abstract (see getDynamicClassID)
    00241     // inline UObject(const UObject &other) {}
    00242
    00243 #if 0
    00244     // TODO Sometime in the future. Implement operator==().
    00245     // (This comment inserted in 2.2)
    00246     // some or all of the following "boilerplate" functions may be made public
    00247     // in a future ICU4C release when all subclasses implement them
    00248
    00249     // assignment operator
    00250     // (not virtual, see "Taligent's Guide to Designing Programs" pp.73..74)
    00251     // commented out because the implementation is the same as a compiler's default
    00252     // UObject &operator=(const UObject &other) { return *this; }
    00253
    00254     // comparison operators
    00255     virtual inline UBool operator==(const UObject &other) const { return this==&other; }
    00256     inline UBool operator!=(const UObject &other) const { return !operator==(other); }
    00257
    00258     // clone() commented out from the base class:
    00259     // some compilers do not support co-variant return types
    00260     // (i.e., subclasses would have to return UObject * as well, instead of SubClass *)
    00261     // see also UObject class documentation.
    00262     // virtual UObject *clone() const;
    00263 #endif
    00264
    00265     /*
    00266      * Assignment operator not declared. The compiler will provide one
    00267      * which does nothing since this class does not contain any data members.
    00268      * API/code coverage may show the assignment operator as present and
    00269      * untested - ignore.
    00270      * Subclasses need this assignment operator if they use compiler-provided
    00271      * assignment operators of their own. An alternative to not declaring one
    00272      * here would be to declare and empty-implement a protected or public one.
    00273     UObject &UObject::operator=(const UObject &);
    00274      */
    00275
    00276 // Future implementation for RTTI that support subtyping. [alan]
    00277 //
    00278 //  public:
    00279 //     /**
    00280 //      * @internal
    00281 //      */
    00282 //     static UClassID getStaticClassID();
    00283 //
    00284 //     /**
    00285 //      * @internal
    00286 //      */
    00287 //     UBool instanceOf(UClassID type) const;
    00288 };
    00289
    00297 #define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass) \
    00298     UClassID U_EXPORT2 myClass::getStaticClassID() { \
    00299         static char classID = 0; \
    00300         return (UClassID)&classID; \
    00301     } \
    00302     UClassID myClass::getDynamicClassID() const \
    00303     { return myClass::getStaticClassID(); }
    00304
    00305
    00314 #define UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass) \
    00315     UClassID U_EXPORT2 myClass::getStaticClassID() { \
    00316         static char classID = 0; \
    00317         return (UClassID)&classID; \
    00318     }
    00319
    00320 // /**
    00321 //  * This macro adds ICU RTTI to an ICU concrete class implementation.
    00322 //  * This macro should be invoked in *.cpp files.  The corresponding
    00323 //  * header should declare getDynamicClassID and getStaticClassID.
    00324 //  *
    00325 //  * @param myClass The name of the class that needs RTTI defined.
    00326 //  * @param myParent The name of the myClass's parent.
    00327 //  * @internal
    00328 //  */
    00329 /*#define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass, myParent) \
    00330     UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass, myParent) \
    00331     UClassID myClass::getDynamicClassID() const { \
    00332         return myClass::getStaticClassID(); \
    00333     }
    00334 */
    00335
    00336
    00337 U_NAMESPACE_END
    00338
    00339 #endif

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines