icu::LocalArray< T > Class Template Reference

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

#include <localpointer.h>

Inheritance diagram for icu::LocalArray< T >:
icu::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).

Detailed Description

template<typename T>
class icu::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:

 LocalArray<UnicodeString> a(new UnicodeString[2]);
 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
See also:
LocalPointerBase
Stable:
ICU 4.4

Definition at line 232 of file localpointer.h.


Constructor & Destructor Documentation

template<typename T >
icu::LocalArray< T >::LocalArray ( T *  p = NULL  )  [inline, explicit]

Constructor takes ownership.

Parameters:
p simple pointer to an array of T objects that is adopted
Stable:
ICU 4.4

Definition at line 239 of file localpointer.h.

template<typename T >
icu::LocalArray< T >::~LocalArray (  )  [inline]

Destructor deletes the array it owns.

Stable:
ICU 4.4

Definition at line 244 of file localpointer.h.


Member Function Documentation

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

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

Parameters:
p simple pointer to an array of T objects that is adopted
Stable:
ICU 4.4

Reimplemented from icu::LocalPointerBase< T >.

Definition at line 253 of file localpointer.h.

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

Array item access (writable).

No index bounds check.

Parameters:
i array index
Returns:
reference to the array item
Stable:
ICU 4.4

Definition at line 264 of file localpointer.h.


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

Generated on 5 Feb 2019 for ICU 50.1.2 by  doxygen 1.6.1