00001 /* 00002 ****************************************************************************** 00003 * 00004 * Copyright (C) 2002-2007, 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 00022 U_NAMESPACE_BEGIN 00023 00039 #ifndef U_OVERRIDE_CXX_ALLOCATION 00040 #define U_OVERRIDE_CXX_ALLOCATION 1 00041 #endif 00042 00048 #ifndef U_HAVE_PLACEMENT_NEW 00049 #define U_HAVE_PLACEMENT_NEW 1 00050 #endif 00051 00052 00058 #ifndef U_HAVE_DEBUG_LOCATION_NEW 00059 #define U_HAVE_DEBUG_LOCATION_NEW 0 00060 #endif 00061 00077 class U_COMMON_API UMemory { 00078 public: 00079 00080 #if U_OVERRIDE_CXX_ALLOCATION 00081 00089 static void * U_EXPORT2 operator new(size_t size); 00090 00096 static void * U_EXPORT2 operator new[](size_t size); 00097 00106 static void U_EXPORT2 operator delete(void *p); 00107 00113 static void U_EXPORT2 operator delete[](void *p); 00114 00115 #if U_HAVE_PLACEMENT_NEW 00116 00121 static inline void * U_EXPORT2 operator new(size_t, void *ptr) { return ptr; } 00122 00128 static inline void U_EXPORT2 operator delete(void *, void *) {} 00129 #endif /* U_HAVE_PLACEMENT_NEW */ 00130 #if U_HAVE_DEBUG_LOCATION_NEW 00131 00138 static void * U_EXPORT2 operator new(size_t size, const char* file, int line); 00146 static void U_EXPORT2 operator delete(void* p, const char* file, int line); 00147 #endif /* U_HAVE_DEBUG_LOCATION_NEW */ 00148 #endif /* U_OVERRIDE_CXX_ALLOCATION */ 00149 00150 /* 00151 * Assignment operator not declared. The compiler will provide one 00152 * which does nothing since this class does not contain any data members. 00153 * API/code coverage may show the assignment operator as present and 00154 * untested - ignore. 00155 * Subclasses need this assignment operator if they use compiler-provided 00156 * assignment operators of their own. An alternative to not declaring one 00157 * here would be to declare and empty-implement a protected or public one. 00158 UMemory &UMemory::operator=(const UMemory &); 00159 */ 00160 }; 00161 00184 class U_COMMON_API UObject : public UMemory { 00185 public: 00191 virtual ~UObject(); 00192 00198 virtual UClassID getDynamicClassID() const = 0; 00199 00200 protected: 00201 // the following functions are protected to prevent instantiation and 00202 // direct use of UObject itself 00203 00204 // default constructor 00205 // commented out because UObject is abstract (see getDynamicClassID) 00206 // inline UObject() {} 00207 00208 // copy constructor 00209 // commented out because UObject is abstract (see getDynamicClassID) 00210 // inline UObject(const UObject &other) {} 00211 00212 #if 0 00213 // TODO Sometime in the future. Implement operator==(). 00214 // (This comment inserted in 2.2) 00215 // some or all of the following "boilerplate" functions may be made public 00216 // in a future ICU4C release when all subclasses implement them 00217 00218 // assignment operator 00219 // (not virtual, see "Taligent's Guide to Designing Programs" pp.73..74) 00220 // commented out because the implementation is the same as a compiler's default 00221 // UObject &operator=(const UObject &other) { return *this; } 00222 00223 // comparison operators 00224 virtual inline UBool operator==(const UObject &other) const { return this==&other; } 00225 inline UBool operator!=(const UObject &other) const { return !operator==(other); } 00226 00227 // clone() commented out from the base class: 00228 // some compilers do not support co-variant return types 00229 // (i.e., subclasses would have to return UObject * as well, instead of SubClass *) 00230 // see also UObject class documentation. 00231 // virtual UObject *clone() const; 00232 #endif 00233 00234 /* 00235 * Assignment operator not declared. The compiler will provide one 00236 * which does nothing since this class does not contain any data members. 00237 * API/code coverage may show the assignment operator as present and 00238 * untested - ignore. 00239 * Subclasses need this assignment operator if they use compiler-provided 00240 * assignment operators of their own. An alternative to not declaring one 00241 * here would be to declare and empty-implement a protected or public one. 00242 UObject &UObject::operator=(const UObject &); 00243 */ 00244 00245 // Future implementation for RTTI that support subtyping. [alan] 00246 // 00247 // public: 00248 // /** 00249 // * @internal 00250 // */ 00251 // static UClassID getStaticClassID(); 00252 // 00253 // /** 00254 // * @internal 00255 // */ 00256 // UBool instanceOf(UClassID type) const; 00257 }; 00258 00266 #define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass) \ 00267 UClassID U_EXPORT2 myClass::getStaticClassID() { \ 00268 static char classID = 0; \ 00269 return (UClassID)&classID; \ 00270 } \ 00271 UClassID myClass::getDynamicClassID() const \ 00272 { return myClass::getStaticClassID(); } 00273 00274 00283 #define UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass) \ 00284 UClassID U_EXPORT2 myClass::getStaticClassID() { \ 00285 static char classID = 0; \ 00286 return (UClassID)&classID; \ 00287 } 00288 00289 // /** 00290 // * This macro adds ICU RTTI to an ICU concrete class implementation. 00291 // * This macro should be invoked in *.cpp files. The corresponding 00292 // * header should declare getDynamicClassID and getStaticClassID. 00293 // * 00294 // * @param myClass The name of the class that needs RTTI defined. 00295 // * @param myParent The name of the myClass's parent. 00296 // * @internal 00297 // */ 00298 /*#define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass, myParent) \ 00299 UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass, myParent) \ 00300 UClassID myClass::getDynamicClassID() const { \ 00301 return myClass::getStaticClassID(); \ 00302 } 00303 */ 00304 00305 00306 U_NAMESPACE_END 00307 00308 #endif