ICU 50.1.2  50.1.2
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 >:
icu::LocalPointerBase< T >

Public Member Functions

 LocalPointer (T *p=NULL)
 Constructor takes ownership. More...
 
 ~LocalPointer ()
 Destructor deletes the object it owns. More...
 
void adoptInstead (T *p)
 Deletes the object it owns, and adopts (takes ownership of) the one passed in. More...
 
- Public Member Functions inherited from icu::LocalPointerBase< T >
 LocalPointerBase (T *p=NULL)
 Constructor takes ownership. More...
 
 ~LocalPointerBase ()
 Destructor deletes the object it owns. More...
 
UBool isNull () const
 NULL check. More...
 
UBool isValid () const
 NULL check. More...
 
bool operator== (const T *other) const
 Comparison with a simple pointer, so that existing code with ==NULL need not be changed. More...
 
bool operator!= (const T *other) const
 Comparison with a simple pointer, so that existing code with !=NULL need not be changed. More...
 
T * getAlias () const
 Access without ownership change. More...
 
T & operator* () const
 Access without ownership change. More...
 
T * operator-> () const
 Access without ownership change. More...
 
T * orphan ()
 Gives up ownership; the internal pointer becomes NULL. More...
 
void adoptInstead (T *p)
 Deletes the object it owns, and adopts (takes ownership of) the one passed in. More...
 

Additional Inherited Members

- Protected Attributes inherited from icu::LocalPointerBase< T >
T * ptr
 Actual pointer. More...
 

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)
inlineexplicit

Constructor takes ownership.

Parameters
psimple 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 ( )
inline

Destructor deletes the object it owns.

Stable:
ICU 4.4

Definition at line 198 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
psimple pointer to an object that is adopted
Stable:
ICU 4.4

Definition at line 207 of file localpointer.h.


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