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 00042 #ifndef U_NO_THROW 00043 #define U_NO_THROW throw() 00044 #endif 00045 00046 /*===========================================================================*/ 00047 /* UClassID-based RTTI */ 00048 /*===========================================================================*/ 00049 00090 typedef void* UClassID; 00091 00092 U_NAMESPACE_BEGIN 00093 00109 class U_COMMON_API UMemory { 00110 public: 00111 00112 /* test versions for debugging shaper heap memory problems */ 00113 #ifdef SHAPER_MEMORY_DEBUG 00114 static void * NewArray(int size, int count); 00115 static void * GrowArray(void * array, int newSize ); 00116 static void FreeArray(void * array ); 00117 #endif 00118 00119 #if U_OVERRIDE_CXX_ALLOCATION 00120 00128 static void * U_EXPORT2 operator new(size_t size) U_NO_THROW; 00129 00135 static void * U_EXPORT2 operator new[](size_t size) U_NO_THROW; 00136 00145 static void U_EXPORT2 operator delete(void *p) U_NO_THROW; 00146 00152 static void U_EXPORT2 operator delete[](void *p) U_NO_THROW; 00153 00154 #if U_HAVE_PLACEMENT_NEW 00155 00160 static inline void * U_EXPORT2 operator new(size_t, void *ptr) U_NO_THROW { return ptr; } 00161 00167 static inline void U_EXPORT2 operator delete(void *, void *) U_NO_THROW {} 00168 #endif /* U_HAVE_PLACEMENT_NEW */ 00169 #if U_HAVE_DEBUG_LOCATION_NEW 00170 00177 static void * U_EXPORT2 operator new(size_t size, const char* file, int line) U_NO_THROW; 00185 static void U_EXPORT2 operator delete(void* p, const char* file, int line) U_NO_THROW; 00186 #endif /* U_HAVE_DEBUG_LOCATION_NEW */ 00187 #endif /* U_OVERRIDE_CXX_ALLOCATION */ 00188 00189 /* 00190 * Assignment operator not declared. The compiler will provide one 00191 * which does nothing since this class does not contain any data members. 00192 * API/code coverage may show the assignment operator as present and 00193 * untested - ignore. 00194 * Subclasses need this assignment operator if they use compiler-provided 00195 * assignment operators of their own. An alternative to not declaring one 00196 * here would be to declare and empty-implement a protected or public one. 00197 UMemory &UMemory::operator=(const UMemory &); 00198 */ 00199 }; 00200 00220 class U_COMMON_API UObject : public UMemory { 00221 public: 00227 virtual ~UObject(); 00228 00238 virtual UClassID getDynamicClassID() const; 00239 00240 protected: 00241 // the following functions are protected to prevent instantiation and 00242 // direct use of UObject itself 00243 00244 // default constructor 00245 // inline UObject() {} 00246 00247 // copy constructor 00248 // inline UObject(const UObject &other) {} 00249 00250 #if 0 00251 // TODO Sometime in the future. Implement operator==(). 00252 // (This comment inserted in 2.2) 00253 // some or all of the following "boilerplate" functions may be made public 00254 // in a future ICU4C release when all subclasses implement them 00255 00256 // assignment operator 00257 // (not virtual, see "Taligent's Guide to Designing Programs" pp.73..74) 00258 // commented out because the implementation is the same as a compiler's default 00259 // UObject &operator=(const UObject &other) { return *this; } 00260 00261 // comparison operators 00262 virtual inline UBool operator==(const UObject &other) const { return this==&other; } 00263 inline UBool operator!=(const UObject &other) const { return !operator==(other); } 00264 00265 // clone() commented out from the base class: 00266 // some compilers do not support co-variant return types 00267 // (i.e., subclasses would have to return UObject * as well, instead of SubClass *) 00268 // see also UObject class documentation. 00269 // virtual UObject *clone() const; 00270 #endif 00271 00272 /* 00273 * Assignment operator not declared. The compiler will provide one 00274 * which does nothing since this class does not contain any data members. 00275 * API/code coverage may show the assignment operator as present and 00276 * untested - ignore. 00277 * Subclasses need this assignment operator if they use compiler-provided 00278 * assignment operators of their own. An alternative to not declaring one 00279 * here would be to declare and empty-implement a protected or public one. 00280 UObject &UObject::operator=(const UObject &); 00281 */ 00282 }; 00283 00284 #ifndef U_HIDE_INTERNAL_API 00285 00292 #define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass) \ 00293 UClassID U_EXPORT2 myClass::getStaticClassID() { \ 00294 static char classID = 0; \ 00295 return (UClassID)&classID; \ 00296 } \ 00297 UClassID myClass::getDynamicClassID() const \ 00298 { return myClass::getStaticClassID(); } 00299 00300 00309 #define UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass) \ 00310 UClassID U_EXPORT2 myClass::getStaticClassID() { \ 00311 static char classID = 0; \ 00312 return (UClassID)&classID; \ 00313 } 00314 00315 #endif /* U_HIDE_INTERNAL_API */ 00316 00317 U_NAMESPACE_END 00318 00319 #endif
1.6.1