ICU-7245 implement C++ public smart pointers; LocalPointer, LocalArray, LocalUConverterPointer etc.

X-SVN-Rev: 26904
This commit is contained in:
Markus Scherer 2009-11-14 00:36:06 +00:00
parent 97725c7854
commit 1dbea6f001
34 changed files with 544 additions and 133 deletions

View file

@ -2172,6 +2172,46 @@
RelativePath=".\cmemory.h"
>
</File>
<File
RelativePath=".\unicode\localpointer.h"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="copy &quot;$(InputPath)&quot; ..\..\include\unicode&#x0D;&#x0A;"
Outputs="..\..\include\unicode\$(InputFileName)"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="copy &quot;$(InputPath)&quot; ..\..\include\unicode&#x0D;&#x0A;"
Outputs="..\..\include\unicode\$(InputFileName)"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="copy &quot;$(InputPath)&quot; ..\..\include\unicode&#x0D;&#x0A;"
Outputs="..\..\include\unicode\$(InputFileName)"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="copy &quot;$(InputPath)&quot; ..\..\include\unicode&#x0D;&#x0A;"
Outputs="..\..\include\unicode\$(InputFileName)"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\unicode\uclean.h"
>
@ -2930,11 +2970,11 @@
>
</File>
<File
RelativePath=".\ureslocs.h"
RelativePath=".\uresimp.h"
>
</File>
<File
RelativePath=".\uresimp.h"
RelativePath=".\ureslocs.h"
>
</File>
</Filter>

View file

