19 #ifndef __LOCALPOINTER_H__ 20 #define __LOCALPOINTER_H__ 43 #if U_SHOW_CPLUSPLUS_API 99 bool operator==(
const T *other)
const {
return ptr==other; }
162 static void * U_EXPORT2
operator new(
size_t size);
163 static void * U_EXPORT2
operator new[](
size_t size);
164 #if U_HAVE_PLACEMENT_NEW 165 static void * U_EXPORT2
operator new(size_t,
void *ptr);
216 #if U_HAVE_RVALUE_REFERENCES 233 #if U_HAVE_RVALUE_REFERENCES 242 return moveFrom(src);
365 #if U_HAVE_RVALUE_REFERENCES 382 #if U_HAVE_RVALUE_REFERENCES 391 return moveFrom(src);
495 #if U_HAVE_RVALUE_REFERENCES 496 #define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction) \ 497 class LocalPointerClassName : public LocalPointerBase<Type> { \ 499 using LocalPointerBase<Type>::operator*; \ 500 using LocalPointerBase<Type>::operator->; \ 501 explicit LocalPointerClassName(Type *p=NULL) : LocalPointerBase<Type>(p) {} \ 502 LocalPointerClassName(LocalPointerClassName &&src) U_NOEXCEPT \ 503 : LocalPointerBase<Type>(src.ptr) { \ 506 ~LocalPointerClassName() { if (ptr != NULL) { closeFunction(ptr); } } \ 507 LocalPointerClassName &operator=(LocalPointerClassName &&src) U_NOEXCEPT { \ 508 return moveFrom(src); \ 510 LocalPointerClassName &moveFrom(LocalPointerClassName &src) U_NOEXCEPT { \ 511 if (ptr != NULL) { closeFunction(ptr); } \ 512 LocalPointerBase<Type>::ptr=src.ptr; \ 516 void swap(LocalPointerClassName &other) U_NOEXCEPT { \ 517 Type *temp=LocalPointerBase<Type>::ptr; \ 518 LocalPointerBase<Type>::ptr=other.ptr; \ 521 friend inline void swap(LocalPointerClassName &p1, LocalPointerClassName &p2) U_NOEXCEPT { \ 524 void adoptInstead(Type *p) { \ 525 if (ptr != NULL) { closeFunction(ptr); } \ 530 #define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction) \ 531 class LocalPointerClassName : public LocalPointerBase<Type> { \ 533 using LocalPointerBase<Type>::operator*; \ 534 using LocalPointerBase<Type>::operator->; \ 535 explicit LocalPointerClassName(Type *p=NULL) : LocalPointerBase<Type>(p) {} \ 536 ~LocalPointerClassName() { closeFunction(ptr); } \ 537 LocalPointerClassName &moveFrom(LocalPointerClassName &src) U_NOEXCEPT { \ 538 if (ptr != NULL) { closeFunction(ptr); } \ 539 LocalPointerBase<Type>::ptr=src.ptr; \ 543 void swap(LocalPointerClassName &other) U_NOEXCEPT { \ 544 Type *temp=LocalPointerBase<Type>::ptr; \ 545 LocalPointerBase<Type>::ptr=other.ptr; \ 548 friend inline void swap(LocalPointerClassName &p1, LocalPointerClassName &p2) U_NOEXCEPT { \ 551 void adoptInstead(Type *p) { \ 552 if (ptr != NULL) { 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.