ICU 57.1 57.1
Data Structures | Macros
localpointer.h File Reference

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

#include "unicode/utypes.h"

Go to the source code of this file.

Data Structures

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

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

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

For details see http://site.icu-project.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:
class LocalPointerClassName : public LocalPointerBase<Type> { \
public: \
using LocalPointerBase<Type>::operator->; \
explicit LocalPointerClassName(Type *p=NULL) : LocalPointerBase<Type>(p) {} \
return *this; \
} \
} \
p1.swap(p2); \
} \
void adoptInstead(Type *p) { \
ptr=p; \
} \
}
"Smart pointer" base class; do not use directly: use LocalPointer etc.
T * ptr
Actual pointer.
void adoptInstead(T *p)
Deletes the object it owns, and adopts (takes ownership of) the one passed in.
#define U_NOEXCEPT
"noexcept" if supported, otherwise empty.
Definition platform.h:529
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
Definition utypes.h:186

"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.

Requirement: The closeFunction must tolerate a NULL pointer. (We could add a NULL check here but it is normally redundant.)

Usage example:

utf8Out, (int32_t)sizeof(utf8Out),
utf8In, utf8InLength, &errorCode);
if(U_FAILURE(errorCode)) { return; } // no need to explicitly delete the UCaseMap
T * getAlias() const
Access without ownership change.
"Smart pointer" class, closes a UCaseMap via ucasemap_close().
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 * ucasemap_open(const char *locale, uint32_t options, UErrorCode *pErrorCode)
Open a UCaseMap service object for a locale and a set of options.
#define U_FAILURE(x)
Does the error code indicate a failure?
Definition utypes.h:714
See also
LocalPointerBase
LocalPointer
Stable:
ICU 4.4

Definition at line 539 of file localpointer.h.