ICU 55.1 55.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- Data Structures
- Data Structure Index
- Class Hierarchy
- Data Fields

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions
icu::LocalPointer< T > Class Template Reference

"Smart pointer" class, deletes objects via the standard C++ delete operator. More...

`#include <localpointer.h>`

Inheritance diagram for icu::LocalPointer< T >:

## 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.
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.
Public Member Functions inherited from icu::LocalPointerBase< T >
| LocalPointerBase (T *p=NULL)
| Constructor takes ownership.
| ~LocalPointerBase ()
| Destructor deletes the object it owns.
UBool | isNull () const
| NULL check.
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.
bool | operator!= (const T *other) const
| Comparison with a simple pointer, so that existing code with !=NULL 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 NULL.

## Additional Inherited Members
Protected Attributes inherited from icu::LocalPointerBase< T >
T * | ptr
| Actual pointer.

## Detailed Description

### template<typename T>
class icu::LocalPointer< T >

"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

See Also
  LocalPointerBase

Stable:
  ICU 4.4

Definition at line 186 of file localpointer.h.

## Constructor & Destructor Documentation

template<typename T >

icu::LocalPointer< T >::LocalPointer | ( | T * | p = `NULL` | ) |
| inline explicit

Constructor takes ownership.

Parameters

  p | simple pointer to an object that is adopted

Stable:
  ICU 4.4

Definition at line 193 of file localpointer.h.

template<typename T >

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().

Parameters

  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

Draft:
  This API may be changed in the future versions and was introduced in ICU 55

Definition at line 208 of file localpointer.h.

References NULL, U_MEMORY_ALLOCATION_ERROR, and U_SUCCESS.

template<typename T >

icu::LocalPointer< T >::~LocalPointer | ( |  | ) |
| inline

Destructor deletes the object it owns.

Stable:
  ICU 4.4

Definition at line 218 of file localpointer.h.

## Member Function Documentation

template<typename T >

void icu::LocalPointer< T >::adoptInstead | ( | T * | p | ) |
| inline

Deletes the object it owns, and adopts (takes ownership of) the one passed in.

Parameters

  p | simple pointer to an object that is adopted

Stable:
  ICU 4.4

Reimplemented from icu::LocalPointerBase< T >.

Definition at line 227 of file localpointer.h.

template<typename T >

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.

Parameters

  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

Draft:
  This API may be changed in the future versions and was introduced in ICU 55

Definition at line 247 of file localpointer.h.

References NULL, U_MEMORY_ALLOCATION_ERROR, and U_SUCCESS.

The documentation for this class was generated from the following file:

- localpointer.h