uobject.h

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

Generated on Mon Aug 13 07:17:24 2007 for ICU 3.6 by  doxygen 1.5.2