19 #ifndef __LOCALPOINTER_H__ 20 #define __LOCALPOINTER_H__ 43 #if U_SHOW_CPLUSPLUS_API 71 static void* U_EXPORT2
operator new(size_t) =
delete;
72 static void* U_EXPORT2
operator new[](size_t) =
delete;
73 #if U_HAVE_PLACEMENT_NEW 74 static void* U_EXPORT2
operator new(size_t,
void*) =
delete;
228 #ifndef U_HIDE_DRAFT_API 264 #ifndef U_HIDE_DRAFT_API 274 adoptInstead(p.release());
335 #ifndef U_HIDE_DRAFT_API 347 operator std::unique_ptr<T> () && {
409 #ifndef U_HIDE_DRAFT_API 445 #ifndef U_HIDE_DRAFT_API 455 adoptInstead(p.release());
524 #ifndef U_HIDE_DRAFT_API 536 operator std::unique_ptr<T[]> () && {
562 #define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction) \ 563 class LocalPointerClassName : public LocalPointerBase<Type> { \ 565 using LocalPointerBase<Type>::operator*; \ 566 using LocalPointerBase<Type>::operator->; \ 567 explicit LocalPointerClassName(Type *p=NULL) : LocalPointerBase<Type>(p) {} \ 568 LocalPointerClassName(LocalPointerClassName &&src) U_NOEXCEPT \ 569 : LocalPointerBase<Type>(src.ptr) { \ 573 explicit LocalPointerClassName(std::unique_ptr<Type, decltype(&closeFunction)> &&p) \ 574 : LocalPointerBase<Type>(p.release()) {} \ 575 ~LocalPointerClassName() { if (ptr != NULL) { closeFunction(ptr); } } \ 576 LocalPointerClassName &operator=(LocalPointerClassName &&src) U_NOEXCEPT { \ 577 if (ptr != NULL) { closeFunction(ptr); } \ 578 LocalPointerBase<Type>::ptr=src.ptr; \ 583 LocalPointerClassName &operator=(std::unique_ptr<Type, decltype(&closeFunction)> &&p) { \ 584 adoptInstead(p.release()); \ 587 void swap(LocalPointerClassName &other) U_NOEXCEPT { \ 588 Type *temp=LocalPointerBase<Type>::ptr; \ 589 LocalPointerBase<Type>::ptr=other.ptr; \ 592 friend inline void swap(LocalPointerClassName &p1, LocalPointerClassName &p2) U_NOEXCEPT { \ 595 void adoptInstead(Type *p) { \ 596 if (ptr != NULL) { closeFunction(ptr); } \ 599 operator std::unique_ptr<Type, decltype(&closeFunction)> () && { \ 600 return std::unique_ptr<Type, decltype(&closeFunction)>(LocalPointerBase<Type>::orphan(), closeFunction); \ LocalPointer< T > & operator=(LocalPointer< T > &&src) U_NOEXCEPT
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.
#define U_SUCCESS(x)
Does the error code indicate success?
LocalPointer(T *p, UErrorCode &errorCode)
Constructor takes ownership and reports an error if NULL.
LocalPointer(std::unique_ptr< T > &&p)
Constructs a LocalPointer from a C++11 std::unique_ptr.
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.
void swap(LocalPointer< T > &other) U_NOEXCEPT
Swap pointers.
LocalPointer< T > & operator=(std::unique_ptr< T > &&p) U_NOEXCEPT
Move-assign from an std::unique_ptr to this LocalPointer.
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.
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 isNull() const
NULL check.
LocalPointer(LocalPointer< T > &&src) U_NOEXCEPT
Move constructor, leaves src with isNull().
LocalArray(std::unique_ptr< T[]> &&p)
Constructs a LocalArray from a C++11 std::unique_ptr of an array type.
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 nullptr for C++ and to ((void *)0) for C.
"Smart pointer" class, deletes objects via the C++ array delete[] operator.
LocalArray(LocalArray< T > &&src) U_NOEXCEPT
Move constructor, leaves src with isNull().
~LocalPointer()
Destructor deletes the object it owns.
LocalArray< T > & operator=(LocalArray< T > &&src) U_NOEXCEPT
Move assignment operator, leaves src with isNull().
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
Standard ICU4C error code type, a substitute for exceptions.
void swap(LocalArray< T > &other) U_NOEXCEPT
Swap pointers.
~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.
void adoptInstead(T *p)
Deletes the object it owns, and adopts (takes ownership of) the one passed in.
LocalArray< T > & operator=(std::unique_ptr< T[]> &&p) U_NOEXCEPT
Move-assign from an std::unique_ptr to this LocalPointer.
int8_t UBool
The ICU boolean type.