ICU 76.1: common/unicode/localpointer.h File Reference

ICU 76.1 76.1

Data Structures | Namespaces | Macros
localpointer.h File Reference

C++ API: "Smart pointers" for use with and in ICU4C C++ code. More...

`#include "unicode/utypes.h"`
`#include <memory>`

Go to the source code of this file.

## Data Structures
class | icu::LocalPointerBase< T >
| "Smart pointer" base class; do not use directly: use LocalPointer etc. More...
class | icu::LocalPointer< T >
| "Smart pointer" class, deletes objects via the standard C++ delete operator. More...
class | icu::LocalArray< T >
| "Smart pointer" class, deletes objects via the C++ array delete[] operator. More...

## Namespaces
namespace | icu
| File coll.h.

## Macros
#define | U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction)
| "Smart pointer" definition macro, deletes objects via the closeFunction.

## Detailed Description

C++ API: "Smart pointers" for use with and in ICU4C C++ code.

These classes are inspired by

- std::auto_ptr
- boost::scoped_ptr & boost::scoped_array
- Taligent Safe Pointers (TOnlyPointerTo)

but none of those provide for all of the goals for ICU smart pointers:

- Smart pointer owns the object and releases it when it goes out of scope.
- No transfer of ownership via copy/assignment to reduce misuse. Simpler & more robust.
- ICU-compatible: No exceptions.
- Need to be able to orphan/release the pointer and its ownership.
- Need variants for normal C++ object pointers, C++ arrays, and ICU C service objects.

For details see https://icu.unicode.org/design/cpp/scoped_ptr

Definition in file localpointer.h.

## Macro Definition Documentation

## ◆ U_DEFINE_LOCAL_OPEN_POINTER

#define U_DEFINE_LOCAL_OPEN_POINTER | ( |  | LocalPointerClassName,
|  |  | Type,
|  |  | closeFunction )

Value:
using LocalPointerClassName = internal::LocalOpenPointer<Type, closeFunction>

"Smart pointer" definition macro, deletes objects via the closeFunction.

Defines a subclass of LocalPointerBase which works just like LocalPointer<Type> except that this subclass will use the closeFunction rather than the C++ delete operator.

Usage example:

LocalUCaseMapPointer csm(ucasemap_open(localeID, options, &errorCode));
utf8OutLength=ucasemap_utf8ToLower(csm.getAlias(),
utf8Out, (int32_t)sizeof(utf8Out),
utf8In, utf8InLength, &errorCode);
if(U_FAILURE(errorCode)) { return; } // no need to explicitly delete the UCaseMap
LocalUCaseMapPointer
"Smart pointer" class, closes a UCaseMap via ucasemap_close().
ucasemap_utf8ToLower
U_CAPI int32_t ucasemap_utf8ToLower(const UCaseMap *csm, char *dest, int32_t destCapacity, const char *src, int32_t srcLength, UErrorCode *pErrorCode)
Lowercase the characters in a UTF-8 string.
ucasemap_open
U_CAPI UCaseMap * ucasemap_open(const char *locale, uint32_t options, UErrorCode *pErrorCode)
Open a UCaseMap service object for a locale and a set of options.
U_FAILURE
#define U_FAILURE(x)
Does the error code indicate a failure?
Definition utypes.h:747

See also
  LocalPointerBase
  LocalPointer

Stable
  ICU 4.4

Definition at line 550 of file localpointer.h.