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 #include "unicode/platform.h" 00024 00045 #ifndef U_NO_THROW 00046 #define U_NO_THROW throw() 00047 #endif 00048 00049 /*===========================================================================*/ 00050 /* UClassID-based RTTI */ 00051 /*===========================================================================*/ 00052 00093 typedef void* UClassID; 00094 00095 U_NAMESPACE_BEGIN 00096 00112 class U_COMMON_API UMemory { 00113 public: 00114 00115 /* test versions for debugging shaper heap memory problems */ 00116 #ifdef SHAPER_MEMORY_DEBUG 00117 static void * NewArray(int size, int count); 00118 static void * GrowArray(void * array, int newSize ); 00119 static void FreeArray(void * array ); 00120 #endif 00121 00122 #if U_OVERRIDE_CXX_ALLOCATION 00123 00131 static void * U_EXPORT2 operator new(size_t size) U_NOEXCEPT; 00132 00138 static void * U_EXPORT2 operator new[](size_t size) U_NOEXCEPT; 00139 00148 static void U_EXPORT2 operator delete(void *p) U_NOEXCEPT; 00149 00155 static void U_EXPORT2 operator delete[](void *p) U_NOEXCEPT; 00156 00157 #if U_HAVE_PLACEMENT_NEW 00158 00163 static inline void * U_EXPORT2 operator new(size_t, void *ptr) U_NOEXCEPT { return ptr; } 00164 00170 static inline void U_EXPORT2 operator delete(void *, void *) U_NOEXCEPT {} 00171 #endif /* U_HAVE_PLACEMENT_NEW */ 00172 #if U_HAVE_DEBUG_LOCATION_NEW 00173 00180 static void * U_EXPORT2 operator new(size_t size, const char* file, int line) U_NOEXCEPT; 00188 static void U_EXPORT2 operator delete(void* p, const char* file, int line) U_NOEXCEPT; 00189 #endif /* U_HAVE_DEBUG_LOCATION_NEW */ 00190 #endif /* U_OVERRIDE_CXX_ALLOCATION */ 00191 00192 /* 00193 * Assignment operator not declared. The compiler will provide one 00194 * which does nothing since this class does not contain any data members. 00195 * API/code coverage may show the assignment operator as present and 00196 * untested - ignore. 00197 * Subclasses need this assignment operator if they use compiler-provided 00198 * assignment operators of their own. An alternative to not declaring one 00199 * here would be to declare and empty-implement a protected or public one. 00200 UMemory &UMemory::operator=(const UMemory &); 00201 */ 00202 }; 00203 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 UBool operator==(const UObject &other) const { return this==&other; } 00266 inline UBool 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
1.6.1