ICU 49.1.1
49.1.1
|
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 00096 typedef void* UClassID; 00097 00098 U_NAMESPACE_BEGIN 00099 00115 class U_COMMON_API UMemory { 00116 public: 00117 00118 /* test versions for debugging shaper heap memory problems */ 00119 #ifdef SHAPER_MEMORY_DEBUG 00120 static void * NewArray(int size, int count); 00121 static void * GrowArray(void * array, int newSize ); 00122 static void FreeArray(void * array ); 00123 #endif 00124 00125 #if U_OVERRIDE_CXX_ALLOCATION 00126 00134 static void * U_EXPORT2 operator new(size_t size) U_NO_THROW; 00135 00141 static void * U_EXPORT2 operator new[](size_t size) U_NO_THROW; 00142 00151 static void U_EXPORT2 operator delete(void *p) U_NO_THROW; 00152 00158 static void U_EXPORT2 operator delete[](void *p) U_NO_THROW; 00159 00160 #if U_HAVE_PLACEMENT_NEW 00161 00166 static inline void * U_EXPORT2 operator new(size_t, void *ptr) U_NO_THROW { return ptr; } 00167 00173 static inline void U_EXPORT2 operator delete(void *, void *) U_NO_THROW {} 00174 #endif /* U_HAVE_PLACEMENT_NEW */ 00175 #if U_HAVE_DEBUG_LOCATION_NEW 00176 00183 static void * U_EXPORT2 operator new(size_t size, const char* file, int line) U_NO_THROW; 00191 static void U_EXPORT2 operator delete(void* p, const char* file, int line) U_NO_THROW; 00192 #endif /* U_HAVE_DEBUG_LOCATION_NEW */ 00193 #endif /* U_OVERRIDE_CXX_ALLOCATION */ 00194 00195 /* 00196 * Assignment operator not declared. The compiler will provide one 00197 * which does nothing since this class does not contain any data members. 00198 * API/code coverage may show the assignment operator as present and 00199 * untested - ignore. 00200 * Subclasses need this assignment operator if they use compiler-provided 00201 * assignment operators of their own. An alternative to not declaring one 00202 * here would be to declare and empty-implement a protected or public one. 00203 UMemory &UMemory::operator=(const UMemory &); 00204 */ 00205 }; 00206 00229 class U_COMMON_API UObject : public UMemory { 00230 public: 00236 virtual ~UObject(); 00237 00243 virtual UClassID getDynamicClassID() const = 0; 00244 00245 protected: 00246 // the following functions are protected to prevent instantiation and 00247 // direct use of UObject itself 00248 00249 // default constructor 00250 // commented out because UObject is abstract (see getDynamicClassID) 00251 // inline UObject() {} 00252 00253 // copy constructor 00254 // commented out because UObject is abstract (see getDynamicClassID) 00255 // inline UObject(const UObject &other) {} 00256 00257 #if 0 00258 // TODO Sometime in the future. Implement operator==(). 00259 // (This comment inserted in 2.2) 00260 // some or all of the following "boilerplate" functions may be made public 00261 // in a future ICU4C release when all subclasses implement them 00262 00263 // assignment operator 00264 // (not virtual, see "Taligent's Guide to Designing Programs" pp.73..74) 00265 // commented out because the implementation is the same as a compiler's default 00266 // UObject &operator=(const UObject &other) { return *this; } 00267 00268 // comparison operators 00269 virtual inline UBool operator==(const UObject &other) const { return this==&other; } 00270 inline UBool operator!=(const UObject &other) const { return !operator==(other); } 00271 00272 // clone() commented out from the base class: 00273 // some compilers do not support co-variant return types 00274 // (i.e., subclasses would have to return UObject * as well, instead of SubClass *) 00275 // see also UObject class documentation. 00276 // virtual UObject *clone() const; 00277 #endif 00278 00279 /* 00280 * Assignment operator not declared. The compiler will provide one 00281 * which does nothing since this class does not contain any data members. 00282 * API/code coverage may show the assignment operator as present and 00283 * untested - ignore. 00284 * Subclasses need this assignment operator if they use compiler-provided 00285 * assignment operators of their own. An alternative to not declaring one 00286 * here would be to declare and empty-implement a protected or public one. 00287 UObject &UObject::operator=(const UObject &); 00288 */ 00289 00290 // Future implementation for RTTI that support subtyping. [alan] 00291 // 00292 // public: 00293 // /** 00294 // * @internal 00295 // */ 00296 // static UClassID getStaticClassID(); 00297 // 00298 // /** 00299 // * @internal 00300 // */ 00301 // UBool instanceOf(UClassID type) const; 00302 }; 00303 00304 #ifndef U_HIDE_INTERNAL_API 00305 00312 #define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass) \ 00313 UClassID U_EXPORT2 myClass::getStaticClassID() { \ 00314 static char classID = 0; \ 00315 return (UClassID)&classID; \ 00316 } \ 00317 UClassID myClass::getDynamicClassID() const \ 00318 { return myClass::getStaticClassID(); } 00319 00320 00329 #define UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass) \ 00330 UClassID U_EXPORT2 myClass::getStaticClassID() { \ 00331 static char classID = 0; \ 00332 return (UClassID)&classID; \ 00333 } 00334 00345 #define UOBJECT_DEFINE_NO_RTTI_IMPLEMENTATION(myClass) \ 00346 UClassID myClass::getDynamicClassID() const { return NULL; } 00347 00348 // /** 00349 // * This macro adds ICU RTTI to an ICU concrete class implementation. 00350 // * This macro should be invoked in *.cpp files. The corresponding 00351 // * header should declare getDynamicClassID and getStaticClassID. 00352 // * 00353 // * @param myClass The name of the class that needs RTTI defined. 00354 // * @param myParent The name of the myClass's parent. 00355 // * @internal 00356 // */ 00357 /*#define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass, myParent) \ 00358 UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass, myParent) \ 00359 UClassID myClass::getDynamicClassID() const { \ 00360 return myClass::getStaticClassID(); \ 00361 } 00362 */ 00363 #endif /* U_HIDE_INTERNAL_API */ 00364 00365 U_NAMESPACE_END 00366 00367 #endif