ICU 4.8.1.1  4.8.1.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
uobject.h
Go to the documentation of this file.
1 /*
2 ******************************************************************************
3 *
4 * Copyright (C) 2002-2010, International Business Machines
5 * Corporation and others. All Rights Reserved.
6 *
7 ******************************************************************************
8 * file name: uobject.h
9 * encoding: US-ASCII
10 * tab size: 8 (not used)
11 * indentation:4
12 *
13 * created on: 2002jun26
14 * created by: Markus W. Scherer
15 */
16 
17 #ifndef __UOBJECT_H__
18 #define __UOBJECT_H__
19 
20 #include "unicode/utypes.h"
21 
23 
39 #ifndef U_OVERRIDE_CXX_ALLOCATION
40 #define U_OVERRIDE_CXX_ALLOCATION 1
41 #endif
42 
50 #ifndef U_HAVE_PLACEMENT_NEW
51 #define U_HAVE_PLACEMENT_NEW 1
52 #endif
53 
54 
62 #ifndef U_HAVE_DEBUG_LOCATION_NEW
63 #define U_HAVE_DEBUG_LOCATION_NEW 0
64 #endif
65 
80 #ifndef U_NO_THROW
81 #define U_NO_THROW throw()
82 #endif
83 
102 public:
103 
104 /* test versions for debugging shaper heap memory problems */
105 #ifdef SHAPER_MEMORY_DEBUG
106  static void * NewArray(int size, int count);
107  static void * GrowArray(void * array, int newSize );
108  static void FreeArray(void * array );
109 #endif
110 
111 #if U_OVERRIDE_CXX_ALLOCATION
112 
120  static void * U_EXPORT2 operator new(size_t size) U_NO_THROW;
121 
127  static void * U_EXPORT2 operator new[](size_t size) U_NO_THROW;
128 
137  static void U_EXPORT2 operator delete(void *p) U_NO_THROW;
138 
144  static void U_EXPORT2 operator delete[](void *p) U_NO_THROW;
145 
146 #if U_HAVE_PLACEMENT_NEW
147 
152  static inline void * U_EXPORT2 operator new(size_t, void *ptr) U_NO_THROW { return ptr; }
153 
159  static inline void U_EXPORT2 operator delete(void *, void *) U_NO_THROW {}
160 #endif /* U_HAVE_PLACEMENT_NEW */
161 #if U_HAVE_DEBUG_LOCATION_NEW
162 
169  static void * U_EXPORT2 operator new(size_t size, const char* file, int line) U_NO_THROW;
177  static void U_EXPORT2 operator delete(void* p, const char* file, int line) U_NO_THROW;
178 #endif /* U_HAVE_DEBUG_LOCATION_NEW */
179 #endif /* U_OVERRIDE_CXX_ALLOCATION */
180 
181  /*
182  * Assignment operator not declared. The compiler will provide one
183  * which does nothing since this class does not contain any data members.
184  * API/code coverage may show the assignment operator as present and
185  * untested - ignore.
186  * Subclasses need this assignment operator if they use compiler-provided
187  * assignment operators of their own. An alternative to not declaring one
188  * here would be to declare and empty-implement a protected or public one.
189  UMemory &UMemory::operator=(const UMemory &);
190  */
191 };
192 
215 class U_COMMON_API UObject : public UMemory {
216 public:
222  virtual ~UObject();
223 
229  virtual UClassID getDynamicClassID() const = 0;
230 
231 protected:
232  // the following functions are protected to prevent instantiation and
233  // direct use of UObject itself
234 
235  // default constructor
236  // commented out because UObject is abstract (see getDynamicClassID)
237  // inline UObject() {}
238 
239  // copy constructor
240  // commented out because UObject is abstract (see getDynamicClassID)
241  // inline UObject(const UObject &other) {}
242 
243 #if 0
244  // TODO Sometime in the future. Implement operator==().
245  // (This comment inserted in 2.2)
246  // some or all of the following "boilerplate" functions may be made public
247  // in a future ICU4C release when all subclasses implement them
248 
249  // assignment operator
250  // (not virtual, see "Taligent's Guide to Designing Programs" pp.73..74)
251  // commented out because the implementation is the same as a compiler's default
252  // UObject &operator=(const UObject &other) { return *this; }
253 
254  // comparison operators
255  virtual inline UBool operator==(const UObject &other) const { return this==&other; }
256  inline UBool operator!=(const UObject &other) const { return !operator==(other); }
257 
258  // clone() commented out from the base class:
259  // some compilers do not support co-variant return types
260  // (i.e., subclasses would have to return UObject * as well, instead of SubClass *)
261  // see also UObject class documentation.
262  // virtual UObject *clone() const;
263 #endif
264 
265  /*
266  * Assignment operator not declared. The compiler will provide one
267  * which does nothing since this class does not contain any data members.
268  * API/code coverage may show the assignment operator as present and
269  * untested - ignore.
270  * Subclasses need this assignment operator if they use compiler-provided
271  * assignment operators of their own. An alternative to not declaring one
272  * here would be to declare and empty-implement a protected or public one.
273  UObject &UObject::operator=(const UObject &);
274  */
275 
276 // Future implementation for RTTI that support subtyping. [alan]
277 //
278 // public:
279 // /**
280 // * @internal
281 // */
282 // static UClassID getStaticClassID();
283 //
284 // /**
285 // * @internal
286 // */
287 // UBool instanceOf(UClassID type) const;
288 };
289 
297 #define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass) \
298  UClassID U_EXPORT2 myClass::getStaticClassID() { \
299  static char classID = 0; \
300  return (UClassID)&classID; \
301  } \
302  UClassID myClass::getDynamicClassID() const \
303  { return myClass::getStaticClassID(); }
304 
305 
314 #define UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass) \
315  UClassID U_EXPORT2 myClass::getStaticClassID() { \
316  static char classID = 0; \
317  return (UClassID)&classID; \
318  }
319 
330 #define UOBJECT_DEFINE_NO_RTTI_IMPLEMENTATION(myClass) \
331  UClassID myClass::getDynamicClassID() const { return NULL; }
332 
333 // /**
334 // * This macro adds ICU RTTI to an ICU concrete class implementation.
335 // * This macro should be invoked in *.cpp files. The corresponding
336 // * header should declare getDynamicClassID and getStaticClassID.
337 // *
338 // * @param myClass The name of the class that needs RTTI defined.
339 // * @param myParent The name of the myClass's parent.
340 // * @internal
341 // */
342 /*#define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass, myParent) \
343  UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass, myParent) \
344  UClassID myClass::getDynamicClassID() const { \
345  return myClass::getStaticClassID(); \
346  }
347 */
348 
349 
351 
352 #endif