ICU 50.2 50.2
LocalArray< T > Class Template Reference

"Smart pointer" class, deletes objects via the C++ array delete[] operator. More...

#include <localpointer.h>

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

Public Member Functions

 LocalArray (T *p=NULL)
 Constructor takes ownership.
 
 ~LocalArray ()
 Destructor deletes the array it owns.
 
void adoptInstead (T *p)
 Deletes the array it owns, and adopts (takes ownership of) the one passed in.
 
T & operator[] (ptrdiff_t i) const
 Array item access (writable).
 
- Public Member Functions inherited from 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.
 
void adoptInstead (T *p)
 Deletes the object it owns, and adopts (takes ownership of) the one passed in.
 

Additional Inherited Members

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

Detailed Description

template<typename T>
class LocalArray< T >

"Smart pointer" class, deletes objects via the C++ array delete[] operator.

For most methods see the LocalPointerBase base class. Adds operator[] for array item access.

Usage example:

a[0].append((UChar)0x61);
if(some condition) { return; } // no need to explicitly delete the array
a.adoptInstead(new UnicodeString[4]);
a[3].append((UChar)0x62).append((UChar)0x63).reverse();
// no need to explicitly delete the array
LocalArray(T *p=NULL)
Constructor takes ownership.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:247
uint16_t UChar
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
Definition umachine.h:278
See also
LocalPointerBase
Stable
ICU 4.4

Definition at line 232 of file localpointer.h.

Constructor & Destructor Documentation

◆ LocalArray()

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

Constructor takes ownership.

Parameters
psimple pointer to an array of T objects that is adopted
Stable
ICU 4.4

Definition at line 239 of file localpointer.h.

References LocalPointerBase< T >::LocalPointerBase(), and NULL.

◆ ~LocalArray()

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

Destructor deletes the array it owns.

Stable
ICU 4.4

Definition at line 244 of file localpointer.h.

References LocalPointerBase< T >::ptr.

Member Function Documentation

◆ adoptInstead()

template<typename T>
void LocalArray< T >::adoptInstead ( T * p)
inline

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

Parameters
psimple pointer to an array of T objects that is adopted
Stable
ICU 4.4

Definition at line 253 of file localpointer.h.

References LocalPointerBase< T >::ptr.

◆ operator[]()

template<typename T>
T & LocalArray< T >::operator[] ( ptrdiff_t i) const
inline

Array item access (writable).

No index bounds check.

Parameters
iarray index
Returns
reference to the array item
Stable
ICU 4.4

Definition at line 264 of file localpointer.h.

References LocalPointerBase< T >::ptr.


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