ICU 64.2  64.2
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 #include "unicode/platform.h"
24 
45 #ifndef U_NO_THROW
46 #define U_NO_THROW throw()
47 #endif
48 
49 /*===========================================================================*/
50 /* UClassID-based RTTI */
51 /*===========================================================================*/
52 
93 typedef void* UClassID;
94 
96 
113 public:
114 
115 /* test versions for debugging shaper heap memory problems */
116 #ifdef SHAPER_MEMORY_DEBUG
117  static void * NewArray(int size, int count);
118  static void * GrowArray(void * array, int newSize );
119  static void FreeArray(void * array );
120 #endif
121 
122 #if U_OVERRIDE_CXX_ALLOCATION
123 
131  static void * U_EXPORT2 operator new(size_t size) U_NOEXCEPT;
132 
138  static void * U_EXPORT2 operator new[](size_t size) U_NOEXCEPT;
139 
148  static void U_EXPORT2 operator delete(void *p) U_NOEXCEPT;
149 
155  static void U_EXPORT2 operator delete[](void *p) U_NOEXCEPT;
156 
157 #if U_HAVE_PLACEMENT_NEW
158 
163  static inline void * U_EXPORT2 operator new(size_t, void *ptr) U_NOEXCEPT { return ptr; }
164 
170  static inline void U_EXPORT2 operator delete(void *, void *) U_NOEXCEPT {}
171 #endif /* U_HAVE_PLACEMENT_NEW */
172 #if U_HAVE_DEBUG_LOCATION_NEW
173 
180  static void * U_EXPORT2 operator new(size_t size, const char* file, int line) U_NOEXCEPT;
188  static void U_EXPORT2 operator delete(void* p, const char* file, int line) U_NOEXCEPT;
189 #endif /* U_HAVE_DEBUG_LOCATION_NEW */
190 #endif /* U_OVERRIDE_CXX_ALLOCATION */
191 
192  /*
193  * Assignment operator not declared. The compiler will provide one
194  * which does nothing since this class does not contain any data members.
195  * API/code coverage may show the assignment operator as present and
196  * untested - ignore.
197  * Subclasses need this assignment operator if they use compiler-provided
198  * assignment operators of their own. An alternative to not declaring one
199  * here would be to declare and empty-implement a protected or public one.
200  UMemory &UMemory::operator=(const UMemory &);
201  */
202 };
203 
223 class U_COMMON_API UObject : public UMemory {
224 public:
230  virtual ~UObject();
231 
241  virtual UClassID getDynamicClassID() const;
242 
243 protected:
244  // the following functions are protected to prevent instantiation and
245  // direct use of UObject itself
246 
247  // default constructor
248  // inline UObject() {}
249 
250  // copy constructor
251  // inline UObject(const UObject &other) {}
252 
253 #if 0
254  // TODO Sometime in the future. Implement operator==().
255  // (This comment inserted in 2.2)
256  // some or all of the following "boilerplate" functions may be made public
257  // in a future ICU4C release when all subclasses implement them
258 
259  // assignment operator
260  // (not virtual, see "Taligent's Guide to Designing Programs" pp.73..74)
261  // commented out because the implementation is the same as a compiler's default
262  // UObject &operator=(const UObject &other) { return *this; }
263 
264  // comparison operators
265  virtual inline UBool operator==(const UObject &other) const { return this==&other; }
266  inline UBool operator!=(const UObject &other) const { return !operator==(other); }
267 
268  // clone() commented out from the base class:
269  // some compilers do not support co-variant return types
270  // (i.e., subclasses would have to return UObject * as well, instead of SubClass *)
271  // see also UObject class documentation.
272  // virtual UObject *clone() const;
273 #endif
274 
275  /*
276  * Assignment operator not declared. The compiler will provide one
277  * which does nothing since this class does not contain any data members.
278  * API/code coverage may show the assignment operator as present and
279  * untested - ignore.
280  * Subclasses need this assignment operator if they use compiler-provided
281  * assignment operators of their own. An alternative to not declaring one
282  * here would be to declare and empty-implement a protected or public one.
283  UObject &UObject::operator=(const UObject &);
284  */
285 };
286 
287 #ifndef U_HIDE_INTERNAL_API
288 
295 #define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass) \
296  UClassID U_EXPORT2 myClass::getStaticClassID() { \
297  static char classID = 0; \
298  return (UClassID)&classID; \
299  } \
300  UClassID myClass::getDynamicClassID() const \
301  { return myClass::getStaticClassID(); }
302 
303 
312 #define UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass) \
313  UClassID U_EXPORT2 myClass::getStaticClassID() { \
314  static char classID = 0; \
315  return (UClassID)&classID; \
316  }
317 
318 #endif /* U_HIDE_INTERNAL_API */
319 
321 
322 #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:93
Basic types for the platform.
#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_NOEXCEPT
"noexcept" if supported, otherwise empty.
Definition: platform.h:503
#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:223
UMemory is the common ICU base class.
Definition: uobject.h:112
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225