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 (T *p, UErrorCode &errorCode)
 Constructor takes ownership and reports an error if NULL.
 LocalArray (LocalArray< T > &&src)
 Move constructor, leaves src with isNull().
 ~LocalArray ()
 Destructor deletes the array it owns.
LocalArray< T > & operator= (LocalArray< T > &&src)
 Move assignment operator, leaves src with isNull().
LocalArray< T > & moveFrom (LocalArray< T > &src)
 Move assignment, leaves src with isNull().
void swap (LocalArray< T > &other)
 Swap pointers.
void adoptInstead (T *p)
 Deletes the array it owns, and adopts (takes ownership of) the one passed in.
void adoptInsteadAndCheckErrorCode (T *p, UErrorCode &errorCode)
 Deletes the array it owns, and adopts (takes ownership of) the one passed in.
T & operator[] (ptrdiff_t i) const
 Array item access (writable).

Friends

void swap (LocalArray< T > &p1, LocalArray< T > &p2)
 Non-member LocalArray swap function.

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((char16_t)0x61);
 if(some condition) { return; }  // no need to explicitly delete the array
 a.adoptInstead(new UnicodeString[4]);
 a[3].append((char16_t)0x62).append((char16_t)0x63).reverse();
 // no need to explicitly delete the array
See also:
LocalPointerBase
Stable:
ICU 4.4

Definition at line 333 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 342 of file localpointer.h.

template<typename T>
icu::LocalArray< T >::LocalArray ( T *  p,
UErrorCode errorCode 
) [inline]

Constructor takes ownership and reports an error if NULL.

This constructor is intended to be used with other-class constructors that may report a failure UErrorCode, so that callers need to check only for U_FAILURE(errorCode) and not also separately for isNull().

Parameters:
p simple pointer to an array of T objects that is adopted
errorCode in/out UErrorCode, set to U_MEMORY_ALLOCATION_ERROR if p==NULL and no other failure code had been set
Stable:
ICU 56

Definition at line 356 of file localpointer.h.

References NULL, U_MEMORY_ALLOCATION_ERROR, and U_SUCCESS.

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

Move constructor, leaves src with isNull().

Parameters:
src source smart pointer
Stable:
ICU 56

Definition at line 366 of file localpointer.h.

References NULL.

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

Destructor deletes the array it owns.

Stable:
ICU 4.4

Definition at line 373 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 427 of file localpointer.h.

template<typename T>
void icu::LocalArray< T >::adoptInsteadAndCheckErrorCode ( T *  p,
UErrorCode errorCode 
) [inline]

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

If U_FAILURE(errorCode), then the current array is retained and the new one deleted.

If U_SUCCESS(errorCode) but the input pointer is NULL, then U_MEMORY_ALLOCATION_ERROR is set, the current array is deleted, and NULL is set.

Parameters:
p simple pointer to an array of T objects that is adopted
errorCode in/out UErrorCode, set to U_MEMORY_ALLOCATION_ERROR if p==NULL and no other failure code had been set
Stable:
ICU 56

Definition at line 446 of file localpointer.h.

References NULL, U_MEMORY_ALLOCATION_ERROR, and U_SUCCESS.

template<typename T>
LocalArray<T>& icu::LocalArray< T >::moveFrom ( LocalArray< T > &  src  )  [inline]

Move assignment, leaves src with isNull().

The behavior is undefined if *this and src are the same object.

Can be called explicitly, does not need C++11 support.

Parameters:
src source smart pointer
Returns:
*this
Draft:
This API may be changed in the future versions and was introduced in ICU 56

Definition at line 396 of file localpointer.h.

References NULL.

template<typename T>
LocalArray<T>& icu::LocalArray< T >::operator= ( LocalArray< T > &&  src  )  [inline]

Move assignment operator, leaves src with isNull().

The behavior is undefined if *this and src are the same object.

Parameters:
src source smart pointer
Returns:
*this
Stable:
ICU 56

Definition at line 383 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 464 of file localpointer.h.

template<typename T>
void icu::LocalArray< T >::swap ( LocalArray< T > &  other  )  [inline]

Swap pointers.

Parameters:
other other smart pointer
Stable:
ICU 56

Definition at line 407 of file localpointer.h.


Friends And Related Function Documentation

template<typename T>
void swap ( LocalArray< T > &  p1,
LocalArray< T > &  p2 
) [friend]

Non-member LocalArray swap function.

Parameters:
p1 will get p2's pointer
p2 will get p1's pointer
Stable:
ICU 56

Definition at line 418 of file localpointer.h.


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

Generated on 27 Mar 2018 for ICU 60.1 by  doxygen 1.6.1