Movatterモバイル変換


[0]ホーム

URL:


ICU 78.1  78.1
Public Member Functions |Friends
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 >:

Public Member Functions

 LocalArray (T *p=nullptr)
 Constructor takes ownership.More...
 
 LocalArray (T *p,UErrorCode &errorCode)
 Constructor takes ownership and reports an error if nullptr.More...
 
 LocalArray (LocalArray< T > &&src) noexcept
 Move constructor, leaves src withisNull().More...
 
 LocalArray (std::unique_ptr< T[]> &&p)
 Constructs aLocalArray from a C++11 std::unique_ptr of an array type.More...
 
 ~LocalArray ()
 Destructor deletes the array it owns.More...
 
LocalArray< T > & operator= (LocalArray< T > &&src) noexcept
 Move assignment operator, leaves src withisNull().More...
 
LocalArray< T > & operator= (std::unique_ptr< T[]> &&p) noexcept
 Move-assign from an std::unique_ptr to thisLocalPointer.More...
 
void swap (LocalArray< T > &other) noexcept
 Swap pointers.More...
 
void adoptInstead (T *p)
 Deletes the array it owns, and adopts (takes ownership of) the one passed in.More...
 
void adoptInsteadAndCheckErrorCode (T *p,UErrorCode &errorCode)
 Deletes the array it owns, and adopts (takes ownership of) the one passed in.More...
 
T & operator[] (ptrdiff_t i) const
 Array item access (writable).More...
 
 operator std::unique_ptr< T[]> () &&
 Conversion operator to a C++11 std::unique_ptr.More...
 
- Public Member Functions inherited fromicu::LocalPointerBase< T >
 LocalPointerBase (T *p=nullptr)
 Constructor takes ownership.More...
 
 ~LocalPointerBase ()
 Destructor deletes the object it owns.More...
 
UBool isNull () const
 nullptr check.More...
 
UBool isValid () const
 nullptr check.More...
 
bool operator== (const T *other) const
 Comparison with a simple pointer, so that existing code with ==nullptr need not be changed.More...
 
bool operator!= (const T *other) const
 Comparison with a simple pointer, so that existing code with !=nullptr 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 nullptr.More...
 
void adoptInstead (T *p)
 Deletes the object it owns, and adopts (takes ownership of) the one passed in.More...
 

Friends

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

Additional Inherited Members

- Static Public Member Functions inherited fromicu::LocalPointerBase< T >
static void * operator new (size_t)=delete
 
static void * operator new[] (size_t)=delete
 
static void * operator new (size_t, void *)=delete
 
- Protected Attributes inherited fromicu::LocalPointerBase< T >
T * ptr
 Actual pointer.More...
 

Detailed Description

template<typename T>
class icu::LocalArray< T >

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

For most methods see theLocalPointerBase 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 line364 of filelocalpointer.h.

Constructor & Destructor Documentation

◆ LocalArray()[1/4]

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

Constructor takes ownership.

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

Definition at line373 of filelocalpointer.h.

◆ LocalArray()[2/4]

template<typename T >
icu::LocalArray< T >::LocalArray(T * p,
UErrorCodeerrorCode 
)
inline

Constructor takes ownership and reports an error if nullptr.

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

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

Definition at line387 of filelocalpointer.h.

ReferencesU_MEMORY_ALLOCATION_ERROR, andU_SUCCESS.

◆ LocalArray()[3/4]

template<typename T >
icu::LocalArray< T >::LocalArray(LocalArray< T > && src)
inlinenoexcept

Move constructor, leaves src withisNull().

Parameters
srcsource smart pointer
Stable:
ICU 56

Definition at line397 of filelocalpointer.h.

Referencesicu::LocalPointerBase< T >::ptr.

◆ LocalArray()[4/4]

template<typename T >
icu::LocalArray< T >::LocalArray(std::unique_ptr< T[]> && p)
inlineexplicit

Constructs aLocalArray from a C++11 std::unique_ptr of an array type.

TheLocalPointer steals the array owned by the std::unique_ptr.

This constructor works via move semantics. If your std::unique_ptr is in a local variable, you must use std::move.

Parameters
pThe std::unique_ptr from which the array will be stolen.
Stable:
ICU 64

Definition at line411 of filelocalpointer.h.

◆ ~LocalArray()

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

Destructor deletes the array it owns.

Stable:
ICU 4.4

Definition at line418 of filelocalpointer.h.

Member Function Documentation

◆ adoptInstead()

template<typename T >
voidicu::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 line473 of filelocalpointer.h.

◆ adoptInsteadAndCheckErrorCode()

template<typename T >
voidicu::LocalArray< T >::adoptInsteadAndCheckErrorCode(T * p,
UErrorCodeerrorCode 
)
inline

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

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

IfU_SUCCESS(errorCode) but the input pointer is nullptr, then U_MEMORY_ALLOCATION_ERROR is set, the current array is deleted, and nullptr is set.

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

Definition at line492 of filelocalpointer.h.

ReferencesU_MEMORY_ALLOCATION_ERROR, andU_SUCCESS.

◆ operator std::unique_ptr< T[]>()

template<typename T >
icu::LocalArray< T >::operator std::unique_ptr< T[]>() &&
inline

Conversion operator to a C++11 std::unique_ptr.

Disowns the object and gives it to the returned std::unique_ptr.

This operator works via move semantics. If yourLocalPointer is in a local variable, you must use std::move.

Returns
An std::unique_ptr owning the pointer previously owned by thisicu::LocalPointer.
Stable:
ICU 64

Definition at line523 of filelocalpointer.h.

◆ operator=()[1/2]

template<typename T >
LocalArray<T>&icu::LocalArray< T >::operator=(LocalArray< T > && src)
inlinenoexcept

Move assignment operator, leaves src withisNull().

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

Parameters
srcsource smart pointer
Returns
*this
Stable:
ICU 56

Definition at line428 of filelocalpointer.h.

Referencesicu::LocalPointerBase< T >::ptr.

◆ operator=()[2/2]

template<typename T >
LocalArray<T>&icu::LocalArray< T >::operator=(std::unique_ptr< T[]> && p)
inlinenoexcept

Move-assign from an std::unique_ptr to thisLocalPointer.

Steals the array from the std::unique_ptr.

Parameters
pThe std::unique_ptr from which the array will be stolen.
Returns
*this
Stable:
ICU 64

Definition at line443 of filelocalpointer.h.

◆ operator[]()

template<typename T >
T&icu::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 line510 of filelocalpointer.h.

◆ swap()

template<typename T >
voidicu::LocalArray< T >::swap(LocalArray< T > & other)
inlinenoexcept

Swap pointers.

Parameters
otherother smart pointer
Stable:
ICU 56

Definition at line453 of filelocalpointer.h.

Referencesicu::LocalPointerBase< T >::ptr.

Friends And Related Function Documentation

◆ swap

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

Non-memberLocalArray swap function.

Parameters
p1will get p2's pointer
p2will get p1's pointer
Stable:
ICU 56

Definition at line464 of filelocalpointer.h.


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

Generated by doxygen 1.9.1
[8]ページ先頭

©2009-2025 Movatter.jp