Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals

uobject.h

Go to the documentation of this file.
00001 /*
00002 ******************************************************************************
00003 *
00004 *   Copyright (C) 2002-2004, 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 
00067 class U_COMMON_API UMemory {
00068 public:
00069 
00070 #if U_OVERRIDE_CXX_ALLOCATION
00071 
00079     static void * U_EXPORT2 operator new(size_t size);
00080 
00086     static void * U_EXPORT2 operator new[](size_t size);
00087 
00096     static void U_EXPORT2 operator delete(void *p);
00097 
00103     static void U_EXPORT2 operator delete[](void *p);
00104 
00105 #if U_HAVE_PLACEMENT_NEW
00106 
00111     static inline void * U_EXPORT2 operator new(size_t, void *ptr) { return ptr; }
00112 
00118     static inline void U_EXPORT2 operator delete(void *, void *) {}
00119 #endif /* U_HAVE_PLACEMENT_NEW */
00120 #endif /* U_OVERRIDE_CXX_ALLOCATION */
00121 
00122     /*
00123      * Assignment operator not declared. The compiler will provide one
00124      * which does nothing since this class does not contain any data members.
00125      * API/code coverage may show the assignment operator as present and
00126      * untested - ignore.
00127      * Subclasses need this assignment operator if they use compiler-provided
00128      * assignment operators of their own. An alternative to not declaring one
00129      * here would be to declare and empty-implement a protected or public one.
00130     UMemory &UMemory::operator=(const UMemory &);
00131      */
00132 };
00133 
00156 class U_COMMON_API UObject : public UMemory {
00157 public:
00163     virtual ~UObject();
00164 
00170     virtual UClassID getDynamicClassID() const = 0;
00171 
00172 protected:
00173     // the following functions are protected to prevent instantiation and
00174     // direct use of UObject itself
00175 
00176     // default constructor
00177     // commented out because UObject is abstract (see getDynamicClassID)
00178     // inline UObject() {}
00179 
00180     // copy constructor
00181     // commented out because UObject is abstract (see getDynamicClassID)
00182     // inline UObject(const UObject &other) {}
00183 
00184 #if 0
00185     // TODO Sometime in the future. Implement operator==().
00186     // (This comment inserted in 2.2)
00187     // some or all of the following "boilerplate" functions may be made public
00188     // in a future ICU4C release when all subclasses implement them
00189 
00190     // assignment operator
00191     // (not virtual, see "Taligent's Guide to Designing Programs" pp.73..74)
00192     // commented out because the implementation is the same as a compiler's default
00193     // UObject &operator=(const UObject &other) { return *this; }
00194 
00195     // comparison operators
00196     virtual inline UBool operator==(const UObject &other) const { return this==&other; }
00197     inline UBool operator!=(const UObject &other) const { return !operator==(other); }
00198 
00199     // clone() commented out from the base class:
00200     // some compilers do not support co-variant return types
00201     // (i.e., subclasses would have to return UObject * as well, instead of SubClass *)
00202     // see also UObject class documentation.
00203     // virtual UObject *clone() const;
00204 #endif
00205 
00206     /*
00207      * Assignment operator not declared. The compiler will provide one
00208      * which does nothing since this class does not contain any data members.
00209      * API/code coverage may show the assignment operator as present and
00210      * untested - ignore.
00211      * Subclasses need this assignment operator if they use compiler-provided
00212      * assignment operators of their own. An alternative to not declaring one
00213      * here would be to declare and empty-implement a protected or public one.
00214     UObject &UObject::operator=(const UObject &);
00215      */
00216 
00217 // Future implementation for RTTI that support subtyping. [alan]
00218 // 
00219 //  public:
00220 //     /**
00221 //      * @internal
00222 //      */
00223 //     static UClassID getStaticClassID();
00224 // 
00225 //     /**
00226 //      * @internal
00227 //      */
00228 //     UBool instanceOf(UClassID type) const;
00229 };
00230 
00238 #define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass) \
00239     UClassID U_EXPORT2 myClass::getStaticClassID() { \
00240         static const char classID = 0; \
00241         return (UClassID)&classID; \
00242     } \
00243     UClassID myClass::getDynamicClassID() const \
00244     { return myClass::getStaticClassID(); }
00245 
00246 
00255 #define UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass) \
00256     UClassID U_EXPORT2 myClass::getStaticClassID() { \
00257         static const char classID = 0; \
00258         return (UClassID)&classID; \
00259     }
00260 
00261 // /**
00262 //  * This macro adds ICU RTTI to an ICU concrete class implementation.
00263 //  * This macro should be invoked in *.cpp files.  The corresponding
00264 //  * header should declare getDynamicClassID and getStaticClassID.
00265 //  *
00266 //  * @param myClass The name of the class that needs RTTI defined.
00267 //  * @param myParent The name of the myClass's parent.
00268 //  * @internal
00269 //  */
00270 /*#define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass, myParent) \
00271     UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass, myParent) \
00272     UClassID myClass::getDynamicClassID() const { \
00273         return myClass::getStaticClassID(); \
00274     }
00275 */
00276 
00277 
00278 U_NAMESPACE_END
00279 
00280 #endif

Generated on Tue Jul 26 00:40:02 2005 for ICU 3.2 by  doxygen 1.3.9.1