ICU 78.1 78.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
24 #if U_SHOW_CPLUSPLUS_API
25
26 #include "unicode/platform.h"
27
48 #ifndef U_NO_THROW
49 #define U_NO_THROW noexcept
50 #endif
51
52 /*===========================================================================*/
53 /* UClassID-based RTTI */
54 /*===========================================================================*/
55
96 typedef void* UClassID;
97
98 U_NAMESPACE_BEGIN
99
115 class U_COMMON_API UMemory {
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
134 static void * U_EXPORT2 operator new(size_t size) noexcept;
135
141 static void * U_EXPORT2 operator new[](size_t size) noexcept;
142
151 static void U_EXPORT2 operator delete(void *p) noexcept;
152
158 static void U_EXPORT2 operator delete[](void *p) noexcept;
159
165 static inline void * U_EXPORT2 operator new(size_t, void *ptr) noexcept { return ptr; }
166
172 static inline void U_EXPORT2 operator delete(void *, void *) noexcept {}
173
174 #if U_HAVE_DEBUG_LOCATION_NEW
182 static void * U_EXPORT2 operator new(size_t size, const char* file, int line) noexcept;
190 static void U_EXPORT2 operator delete(void* p, const char* file, int line) noexcept;
191 #endif /* U_HAVE_DEBUG_LOCATION_NEW */
192 #endif /* U_OVERRIDE_CXX_ALLOCATION */
193
194 /*
195 * Assignment operator not declared. The compiler will provide one
196 * which does nothing since this class does not contain any data members.
197 * API/code coverage may show the assignment operator as present and
198 * untested - ignore.
199 * Subclasses need this assignment operator if they use compiler-provided
200 * assignment operators of their own. An alternative to not declaring one
201 * here would be to declare and empty-implement a protected or public one.
202 UMemory &UMemory::operator=(const UMemory &);
203 */
204 };
205
222 class U_COMMON_API UObject : public UMemory {
223 public:
229 virtual ~UObject();
230
240 virtual UClassID getDynamicClassID() const;
241
242 protected:
243 // the following functions are protected to prevent instantiation and
244 // direct use of UObject itself
245
246 // default constructor
247 // inline UObject() {}
248
249 // copy constructor
250 // inline UObject(const UObject &other) {}
251
252 #if 0
253 // TODO Sometime in the future. Implement operator==().
254 // (This comment inserted in 2.2)
255 // some or all of the following "boilerplate" functions may be made public
256 // in a future ICU4C release when all subclasses implement them
257
258 // assignment operator
259 // (not virtual, see "Taligent's Guide to Designing Programs" pp.73..74)
260 // commented out because the implementation is the same as a compiler's default
261 // UObject &operator=(const UObject &other) { return *this; }
262
263 // comparison operators
264 virtual inline bool operator==(const UObject &other) const { return this==&other; }
265 inline bool operator!=(const UObject &other) const { return !operator==(other); }
266
267 // clone() commented out from the base class:
268 // some compilers do not support co-variant return types
269 // (i.e., subclasses would have to return UObject * as well, instead of SubClass *)
270 // see also UObject class documentation.
271 // virtual UObject *clone() const;
272 #endif
273
274 /*
275 * Assignment operator not declared. The compiler will provide one
276 * which does nothing since this class does not contain any data members.
277 * API/code coverage may show the assignment operator as present and
278 * untested - ignore.
279 * Subclasses need this assignment operator if they use compiler-provided
280 * assignment operators of their own. An alternative to not declaring one
281 * here would be to declare and empty-implement a protected or public one.
282 UObject &UObject::operator=(const UObject &);
283 */
284 };
285
286 #ifndef U_HIDE_INTERNAL_API
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 #endif /* U_HIDE_INTERNAL_API */
318
319 U_NAMESPACE_END
320
321 #endif /* U_SHOW_CPLUSPLUS_API */
322
323 #endif
icu::UMemory
UMemory is the common ICU base class.
Definition: uobject.h:115
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:222
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
icu::UObject::~UObject
virtual ~UObject()
Destructor.
icu::operator==
U_COMMON_API UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
icu::operator!=
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:346
platform.h
Basic types for the platform.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
U_COMMON_API
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition: utypes.h:315