Loading...
Searching...
No Matches
icu::LocalPointerBase< T > Class Template Reference

"Smart pointer" base class; do not use directly: use LocalPointer etc. More...

`#include <localpointer.h>`

Inheritance diagram for icu::LocalPointerBase< T >:

## Public Member Functions

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

## Static Public Member Functions

static void * | operator new (size_t)=delete
static void * | operator new[] (size_t)=delete
static void * | operator new (size_t, void *)=delete

## Protected Attributes

T * | ptr
| Actual pointer.

## Detailed Description

template<typename T>
class icu::LocalPointerBase< T >

"Smart pointer" base class; do not use directly: use LocalPointer etc.

Base class for smart pointer classes that do not throw exceptions.

Do not use this base class directly, since it does not delete its pointer. A subclass must implement methods that delete the pointer: Destructor and adoptInstead().

There is no operator T *() provided because the programmer must decide whether to use getAlias() (without transfer of ownership) or orphan() (with transfer of ownership and NULLing of the pointer).

See also
  LocalPointer
  LocalArray
  U_DEFINE_LOCAL_OPEN_POINTER

Stable
  ICU 4.4

Definition at line 68 of file localpointer.h.

## Constructor & Destructor Documentation

## LocalPointerBase()

template<typename T>

icu::LocalPointerBase< T >::LocalPointerBase | ( | T * | p = nullptr | ) |

inline explicit

Constructor takes ownership.

Parameters

  p | simple pointer to an object that is adopted

Stable
  ICU 4.4

Definition at line 80 of file localpointer.h.

References ptr.

Referenced by icu::LocalArray< T >::LocalArray(), icu::LocalArray< T >::LocalArray(), icu::LocalArray< T >::LocalArray(), icu::LocalArray< T >::LocalArray(), icu::LocalPointer< T >::LocalPointer(), icu::LocalPointer< T >::LocalPointer(), icu::LocalPointer< T >::LocalPointer(), and icu::LocalPointer< T >::LocalPointer().

## ~LocalPointerBase()

template<typename T>

icu::LocalPointerBase< T >::~LocalPointerBase | ( |  | ) |

inline

Destructor deletes the object it owns.

Subclass must override: Base class does nothing.

Stable
  ICU 4.4

Definition at line 86 of file localpointer.h.

## Member Function Documentation

## adoptInstead()

template<typename T>

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

inline

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

Subclass must override: Base class does not delete the object.

Parameters

  p | simple pointer to an object that is adopted

Stable
  ICU 4.4

Definition at line 151 of file localpointer.h.

References ptr.

## getAlias()

template<typename T>

T * icu::LocalPointerBase< T >::getAlias | ( |  | ) | const

inline

Access without ownership change.

Returns
  the pointer value

Stable
  ICU 4.4

Definition at line 120 of file localpointer.h.

References ptr.

## isNull()

template<typename T>

UBool icu::LocalPointerBase< T >::isNull | ( |  | ) | const

inline

nullptr check.

Returns
  true if ==nullptr

Stable
  ICU 4.4

Definition at line 92 of file localpointer.h.

References ptr.

Referenced by icu::Locale::getKeywords(), and icu::Locale::getUnicodeKeywords().

## isValid()

template<typename T>

UBool icu::LocalPointerBase< T >::isValid | ( |  | ) | const

inline

nullptr check.

Returns
  true if !=nullptr

Stable
  ICU 4.4

Definition at line 98 of file localpointer.h.

References ptr.

## operator!=()

template<typename T>

bool icu::LocalPointerBase< T >::operator!= | ( | const T * | other | ) | const

inline

Comparison with a simple pointer, so that existing code with !=nullptr need not be changed.

Parameters

  other | simple pointer for comparison

Returns
  true if this pointer value differs from other

Stable
  ICU 4.4

Definition at line 114 of file localpointer.h.

References ptr.

## operator*()

template<typename T>

T & icu::LocalPointerBase< T >::operator* | ( |  | ) | const

inline

Access without ownership change.

Returns
  the pointer value as a reference

Stable
  ICU 4.4

Definition at line 126 of file localpointer.h.

References ptr.

## operator->()

template<typename T>

T * icu::LocalPointerBase< T >::operator-> | ( |  | ) | const

inline

Access without ownership change.

Returns
  the pointer value

Stable
  ICU 4.4

Definition at line 132 of file localpointer.h.

References ptr.

## operator==()

template<typename T>

bool icu::LocalPointerBase< T >::operator== | ( | const T * | other | ) | const

inline

Comparison with a simple pointer, so that existing code with ==nullptr need not be changed.

Parameters

  other | simple pointer for comparison

Returns
  true if this pointer value equals other

Stable
  ICU 4.4

Definition at line 106 of file localpointer.h.

References ptr.

## orphan()

template<typename T>

T * icu::LocalPointerBase< T >::orphan | ( |  | ) |

inline

Gives up ownership; the internal pointer becomes nullptr.

Returns
  the pointer value; caller becomes responsible for deleting the object

Stable
  ICU 4.4

Definition at line 139 of file localpointer.h.

References ptr.

Referenced by icu::LocalArray< icu::message2::data_model::Binding >::operator std::unique_ptr< icu::message2::data_model::Binding[]>(), and icu::LocalPointer< T >::operator std::unique_ptr< T >().

## Field Documentation

## ptr

template<typename T>

T* icu::LocalPointerBase< T >::ptr

protected

Actual pointer.

Internal
  Do not use. This API is for internal use only.

Definition at line 160 of file localpointer.h.

Referenced by icu::LocalArray< T >::adoptInstead(), icu::LocalPointer< T >::adoptInstead(), adoptInstead(), icu::LocalArray< T >::adoptInsteadAndCheckErrorCode(), icu::LocalPointer< T >::adoptInsteadAndCheckErrorCode(), getAlias(), isNull(), isValid(), LocalPointerBase(), operator!=(), operator*(), operator->(), icu::LocalArray< T >::operator=(), icu::LocalPointer< T >::operator=(), operator==(), icu::LocalArray< T >::operator[](), orphan(), icu::LocalArray< T >::swap(), icu::LocalPointer< T >::swap(), icu::LocalArray< T >::~LocalArray(), and icu::LocalPointer< T >::~LocalPointer().

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

- common/unicode/localpointer.h