ICU 73.2  73.2
uobject.h
Go to the documentation of this file.
00001 // © 2016 and later: Unicode, Inc. and others.
00002 // License & terms of use: http://www.unicode.org/copyright.html
00003 /*
00004 ******************************************************************************
00005 *
00006 *   Copyright (C) 2002-2012, International Business Machines
00007 *   Corporation and others.  All Rights Reserved.
00008 *
00009 ******************************************************************************
00010 *   file name:  uobject.h
00011 *   encoding:   UTF-8
00012 *   tab size:   8 (not used)
00013 *   indentation:4
00014 *
00015 *   created on: 2002jun26
00016 *   created by: Markus W. Scherer
00017 */
00018 
00019 #ifndef __UOBJECT_H__
00020 #define __UOBJECT_H__
00021 
00022 #include "unicode/utypes.h"
00023 
00024 #if U_SHOW_CPLUSPLUS_API
00025 
00026 #include "unicode/platform.h"
00027 
00048 #ifndef U_NO_THROW
00049 #define U_NO_THROW noexcept
00050 #endif
00051 
00052 /*===========================================================================*/
00053 /* UClassID-based RTTI */
00054 /*===========================================================================*/
00055 
00096 typedef void* UClassID;
00097 
00098 U_NAMESPACE_BEGIN
00099 
00115 class U_COMMON_API UMemory {
00116 public:
00117 
00118 /* test versions for debugging shaper heap memory problems */
00119 #ifdef SHAPER_MEMORY_DEBUG  
00120     static void * NewArray(int size, int count);
00121     static void * GrowArray(void * array, int newSize );
00122     static void   FreeArray(void * array );
00123 #endif
00124 
00125 #if U_OVERRIDE_CXX_ALLOCATION
00126 
00134     static void * U_EXPORT2 operator new(size_t size) noexcept;
00135 
00141     static void * U_EXPORT2 operator new[](size_t size) noexcept;
00142 
00151     static void U_EXPORT2 operator delete(void *p) noexcept;
00152 
00158     static void U_EXPORT2 operator delete[](void *p) noexcept;
00159 
00160 #if U_HAVE_PLACEMENT_NEW
00161 
00166     static inline void * U_EXPORT2 operator new(size_t, void *ptr) noexcept { return ptr; }
00167 
00173     static inline void U_EXPORT2 operator delete(void *, void *) noexcept {}
00174 #endif /* U_HAVE_PLACEMENT_NEW */
00175 #if U_HAVE_DEBUG_LOCATION_NEW
00176 
00183     static void * U_EXPORT2 operator new(size_t size, const char* file, int line) noexcept;
00191     static void U_EXPORT2 operator delete(void* p, const char* file, int line) noexcept;
00192 #endif /* U_HAVE_DEBUG_LOCATION_NEW */
00193 #endif /* U_OVERRIDE_CXX_ALLOCATION */
00194 
00195     /*
00196      * Assignment operator not declared. The compiler will provide one
00197      * which does nothing since this class does not contain any data members.
00198      * API/code coverage may show the assignment operator as present and
00199      * untested - ignore.
00200      * Subclasses need this assignment operator if they use compiler-provided
00201      * assignment operators of their own. An alternative to not declaring one
00202      * here would be to declare and empty-implement a protected or public one.
00203     UMemory &UMemory::operator=(const UMemory &);
00204      */
00205 };
00206 
00223 class U_COMMON_API UObject : public UMemory {
00224 public:
00230     virtual ~UObject();
00231 
00241     virtual UClassID getDynamicClassID() const;
00242 
00243 protected:
00244     // the following functions are protected to prevent instantiation and
00245     // direct use of UObject itself
00246 
00247     // default constructor
00248     // inline UObject() {}
00249 
00250     // copy constructor
00251     // inline UObject(const UObject &other) {}
00252 
00253 #if 0
00254     // TODO Sometime in the future. Implement operator==().
00255     // (This comment inserted in 2.2)
00256     // some or all of the following "boilerplate" functions may be made public
00257     // in a future ICU4C release when all subclasses implement them
00258 
00259     // assignment operator
00260     // (not virtual, see "Taligent's Guide to Designing Programs" pp.73..74)
00261     // commented out because the implementation is the same as a compiler's default
00262     // UObject &operator=(const UObject &other) { return *this; }
00263 
00264     // comparison operators
00265     virtual inline bool operator==(const UObject &other) const { return this==&other; }
00266     inline bool operator!=(const UObject &other) const { return !operator==(other); }
00267 
00268     // clone() commented out from the base class:
00269     // some compilers do not support co-variant return types
00270     // (i.e., subclasses would have to return UObject * as well, instead of SubClass *)
00271     // see also UObject class documentation.
00272     // virtual UObject *clone() const;
00273 #endif
00274 
00275     /*
00276      * Assignment operator not declared. The compiler will provide one
00277      * which does nothing since this class does not contain any data members.
00278      * API/code coverage may show the assignment operator as present and
00279      * untested - ignore.
00280      * Subclasses need this assignment operator if they use compiler-provided
00281      * assignment operators of their own. An alternative to not declaring one
00282      * here would be to declare and empty-implement a protected or public one.
00283     UObject &UObject::operator=(const UObject &);
00284      */
00285 };
00286 
00287 #ifndef U_HIDE_INTERNAL_API
00288 
00295 #define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass) \
00296     UClassID U_EXPORT2 myClass::getStaticClassID() { \
00297         static char classID = 0; \
00298         return (UClassID)&classID; \
00299     } \
00300     UClassID myClass::getDynamicClassID() const \
00301     { return myClass::getStaticClassID(); }
00302 
00303 
00312 #define UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass) \
00313     UClassID U_EXPORT2 myClass::getStaticClassID() { \
00314         static char classID = 0; \
00315         return (UClassID)&classID; \
00316     }
00317 
00318 #endif  /* U_HIDE_INTERNAL_API */
00319 
00320 U_NAMESPACE_END
00321 
00322 #endif /* U_SHOW_CPLUSPLUS_API */
00323 
00324 #endif