00001 /* 00002 ****************************************************************************** 00003 * 00004 * Copyright (C) 2002-2009, 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 00050 #ifndef U_HAVE_PLACEMENT_NEW 00051 #define U_HAVE_PLACEMENT_NEW 1 00052 #endif 00053 00054 00062 #ifndef U_HAVE_DEBUG_LOCATION_NEW 00063 #define U_HAVE_DEBUG_LOCATION_NEW 0 00064 #endif 00065 00079 #ifndef U_NO_THROW 00080 #define U_NO_THROW throw() 00081 #endif 00082 00098 class U_COMMON_API UMemory { 00099 public: 00100 00101 /* test versions for debugging shaper heap memory problems */ 00102 #ifdef SHAPER_MEMORY_DEBUG 00103 static void * NewArray(int size, int count); 00104 static void * GrowArray(void * array, int newSize ); 00105 static void FreeArray(void * array ); 00106 #endif 00107 00108 #if U_OVERRIDE_CXX_ALLOCATION 00109 00117 static void * U_EXPORT2 operator new(size_t size) U_NO_THROW; 00118 00124 static void * U_EXPORT2 operator new[](size_t size) U_NO_THROW; 00125 00134 static void U_EXPORT2 operator delete(void *p) U_NO_THROW; 00135 00141 static void U_EXPORT2 operator delete[](void *p) U_NO_THROW; 00142 00143 #if U_HAVE_PLACEMENT_NEW 00144 00149 static inline void * U_EXPORT2 operator new(size_t, void *ptr) U_NO_THROW { return ptr; } 00150 00156 static inline void U_EXPORT2 operator delete(void *, void *) U_NO_THROW {} 00157 #endif /* U_HAVE_PLACEMENT_NEW */ 00158 #if U_HAVE_DEBUG_LOCATION_NEW 00159 00166 static void * U_EXPORT2 operator new(size_t size, const char* file, int line) U_NO_THROW; 00174 static void U_EXPORT2 operator delete(void* p, const char* file, int line) U_NO_THROW; 00175 #endif /* U_HAVE_DEBUG_LOCATION_NEW */ 00176 #endif /* U_OVERRIDE_CXX_ALLOCATION */ 00177 00178 /* 00179 * Assignment operator not declared. The compiler will provide one 00180 * which does nothing since this class does not contain any data members. 00181 * API/code coverage may show the assignment operator as present and 00182 * untested - ignore. 00183 * Subclasses need this assignment operator if they use compiler-provided 00184 * assignment operators of their own. An alternative to not declaring one 00185 * here would be to declare and empty-implement a protected or public one. 00186 UMemory &UMemory::operator=(const UMemory &); 00187 */ 00188 }; 00189 00212 class U_COMMON_API UObject : public UMemory { 00213 public: 00219 virtual ~UObject(); 00220 00226 virtual UClassID getDynamicClassID() const = 0; 00227 00228 protected: 00229 // the following functions are protected to prevent instantiation and 00230 // direct use of UObject itself 00231 00232 // default constructor 00233 // commented out because UObject is abstract (see getDynamicClassID) 00234 // inline UObject() {} 00235 00236 // copy constructor 00237 // commented out because UObject is abstract (see getDynamicClassID) 00238 // inline UObject(const UObject &other) {} 00239 00240 #if 0 00241 // TODO Sometime in the future. Implement operator==(). 00242 // (This comment inserted in 2.2) 00243 // some or all of the following "boilerplate" functions may be made public 00244 // in a future ICU4C release when all subclasses implement them 00245 00246 // assignment operator 00247 // (not virtual, see "Taligent's Guide to Designing Programs" pp.73..74) 00248 // commented out because the implementation is the same as a compiler's default 00249 // UObject &operator=(const UObject &other) { return *this; } 00250 00251 // comparison operators 00252 virtual inline UBool operator==(const UObject &other) const { return this==&other; } 00253 inline UBool operator!=(const UObject &other) const { return !operator==(other); } 00254 00255 // clone() commented out from the base class: 00256 // some compilers do not support co-variant return types 00257 // (i.e., subclasses would have to return UObject * as well, instead of SubClass *) 00258 // see also UObject class documentation. 00259 // virtual UObject *clone() const; 00260 #endif 00261 00262 /* 00263 * Assignment operator not declared. The compiler will provide one 00264 * which does nothing since this class does not contain any data members. 00265 * API/code coverage may show the assignment operator as present and 00266 * untested - ignore. 00267 * Subclasses need this assignment operator if they use compiler-provided 00268 * assignment operators of their own. An alternative to not declaring one 00269 * here would be to declare and empty-implement a protected or public one. 00270 UObject &UObject::operator=(const UObject &); 00271 */ 00272 00273 // Future implementation for RTTI that support subtyping. [alan] 00274 // 00275 // public: 00276 // /** 00277 // * @internal 00278 // */ 00279 // static UClassID getStaticClassID(); 00280 // 00281 // /** 00282 // * @internal 00283 // */ 00284 // UBool instanceOf(UClassID type) const; 00285 }; 00286 00294 #define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass) \ 00295 UClassID U_EXPORT2 myClass::getStaticClassID() { \ 00296 static char classID = 0; \ 00297 return (UClassID)&classID; \ 00298 } \ 00299 UClassID myClass::getDynamicClassID() const \ 00300 { return myClass::getStaticClassID(); } 00301 00302 00311 #define UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass) \ 00312 UClassID U_EXPORT2 myClass::getStaticClassID() { \ 00313 static char classID = 0; \ 00314 return (UClassID)&classID; \ 00315 } 00316 00317 // /** 00318 // * This macro adds ICU RTTI to an ICU concrete class implementation. 00319 // * This macro should be invoked in *.cpp files. The corresponding 00320 // * header should declare getDynamicClassID and getStaticClassID. 00321 // * 00322 // * @param myClass The name of the class that needs RTTI defined. 00323 // * @param myParent The name of the myClass's parent. 00324 // * @internal 00325 // */ 00326 /*#define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass, myParent) \ 00327 UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass, myParent) \ 00328 UClassID myClass::getDynamicClassID() const { \ 00329 return myClass::getStaticClassID(); \ 00330 } 00331 */ 00332 00333 00334 U_NAMESPACE_END 00335 00336 #endif