17 #ifndef __LOCALPOINTER_H__
18 #define __LOCALPOINTER_H__
41 #if U_SHOW_CPLUSPLUS_API
97 bool operator==(
const T *other)
const {
return ptr==other; }
160 static void * U_EXPORT2
operator new(
size_t size);
161 static void * U_EXPORT2
operator new[](
size_t size);
162 #if U_HAVE_PLACEMENT_NEW
163 static void * U_EXPORT2
operator new(size_t,
void *ptr);
214 #ifndef U_HIDE_DRAFT_API
215 #if U_HAVE_RVALUE_REFERENCES
233 #ifndef U_HIDE_DRAFT_API
234 #if U_HAVE_RVALUE_REFERENCES
243 return moveFrom(src);
348 #ifndef U_HIDE_DRAFT_API
367 #if U_HAVE_RVALUE_REFERENCES
385 #ifndef U_HIDE_DRAFT_API
386 #if U_HAVE_RVALUE_REFERENCES
395 return moveFrom(src);
443 #ifndef U_HIDE_DRAFT_API
504 #if U_HAVE_RVALUE_REFERENCES
505 #define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction) \
506 class LocalPointerClassName : public LocalPointerBase<Type> { \
508 using LocalPointerBase<Type>::operator*; \
509 using LocalPointerBase<Type>::operator->; \
510 explicit LocalPointerClassName(Type *p=NULL) : LocalPointerBase<Type>(p) {} \
511 LocalPointerClassName(LocalPointerClassName &&src) U_NOEXCEPT \
512 : LocalPointerBase<Type>(src.ptr) { \
515 ~LocalPointerClassName() { closeFunction(ptr); } \
516 LocalPointerClassName &operator=(LocalPointerClassName &&src) U_NOEXCEPT { \
517 return moveFrom(src); \
519 LocalPointerClassName &moveFrom(LocalPointerClassName &src) U_NOEXCEPT { \
520 closeFunction(ptr); \
521 LocalPointerBase<Type>::ptr=src.ptr; \
525 void swap(LocalPointerClassName &other) U_NOEXCEPT { \
526 Type *temp=LocalPointerBase<Type>::ptr; \
527 LocalPointerBase<Type>::ptr=other.ptr; \
530 friend inline void swap(LocalPointerClassName &p1, LocalPointerClassName &p2) U_NOEXCEPT { \
533 void adoptInstead(Type *p) { \
534 closeFunction(ptr); \
539 #define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction) \
540 class LocalPointerClassName : public LocalPointerBase<Type> { \
542 using LocalPointerBase<Type>::operator*; \
543 using LocalPointerBase<Type>::operator->; \
544 explicit LocalPointerClassName(Type *p=NULL) : LocalPointerBase<Type>(p) {} \
545 ~LocalPointerClassName() { closeFunction(ptr); } \
546 LocalPointerClassName &moveFrom(LocalPointerClassName &src) U_NOEXCEPT { \
547 closeFunction(ptr); \
548 LocalPointerBase<Type>::ptr=src.ptr; \
552 void swap(LocalPointerClassName &other) U_NOEXCEPT { \
553 Type *temp=LocalPointerBase<Type>::ptr; \
554 LocalPointerBase<Type>::ptr=other.ptr; \
557 friend inline void swap(LocalPointerClassName &p1, LocalPointerClassName &p2) U_NOEXCEPT { \
560 void adoptInstead(Type *p) { \
561 closeFunction(ptr); \
void adoptInsteadAndCheckErrorCode(T *p, UErrorCode &errorCode)
Deletes the array it owns, and adopts (takes ownership of) the one passed in.
void adoptInstead(T *p)
Deletes the object it owns, and adopts (takes ownership of) the one passed in.
bool operator==(const T *other) const
Comparison with a simple pointer, so that existing code with ==NULL need not be changed.
#define U_SUCCESS(x)
Does the error code indicate success?
LocalPointer(T *p, UErrorCode &errorCode)
Constructor takes ownership and reports an error if NULL.
LocalArray(T *p=NULL)
Constructor takes ownership.
T * getAlias() const
Access without ownership change.
T * operator->() const
Access without ownership change.
"Smart pointer" class, deletes objects via the standard C++ delete operator.
LocalArray(T *p, UErrorCode &errorCode)
Constructor takes ownership and reports an error if NULL.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
void swap(LocalPointer< T > &other) U_NOEXCEPT
Swap pointers.
UBool isNull() const
NULL check.
T & operator*() const
Access without ownership change.
LocalPointer(T *p=NULL)
Constructor takes ownership.
LocalPointer< T > & moveFrom(LocalPointer< T > &src) U_NOEXCEPT
Move assignment, leaves src with isNull().
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
friend void swap(LocalPointer< T > &p1, LocalPointer< T > &p2) U_NOEXCEPT
Non-member LocalPointer swap function.
T * orphan()
Gives up ownership; the internal pointer becomes NULL.
LocalPointerBase(T *p=NULL)
Constructor takes ownership.
"Smart pointer" base class; do not use directly: use LocalPointer etc.
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
friend void swap(LocalArray< T > &p1, LocalArray< T > &p2) U_NOEXCEPT
Non-member LocalArray swap function.
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
"Smart pointer" class, deletes objects via the C++ array delete[] operator.
~LocalPointer()
Destructor deletes the object it owns.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
void adoptInstead(T *p)
Deletes the array it owns, and adopts (takes ownership of) the one passed in.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
void swap(LocalArray< T > &other) U_NOEXCEPT
Swap pointers.
bool operator!=(const T *other) const
Comparison with a simple pointer, so that existing code with !=NULL need not be changed.
~LocalArray()
Destructor deletes the array it owns.
void adoptInsteadAndCheckErrorCode(T *p, UErrorCode &errorCode)
Deletes the object it owns, and adopts (takes ownership of) the one passed in.
~LocalPointerBase()
Destructor deletes the object it owns.
Basic definitions for ICU, for both C and C++ APIs.
LocalArray< T > & moveFrom(LocalArray< T > &src) U_NOEXCEPT
Move assignment, leaves src with isNull().
UBool isValid() const
NULL check.
void adoptInstead(T *p)
Deletes the object it owns, and adopts (takes ownership of) the one passed in.
T & operator[](ptrdiff_t i) const
Array item access (writable).
int8_t UBool
The ICU boolean type.