ICU 54.1 54.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

All Data Structures Namespaces 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-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
91 typedef void* UClassID;
92
93 U_NAMESPACE_BEGIN
94
110 class U_COMMON_API UMemory {
111 public:
112
113 /* test versions for debugging shaper heap memory problems */
114 #ifdef SHAPER_MEMORY_DEBUG
115 static void * NewArray(int size, int count);
116 static void * GrowArray(void * array, int newSize );
117 static void FreeArray(void * array );
118 #endif
119
120 #if U_OVERRIDE_CXX_ALLOCATION
121
129 static void * U_EXPORT2 operator new(size_t size) U_NO_THROW;
130
136 static void * U_EXPORT2 operator new[](size_t size) U_NO_THROW;
137
146 static void U_EXPORT2 operator delete(void *p) U_NO_THROW;
147
153 static void U_EXPORT2 operator delete[](void *p) U_NO_THROW;
154
155 #if U_HAVE_PLACEMENT_NEW
156
161 static inline void * U_EXPORT2 operator new(size_t, void *ptr) U_NO_THROW { return ptr; }
162
168 static inline void U_EXPORT2 operator delete(void *, void *) U_NO_THROW {}
169 #endif /* U_HAVE_PLACEMENT_NEW */
170 #if U_HAVE_DEBUG_LOCATION_NEW
171
178 static void * U_EXPORT2 operator new(size_t size, const char* file, int line) U_NO_THROW;
186 static void U_EXPORT2 operator delete(void* p, const char* file, int line) U_NO_THROW;
187 #endif /* U_HAVE_DEBUG_LOCATION_NEW */
188 #endif /* U_OVERRIDE_CXX_ALLOCATION */
189
190 /*
191 * Assignment operator not declared. The compiler will provide one
192 * which does nothing since this class does not contain any data members.
193 * API/code coverage may show the assignment operator as present and
194 * untested - ignore.
195 * Subclasses need this assignment operator if they use compiler-provided
196 * assignment operators of their own. An alternative to not declaring one
197 * here would be to declare and empty-implement a protected or public one.
198 UMemory &UMemory::operator=(const UMemory &);
199 */
200 };
201
221 class U_COMMON_API UObject : public UMemory {
222 public:
228 virtual ~UObject();
229
239 virtual UClassID getDynamicClassID() const;
240
241 protected:
242 // the following functions are protected to prevent instantiation and
243 // direct use of UObject itself
244
245 // default constructor
246 // inline UObject() {}
247
248 // copy constructor
249 // inline UObject(const UObject &other) {}
250
251 #if 0
252 // TODO Sometime in the future. Implement operator==().
253 // (This comment inserted in 2.2)
254 // some or all of the following "boilerplate" functions may be made public
255 // in a future ICU4C release when all subclasses implement them
256
257 // assignment operator
258 // (not virtual, see "Taligent's Guide to Designing Programs" pp.73..74)
259 // commented out because the implementation is the same as a compiler's default
260 // UObject &operator=(const UObject &other) { return *this; }
261
262 // comparison operators
263 virtual inline UBool operator==(const UObject &other) const { return this==&other; }
264 inline UBool operator!=(const UObject &other) const { return !operator==(other); }
265
266 // clone() commented out from the base class:
267 // some compilers do not support co-variant return types
268 // (i.e., subclasses would have to return UObject * as well, instead of SubClass *)
269 // see also UObject class documentation.
270 // virtual UObject *clone() const;
271 #endif
272
273 /*
274 * Assignment operator not declared. The compiler will provide one
275 * which does nothing since this class does not contain any data members.
276 * API/code coverage may show the assignment operator as present and
277 * untested - ignore.
278 * Subclasses need this assignment operator if they use compiler-provided
279 * assignment operators of their own. An alternative to not declaring one
280 * here would be to declare and empty-implement a protected or public one.
281 UObject &UObject::operator=(const UObject &);
282 */
283 };
284
285 #ifndef U_HIDE_INTERNAL_API
286
293 #define UOBJECT_DEFINE_RTTI_IMPLEMENTATION(myClass) \
294 UClassID U_EXPORT2 myClass::getStaticClassID() { \
295 static char classID = 0; \
296 return (UClassID)&classID; \
297 } \
298 UClassID myClass::getDynamicClassID() const \
299 { return myClass::getStaticClassID(); }
300
301
310 #define UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(myClass) \
311 UClassID U_EXPORT2 myClass::getStaticClassID() { \
312 static char classID = 0; \
313 return (UClassID)&classID; \
314 }
315
316 #endif /* U_HIDE_INTERNAL_API */
317
318 U_NAMESPACE_END
319
320 #endif