"Smart pointer" class, deletes objects via the standard C++ delete operator. More...
#include <localpointer.h>
Public Member Functions | |
| LocalPointer (T *p=NULL) | |
| Constructor takes ownership. | |
| LocalPointer (T *p, UErrorCode &errorCode) | |
| Constructor takes ownership and reports an error if NULL. | |
| ~LocalPointer () | |
| Destructor deletes the object it owns. | |
| LocalPointer< T > & | moveFrom (LocalPointer< T > &src) U_NOEXCEPT |
| Move assignment, leaves src with isNull(). | |
| void | swap (LocalPointer< T > &other) U_NOEXCEPT |
| Swap pointers. | |
| void | adoptInstead (T *p) |
| Deletes the object it owns, and adopts (takes ownership of) the one passed in. | |
| void | adoptInsteadAndCheckErrorCode (T *p, UErrorCode &errorCode) |
| Deletes the object it owns, and adopts (takes ownership of) the one passed in. | |
Friends | |
| void | swap (LocalPointer< T > &p1, LocalPointer< T > &p2) U_NOEXCEPT |
| Non-member LocalPointer swap function. | |
"Smart pointer" class, deletes objects via the standard C++ delete operator.
For most methods see the LocalPointerBase base class.
Usage example:
LocalPointer<UnicodeString> s(new UnicodeString((UChar32)0x50005)); int32_t length=s->length(); // 2 UChar lead=s->charAt(0); // 0xd900 if(some condition) { return; } // no need to explicitly delete the pointer s.adoptInstead(new UnicodeString((UChar)0xfffc)); length=s->length(); // 1 // no need to explicitly delete the pointer
Definition at line 186 of file localpointer.h.
| icu::LocalPointer< T >::LocalPointer | ( | T * | p = NULL |
) | [inline, explicit] |
Constructor takes ownership.
| p | simple pointer to an object that is adopted |
Definition at line 195 of file localpointer.h.
| icu::LocalPointer< T >::LocalPointer | ( | T * | p, | |
| UErrorCode & | errorCode | |||
| ) | [inline] |
Constructor takes ownership and reports an error if NULL.
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 object that is adopted | |
| errorCode | in/out UErrorCode, set to U_MEMORY_ALLOCATION_ERROR if p==NULL and no other failure code had been set |
Definition at line 209 of file localpointer.h.
References NULL, U_MEMORY_ALLOCATION_ERROR, and U_SUCCESS.
| icu::LocalPointer< T >::~LocalPointer | ( | ) | [inline] |
Destructor deletes the object it owns.
Definition at line 230 of file localpointer.h.
| void icu::LocalPointer< T >::adoptInstead | ( | T * | p | ) | [inline] |
Deletes the object it owns, and adopts (takes ownership of) the one passed in.
| p | simple pointer to an object that is adopted |
Reimplemented from icu::LocalPointerBase< T >.
Definition at line 287 of file localpointer.h.
| void icu::LocalPointer< T >::adoptInsteadAndCheckErrorCode | ( | T * | p, | |
| UErrorCode & | errorCode | |||
| ) | [inline] |
Deletes the object it owns, and adopts (takes ownership of) the one passed in.
If U_FAILURE(errorCode), then the current object is retained and the new one deleted.
If U_SUCCESS(errorCode) but the input pointer is NULL, then U_MEMORY_ALLOCATION_ERROR is set, the current object is deleted, and NULL is set.
| p | simple pointer to an object that is adopted | |
| errorCode | in/out UErrorCode, set to U_MEMORY_ALLOCATION_ERROR if p==NULL and no other failure code had been set |
Definition at line 306 of file localpointer.h.
References NULL, U_MEMORY_ALLOCATION_ERROR, and U_SUCCESS.
| LocalPointer<T>& icu::LocalPointer< T >::moveFrom | ( | LocalPointer< T > & | src | ) | [inline] |
Move assignment, leaves src with isNull().
The behavior is undefined if *this and src are the same object.
Can be called explicitly, does not need C++11 support.
| src | source smart pointer |
Definition at line 255 of file localpointer.h.
References NULL.
| void icu::LocalPointer< T >::swap | ( | LocalPointer< T > & | other | ) | [inline] |
Swap pointers.
| other | other smart pointer |
Definition at line 266 of file localpointer.h.
| void swap | ( | LocalPointer< T > & | p1, | |
| LocalPointer< T > & | p2 | |||
| ) | [friend] |
Non-member LocalPointer swap function.
| p1 | will get p2's pointer | |
| p2 | will get p1's pointer |
Definition at line 278 of file localpointer.h.
1.6.1