ICU 57.1 57.1
LocalPointerBase< T > Class Template Reference

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

#include <localpointer.h>

Inheritance diagram for LocalPointerBase< T >:
LocalArray< T > LocalPointer< T >

Public Member Functions

 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.
 
void adoptInstead (T *p)
 Deletes the object it owns, and adopts (takes ownership of) the one passed in.
 

Protected Attributes

T * ptr
 Actual pointer.
 

Detailed Description

template<typename T>
class 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 64 of file localpointer.h.

Constructor & Destructor Documentation

◆ LocalPointerBase()

template<typename T>
LocalPointerBase< T >::LocalPointerBase ( T * p = NULL)
inlineexplicit

Constructor takes ownership.

Parameters
psimple pointer to an object that is adopted
Stable
ICU 4.4

Definition at line 71 of file localpointer.h.

References NULL, and ptr.

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

◆ ~LocalPointerBase()

template<typename T>
LocalPointerBase< T >::~LocalPointerBase ( )
inline

Destructor deletes the object it owns.

Subclass must override: Base class does nothing.

Stable
ICU 4.4

Definition at line 77 of file localpointer.h.

Member Function Documentation

◆ adoptInstead()

template<typename T>
void 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
psimple pointer to an object that is adopted
Stable
ICU 4.4

Definition at line 142 of file localpointer.h.

References ptr.

◆ getAlias()

template<typename T>
T * LocalPointerBase< T >::getAlias ( ) const
inline

Access without ownership change.

Returns
the pointer value
Stable
ICU 4.4

Definition at line 111 of file localpointer.h.

References ptr.

◆ isNull()

template<typename T>
UBool LocalPointerBase< T >::isNull ( ) const
inline

NULL check.

Returns
TRUE if ==NULL
Stable
ICU 4.4

Definition at line 83 of file localpointer.h.

References NULL, and ptr.

◆ isValid()

template<typename T>
UBool LocalPointerBase< T >::isValid ( ) const
inline

NULL check.

Returns
TRUE if !=NULL
Stable
ICU 4.4

Definition at line 89 of file localpointer.h.

References NULL, and ptr.

◆ operator!=()

template<typename T>
bool LocalPointerBase< T >::operator!= ( const T * other) const
inline

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

Parameters
othersimple pointer for comparison
Returns
true if this pointer value differs from other
Stable
ICU 4.4

Definition at line 105 of file localpointer.h.

References ptr.

◆ operator*()

template<typename T>
T & LocalPointerBase< T >::operator* ( ) const
inline

Access without ownership change.

Returns
the pointer value as a reference
Stable
ICU 4.4

Definition at line 117 of file localpointer.h.

References ptr.

◆ operator->()

template<typename T>
T * LocalPointerBase< T >::operator-> ( ) const
inline

Access without ownership change.

Returns
the pointer value
Stable
ICU 4.4

Definition at line 123 of file localpointer.h.

References ptr.

◆ operator==()

template<typename T>
bool LocalPointerBase< T >::operator== ( const T * other) const
inline

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

Parameters
othersimple pointer for comparison
Returns
true if this pointer value equals other
Stable
ICU 4.4

Definition at line 97 of file localpointer.h.

References ptr.

◆ orphan()

template<typename T>
T * LocalPointerBase< T >::orphan ( )
inline

Gives up ownership; the internal pointer becomes NULL.

Returns
the pointer value; caller becomes responsible for deleting the object
Stable
ICU 4.4

Definition at line 130 of file localpointer.h.

References NULL, and ptr.

Field Documentation

◆ ptr


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