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);
239 return moveFrom(src);
384 return moveFrom(src);
487 #define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction) \ 488 class LocalPointerClassName : public LocalPointerBase<Type> { \ 490 using LocalPointerBase<Type>::operator*; \ 491 using LocalPointerBase<Type>::operator->; \ 492 explicit LocalPointerClassName(Type *p=NULL) : LocalPointerBase<Type>(p) {} \ 493 LocalPointerClassName(LocalPointerClassName &&src) U_NOEXCEPT \ 494 : LocalPointerBase<Type>(src.ptr) { \ 497 ~LocalPointerClassName() { if (ptr != NULL) { closeFunction(ptr); } } \ 498 LocalPointerClassName &operator=(LocalPointerClassName &&src) U_NOEXCEPT { \ 499 return moveFrom(src); \ 501 LocalPointerClassName &moveFrom(LocalPointerClassName &src) U_NOEXCEPT { \ 502 if (ptr != NULL) { closeFunction(ptr); } \ 503 LocalPointerBase<Type>::ptr=src.ptr; \ 507 void swap(LocalPointerClassName &other) U_NOEXCEPT { \ 508 Type *temp=LocalPointerBase<Type>::ptr; \ 509 LocalPointerBase<Type>::ptr=other.ptr; \ 512 friend inline void swap(LocalPointerClassName &p1, LocalPointerClassName &p2) U_NOEXCEPT { \ 515 void adoptInstead(Type *p) { \ 516 if (ptr != NULL) { closeFunction(ptr); } \ friend void swap(LocalArray< T > &p1, LocalArray< T > &p2)
Non-member LocalArray swap function.
LocalPointer< T > & operator=(LocalPointer< T > &&src)
Move assignment operator, leaves src with isNull().
void adoptInsteadAndCheckErrorCode(T *p, UErrorCode &errorCode)
Deletes the array it owns, and adopts (takes ownership of) the one passed in.
T & operator[](ptrdiff_t i) const
Array item access (writable).
T * getAlias() const
Access without ownership change.
void adoptInstead(T *p)
Deletes the object it owns, and adopts (takes ownership of) the one passed in.
void swap(LocalArray< T > &other)
Swap pointers.
#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.
"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.
LocalArray< T > & moveFrom(LocalArray< T > &src)
Move assignment, leaves src with isNull().
void swap(LocalPointer< T > &other)
Swap pointers.
LocalArray(LocalArray< T > &&src)
Move constructor, leaves src with isNull().
LocalPointer< T > & moveFrom(LocalPointer< T > &src)
Move assignment, leaves src with isNull().
bool operator!=(const T *other) const
Comparison with a simple pointer, so that existing code with !=NULL need not be changed.
LocalPointer(T *p=NULL)
Constructor takes ownership.
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
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 isNull() const
NULL check.
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
#define NULL
Define NULL if necessary, to nullptr 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.
LocalArray< T > & operator=(LocalArray< T > &&src)
Move assignment operator, leaves src with isNull().
#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.
UBool isValid() const
NULL check.
bool operator==(const T *other) const
Comparison with a simple pointer, so that existing code with ==NULL need not be changed.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
~LocalArray()
Destructor deletes the array it owns.
T * operator->() const
Access without ownership change.
void adoptInsteadAndCheckErrorCode(T *p, UErrorCode &errorCode)
Deletes the object it owns, and adopts (takes ownership of) the one passed in.
T & operator*() const
Access without ownership change.
~LocalPointerBase()
Destructor deletes the object it owns.
Basic definitions for ICU, for both C and C++ APIs.
friend void swap(LocalPointer< T > &p1, LocalPointer< T > &p2)
Non-member LocalPointer swap function.
void adoptInstead(T *p)
Deletes the object it owns, and adopts (takes ownership of) the one passed in.
LocalPointer(LocalPointer< T > &&src)
Move constructor, leaves src with isNull().
int8_t UBool
The ICU boolean type.