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;
271 adoptInstead(p.release());
342 operator std::unique_ptr<T> () && {
446 adoptInstead(p.release());
525 operator std::unique_ptr<T[]> () && {
550#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction) \
551 class LocalPointerClassName : public LocalPointerBase<Type> { \
553 using LocalPointerBase<Type>::operator*; \
554 using LocalPointerBase<Type>::operator->; \
555 explicit LocalPointerClassName(Type *p=NULL) : LocalPointerBase<Type>(p) {} \
556 LocalPointerClassName(LocalPointerClassName &&src) U_NOEXCEPT \
557 : LocalPointerBase<Type>(src.ptr) { \
561 explicit LocalPointerClassName(std::unique_ptr<Type, decltype(&closeFunction)> &&p) \
562 : LocalPointerBase<Type>(p.release()) {} \
563 ~LocalPointerClassName() { if (ptr != NULL) { closeFunction(ptr); } } \
564 LocalPointerClassName &operator=(LocalPointerClassName &&src) U_NOEXCEPT { \
565 if (ptr != NULL) { closeFunction(ptr); } \
566 LocalPointerBase<Type>::ptr=src.ptr; \
571 LocalPointerClassName &operator=(std::unique_ptr<Type, decltype(&closeFunction)> &&p) { \
572 adoptInstead(p.release()); \
575 void swap(LocalPointerClassName &other) U_NOEXCEPT { \
576 Type *temp=LocalPointerBase<Type>::ptr; \
577 LocalPointerBase<Type>::ptr=other.ptr; \
580 friend inline void swap(LocalPointerClassName &p1, LocalPointerClassName &p2) U_NOEXCEPT { \
583 void adoptInstead(Type *p) { \
584 if (ptr != NULL) { closeFunction(ptr); } \
587 operator std::unique_ptr<Type, decltype(&closeFunction)> () && { \
588 return std::unique_ptr<Type, decltype(&closeFunction)>(LocalPointerBase<Type>::orphan(), closeFunction); \
"Smart pointer" class, deletes objects via the C++ array delete[] operator.
friend void swap(LocalArray< T > &p1, LocalArray< T > &p2) U_NOEXCEPT
Non-member LocalArray swap function.
T & operator[](ptrdiff_t i) const
Array item access (writable).
LocalArray(LocalArray< T > &&src) U_NOEXCEPT
Move constructor, leaves src with isNull().
LocalArray< T > & operator=(LocalArray< T > &&src) U_NOEXCEPT
Move assignment operator, leaves src with isNull().
~LocalArray()
Destructor deletes the array it owns.
LocalArray(T *p=NULL)
Constructor takes ownership.
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 array it owns, and adopts (takes ownership of) the one passed in.
LocalArray(T *p, UErrorCode &errorCode)
Constructor takes ownership and reports an error if NULL.
LocalArray(std::unique_ptr< T[]> &&p)
Constructs a LocalArray from a C++11 std::unique_ptr of an array type.
void swap(LocalArray< T > &other) U_NOEXCEPT
Swap pointers.
LocalArray< T > & operator=(std::unique_ptr< T[]> &&p) U_NOEXCEPT
Move-assign from an std::unique_ptr to this LocalPointer.
"Smart pointer" base class; do not use directly: use LocalPointer etc.
bool operator!=(const T *other) const
Comparison with a simple pointer, so that existing code with !=NULL need not be changed.
UBool isValid() const
NULL check.
T * orphan()
Gives up ownership; the internal pointer becomes NULL.
LocalPointerBase(T *p=NULL)
Constructor takes ownership.
UBool isNull() const
NULL check.
T & operator*() const
Access without ownership change.
T * operator->() const
Access without ownership change.
bool operator==(const T *other) const
Comparison with a simple pointer, so that existing code with ==NULL need not be changed.
void adoptInstead(T *p)
Deletes the object it owns, and adopts (takes ownership of) the one passed in.
T * getAlias() const
Access without ownership change.
~LocalPointerBase()
Destructor deletes the object it owns.
"Smart pointer" class, deletes objects via the standard C++ delete operator.
LocalPointer< T > & operator=(LocalPointer< T > &&src) U_NOEXCEPT
Move assignment operator, leaves src with isNull().
void swap(LocalPointer< T > &other) U_NOEXCEPT
Swap pointers.
void adoptInsteadAndCheckErrorCode(T *p, UErrorCode &errorCode)
Deletes the object it owns, and adopts (takes ownership of) the one passed in.
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.
friend void swap(LocalPointer< T > &p1, LocalPointer< T > &p2) U_NOEXCEPT
Non-member LocalPointer swap function.
LocalPointer< T > & operator=(std::unique_ptr< T > &&p) U_NOEXCEPT
Move-assign from an std::unique_ptr to this LocalPointer.
~LocalPointer()
Destructor deletes the object it owns.
void adoptInstead(T *p)
Deletes the object it owns, and adopts (takes ownership of) the one passed in.
LocalPointer(LocalPointer< T > &&src) U_NOEXCEPT
Move constructor, leaves src with isNull().
LocalPointer(T *p=NULL)
Constructor takes ownership.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
int8_t UBool
The ICU boolean type, a signed-byte integer.
Basic definitions for ICU, for both C and C++ APIs.
#define NULL
Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
@ U_MEMORY_ALLOCATION_ERROR
Memory allocation error.
#define U_SUCCESS(x)
Does the error code indicate success?