1b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* 2b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru****************************************************************************** 3b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* 4103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius* Copyright (C) 2002-2012, International Business Machines 5b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* Corporation and others. All Rights Reserved. 6b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* 7b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru****************************************************************************** 8b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* file name: uobject.h 9b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* encoding: US-ASCII 10b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* tab size: 8 (not used) 11b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* indentation:4 12b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* 13b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* created on: 2002jun26 14b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* created by: Markus W. Scherer 15b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*/ 16b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 17b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#ifndef __UOBJECT_H__ 18b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define __UOBJECT_H__ 19b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 20b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/utypes.h" 21b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 22b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 23b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * \file 24b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * \brief C++ API: Common ICU base class UObject. 25b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 26b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 27b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 2850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * @{ 29b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * \def U_NO_THROW 30b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * Define this to define the throw() specification so 3150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * certain functions do not throw any exceptions 32b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * 33b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * UMemory operator new methods should have the throw() specification 34b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * appended to them, so that the compiler adds the additional NULL check 35b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * before calling constructors. Without, if <code>operator new</code> returns NULL the 36b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * constructor is still called, and if the constructor references member 37b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * data, (which it typically does), the result is a segmentation violation. 38b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * 39103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * @stable ICU 4.2 40103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius */ 41b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#ifndef U_NO_THROW 42b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#define U_NO_THROW throw() 43b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#endif 44b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 4550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho/** @} */ 4650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 47103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius/*===========================================================================*/ 48103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius/* UClassID-based RTTI */ 49103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius/*===========================================================================*/ 50103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 51103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius/** 52103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * UClassID is used to identify classes without using the compiler's RTTI. 53103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * This was used before C++ compilers consistently supported RTTI. 54103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * ICU 4.6 requires compiler RTTI to be turned on. 55103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * 56103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * Each class hierarchy which needs 57103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * to implement polymorphic clone() or operator==() defines two methods, 58103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * described in detail below. UClassID values can be compared using 59103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * operator==(). Nothing else should be done with them. 60103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * 61103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * \par 628393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius * In class hierarchies that implement "poor man's RTTI", 638393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius * each concrete subclass implements getDynamicClassID() in the same way: 64103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * 65103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * \code 66103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * class Derived { 67103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * public: 68103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * virtual UClassID getDynamicClassID() const 69103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * { return Derived::getStaticClassID(); } 70103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * } 71103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * \endcode 72103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * 73103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * Each concrete class implements getStaticClassID() as well, which allows 74103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * clients to test for a specific type. 75103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * 76103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * \code 77103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * class Derived { 78103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * public: 79103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * static UClassID U_EXPORT2 getStaticClassID(); 80103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * private: 81103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * static char fgClassID; 82103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * } 83103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * 84103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * // In Derived.cpp: 85103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * UClassID Derived::getStaticClassID() 86103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * { return (UClassID)&Derived::fgClassID; } 87103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * char Derived::fgClassID = 0; // Value is irrelevant 88103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * \endcode 89103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * @stable ICU 2.0 90103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius */ 91103e9ffba2cba345d0078eb8b8db33249f81840aCraig Corneliustypedef void* UClassID; 92103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 93103e9ffba2cba345d0078eb8b8db33249f81840aCraig CorneliusU_NAMESPACE_BEGIN 94103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 95b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/** 96b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * UMemory is the common ICU base class. 97b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * All other ICU C++ classes are derived from UMemory (starting with ICU 2.4). 98b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 99b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * This is primarily to make it possible and simple to override the 100b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * C++ memory management by adding new/delete operators to this base class. 101b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 102b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * To override ALL ICU memory management, including that from plain C code, 103b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * replace the allocation functions declared in cmemory.h 104b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 105b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * UMemory does not contain any virtual functions. 106b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Common "boilerplate" functions are defined in UObject. 107b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 108b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @stable ICU 2.4 109b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 110b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruclass U_COMMON_API UMemory { 111b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querupublic: 112b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 113b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/* test versions for debugging shaper heap memory problems */ 114b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#ifdef SHAPER_MEMORY_DEBUG 115b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru static void * NewArray(int size, int count); 116b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru static void * GrowArray(void * array, int newSize ); 117b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru static void FreeArray(void * array ); 118b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#endif 119b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 120b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#if U_OVERRIDE_CXX_ALLOCATION 121b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /** 122b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Override for ICU4C C++ memory management. 123b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * simple, non-class types are allocated using the macros in common/cmemory.h 124b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * (uprv_malloc(), uprv_free(), uprv_realloc()); 125b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * they or something else could be used here to implement C++ new/delete 126b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * for ICU4C C++ classes 127b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @stable ICU 2.4 128b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 129b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru static void * U_EXPORT2 operator new(size_t size) U_NO_THROW; 130b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 131b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /** 132b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Override for ICU4C C++ memory management. 133b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * See new(). 134b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @stable ICU 2.4 135b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 136b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru static void * U_EXPORT2 operator new[](size_t size) U_NO_THROW; 137b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 138b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /** 139b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Override for ICU4C C++ memory management. 140b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * simple, non-class types are allocated using the macros in common/cmemory.h 141b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * (uprv_malloc(), uprv_free(), uprv_realloc()); 142b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * they or something else could be used here to implement C++ new/delete 143b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * for ICU4C C++ classes 144b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @stable ICU 2.4 145b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 146b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru static void U_EXPORT2 operator delete(void *p) U_NO_THROW; 147b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 148b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /** 149b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Override for ICU4C C++ memory management. 150b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * See delete(). 151b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @stable ICU 2.4 152b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 153b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru static void U_EXPORT2 operator delete[](void *p) U_NO_THROW; 154b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 155b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#if U_HAVE_PLACEMENT_NEW 156b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /** 157b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Override for ICU4C C++ memory management for STL. 158b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * See new(). 159b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @stable ICU 2.6 160b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 161b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru static inline void * U_EXPORT2 operator new(size_t, void *ptr) U_NO_THROW { return ptr; } 162b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 163b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /** 164b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Override for ICU4C C++ memory management for STL. 165b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * See delete(). 166b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @stable ICU 2.6 167b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 168b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru static inline void U_EXPORT2 operator delete(void *, void *) U_NO_THROW {} 169b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif /* U_HAVE_PLACEMENT_NEW */ 170b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#if U_HAVE_DEBUG_LOCATION_NEW 171b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /** 172b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * This method overrides the MFC debug version of the operator new 173b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 174b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @param size The requested memory size 175b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @param file The file where the allocation was requested 176b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @param line The line where the allocation was requested 177b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 178b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru static void * U_EXPORT2 operator new(size_t size, const char* file, int line) U_NO_THROW; 179b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /** 180b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * This method provides a matching delete for the MFC debug new 181b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 182b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @param p The pointer to the allocated memory 183b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @param file The file where the allocation was requested 184b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @param line The line where the allocation was requested 185b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 186b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru static void U_EXPORT2 operator delete(void* p, const char* file, int line) U_NO_THROW; 187b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif /* U_HAVE_DEBUG_LOCATION_NEW */ 188b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif /* U_OVERRIDE_CXX_ALLOCATION */ 189b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 190b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 191b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Assignment operator not declared. The compiler will provide one 192b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * which does nothing since this class does not contain any data members. 193b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * API/code coverage may show the assignment operator as present and 194b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * untested - ignore. 195b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Subclasses need this assignment operator if they use compiler-provided 196b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * assignment operators of their own. An alternative to not declaring one 197b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * here would be to declare and empty-implement a protected or public one. 198b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UMemory &UMemory::operator=(const UMemory &); 199b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 200b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}; 201b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 202b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 203b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * UObject is the common ICU "boilerplate" class. 204b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * UObject inherits UMemory (starting with ICU 2.4), 205b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * and all other public ICU C++ classes 206b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * are derived from UObject (starting with ICU 2.2). 207b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 2088393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius * UObject contains common virtual functions, in particular a virtual destructor. 209b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 210b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * The clone() function is not available in UObject because it is not 211b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * implemented by all ICU classes. 212b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Many ICU services provide a clone() function for their class trees, 213b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * defined on the service's C++ base class, and all subclasses within that 214b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * service class tree return a pointer to the service base class 215b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * (which itself is a subclass of UObject). 216b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * This is because some compilers do not support covariant (same-as-this) 217b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * return types; cast to the appropriate subclass if necessary. 218b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 219b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @stable ICU 2.2 220b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 221b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruclass U_COMMON_API UObject : public UMemory { 222b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querupublic: 223b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /** 224b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Destructor. 225b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 226b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @stable ICU 2.2 227b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 228b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru virtual ~UObject(); 229b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 230b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /** 231b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class. 2328393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius * The base class implementation returns a dummy value. 2338393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius * 2348393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius * Use compiler RTTI rather than ICU's "poor man's RTTI". 2358393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius * Since ICU 4.6, new ICU C++ class hierarchies do not implement "poor man's RTTI". 236b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 237b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @stable ICU 2.2 238b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 2398393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius virtual UClassID getDynamicClassID() const; 240b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 241b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruprotected: 242b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // the following functions are protected to prevent instantiation and 243b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // direct use of UObject itself 244b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 245b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // default constructor 246b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // inline UObject() {} 247b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 248b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // copy constructor 249b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // inline UObject(const UObject &other) {} 250b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 251b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#if 0 252b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // TODO Sometime in the future. Implement operator==(). 253b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // (This comment inserted in 2.2) 254b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // some or all of the following "boilerplate" functions may be made public 255b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // in a future ICU4C release when all subclasses implement them 256b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 257b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // assignment operator 258b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // (not virtual, see "Taligent's Guide to Designing Programs" pp.73..74) 259b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // commented out because the implementation is the same as a compiler's default 260b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // UObject &operator=(const UObject &other) { return *this; } 261b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 262b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // comparison operators 263b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru virtual inline UBool operator==(const UObject &other) const { return this==&other; } 264b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru inline UBool operator!=(const UObject &other) const { return !operator==(other); } 265b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 266b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // clone() commented out from the base class: 267b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // some compilers do not support co-variant return types 268b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // (i.e., subclasses would have to return UObject * as well, instead of SubClass *) 269b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // see also UObject class documentation. 270b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // virtual UObject *clone() const; 271b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif 272b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 273b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 274b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Assignment operator not declared. The compiler will provide one 275b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * which does nothing since this class does not contain any data members. 276b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * API/code coverage may show the assignment operator as present and 277b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * untested - ignore. 278b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Subclasses need this assignment operator if they use compiler-provided 279b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * assignment operators of their own. An alternative to not declaring one 280b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * here would be to declare and empty-implement a protected or public one. 281b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UObject &UObject::operator=(const UObject &); 282b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 283b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}; 284b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 285103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius#ifndef U_HIDE_INTERNAL_API 286b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 287b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * This is a simple macro to add ICU RTTI to an ICU object implementation. 288b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * This does not go into the header. This should only be used in *.cpp files. 289b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 290b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @param myClass The name of the class that needs RTTI defined. 291b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @internal 292b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 293b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass) \ 294b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UClassID U_EXPORT2 myClass::getStaticClassID() { \ 295b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru static char classID = 0; \ 296b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return (UClassID)&classID; \ 297b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } \ 298b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UClassID myClass::getDynamicClassID() const \ 299b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { return myClass::getStaticClassID(); } 300b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 301b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 302b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 303b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * This macro adds ICU RTTI to an ICU abstract class implementation. 304b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * This macro should be invoked in *.cpp files. The corresponding 305b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * header should declare getStaticClassID. 306b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 307b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @param myClass The name of the class that needs RTTI defined. 308b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @internal 309b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 310b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass) \ 311b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UClassID U_EXPORT2 myClass::getStaticClassID() { \ 312b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru static char classID = 0; \ 313b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return (UClassID)&classID; \ 314b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 315b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 316103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius#endif /* U_HIDE_INTERNAL_API */ 317b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 318b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_NAMESPACE_END 319b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 320b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif 321