ICU 63.1  63.1
uobject.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 ******************************************************************************
5 *
6 * Copyright (C) 2002-2012, International Business Machines
7 * Corporation and others. All Rights Reserved.
8 *
9 ******************************************************************************
10 * file name: uobject.h
11 * encoding: UTF-8
12 * tab size: 8 (not used)
13 * indentation:4
14 *
15 * created on: 2002jun26
16 * created by: Markus W. Scherer
17 */
18 
19 #ifndef __UOBJECT_H__
20 #define __UOBJECT_H__
21 
22 #include "unicode/utypes.h"
23 
42 #ifndef U_NO_THROW
43 #define U_NO_THROW throw()
44 #endif
45 
46 /*===========================================================================*/
47 /* UClassID-based RTTI */
48 /*===========================================================================*/
49 
90 typedef void* UClassID;
91 
93 
110 public:
111 
112 /* test versions for debugging shaper heap memory problems */
113 #ifdef SHAPER_MEMORY_DEBUG
114  static void * NewArray(int size, int count);
115  static void * GrowArray(void * array, int newSize );
116  static void FreeArray(void * array );
117 #endif
118 
119 #if U_OVERRIDE_CXX_ALLOCATION
120 
128  static void * U_EXPORT2 operator new(size_t size) U_NO_THROW;
129 
135  static void * U_EXPORT2 operator new[](size_t size) U_NO_THROW;
136 
145  static void U_EXPORT2 operator delete(void *p) U_NO_THROW;
146 
152  static void U_EXPORT2 operator delete[](void *p) U_NO_THROW;
153 
154 #if U_HAVE_PLACEMENT_NEW
155 
160  static inline void * U_EXPORT2 operator new(size_t, void *ptr) U_NO_THROW { return ptr; }
161 
167  static inline void U_EXPORT2 operator delete(void *, void *) U_NO_THROW {}
168 #endif /* U_HAVE_PLACEMENT_NEW */
169 #if U_HAVE_DEBUG_LOCATION_NEW
170 
177  static void * U_EXPORT2 operator new(size_t size, const char* file, int line) U_NO_THROW;
185  static void U_EXPORT2 operator delete(void* p, const char* file, int line) U_NO_THROW;
186 #endif /* U_HAVE_DEBUG_LOCATION_NEW */
187 #endif /* U_OVERRIDE_CXX_ALLOCATION */
188 
189  /*
190  * Assignment operator not declared. The compiler will provide one
191  * which does nothing since this class does not contain any data members.
192  * API/code coverage may show the assignment operator as present and
193  * untested - ignore.
194  * Subclasses need this assignment operator if they use compiler-provided
195  * assignment operators of their own. An alternative to not declaring one
196  * here would be to declare and empty-implement a protected or public one.
197  UMemory &UMemory::operator=(const UMemory &);
198  */
199 };
200 
220 class U_COMMON_API UObject : public UMemory {
221 public:
227  virtual ~UObject();
228 
238  virtual UClassID getDynamicClassID() const;
239 
240 protected:
241  // the following functions are protected to prevent instantiation and
242  // direct use of UObject itself
243 
244  // default constructor
245  // inline UObject() {}
246 
247  // copy constructor
248  // inline UObject(const UObject &other) {}
249 
250 #if 0
251  // TODO Sometime in the future. Implement operator==().
252  // (This comment inserted in 2.2)
253  // some or all of the following "boilerplate" functions may be made public
254  // in a future ICU4C release when all subclasses implement them
255 
256  // assignment operator
257  // (not virtual, see "Taligent's Guide to Designing Programs" pp.73..74)
258  // commented out because the implementation is the same as a compiler's default
259  // UObject &operator=(const UObject &other) { return *this; }
260 
261  // comparison operators
262  virtual inline UBool operator==(const UObject &other) const { return this==&other; }
263  inline UBool operator!=(const UObject &other) const { return !operator==(other); }
264 
265  // clone() commented out from the base class:
266  // some compilers do not support co-variant return types
267  // (i.e., subclasses would have to return UObject * as well, instead of SubClass *)
268  // see also UObject class documentation.
269  // virtual UObject *clone() const;
270 #endif
271 
272  /*
273  * Assignment operator not declared. The compiler will provide one
274  * which does nothing since this class does not contain any data members.
275  * API/code coverage may show the assignment operator as present and
276  * untested - ignore.
277  * Subclasses need this assignment operator if they use compiler-provided
278  * assignment operators of their own. An alternative to not declaring one
279  * here would be to declare and empty-implement a protected or public one.
280  UObject &UObject::operator=(const UObject &);
281  */
282 };
283 
284 #ifndef U_HIDE_INTERNAL_API
285 
292 #define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass) \
293  UClassID U_EXPORT2 myClass::getStaticClassID() { \
294  static char classID = 0; \
295  return (UClassID)&classID; \
296  } \
297  UClassID myClass::getDynamicClassID() const \
298  { return myClass::getStaticClassID(); }
299 
300 
309 #define UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass) \
310  UClassID U_EXPORT2 myClass::getStaticClassID() { \
311  static char classID = 0; \
312  return (UClassID)&classID; \
313  }
314 
315 #endif /* U_HIDE_INTERNAL_API */
316 
318 
319 #endif
#define U_NO_THROW
Define this to define the throw() specification so certain functions do not throw any...
Definition: uobject.h:43
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:90
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
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:138
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:300
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:220
UMemory is the common ICU base class.
Definition: uobject.h:109
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225