|
ICU 51.2
51.2
|
00001 /* 00002 ****************************************************************************** 00003 * 00004 * Copyright (C) 2002-2012, International Business Machines 00005 * Corporation and others. All Rights Reserved. 00006 * 00007 ****************************************************************************** 00008 * file name: uobject.h 00009 * encoding: US-ASCII 00010 * tab size: 8 (not used) 00011 * indentation:4 00012 * 00013 * created on: 2002jun26 00014 * created by: Markus W. Scherer 00015 */ 00016 00017 #ifndef __UOBJECT_H__ 00018 #define __UOBJECT_H__ 00019 00020 #include "unicode/utypes.h" 00021 00041 #ifndef U_NO_THROW 00042 #define U_NO_THROW throw() 00043 #endif 00044 00047 /*===========================================================================*/ 00048 /* UClassID-based RTTI */ 00049 /*===========================================================================*/ 00050 00091 typedef void* UClassID; 00092 00093 U_NAMESPACE_BEGIN 00094 00110 class U_COMMON_API UMemory { 00111 public: 00112 00113 /* test versions for debugging shaper heap memory problems */ 00114 #ifdef SHAPER_MEMORY_DEBUG 00115 static void * NewArray(int size, int count); 00116 static void * GrowArray(void * array, int newSize ); 00117 static void FreeArray(void * array ); 00118 #endif 00119 00120 #if U_OVERRIDE_CXX_ALLOCATION 00121 00129 static void * U_EXPORT2 operator new(size_t size) U_NO_THROW; 00130 00136 static void * U_EXPORT2 operator new[](size_t size) U_NO_THROW; 00137 00146 static void U_EXPORT2 operator delete(void *p) U_NO_THROW; 00147 00153 static void U_EXPORT2 operator delete[](void *p) U_NO_THROW; 00154 00155 #if U_HAVE_PLACEMENT_NEW 00156 00161 static inline void * U_EXPORT2 operator new(size_t, void *ptr) U_NO_THROW { return ptr; } 00162 00168 static inline void U_EXPORT2 operator delete(void *, void *) U_NO_THROW {} 00169 #endif /* U_HAVE_PLACEMENT_NEW */ 00170 #if U_HAVE_DEBUG_LOCATION_NEW 00171 00178 static void * U_EXPORT2 operator new(size_t size, const char* file, int line) U_NO_THROW; 00186 static void U_EXPORT2 operator delete(void* p, const char* file, int line) U_NO_THROW; 00187 #endif /* U_HAVE_DEBUG_LOCATION_NEW */ 00188 #endif /* U_OVERRIDE_CXX_ALLOCATION */ 00189 00190 /* 00191 * Assignment operator not declared. The compiler will provide one 00192 * which does nothing since this class does not contain any data members. 00193 * API/code coverage may show the assignment operator as present and 00194 * untested - ignore. 00195 * Subclasses need this assignment operator if they use compiler-provided 00196 * assignment operators of their own. An alternative to not declaring one 00197 * here would be to declare and empty-implement a protected or public one. 00198 UMemory &UMemory::operator=(const UMemory &); 00199 */ 00200 }; 00201 00221 class U_COMMON_API UObject : public UMemory { 00222 public: 00228 virtual ~UObject(); 00229 00239 virtual UClassID getDynamicClassID() const; 00240 00241 protected: 00242 // the following functions are protected to prevent instantiation and 00243 // direct use of UObject itself 00244 00245 // default constructor 00246 // inline UObject() {} 00247 00248 // copy constructor 00249 // inline UObject(const UObject &other) {} 00250 00251 #if 0 00252 // TODO Sometime in the future. Implement operator==(). 00253 // (This comment inserted in 2.2) 00254 // some or all of the following "boilerplate" functions may be made public 00255 // in a future ICU4C release when all subclasses implement them 00256 00257 // assignment operator 00258 // (not virtual, see "Taligent's Guide to Designing Programs" pp.73..74) 00259 // commented out because the implementation is the same as a compiler's default 00260 // UObject &operator=(const UObject &other) { return *this; } 00261 00262 // comparison operators 00263 virtual inline UBool operator==(const UObject &other) const { return this==&other; } 00264 inline UBool operator!=(const UObject &other) const { return !operator==(other); } 00265 00266 // clone() commented out from the base class: 00267 // some compilers do not support co-variant return types 00268 // (i.e., subclasses would have to return UObject * as well, instead of SubClass *) 00269 // see also UObject class documentation. 00270 // virtual UObject *clone() const; 00271 #endif 00272 00273 /* 00274 * Assignment operator not declared. The compiler will provide one 00275 * which does nothing since this class does not contain any data members. 00276 * API/code coverage may show the assignment operator as present and 00277 * untested - ignore. 00278 * Subclasses need this assignment operator if they use compiler-provided 00279 * assignment operators of their own. An alternative to not declaring one 00280 * here would be to declare and empty-implement a protected or public one. 00281 UObject &UObject::operator=(const UObject &); 00282 */ 00283 }; 00284 00285 #ifndef U_HIDE_INTERNAL_API 00286 00293 #define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass) \ 00294 UClassID U_EXPORT2 myClass::getStaticClassID() { \ 00295 static char classID = 0; \ 00296 return (UClassID)&classID; \ 00297 } \ 00298 UClassID myClass::getDynamicClassID() const \ 00299 { return myClass::getStaticClassID(); } 00300 00301 00310 #define UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass) \ 00311 UClassID U_EXPORT2 myClass::getStaticClassID() { \ 00312 static char classID = 0; \ 00313 return (UClassID)&classID; \ 00314 } 00315 00316 #endif /* U_HIDE_INTERNAL_API */ 00317 00318 U_NAMESPACE_END 00319 00320 #endif
1.7.6.1