ICU 4.2.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-2009, 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 
79 #ifndef U_NO_THROW
80 #define U_NO_THROW throw()
81 #endif
82 
99 public:
100 
101 /* test versions for debugging shaper heap memory problems */
102 #ifdef SHAPER_MEMORY_DEBUG
103  static void * NewArray(int size, int count);
104  static void * GrowArray(void * array, int newSize );
105  static void FreeArray(void * array );
106 #endif
107 
108 #if U_OVERRIDE_CXX_ALLOCATION
109 
117  static void * U_EXPORT2 operator new(size_t size) U_NO_THROW;
118 
124  static void * U_EXPORT2 operator new[](size_t size) U_NO_THROW;
125 
134  static void U_EXPORT2 operator delete(void *p) U_NO_THROW;
135 
141  static void U_EXPORT2 operator delete[](void *p) U_NO_THROW;
142 
143 #if U_HAVE_PLACEMENT_NEW
144 
149  static inline void * U_EXPORT2 operator new(size_t, void *ptr) U_NO_THROW { return ptr; }
150 
156  static inline void U_EXPORT2 operator delete(void *, void *) U_NO_THROW {}
157 #endif /* U_HAVE_PLACEMENT_NEW */
158 #if U_HAVE_DEBUG_LOCATION_NEW
159 
166  static void * U_EXPORT2 operator new(size_t size, const char* file, int line) U_NO_THROW;
174  static void U_EXPORT2 operator delete(void* p, const char* file, int line) U_NO_THROW;
175 #endif /* U_HAVE_DEBUG_LOCATION_NEW */
176 #endif /* U_OVERRIDE_CXX_ALLOCATION */
177 
178  /*
179  * Assignment operator not declared. The compiler will provide one
180  * which does nothing since this class does not contain any data members.
181  * API/code coverage may show the assignment operator as present and
182  * untested - ignore.
183  * Subclasses need this assignment operator if they use compiler-provided
184  * assignment operators of their own. An alternative to not declaring one
185  * here would be to declare and empty-implement a protected or public one.
186  UMemory &UMemory::operator=(const UMemory &);
187  */
188 };
189 
212 class U_COMMON_API UObject : public UMemory {
213 public:
219  virtual ~UObject();
220 
226  virtual UClassID getDynamicClassID() const = 0;
227 
228 protected:
229  // the following functions are protected to prevent instantiation and
230  // direct use of UObject itself
231 
232  // default constructor
233  // commented out because UObject is abstract (see getDynamicClassID)
234  // inline UObject() {}
235 
236  // copy constructor
237  // commented out because UObject is abstract (see getDynamicClassID)
238  // inline UObject(const UObject &other) {}
239 
240 #if 0
241  // TODO Sometime in the future. Implement operator==().
242  // (This comment inserted in 2.2)
243  // some or all of the following "boilerplate" functions may be made public
244  // in a future ICU4C release when all subclasses implement them
245 
246  // assignment operator
247  // (not virtual, see "Taligent's Guide to Designing Programs" pp.73..74)
248  // commented out because the implementation is the same as a compiler's default
249  // UObject &operator=(const UObject &other) { return *this; }
250 
251  // comparison operators
252  virtual inline UBool operator==(const UObject &other) const { return this==&other; }
253  inline UBool operator!=(const UObject &other) const { return !operator==(other); }
254 
255  // clone() commented out from the base class:
256  // some compilers do not support co-variant return types
257  // (i.e., subclasses would have to return UObject * as well, instead of SubClass *)
258  // see also UObject class documentation.
259  // virtual UObject *clone() const;
260 #endif
261 
262  /*
263  * Assignment operator not declared. The compiler will provide one
264  * which does nothing since this class does not contain any data members.
265  * API/code coverage may show the assignment operator as present and
266  * untested - ignore.
267  * Subclasses need this assignment operator if they use compiler-provided
268  * assignment operators of their own. An alternative to not declaring one
269  * here would be to declare and empty-implement a protected or public one.
270  UObject &UObject::operator=(const UObject &);
271  */
272 
273 // Future implementation for RTTI that support subtyping. [alan]
274 //
275 // public:
276 // /**
277 // * @internal
278 // */
279 // static UClassID getStaticClassID();
280 //
281 // /**
282 // * @internal
283 // */
284 // UBool instanceOf(UClassID type) const;
285 };
286 
294 #define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass) \
295  UClassID U_EXPORT2 myClass::getStaticClassID() { \
296  static char classID = 0; \
297  return (UClassID)&classID; \
298  } \
299  UClassID myClass::getDynamicClassID() const \
300  { return myClass::getStaticClassID(); }
301 
302 
311 #define UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass) \
312  UClassID U_EXPORT2 myClass::getStaticClassID() { \
313  static char classID = 0; \
314  return (UClassID)&classID; \
315  }
316 
317 // /**
318 // * This macro adds ICU RTTI to an ICU concrete class implementation.
319 // * This macro should be invoked in *.cpp files. The corresponding
320 // * header should declare getDynamicClassID and getStaticClassID.
321 // *
322 // * @param myClass The name of the class that needs RTTI defined.
323 // * @param myParent The name of the myClass's parent.
324 // * @internal
325 // */
326 /*#define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass, myParent) \
327  UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass, myParent) \
328  UClassID myClass::getDynamicClassID() const { \
329  return myClass::getStaticClassID(); \
330  }
331 */
332 
333 
335 
336 #endif
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:183
UMemory is the common ICU base class.
Definition: uobject.h:98
#define U_EXPORT2
Definition: platform.h:338
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API If the compiler doesn't support namespaces...
Definition: uversion.h:184
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:212
void * UClassID
UClassID is used to identify classes without using RTTI, since RTTI is not yet supported by all C++ c...
Definition: utypes.h:339
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:474
int8_t UBool
The ICU boolean type.
Definition: umachine.h:208