ICU 76.1 76.1
|
"Smart pointer" class, deletes objects via the C++ array delete[] operator. More...
#include <localpointer.h>
Public Member Functions | |
LocalArray (T *p=nullptr) | |
Constructor takes ownership. | |
LocalArray (T *p, UErrorCode &errorCode) | |
Constructor takes ownership and reports an error if nullptr. | |
LocalArray (LocalArray< T > &&src) 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. | |
~LocalArray () | |
Destructor deletes the array it owns. | |
LocalArray< T > & | operator= (LocalArray< T > &&src) noexcept |
Move assignment operator, leaves src with isNull(). | |
LocalArray< T > & | operator= (std::unique_ptr< T[]> &&p) noexcept |
Move-assign from an std::unique_ptr to this LocalPointer. | |
void | swap (LocalArray< T > &other) noexcept |
Swap pointers. | |
void | adoptInstead (T *p) |
Deletes the array it owns, and adopts (takes ownership of) the one passed in. | |
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). | |
operator std::unique_ptr< T[]> () && | |
Conversion operator to a C++11 std::unique_ptr. | |
Public Member Functions inherited from icu::LocalPointerBase< T > | |
LocalPointerBase (T *p=nullptr) | |
Constructor takes ownership. | |
~LocalPointerBase () | |
Destructor deletes the object it owns. | |
UBool | isNull () const |
nullptr check. | |
UBool | isValid () const |
nullptr check. | |
bool | operator== (const T *other) const |
Comparison with a simple pointer, so that existing code with ==nullptr need not be changed. | |
bool | operator!= (const T *other) const |
Comparison with a simple pointer, so that existing code with !=nullptr need not be changed. | |
T * | getAlias () const |
Access without ownership change. | |
T & | operator* () const |
Access without ownership change. | |
T * | operator-> () const |
Access without ownership change. | |
T * | orphan () |
Gives up ownership; the internal pointer becomes nullptr. | |
void | adoptInstead (T *p) |
Deletes the object it owns, and adopts (takes ownership of) the one passed in. | |
Friends | |
void | swap (LocalArray< T > &p1, LocalArray< T > &p2) noexcept |
Non-member LocalArray swap function. | |
Additional Inherited Members | |
Static Public Member Functions inherited from icu::LocalPointerBase< T > | |
static void * | operator new (size_t)=delete |
static void * | operator new[] (size_t)=delete |
Protected Attributes inherited from icu::LocalPointerBase< T > | |
T * | ptr |
Actual pointer. | |
"Smart pointer" class, deletes objects via the C++ array delete[] operator.
For most methods see the LocalPointerBase base class. Adds operator[] for array item access.
Usage example:
Definition at line 366 of file localpointer.h.
Constructor takes ownership.
p | simple pointer to an array of T objects that is adopted |
Definition at line 375 of file localpointer.h.
|
inline |
Constructor takes ownership and reports an error if nullptr.
This constructor is intended to be used with other-class constructors that may report a failure UErrorCode, so that callers need to check only for U_FAILURE(errorCode) and not also separately for isNull().
p | simple pointer to an array of T objects that is adopted |
errorCode | in/out UErrorCode, set to U_MEMORY_ALLOCATION_ERROR if p==nullptr and no other failure code had been set |
Definition at line 389 of file localpointer.h.
References U_MEMORY_ALLOCATION_ERROR, and U_SUCCESS.
|
inlinenoexcept |
Move constructor, leaves src with isNull().
src | source smart pointer |
Definition at line 399 of file localpointer.h.
References icu::LocalPointerBase< T >::ptr.
|
inlineexplicit |
Constructs a LocalArray from a C++11 std::unique_ptr of an array type.
The LocalPointer steals the array owned by the std::unique_ptr.
This constructor works via move semantics. If your std::unique_ptr is in a local variable, you must use std::move.
p | The std::unique_ptr from which the array will be stolen. |
Definition at line 413 of file localpointer.h.
|
inline |
Deletes the array it owns, and adopts (takes ownership of) the one passed in.
p | simple pointer to an array of T objects that is adopted |
Definition at line 475 of file localpointer.h.
|
inline |
Deletes the array it owns, and adopts (takes ownership of) the one passed in.
If U_FAILURE(errorCode), then the current array is retained and the new one deleted.
If U_SUCCESS(errorCode) but the input pointer is nullptr, then U_MEMORY_ALLOCATION_ERROR is set, the current array is deleted, and nullptr is set.
p | simple pointer to an array of T objects that is adopted |
errorCode | in/out UErrorCode, set to U_MEMORY_ALLOCATION_ERROR if p==nullptr and no other failure code had been set |
Definition at line 494 of file localpointer.h.
References U_MEMORY_ALLOCATION_ERROR, and U_SUCCESS.
|
inline |
Conversion operator to a C++11 std::unique_ptr.
Disowns the object and gives it to the returned std::unique_ptr.
This operator works via move semantics. If your LocalPointer is in a local variable, you must use std::move.
Definition at line 525 of file localpointer.h.
|
inlinenoexcept |
Move assignment operator, leaves src with isNull().
The behavior is undefined if *this and src are the same object.
src | source smart pointer |
Definition at line 430 of file localpointer.h.
References icu::LocalPointerBase< T >::ptr.
|
inlinenoexcept |
Move-assign from an std::unique_ptr to this LocalPointer.
Steals the array from the std::unique_ptr.
p | The std::unique_ptr from which the array will be stolen. |
Definition at line 445 of file localpointer.h.
|
inline |
Array item access (writable).
No index bounds check.
i | array index |
Definition at line 512 of file localpointer.h.
|
inlinenoexcept |
Swap pointers.
other | other smart pointer |
Definition at line 455 of file localpointer.h.
References icu::LocalPointerBase< T >::ptr.
|
friend |
Non-member LocalArray swap function.
p1 | will get p2's pointer |
p2 | will get p1's pointer |
Definition at line 466 of file localpointer.h.