@ -1,7 +1,7 @@
/*
******************************************************************************
*
* Copyright (C) 1999-2008, International Business Machines
* Copyright (C) 1999-2009, International Business Machines
* Corporation and others. All Rights Reserved.
*
******************************************************************************
@ -19,6 +19,7 @@
#include "unicode/utypes.h"
#include "unicode/uchar.h"
#include "unicode/localpointer.h"
/**
*\file
@ -519,6 +520,25 @@ ubidi_openSized(int32_t maxLength, int32_t maxRunCount, UErrorCode *pErrorCode);
U_STABLE void U_EXPORT2
ubidi_close(UBiDi *pBiDi);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUBiDiPointer
* "Smart pointer" class, closes a UBiDi via ubidi_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUBiDiPointer, UBiDi, ubidi_close);
U_NAMESPACE_END
#endif
/**
* Modify the operation of the Bidi algorithm such that it
* approximates an "inverse Bidi" algorithm. This function

View file

@ -11,6 +11,7 @@
#include "unicode/utypes.h"
#include "unicode/uloc.h"
#include "unicode/utext.h"
#include "unicode/localpointer.h"
/**
* A text-break iterator.
@ -22,7 +23,7 @@
* Opaque type representing an ICU Break iterator object.
* @stable ICU 2.0
*/
typedef void UBreakIterator;
typedef struct UBreakIterator UBreakIterator;
#endif
#if !UCONFIG_NO_BREAK_ITERATION
@ -277,6 +278,25 @@ ubrk_safeClone(
U_STABLE void U_EXPORT2
ubrk_close(UBreakIterator *bi);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUBreakIteratorPointer
* "Smart pointer" class, closes a UBreakIterator via ubrk_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUBreakIteratorPointer, UBreakIterator, ubrk_close);
U_NAMESPACE_END
#endif
/**
* Sets an existing iterator to point to a new piece of text
* @param bi The iterator to use

View file

@ -21,6 +21,7 @@
#include "unicode/utypes.h"
#include "unicode/ustring.h"
#include "unicode/localpointer.h"
/**
* \file
@ -76,6 +77,25 @@ ucasemap_open(const char *locale, uint32_t options, UErrorCode *pErrorCode);
U_STABLE void U_EXPORT2
ucasemap_close(UCaseMap *csm);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUCaseMapPointer
* "Smart pointer" class, closes a UCaseMap via ucasemap_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUCaseMapPointer, UCaseMap, ucasemap_close);
U_NAMESPACE_END
#endif
/**
* Get the locale ID that is used for language-dependent case mappings.
* @param csm UCaseMap service object.

View file

@ -49,6 +49,7 @@
#include "unicode/ucnv_err.h"
#include "unicode/uenum.h"
#include "unicode/localpointer.h"
#ifndef __USET_H__
@ -523,6 +524,25 @@ ucnv_safeClone(const UConverter *cnv,
U_STABLE void U_EXPORT2
ucnv_close(UConverter * converter);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUConverterPointer
* "Smart pointer" class, closes a UConverter via ucnv_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUConverterPointer, UConverter, ucnv_close);
U_NAMESPACE_END
#endif
/**
* Fills in the output parameter, subChars, with the substitution characters
* as multiple bytes.

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 2008, International Business Machines
* Copyright (C) 2008-2009, International Business Machines
* Corporation, Google and others. All Rights Reserved.
*
*******************************************************************************
@ -24,6 +24,7 @@
#include "unicode/utf16.h"
#include "unicode/uenum.h"
#include "unicode/ucnv.h"
#include "unicode/localpointer.h"
/**
* \file
@ -87,6 +88,25 @@ ucnvsel_open(const char* const* converterList, int32_t converterListSize,
U_CAPI void U_EXPORT2
ucnvsel_close(UConverterSelector *sel);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUConverterSelectorPointer
* "Smart pointer" class, closes a UConverterSelector via ucnvsel_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUConverterSelectorPointer, UConverterSelector, ucnvsel_close);
U_NAMESPACE_END
#endif
/**
* Open a selector from its serialized form.
* The buffer must remain valid and unchanged for the lifetime of the selector.

View file

@ -18,6 +18,7 @@
#define __UDATA_H__
#include "unicode/utypes.h"
#include "unicode/localpointer.h"
U_CDECL_BEGIN
@ -256,6 +257,25 @@ udata_openChoice(const char *path, const char *type, const char *name,
U_STABLE void U_EXPORT2
udata_close(UDataMemory *pData);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUDataMemoryPointer
* "Smart pointer" class, closes a UDataMemory via udata_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUDataMemoryPointer, UDataMemory, udata_close);
U_NAMESPACE_END
#endif
/**
* Get the pointer to the actual data inside the data memory.
* The data is read-only.

View file

@ -18,6 +18,7 @@
#define __UENUM_H
#include "unicode/utypes.h"
#include "unicode/localpointer.h"
#ifdef XP_CPLUSPLUS
#include "unicode/strenum.h"
@ -47,6 +48,25 @@ typedef struct UEnumeration UEnumeration;
U_STABLE void U_EXPORT2
uenum_close(UEnumeration* en);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUEnumerationPointer
* "Smart pointer" class, closes a UEnumeration via uenum_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUEnumerationPointer, UEnumeration, uenum_close);
U_NAMESPACE_END
#endif
/**
* Returns the number of elements that the iterator traverses. If
* the iterator is out-of-sync with its service, status is set to

View file

@ -25,6 +25,7 @@
#include "unicode/utypes.h"
#include "unicode/uloc.h"
#include "unicode/localpointer.h"
/**
* \file
@ -238,6 +239,25 @@ ures_countArrayItems(const UResourceBundle* resourceBundle,
U_STABLE void U_EXPORT2
ures_close(UResourceBundle* resourceBundle);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUResourceBundlePointer
* "Smart pointer" class, closes a UResourceBundle via ures_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUResourceBundlePointer, UResourceBundle, ures_close);
U_NAMESPACE_END
#endif
/**
* Return the version number associated with this ResourceBundle as a string. Please
* use ures_getVersion as this function is going to be deprecated.

View file

@ -29,6 +29,7 @@
#include "unicode/utypes.h"
#include "unicode/uchar.h"
#include "unicode/localpointer.h"
#ifndef UCNV_H
struct USet;
@ -299,6 +300,25 @@ uset_openPatternOptions(const UChar* pattern, int32_t patternLength,
U_STABLE void U_EXPORT2
uset_close(USet* set);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUSetPointer
* "Smart pointer" class, closes a USet via uset_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUSetPointer, USet, uset_close);
U_NAMESPACE_END
#endif
/**
* Returns a copy of this object.
* If this set is frozen, then the clone will be frozen as well.

View file

@ -23,6 +23,8 @@
*/
#include "unicode/utypes.h"
#include "unicode/localpointer.h"
/**
*
* StringPrep API implements the StingPrep framework as described by RFC 3454.
@ -205,6 +207,24 @@ usprep_openByType(UStringPrepProfileType type,
U_STABLE void U_EXPORT2
usprep_close(UStringPrepProfile* profile);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUStringPrepProfilePointer
* "Smart pointer" class, closes a UStringPrepProfile via usprep_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUStringPrepProfilePointer, UStringPrepProfile, usprep_close);
U_NAMESPACE_END
#endif
/**
* Prepare the input buffer for use in applications with the given profile. This operation maps, normalizes(NFKC),

View file

@ -23,7 +23,7 @@
/** Simple declaration for u_strToTitle() to avoid including unicode/ubrk.h. @stable ICU 2.1*/
#ifndef UBRK_TYPEDEF_UBREAK_ITERATOR
# define UBRK_TYPEDEF_UBREAK_ITERATOR
typedef void UBreakIterator;
typedef struct UBreakIterator UBreakIterator;
#endif
/**

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 2004-2008, International Business Machines
* Copyright (C) 2004-2009, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
@ -137,6 +137,7 @@
#include "unicode/utypes.h"
#ifdef XP_CPLUSPLUS
#include "unicode/localpointer.h"
#include "unicode/rep.h"
#include "unicode/unistr.h"
#include "unicode/chariter.h"
@ -179,6 +180,24 @@ typedef struct UText UText; /**< C typedef for struct UText. @stable ICU 3.6 */
U_STABLE UText * U_EXPORT2
utext_close(UText *ut);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUTextPointer
* "Smart pointer" class, closes a UText via utext_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUTextPointer, UText, utext_close);
U_NAMESPACE_END
#endif
/**
* Open a read-only UText implementation for UTF-8 strings.

View file

@ -22,7 +22,7 @@
/** Simple declaration for u_strToTitle() to avoid including unicode/ubrk.h. */
#ifndef UBRK_TYPEDEF_UBREAK_ITERATOR
# define UBRK_TYPEDEF_UBREAK_ITERATOR
typedef void UBreakIterator;
typedef struct UBreakIterator UBreakIterator;
#endif
/**

View file

@ -14,6 +14,7 @@
*/
#include "unicode/utypes.h"
#include "unicode/localpointer.h"
#include "unicode/uchar.h"
#include "unicode/unistr.h"
#include "unicode/ures.h"
@ -97,23 +98,21 @@ NumberingSystem::createInstance(const Locale & inLocale, UErrorCode& status) {
buffer[count] = '\0'; // Make sure it is null terminated.
return NumberingSystem::createInstanceByName(buffer,status);
} else { // Find the default numbering system for this locale.
UResourceBundle *resource = ures_open(NULL,inLocale.getName(),&status);
LocalUResourceBundlePointer resource(ures_open(NULL, inLocale.getName(), &status));
if (U_FAILURE(status)) {
status = U_USING_FALLBACK_WARNING;
NumberingSystem *ns = new NumberingSystem();
ures_close(resource);
return ns;
}
const UChar *defaultNSName = ures_getStringByKeyWithFallback(resource,gDefaultNumberingSystem,&count,&status);
const UChar *defaultNSName =
ures_getStringByKeyWithFallback(resource.getAlias(), gDefaultNumberingSystem, &count, &status);
if ( count > 0 && count < ULOC_KEYWORDS_CAPACITY ) { // Default numbering system found
u_UCharsToChars(defaultNSName,buffer,count);
buffer[count] = '\0'; // Make sure it is null terminated.
ures_close(resource);
return NumberingSystem::createInstanceByName(buffer,status);
} else {
status = U_USING_FALLBACK_WARNING;
NumberingSystem *ns = new NumberingSystem();
ures_close(resource);
return ns;
}

View file

@ -11,6 +11,7 @@
#include "unicode/utypes.h"
#include "unicode/uenum.h"
#include "unicode/uloc.h"
#include "unicode/localpointer.h"
#if !UCONFIG_NO_FORMATTING
@ -644,6 +645,25 @@ ucal_open(const UChar* zoneID,
U_STABLE void U_EXPORT2
ucal_close(UCalendar *cal);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUCalendarPointer
* "Smart pointer" class, closes a UCalendar via ucal_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUCalendarPointer, UCalendar, ucal_close);
U_NAMESPACE_END
#endif
/**
* Open a copy of a UCalendar.
* This function performs a deep copy.

View file

@ -13,6 +13,7 @@
#if !UCONFIG_NO_COLLATION
#include "unicode/unorm.h"
#include "unicode/localpointer.h"
#include "unicode/parseerr.h"
#include "unicode/uloc.h"
#include "unicode/uset.h"
@ -375,6 +376,25 @@ ucol_getContractionsAndExpansions( const UCollator *coll,
U_STABLE void U_EXPORT2
ucol_close(UCollator *coll);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUCollatorPointer
* "Smart pointer" class, closes a UCollator via ucol_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUCollatorPointer, UCollator, ucol_close);
U_NAMESPACE_END
#endif
/**
* Compare two strings.
* The strings will be compared using the options already specified.

View file

@ -1,6 +1,6 @@
/*
**********************************************************************
* Copyright (C) 2005-2007, International Business Machines
* Copyright (C) 2005-2009, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* file name: ucsdet.h
@ -22,6 +22,8 @@
#include "unicode/utypes.h"
#if !UCONFIG_NO_CONVERSION
#include "unicode/localpointer.h"
#include "unicode/uenum.h"
/**
@ -82,6 +84,25 @@ ucsdet_open(UErrorCode *status);
U_STABLE void U_EXPORT2
ucsdet_close(UCharsetDetector *ucsd);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUCharsetDetectorPointer
* "Smart pointer" class, closes a UCharsetDetector via ucsdet_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUCharsetDetectorPointer, UCharsetDetector, ucsdet_close);
U_NAMESPACE_END
#endif
/**
* Set the input byte data whose charset is to detected.
*

View file

@ -12,6 +12,7 @@
#if !UCONFIG_NO_FORMATTING
#include "unicode/localpointer.h"
#include "unicode/ucal.h"
#include "unicode/unum.h"
/**
@ -535,6 +536,25 @@ udat_open(UDateFormatStyle timeStyle,
U_STABLE void U_EXPORT2
udat_close(UDateFormat* format);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUDateFormatPointer
* "Smart pointer" class, closes a UDateFormat via udat_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUDateFormatPointer, UDateFormat, udat_close);
U_NAMESPACE_END
#endif
/**
* Open a copy of a UDateFormat.
* This function performs a deep copy.

View file

@ -19,6 +19,7 @@
#include "unicode/utypes.h"
#include "unicode/uenum.h"
#include "unicode/localpointer.h"
/**
* \file
@ -130,6 +131,25 @@ udatpg_openEmpty(UErrorCode *pErrorCode);
U_DRAFT void U_EXPORT2
udatpg_close(UDateTimePatternGenerator *dtpg);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUDateTimePatternGeneratorPointer
* "Smart pointer" class, closes a UDateTimePatternGenerator via udatpg_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUDateTimePatternGeneratorPointer, UDateTimePatternGenerator, udatpg_close);
U_NAMESPACE_END
#endif
/**
* Create a copy pf a generator.
* @param dtpg a pointer to UDateTimePatternGenerator to be copied.

View file

@ -20,6 +20,7 @@
#include "unicode/ures.h"
#include "unicode/uloc.h"
#include "unicode/uset.h"
#include "unicode/localpointer.h"
/**
* \file
@ -74,6 +75,25 @@ ulocdata_open(const char *localeID, UErrorCode *status);
U_STABLE void U_EXPORT2
ulocdata_close(ULocaleData *uld);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalULocaleDataPointer
* "Smart pointer" class, closes a ULocaleData via ulocdata_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalULocaleDataPointer, ULocaleData, ulocdata_close);
U_NAMESPACE_END
#endif
/**
* Sets the "no Substitute" attribute of the locale data
* object. If true, then any methods associated with the

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1996-2006, International Business Machines Corporation
* Copyright (C) 1996-2009, International Business Machines Corporation
* and others. All Rights Reserved.
*******************************************************************************
*
@ -23,6 +23,7 @@
#if !UCONFIG_NO_FORMATTING
#include "unicode/localpointer.h"
#include "unicode/uloc.h"
#include "unicode/parseerr.h"
#include <stdarg.h>
@ -453,6 +454,25 @@ umsg_open( const UChar *pattern,
U_STABLE void U_EXPORT2
umsg_close(UMessageFormat* format);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUMessageFormatPointer
* "Smart pointer" class, closes a UMessageFormat via umsg_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUMessageFormatPointer, UMessageFormat, umsg_close);
U_NAMESPACE_END
#endif
/**
* Open a copy of a UMessageFormat.
* This function performs a deep copy.

View file

@ -16,6 +16,7 @@
#if !UCONFIG_NO_FORMATTING
#include "unicode/localpointer.h"
#include "unicode/uloc.h"
#include "unicode/umisc.h"
#include "unicode/parseerr.h"
@ -254,6 +255,25 @@ unum_open( UNumberFormatStyle style,
U_STABLE void U_EXPORT2
unum_close(UNumberFormat* fmt);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUNumberFormatPointer
* "Smart pointer" class, closes a UNumberFormat via unum_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberFormatPointer, UNumberFormat, unum_close);
U_NAMESPACE_END
#endif
/**
* Open a copy of a UNumberFormat.
* This function performs a deep copy.

View file

@ -27,6 +27,7 @@
#if !UCONFIG_NO_REGULAR_EXPRESSIONS
#include "unicode/localpointer.h"
#include "unicode/parseerr.h"
struct URegularExpression;
@ -177,6 +178,25 @@ uregex_openC( const char *pattern,
U_STABLE void U_EXPORT2
uregex_close(URegularExpression *regexp);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalURegularExpressionPointer
* "Smart pointer" class, closes a URegularExpression via uregex_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalURegularExpressionPointer, URegularExpression, uregex_close);
U_NAMESPACE_END
#endif
/**
* Make a copy of a compiled regular expression. Cloning a regular
* expression is faster than opening a second instance from the source

View file

@ -1,6 +1,6 @@
/*
**********************************************************************
* Copyright (C) 2001-2008 IBM and others. All rights reserved.
* Copyright (C) 2001-2009 IBM and others. All rights reserved.
**********************************************************************
* Date Name Description
* 06/28/2001 synwee Creation.
@ -13,6 +13,7 @@
#if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION
#include "unicode/localpointer.h"
#include "unicode/ucol.h"
#include "unicode/ucoleitr.h"
#include "unicode/ubrk.h"
@ -249,6 +250,25 @@ U_STABLE UStringSearch * U_EXPORT2 usearch_openFromCollator(
*/
U_STABLE void U_EXPORT2 usearch_close(UStringSearch *searchiter);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUStringSearchPointer
* "Smart pointer" class, closes a UStringSearch via usearch_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUStringSearchPointer, UStringSearch, usearch_close);
U_NAMESPACE_END
#endif
/* get and set methods -------------------------------------------------- */
/**

View file

@ -25,7 +25,7 @@
#include "unicode/utypes.h"
#include "unicode/uset.h"
#include "unicode/parseerr.h"
#include "unicode/localpointer.h"
#if !UCONFIG_NO_NORMALIZATION
@ -290,6 +290,25 @@ uspoof_openFromSource(const char *confusables, int32_t confusablesLen,
U_DRAFT void U_EXPORT2
uspoof_close(USpoofChecker *sc);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUSpoofCheckerPointer
* "Smart pointer" class, closes a USpoofChecker via uspoof_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUSpoofCheckerPointer, USpoofChecker, uspoof_close);
U_NAMESPACE_END
#endif
/**
* Clone a Spoof Checker. The clone will be set to perform the same checks
* as the original source.

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1997-2005, International Business Machines
* Copyright (C) 1997-2009, International Business Machines
* Corporation and others. All Rights Reserved.
*******************************************************************************
* Date Name Description
@ -15,6 +15,7 @@
#if !UCONFIG_NO_TRANSLITERATION
#include "unicode/localpointer.h"
#include "unicode/urep.h"
#include "unicode/parseerr.h"
#include "unicode/uenum.h"
@ -235,6 +236,25 @@ utrans_clone(const UTransliterator* trans,
U_STABLE void U_EXPORT2
utrans_close(UTransliterator* trans);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUTransliteratorPointer
* "Smart pointer" class, closes a UTransliterator via utrans_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUTransliteratorPointer, UTransliterator, utrans_close);
U_NAMESPACE_END
#endif
/**
* Return the programmatic identifier for this transliterator.
* If this identifier is passed to utrans_openU(), it will open

View file

@ -28,6 +28,7 @@
#include "unicode/utypes.h"
#include "unicode/ucnv.h"
#include "unicode/utrans.h"
#include "unicode/localpointer.h"
/*
TODO
@ -284,6 +285,25 @@ u_fstropen(UChar *stringBuf,
U_DRAFT void U_EXPORT2
u_fclose(UFILE *file);
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
/**
* \class LocalUFILEPointer
* "Smart pointer" class, closes a UFILE via u_fclose().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 4.4
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUFILEPointer, UFILE, u_fclose);
U_NAMESPACE_END
#endif
/**
* Tests if the UFILE is at the end of the file stream.
* @param f The UFILE from which to read.

View file

@ -31,6 +31,7 @@
#if !UCONFIG_NO_COLLATION
#include "unicode/localpointer.h"
#include "unicode/coll.h"
#include "unicode/tblcoll.h"
#include "unicode/coleitr.h"

View file

@ -21,6 +21,7 @@
#include "unicode/utypes.h"
#include "unicode/ubidi.h"
#include "unicode/errorcode.h"
#include "unicode/localpointer.h"
#include "unicode/putil.h"
#include "unicode/unistr.h"
#include "intltest.h"
@ -112,7 +113,6 @@ char *BiDiConformanceTest::getUnidataPath(char path[]) {
}
U_DEFINE_LOCAL_OPEN_POINTER(LocalStdioFilePointer, FILE, fclose);
U_DEFINE_LOCAL_OPEN_POINTER(LocalUBiDiPointer, UBiDi, ubidi_close);
// TODO: Make "public" in uparse.h.
#define U_IS_INV_WHITESPACE(c) ((c)==' ' || (c)=='\t' || (c)=='\r' || (c)=='\n')

View file

@ -261,118 +261,4 @@ extern UnicodeString CharsToUnicodeString(const char* chars);
/* alias for CharsToUnicodeString */
extern UnicodeString ctou(const char* chars);
// TODO(markus): Propose as public API.
/**
* Does not throw exceptions.
* Do not use this base class directly, since it does not delete its pointer.
* A subclass must implement methods that delete the pointer:
* Destructor and adoptInstead().
*
* There is no operator T *() provided because the programmer must decide
* whether to use getAlias() (without transfer of ownership) or orpan()
* (with transfer of ownership and NULLing of the pointer).
*/
template<typename T>
class /* U_COMMON_API */ LocalPointerBase {
public:
// Takes ownership.
explicit LocalPointerBase(T *p=NULL) : ptr(p) {}
// Deletes the object it owns.
~LocalPointerBase() { /* delete ptr; */ }
// NULL checks.
UBool isNull() const { return ptr==NULL; }
UBool isValid() const { return ptr!=NULL; }
// Comparisons with simple pointers, so that existing code
// with ==NULL and !=NULL need not be changed.
bool operator==(const T *other) const { return ptr==other; }
bool operator!=(const T *other) const { return ptr!=other; }
// Access without ownership change.
T *getAlias() const { return ptr; }
T &operator*() const { return *ptr; }
T *operator->() const { return ptr; }
// Gives up ownership; the internal pointer becomes NULL.
T *orphan() {
T *p=ptr;
ptr=NULL;
return p;
}
// Deletes the object it owns and adopt (take ownership of) the one passed in.
void adoptInstead(T *p) {
// delete ptr;
ptr=p;
}
protected:
T *ptr;
private:
// No comparison operators with other LocalPointerBase's.
bool operator==(const LocalPointerBase &other);
bool operator!=(const LocalPointerBase &other);
// No ownership transfer: No copy constructor, no assignment operator.
LocalPointerBase(const LocalPointerBase &other);
void operator=(const LocalPointerBase &other);
// No heap allocation. Use only on the stack.
static void * U_EXPORT2 operator new(size_t size);
static void * U_EXPORT2 operator new[](size_t size);
#if U_HAVE_PLACEMENT_NEW
static void * U_EXPORT2 operator new(size_t, void *ptr);
#endif
};
// TODO: Option 1: Destructor and adoptInstead() and possible future methods
// call a protected handleDelete() which is virtual and is the single method
// which a subclass must override.
// Con: Requires the LocalPointerBase class to be virtual, doubles its size,
// and the linker picks an arbitrary .o file for the vtable.
// virtual void handleDelete() {
// delete ptr;
// }
// Option 2: Require all subclasses to override all deleting methods
// (destructor and adoptInstead()) if they need to use something other than
// the delete operator.
// Con: More methods need to be overwritten, and if we add further deleting
// methods, then that set increases further.
// Also, using a subclass instance via the base class API would not work,
// but that would be outside the intended usage.
template<typename T>
class /* U_COMMON_API */ LocalPointer : public LocalPointerBase<T> {
public:
explicit LocalPointer(T *p=NULL) : LocalPointerBase<T>(p) {}
~LocalPointer() {
delete LocalPointerBase<T>::ptr;
}
void adoptInstead(T *p) {
delete LocalPointerBase<T>::ptr;
LocalPointerBase<T>::ptr=p;
}
};
template<typename T>
class /* U_COMMON_API */ LocalArray : public LocalPointerBase<T> {
public:
explicit LocalArray(T *p=NULL) : LocalPointerBase<T>(p) {}
~LocalArray() {
delete[] LocalPointerBase<T>::ptr;
}
void adoptInstead(T *p) {
delete[] LocalPointerBase<T>::ptr;
LocalPointerBase<T>::ptr=p;
}
T &operator[](ptrdiff_t i) const { return LocalPointerBase<T>::ptr[i]; }
};
// Requirement: The closeFunction must tolerate a NULL pointer.
// Or, we could add a NULL check here.
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction) \
class /* U_COMMON_API */ LocalPointerClassName : public LocalPointerBase<Type> { \
public: \
explicit LocalPointerClassName(Type *p=NULL) : LocalPointerBase<Type>(p) {} \
~LocalPointerClassName() { closeFunction(ptr); } \
void adoptInstead(Type *p) { \
closeFunction(ptr); \
ptr=p; \
} \
}
#endif // _INTLTEST

View file

@ -458,7 +458,11 @@ StringCaseTest::TestCasingImpl(const UnicodeString &input,
void
StringCaseTest::TestCasing() {
UErrorCode status = U_ZERO_ERROR;
#if UCONFIG_NO_BREAK_ITERATION
void *iter;
#else
UBreakIterator *iter;
#endif
char cLocaleID[100];
UnicodeString locale, input, output, optionsString, result;
uint32_t options;

View file

@ -19,6 +19,7 @@
#if !UCONFIG_NO_COLLATION
#include "unicode/localpointer.h"
#include "unicode/uchar.h"
#include "unicode/ustring.h"

View file

@ -18,6 +18,7 @@
#include "cmemory.h"
#include "cstring.h"
#include "uparse.h"
#include "unicode/localpointer.h"
#include "unicode/resbund.h"
#include "unicode/udata.h"
#include "unicode/uloc.h"