1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others. 2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html 3*0e209d39SAndroid Build Coastguard Worker /* 4*0e209d39SAndroid Build Coastguard Worker ****************************************************************************** 5*0e209d39SAndroid Build Coastguard Worker * 6*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 2002-2012, International Business Machines 7*0e209d39SAndroid Build Coastguard Worker * Corporation and others. All Rights Reserved. 8*0e209d39SAndroid Build Coastguard Worker * 9*0e209d39SAndroid Build Coastguard Worker ****************************************************************************** 10*0e209d39SAndroid Build Coastguard Worker * file name: uobject.h 11*0e209d39SAndroid Build Coastguard Worker * encoding: UTF-8 12*0e209d39SAndroid Build Coastguard Worker * tab size: 8 (not used) 13*0e209d39SAndroid Build Coastguard Worker * indentation:4 14*0e209d39SAndroid Build Coastguard Worker * 15*0e209d39SAndroid Build Coastguard Worker * created on: 2002jun26 16*0e209d39SAndroid Build Coastguard Worker * created by: Markus W. Scherer 17*0e209d39SAndroid Build Coastguard Worker */ 18*0e209d39SAndroid Build Coastguard Worker 19*0e209d39SAndroid Build Coastguard Worker #ifndef __UOBJECT_H__ 20*0e209d39SAndroid Build Coastguard Worker #define __UOBJECT_H__ 21*0e209d39SAndroid Build Coastguard Worker 22*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h" 23*0e209d39SAndroid Build Coastguard Worker 24*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API 25*0e209d39SAndroid Build Coastguard Worker 26*0e209d39SAndroid Build Coastguard Worker #include "unicode/platform.h" 27*0e209d39SAndroid Build Coastguard Worker 28*0e209d39SAndroid Build Coastguard Worker /** 29*0e209d39SAndroid Build Coastguard Worker * \file 30*0e209d39SAndroid Build Coastguard Worker * \brief C++ API: Common ICU base class UObject. 31*0e209d39SAndroid Build Coastguard Worker */ 32*0e209d39SAndroid Build Coastguard Worker 33*0e209d39SAndroid Build Coastguard Worker /** 34*0e209d39SAndroid Build Coastguard Worker * \def U_NO_THROW 35*0e209d39SAndroid Build Coastguard Worker * Since ICU 64, use noexcept instead. 36*0e209d39SAndroid Build Coastguard Worker * 37*0e209d39SAndroid Build Coastguard Worker * Previously, define this to define the throw() specification so 38*0e209d39SAndroid Build Coastguard Worker * certain functions do not throw any exceptions 39*0e209d39SAndroid Build Coastguard Worker * 40*0e209d39SAndroid Build Coastguard Worker * UMemory operator new methods should have the throw() specification 41*0e209d39SAndroid Build Coastguard Worker * appended to them, so that the compiler adds the additional nullptr check 42*0e209d39SAndroid Build Coastguard Worker * before calling constructors. Without, if <code>operator new</code> returns nullptr the 43*0e209d39SAndroid Build Coastguard Worker * constructor is still called, and if the constructor references member 44*0e209d39SAndroid Build Coastguard Worker * data, (which it typically does), the result is a segmentation violation. 45*0e209d39SAndroid Build Coastguard Worker * 46*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.2. Since ICU 64, Use noexcept instead. See ICU-20422. 47*0e209d39SAndroid Build Coastguard Worker */ 48*0e209d39SAndroid Build Coastguard Worker #ifndef U_NO_THROW 49*0e209d39SAndroid Build Coastguard Worker #define U_NO_THROW noexcept 50*0e209d39SAndroid Build Coastguard Worker #endif 51*0e209d39SAndroid Build Coastguard Worker 52*0e209d39SAndroid Build Coastguard Worker /*===========================================================================*/ 53*0e209d39SAndroid Build Coastguard Worker /* UClassID-based RTTI */ 54*0e209d39SAndroid Build Coastguard Worker /*===========================================================================*/ 55*0e209d39SAndroid Build Coastguard Worker 56*0e209d39SAndroid Build Coastguard Worker /** 57*0e209d39SAndroid Build Coastguard Worker * UClassID is used to identify classes without using the compiler's RTTI. 58*0e209d39SAndroid Build Coastguard Worker * This was used before C++ compilers consistently supported RTTI. 59*0e209d39SAndroid Build Coastguard Worker * ICU 4.6 requires compiler RTTI to be turned on. 60*0e209d39SAndroid Build Coastguard Worker * 61*0e209d39SAndroid Build Coastguard Worker * Each class hierarchy which needs 62*0e209d39SAndroid Build Coastguard Worker * to implement polymorphic clone() or operator==() defines two methods, 63*0e209d39SAndroid Build Coastguard Worker * described in detail below. UClassID values can be compared using 64*0e209d39SAndroid Build Coastguard Worker * operator==(). Nothing else should be done with them. 65*0e209d39SAndroid Build Coastguard Worker * 66*0e209d39SAndroid Build Coastguard Worker * \par 67*0e209d39SAndroid Build Coastguard Worker * In class hierarchies that implement "poor man's RTTI", 68*0e209d39SAndroid Build Coastguard Worker * each concrete subclass implements getDynamicClassID() in the same way: 69*0e209d39SAndroid Build Coastguard Worker * 70*0e209d39SAndroid Build Coastguard Worker * \code 71*0e209d39SAndroid Build Coastguard Worker * class Derived { 72*0e209d39SAndroid Build Coastguard Worker * public: 73*0e209d39SAndroid Build Coastguard Worker * virtual UClassID getDynamicClassID() const 74*0e209d39SAndroid Build Coastguard Worker * { return Derived::getStaticClassID(); } 75*0e209d39SAndroid Build Coastguard Worker * } 76*0e209d39SAndroid Build Coastguard Worker * \endcode 77*0e209d39SAndroid Build Coastguard Worker * 78*0e209d39SAndroid Build Coastguard Worker * Each concrete class implements getStaticClassID() as well, which allows 79*0e209d39SAndroid Build Coastguard Worker * clients to test for a specific type. 80*0e209d39SAndroid Build Coastguard Worker * 81*0e209d39SAndroid Build Coastguard Worker * \code 82*0e209d39SAndroid Build Coastguard Worker * class Derived { 83*0e209d39SAndroid Build Coastguard Worker * public: 84*0e209d39SAndroid Build Coastguard Worker * static UClassID U_EXPORT2 getStaticClassID(); 85*0e209d39SAndroid Build Coastguard Worker * private: 86*0e209d39SAndroid Build Coastguard Worker * static char fgClassID; 87*0e209d39SAndroid Build Coastguard Worker * } 88*0e209d39SAndroid Build Coastguard Worker * 89*0e209d39SAndroid Build Coastguard Worker * // In Derived.cpp: 90*0e209d39SAndroid Build Coastguard Worker * UClassID Derived::getStaticClassID() 91*0e209d39SAndroid Build Coastguard Worker * { return (UClassID)&Derived::fgClassID; } 92*0e209d39SAndroid Build Coastguard Worker * char Derived::fgClassID = 0; // Value is irrelevant 93*0e209d39SAndroid Build Coastguard Worker * \endcode 94*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0 95*0e209d39SAndroid Build Coastguard Worker */ 96*0e209d39SAndroid Build Coastguard Worker typedef void* UClassID; 97*0e209d39SAndroid Build Coastguard Worker 98*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN 99*0e209d39SAndroid Build Coastguard Worker 100*0e209d39SAndroid Build Coastguard Worker /** 101*0e209d39SAndroid Build Coastguard Worker * UMemory is the common ICU base class. 102*0e209d39SAndroid Build Coastguard Worker * All other ICU C++ classes are derived from UMemory (starting with ICU 2.4). 103*0e209d39SAndroid Build Coastguard Worker * 104*0e209d39SAndroid Build Coastguard Worker * This is primarily to make it possible and simple to override the 105*0e209d39SAndroid Build Coastguard Worker * C++ memory management by adding new/delete operators to this base class. 106*0e209d39SAndroid Build Coastguard Worker * 107*0e209d39SAndroid Build Coastguard Worker * To override ALL ICU memory management, including that from plain C code, 108*0e209d39SAndroid Build Coastguard Worker * replace the allocation functions declared in cmemory.h 109*0e209d39SAndroid Build Coastguard Worker * 110*0e209d39SAndroid Build Coastguard Worker * UMemory does not contain any virtual functions. 111*0e209d39SAndroid Build Coastguard Worker * Common "boilerplate" functions are defined in UObject. 112*0e209d39SAndroid Build Coastguard Worker * 113*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4 114*0e209d39SAndroid Build Coastguard Worker */ 115*0e209d39SAndroid Build Coastguard Worker class U_COMMON_API UMemory { 116*0e209d39SAndroid Build Coastguard Worker public: 117*0e209d39SAndroid Build Coastguard Worker 118*0e209d39SAndroid Build Coastguard Worker /* test versions for debugging shaper heap memory problems */ 119*0e209d39SAndroid Build Coastguard Worker #ifdef SHAPER_MEMORY_DEBUG 120*0e209d39SAndroid Build Coastguard Worker static void * NewArray(int size, int count); 121*0e209d39SAndroid Build Coastguard Worker static void * GrowArray(void * array, int newSize ); 122*0e209d39SAndroid Build Coastguard Worker static void FreeArray(void * array ); 123*0e209d39SAndroid Build Coastguard Worker #endif 124*0e209d39SAndroid Build Coastguard Worker 125*0e209d39SAndroid Build Coastguard Worker #if U_OVERRIDE_CXX_ALLOCATION 126*0e209d39SAndroid Build Coastguard Worker /** 127*0e209d39SAndroid Build Coastguard Worker * Override for ICU4C C++ memory management. 128*0e209d39SAndroid Build Coastguard Worker * simple, non-class types are allocated using the macros in common/cmemory.h 129*0e209d39SAndroid Build Coastguard Worker * (uprv_malloc(), uprv_free(), uprv_realloc()); 130*0e209d39SAndroid Build Coastguard Worker * they or something else could be used here to implement C++ new/delete 131*0e209d39SAndroid Build Coastguard Worker * for ICU4C C++ classes 132*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4 133*0e209d39SAndroid Build Coastguard Worker */ 134*0e209d39SAndroid Build Coastguard Worker static void * U_EXPORT2 operator new(size_t size) noexcept; 135*0e209d39SAndroid Build Coastguard Worker 136*0e209d39SAndroid Build Coastguard Worker /** 137*0e209d39SAndroid Build Coastguard Worker * Override for ICU4C C++ memory management. 138*0e209d39SAndroid Build Coastguard Worker * See new(). 139*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4 140*0e209d39SAndroid Build Coastguard Worker */ 141*0e209d39SAndroid Build Coastguard Worker static void * U_EXPORT2 operator new[](size_t size) noexcept; 142*0e209d39SAndroid Build Coastguard Worker 143*0e209d39SAndroid Build Coastguard Worker /** 144*0e209d39SAndroid Build Coastguard Worker * Override for ICU4C C++ memory management. 145*0e209d39SAndroid Build Coastguard Worker * simple, non-class types are allocated using the macros in common/cmemory.h 146*0e209d39SAndroid Build Coastguard Worker * (uprv_malloc(), uprv_free(), uprv_realloc()); 147*0e209d39SAndroid Build Coastguard Worker * they or something else could be used here to implement C++ new/delete 148*0e209d39SAndroid Build Coastguard Worker * for ICU4C C++ classes 149*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4 150*0e209d39SAndroid Build Coastguard Worker */ 151*0e209d39SAndroid Build Coastguard Worker static void U_EXPORT2 operator delete(void *p) noexcept; 152*0e209d39SAndroid Build Coastguard Worker 153*0e209d39SAndroid Build Coastguard Worker /** 154*0e209d39SAndroid Build Coastguard Worker * Override for ICU4C C++ memory management. 155*0e209d39SAndroid Build Coastguard Worker * See delete(). 156*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4 157*0e209d39SAndroid Build Coastguard Worker */ 158*0e209d39SAndroid Build Coastguard Worker static void U_EXPORT2 operator delete[](void *p) noexcept; 159*0e209d39SAndroid Build Coastguard Worker 160*0e209d39SAndroid Build Coastguard Worker #if U_HAVE_PLACEMENT_NEW 161*0e209d39SAndroid Build Coastguard Worker /** 162*0e209d39SAndroid Build Coastguard Worker * Override for ICU4C C++ memory management for STL. 163*0e209d39SAndroid Build Coastguard Worker * See new(). 164*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.6 165*0e209d39SAndroid Build Coastguard Worker */ new(size_t,void * ptr)166*0e209d39SAndroid Build Coastguard Worker static inline void * U_EXPORT2 operator new(size_t, void *ptr) noexcept { return ptr; } 167*0e209d39SAndroid Build Coastguard Worker 168*0e209d39SAndroid Build Coastguard Worker /** 169*0e209d39SAndroid Build Coastguard Worker * Override for ICU4C C++ memory management for STL. 170*0e209d39SAndroid Build Coastguard Worker * See delete(). 171*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.6 172*0e209d39SAndroid Build Coastguard Worker */ delete(void *,void *)173*0e209d39SAndroid Build Coastguard Worker static inline void U_EXPORT2 operator delete(void *, void *) noexcept {} 174*0e209d39SAndroid Build Coastguard Worker #endif /* U_HAVE_PLACEMENT_NEW */ 175*0e209d39SAndroid Build Coastguard Worker #if U_HAVE_DEBUG_LOCATION_NEW 176*0e209d39SAndroid Build Coastguard Worker /** 177*0e209d39SAndroid Build Coastguard Worker * This method overrides the MFC debug version of the operator new 178*0e209d39SAndroid Build Coastguard Worker * 179*0e209d39SAndroid Build Coastguard Worker * @param size The requested memory size 180*0e209d39SAndroid Build Coastguard Worker * @param file The file where the allocation was requested 181*0e209d39SAndroid Build Coastguard Worker * @param line The line where the allocation was requested 182*0e209d39SAndroid Build Coastguard Worker */ 183*0e209d39SAndroid Build Coastguard Worker static void * U_EXPORT2 operator new(size_t size, const char* file, int line) noexcept; 184*0e209d39SAndroid Build Coastguard Worker /** 185*0e209d39SAndroid Build Coastguard Worker * This method provides a matching delete for the MFC debug new 186*0e209d39SAndroid Build Coastguard Worker * 187*0e209d39SAndroid Build Coastguard Worker * @param p The pointer to the allocated memory 188*0e209d39SAndroid Build Coastguard Worker * @param file The file where the allocation was requested 189*0e209d39SAndroid Build Coastguard Worker * @param line The line where the allocation was requested 190*0e209d39SAndroid Build Coastguard Worker */ 191*0e209d39SAndroid Build Coastguard Worker static void U_EXPORT2 operator delete(void* p, const char* file, int line) noexcept; 192*0e209d39SAndroid Build Coastguard Worker #endif /* U_HAVE_DEBUG_LOCATION_NEW */ 193*0e209d39SAndroid Build Coastguard Worker #endif /* U_OVERRIDE_CXX_ALLOCATION */ 194*0e209d39SAndroid Build Coastguard Worker 195*0e209d39SAndroid Build Coastguard Worker /* 196*0e209d39SAndroid Build Coastguard Worker * Assignment operator not declared. The compiler will provide one 197*0e209d39SAndroid Build Coastguard Worker * which does nothing since this class does not contain any data members. 198*0e209d39SAndroid Build Coastguard Worker * API/code coverage may show the assignment operator as present and 199*0e209d39SAndroid Build Coastguard Worker * untested - ignore. 200*0e209d39SAndroid Build Coastguard Worker * Subclasses need this assignment operator if they use compiler-provided 201*0e209d39SAndroid Build Coastguard Worker * assignment operators of their own. An alternative to not declaring one 202*0e209d39SAndroid Build Coastguard Worker * here would be to declare and empty-implement a protected or public one. 203*0e209d39SAndroid Build Coastguard Worker UMemory &UMemory::operator=(const UMemory &); 204*0e209d39SAndroid Build Coastguard Worker */ 205*0e209d39SAndroid Build Coastguard Worker }; 206*0e209d39SAndroid Build Coastguard Worker 207*0e209d39SAndroid Build Coastguard Worker /** 208*0e209d39SAndroid Build Coastguard Worker * UObject is the common ICU "boilerplate" class. 209*0e209d39SAndroid Build Coastguard Worker * UObject inherits UMemory (starting with ICU 2.4), 210*0e209d39SAndroid Build Coastguard Worker * and all other public ICU C++ classes 211*0e209d39SAndroid Build Coastguard Worker * are derived from UObject (starting with ICU 2.2). 212*0e209d39SAndroid Build Coastguard Worker * 213*0e209d39SAndroid Build Coastguard Worker * UObject contains common virtual functions, in particular a virtual destructor. 214*0e209d39SAndroid Build Coastguard Worker * 215*0e209d39SAndroid Build Coastguard Worker * The clone() function is not available in UObject because it is not 216*0e209d39SAndroid Build Coastguard Worker * implemented by all ICU classes. 217*0e209d39SAndroid Build Coastguard Worker * Many ICU services provide a clone() function for their class trees, 218*0e209d39SAndroid Build Coastguard Worker * defined on the service's C++ base class 219*0e209d39SAndroid Build Coastguard Worker * (which itself is a subclass of UObject). 220*0e209d39SAndroid Build Coastguard Worker * 221*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.2 222*0e209d39SAndroid Build Coastguard Worker */ 223*0e209d39SAndroid Build Coastguard Worker class U_COMMON_API UObject : public UMemory { 224*0e209d39SAndroid Build Coastguard Worker public: 225*0e209d39SAndroid Build Coastguard Worker /** 226*0e209d39SAndroid Build Coastguard Worker * Destructor. 227*0e209d39SAndroid Build Coastguard Worker * 228*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.2 229*0e209d39SAndroid Build Coastguard Worker */ 230*0e209d39SAndroid Build Coastguard Worker virtual ~UObject(); 231*0e209d39SAndroid Build Coastguard Worker 232*0e209d39SAndroid Build Coastguard Worker /** 233*0e209d39SAndroid Build Coastguard Worker * ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class. 234*0e209d39SAndroid Build Coastguard Worker * The base class implementation returns a dummy value. 235*0e209d39SAndroid Build Coastguard Worker * 236*0e209d39SAndroid Build Coastguard Worker * Use compiler RTTI rather than ICU's "poor man's RTTI". 237*0e209d39SAndroid Build Coastguard Worker * Since ICU 4.6, new ICU C++ class hierarchies do not implement "poor man's RTTI". 238*0e209d39SAndroid Build Coastguard Worker * 239*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.2 240*0e209d39SAndroid Build Coastguard Worker */ 241*0e209d39SAndroid Build Coastguard Worker virtual UClassID getDynamicClassID() const; 242*0e209d39SAndroid Build Coastguard Worker 243*0e209d39SAndroid Build Coastguard Worker protected: 244*0e209d39SAndroid Build Coastguard Worker // the following functions are protected to prevent instantiation and 245*0e209d39SAndroid Build Coastguard Worker // direct use of UObject itself 246*0e209d39SAndroid Build Coastguard Worker 247*0e209d39SAndroid Build Coastguard Worker // default constructor 248*0e209d39SAndroid Build Coastguard Worker // inline UObject() {} 249*0e209d39SAndroid Build Coastguard Worker 250*0e209d39SAndroid Build Coastguard Worker // copy constructor 251*0e209d39SAndroid Build Coastguard Worker // inline UObject(const UObject &other) {} 252*0e209d39SAndroid Build Coastguard Worker 253*0e209d39SAndroid Build Coastguard Worker #if 0 254*0e209d39SAndroid Build Coastguard Worker // TODO Sometime in the future. Implement operator==(). 255*0e209d39SAndroid Build Coastguard Worker // (This comment inserted in 2.2) 256*0e209d39SAndroid Build Coastguard Worker // some or all of the following "boilerplate" functions may be made public 257*0e209d39SAndroid Build Coastguard Worker // in a future ICU4C release when all subclasses implement them 258*0e209d39SAndroid Build Coastguard Worker 259*0e209d39SAndroid Build Coastguard Worker // assignment operator 260*0e209d39SAndroid Build Coastguard Worker // (not virtual, see "Taligent's Guide to Designing Programs" pp.73..74) 261*0e209d39SAndroid Build Coastguard Worker // commented out because the implementation is the same as a compiler's default 262*0e209d39SAndroid Build Coastguard Worker // UObject &operator=(const UObject &other) { return *this; } 263*0e209d39SAndroid Build Coastguard Worker 264*0e209d39SAndroid Build Coastguard Worker // comparison operators 265*0e209d39SAndroid Build Coastguard Worker virtual inline bool operator==(const UObject &other) const { return this==&other; } 266*0e209d39SAndroid Build Coastguard Worker inline bool operator!=(const UObject &other) const { return !operator==(other); } 267*0e209d39SAndroid Build Coastguard Worker 268*0e209d39SAndroid Build Coastguard Worker // clone() commented out from the base class: 269*0e209d39SAndroid Build Coastguard Worker // some compilers do not support co-variant return types 270*0e209d39SAndroid Build Coastguard Worker // (i.e., subclasses would have to return UObject * as well, instead of SubClass *) 271*0e209d39SAndroid Build Coastguard Worker // see also UObject class documentation. 272*0e209d39SAndroid Build Coastguard Worker // virtual UObject *clone() const; 273*0e209d39SAndroid Build Coastguard Worker #endif 274*0e209d39SAndroid Build Coastguard Worker 275*0e209d39SAndroid Build Coastguard Worker /* 276*0e209d39SAndroid Build Coastguard Worker * Assignment operator not declared. The compiler will provide one 277*0e209d39SAndroid Build Coastguard Worker * which does nothing since this class does not contain any data members. 278*0e209d39SAndroid Build Coastguard Worker * API/code coverage may show the assignment operator as present and 279*0e209d39SAndroid Build Coastguard Worker * untested - ignore. 280*0e209d39SAndroid Build Coastguard Worker * Subclasses need this assignment operator if they use compiler-provided 281*0e209d39SAndroid Build Coastguard Worker * assignment operators of their own. An alternative to not declaring one 282*0e209d39SAndroid Build Coastguard Worker * here would be to declare and empty-implement a protected or public one. 283*0e209d39SAndroid Build Coastguard Worker UObject &UObject::operator=(const UObject &); 284*0e209d39SAndroid Build Coastguard Worker */ 285*0e209d39SAndroid Build Coastguard Worker }; 286*0e209d39SAndroid Build Coastguard Worker 287*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API 288*0e209d39SAndroid Build Coastguard Worker /** 289*0e209d39SAndroid Build Coastguard Worker * This is a simple macro to add ICU RTTI to an ICU object implementation. 290*0e209d39SAndroid Build Coastguard Worker * This does not go into the header. This should only be used in *.cpp files. 291*0e209d39SAndroid Build Coastguard Worker * 292*0e209d39SAndroid Build Coastguard Worker * @param myClass The name of the class that needs RTTI defined. 293*0e209d39SAndroid Build Coastguard Worker * @internal 294*0e209d39SAndroid Build Coastguard Worker */ 295*0e209d39SAndroid Build Coastguard Worker #define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass) \ 296*0e209d39SAndroid Build Coastguard Worker UClassID U_EXPORT2 myClass::getStaticClassID() { \ 297*0e209d39SAndroid Build Coastguard Worker static char classID = 0; \ 298*0e209d39SAndroid Build Coastguard Worker return (UClassID)&classID; \ 299*0e209d39SAndroid Build Coastguard Worker } \ 300*0e209d39SAndroid Build Coastguard Worker UClassID myClass::getDynamicClassID() const \ 301*0e209d39SAndroid Build Coastguard Worker { return myClass::getStaticClassID(); } 302*0e209d39SAndroid Build Coastguard Worker 303*0e209d39SAndroid Build Coastguard Worker 304*0e209d39SAndroid Build Coastguard Worker /** 305*0e209d39SAndroid Build Coastguard Worker * This macro adds ICU RTTI to an ICU abstract class implementation. 306*0e209d39SAndroid Build Coastguard Worker * This macro should be invoked in *.cpp files. The corresponding 307*0e209d39SAndroid Build Coastguard Worker * header should declare getStaticClassID. 308*0e209d39SAndroid Build Coastguard Worker * 309*0e209d39SAndroid Build Coastguard Worker * @param myClass The name of the class that needs RTTI defined. 310*0e209d39SAndroid Build Coastguard Worker * @internal 311*0e209d39SAndroid Build Coastguard Worker */ 312*0e209d39SAndroid Build Coastguard Worker #define UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass) \ 313*0e209d39SAndroid Build Coastguard Worker UClassID U_EXPORT2 myClass::getStaticClassID() { \ 314*0e209d39SAndroid Build Coastguard Worker static char classID = 0; \ 315*0e209d39SAndroid Build Coastguard Worker return (UClassID)&classID; \ 316*0e209d39SAndroid Build Coastguard Worker } 317*0e209d39SAndroid Build Coastguard Worker 318*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */ 319*0e209d39SAndroid Build Coastguard Worker 320*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END 321*0e209d39SAndroid Build Coastguard Worker 322*0e209d39SAndroid Build Coastguard Worker #endif /* U_SHOW_CPLUSPLUS_API */ 323*0e209d39SAndroid Build Coastguard Worker 324*0e209d39SAndroid Build Coastguard Worker #endif 325