Go to the documentation of this file.
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); } \
LocalPointer(T *p, UErrorCode &errorCode)
Constructor takes ownership and reports an error if NULL.
LocalArray(T *p, UErrorCode &errorCode)
Constructor takes ownership and reports an error if NULL.
friend void swap(LocalArray< T > &p1, LocalArray< T > &p2)
Non-member LocalArray swap function.
Basic definitions for ICU, for both C and C++ APIs.
T * getAlias() const
Access without ownership change.
LocalPointer< T > & moveFrom(LocalPointer< T > &src)
Move assignment, leaves src with isNull().
LocalArray(T *p=NULL)
Constructor takes ownership.
int8_t UBool
The ICU boolean type.
T & operator[](ptrdiff_t i) const
Array item access (writable).
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
"Smart pointer" class, deletes objects via the standard C++ delete operator.
LocalArray(LocalArray< T > &&src)
Move constructor, leaves src with isNull().
LocalArray< T > & moveFrom(LocalArray< T > &src)
Move assignment, leaves src with isNull().
T * orphan()
Gives up ownership; the internal pointer becomes NULL.
@ U_MEMORY_ALLOCATION_ERROR
Memory allocation error.
LocalPointerBase(T *p=NULL)
Constructor takes ownership.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
LocalPointer< T > & operator=(LocalPointer< T > &&src)
Move assignment operator, leaves src with isNull().
"Smart pointer" base class; do not use directly: use LocalPointer etc.
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
bool operator!=(const T *other) const
Comparison with a simple pointer, so that existing code with !=NULL need not be changed.
void swap(LocalPointer< T > &other)
Swap pointers.
LocalArray< T > & operator=(LocalArray< T > &&src)
Move assignment operator, leaves src with isNull().
T * operator->() const
Access without ownership change.
UBool isNull() const
NULL check.
T & operator*() const
Access without ownership change.
#define U_SUCCESS(x)
Does the error code indicate success?
~LocalPointer()
Destructor deletes the object it owns.
void adoptInsteadAndCheckErrorCode(T *p, UErrorCode &errorCode)
Deletes the object 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.
friend void swap(LocalPointer< T > &p1, LocalPointer< T > &p2)
Non-member LocalPointer swap function.
UBool isValid() const
NULL check.
LocalPointer(LocalPointer< T > &&src)
Move constructor, leaves src with isNull().
"Smart pointer" class, deletes objects via the C++ array delete[] operator.
~LocalPointerBase()
Destructor deletes the object it owns.
void adoptInsteadAndCheckErrorCode(T *p, UErrorCode &errorCode)
Deletes the array 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_NAMESPACE_BEGIN
~LocalArray()
Destructor deletes the array it owns.
LocalPointer(T *p=NULL)
Constructor takes ownership.
void swap(LocalArray< T > &other)
Swap pointers.
void adoptInstead(T *p)
Deletes the object 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.