ICU 50.1.2  50.1.2
uobject.h
Go to the documentation of this file.
1 /*
2 ******************************************************************************
3 *
4 * Copyright (C) 2002-2012, 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 
41 #ifndef U_NO_THROW
42 #define U_NO_THROW throw()
43 #endif
44 
47 /*===========================================================================*/
48 /* UClassID-based RTTI */
49 /*===========================================================================*/
50 
96 typedef void* UClassID;
97 
99 
116 public:
117 
118 /* test versions for debugging shaper heap memory problems */
119 #ifdef SHAPER_MEMORY_DEBUG
120  static void * NewArray(int size, int count);
121  static void * GrowArray(void * array, int newSize );
122  static void FreeArray(void * array );
123 #endif
124 
125 #if U_OVERRIDE_CXX_ALLOCATION
126 
134  static void * U_EXPORT2 operator new(size_t size) U_NO_THROW;
135 
141  static void * U_EXPORT2 operator new[](size_t size) U_NO_THROW;
142 
151  static void U_EXPORT2 operator delete(void *p) U_NO_THROW;
152 
158  static void U_EXPORT2 operator delete[](void *p) U_NO_THROW;
159 
160 #if U_HAVE_PLACEMENT_NEW
161 
166  static inline void * U_EXPORT2 operator new(size_t, void *ptr) U_NO_THROW { return ptr; }
167 
173  static inline void U_EXPORT2 operator delete(void *, void *) U_NO_THROW {}
174 #endif /* U_HAVE_PLACEMENT_NEW */
175 #if U_HAVE_DEBUG_LOCATION_NEW
176 
183  static void * U_EXPORT2 operator new(size_t size, const char* file, int line) U_NO_THROW;
191  static void U_EXPORT2 operator delete(void* p, const char* file, int line) U_NO_THROW;
192 #endif /* U_HAVE_DEBUG_LOCATION_NEW */
193 #endif /* U_OVERRIDE_CXX_ALLOCATION */
194 
195  /*
196  * Assignment operator not declared. The compiler will provide one
197  * which does nothing since this class does not contain any data members.
198  * API/code coverage may show the assignment operator as present and
199  * untested - ignore.
200  * Subclasses need this assignment operator if they use compiler-provided
201  * assignment operators of their own. An alternative to not declaring one
202  * here would be to declare and empty-implement a protected or public one.
203  UMemory &UMemory::operator=(const UMemory &);
204  */
205 };
206 
229 class U_COMMON_API UObject : public UMemory {
230 public:
236  virtual ~UObject();
237 
243  virtual UClassID getDynamicClassID() const = 0;
244 
245 protected:
246  // the following functions are protected to prevent instantiation and
247  // direct use of UObject itself
248 
249  // default constructor
250  // commented out because UObject is abstract (see getDynamicClassID)
251  // inline UObject() {}
252 
253  // copy constructor
254  // commented out because UObject is abstract (see getDynamicClassID)
255  // inline UObject(const UObject &other) {}
256 
257 #if 0
258  // TODO Sometime in the future. Implement operator==().
259  // (This comment inserted in 2.2)
260  // some or all of the following "boilerplate" functions may be made public
261  // in a future ICU4C release when all subclasses implement them
262 
263  // assignment operator
264  // (not virtual, see "Taligent's Guide to Designing Programs" pp.73..74)
265  // commented out because the implementation is the same as a compiler's default
266  // UObject &operator=(const UObject &other) { return *this; }
267 
268  // comparison operators
269  virtual inline UBool operator==(const UObject &other) const { return this==&other; }
270  inline UBool operator!=(const UObject &other) const { return !operator==(other); }
271 
272  // clone() commented out from the base class:
273  // some compilers do not support co-variant return types
274  // (i.e., subclasses would have to return UObject * as well, instead of SubClass *)
275  // see also UObject class documentation.
276  // virtual UObject *clone() const;
277 #endif
278 
279  /*
280  * Assignment operator not declared. The compiler will provide one
281  * which does nothing since this class does not contain any data members.
282  * API/code coverage may show the assignment operator as present and
283  * untested - ignore.
284  * Subclasses need this assignment operator if they use compiler-provided
285  * assignment operators of their own. An alternative to not declaring one
286  * here would be to declare and empty-implement a protected or public one.
287  UObject &UObject::operator=(const UObject &);
288  */
289 
290 // Future implementation for RTTI that support subtyping. [alan]
291 //
292 // public:
293 // /**
294 // * @internal
295 // */
296 // static UClassID getStaticClassID();
297 //
298 // /**
299 // * @internal
300 // */
301 // UBool instanceOf(UClassID type) const;
302 };
303 
304 #ifndef U_HIDE_INTERNAL_API
305 
312 #define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass) \
313  UClassID U_EXPORT2 myClass::getStaticClassID() { \
314  static char classID = 0; \
315  return (UClassID)&classID; \
316  } \
317  UClassID myClass::getDynamicClassID() const \
318  { return myClass::getStaticClassID(); }
319 
320 
329 #define UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass) \
330  UClassID U_EXPORT2 myClass::getStaticClassID() { \
331  static char classID = 0; \
332  return (UClassID)&classID; \
333  }
334 
345 #define UOBJECT_DEFINE_NO_RTTI_IMPLEMENTATION(myClass) \
346  UClassID myClass::getDynamicClassID() const { return NULL; }
347 
348 // /**
349 // * This macro adds ICU RTTI to an ICU concrete class implementation.
350 // * This macro should be invoked in *.cpp files. The corresponding
351 // * header should declare getDynamicClassID and getStaticClassID.
352 // *
353 // * @param myClass The name of the class that needs RTTI defined.
354 // * @param myParent The name of the myClass's parent.
355 // * @internal
356 // */
357 /*#define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass, myParent) \
358  UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass, myParent) \
359  UClassID myClass::getDynamicClassID() const { \
360  return myClass::getStaticClassID(); \
361  }
362 */
363 #endif /* U_HIDE_INTERNAL_API */
364 
366 
367 #endif
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
Basic definitions for ICU, for both C and C++ APIs.
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
Definition: utypes.h:357
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:229
UMemory is the common ICU base class.
Definition: uobject.h:115
int8_t UBool
The ICU boolean type.
Definition: umachine.h:200