michael@0: /* michael@0: ******************************************************************************* michael@0: * michael@0: * Copyright (C) 2002-2013, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ******************************************************************************* michael@0: * file name: uenum.h michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:2 michael@0: * michael@0: * created on: 2002jul08 michael@0: * created by: Vladimir Weinstein michael@0: */ michael@0: michael@0: #ifndef __UENUM_H michael@0: #define __UENUM_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/localpointer.h" michael@0: michael@0: #if U_SHOW_CPLUSPLUS_API michael@0: #include "unicode/strenum.h" michael@0: #endif michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C API: String Enumeration michael@0: */ michael@0: michael@0: /** michael@0: * An enumeration object. michael@0: * For usage in C programs. michael@0: * @stable ICU 2.2 michael@0: */ michael@0: struct UEnumeration; michael@0: /** structure representing an enumeration object instance @stable ICU 2.2 */ michael@0: typedef struct UEnumeration UEnumeration; michael@0: michael@0: /** michael@0: * Disposes of resources in use by the iterator. If en is NULL, michael@0: * does nothing. After this call, any char* or UChar* pointer michael@0: * returned by uenum_unext() or uenum_next() is invalid. michael@0: * @param en UEnumeration structure pointer michael@0: * @stable ICU 2.2 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uenum_close(UEnumeration* en); michael@0: michael@0: #if U_SHOW_CPLUSPLUS_API michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: /** michael@0: * \class LocalUEnumerationPointer michael@0: * "Smart pointer" class, closes a UEnumeration via uenum_close(). michael@0: * For most methods see the LocalPointerBase base class. michael@0: * michael@0: * @see LocalPointerBase michael@0: * @see LocalPointer michael@0: * @stable ICU 4.4 michael@0: */ michael@0: U_DEFINE_LOCAL_OPEN_POINTER(LocalUEnumerationPointer, UEnumeration, uenum_close); michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif michael@0: michael@0: /** michael@0: * Returns the number of elements that the iterator traverses. If michael@0: * the iterator is out-of-sync with its service, status is set to michael@0: * U_ENUM_OUT_OF_SYNC_ERROR. michael@0: * This is a convenience function. It can end up being very michael@0: * expensive as all the items might have to be pre-fetched (depending michael@0: * on the type of data being traversed). Use with caution and only michael@0: * when necessary. michael@0: * @param en UEnumeration structure pointer michael@0: * @param status error code, can be U_ENUM_OUT_OF_SYNC_ERROR if the michael@0: * iterator is out of sync. michael@0: * @return number of elements in the iterator michael@0: * @stable ICU 2.2 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uenum_count(UEnumeration* en, UErrorCode* status); michael@0: michael@0: /** michael@0: * Returns the next element in the iterator's list. If there are michael@0: * no more elements, returns NULL. If the iterator is out-of-sync michael@0: * with its service, status is set to U_ENUM_OUT_OF_SYNC_ERROR and michael@0: * NULL is returned. If the native service string is a char* string, michael@0: * it is converted to UChar* with the invariant converter. michael@0: * The result is terminated by (UChar)0. michael@0: * @param en the iterator object michael@0: * @param resultLength pointer to receive the length of the result michael@0: * (not including the terminating \\0). michael@0: * If the pointer is NULL it is ignored. michael@0: * @param status the error code, set to U_ENUM_OUT_OF_SYNC_ERROR if michael@0: * the iterator is out of sync with its service. michael@0: * @return a pointer to the string. The string will be michael@0: * zero-terminated. The return pointer is owned by this iterator michael@0: * and must not be deleted by the caller. The pointer is valid michael@0: * until the next call to any uenum_... method, including michael@0: * uenum_next() or uenum_unext(). When all strings have been michael@0: * traversed, returns NULL. michael@0: * @stable ICU 2.2 michael@0: */ michael@0: U_STABLE const UChar* U_EXPORT2 michael@0: uenum_unext(UEnumeration* en, michael@0: int32_t* resultLength, michael@0: UErrorCode* status); michael@0: michael@0: /** michael@0: * Returns the next element in the iterator's list. If there are michael@0: * no more elements, returns NULL. If the iterator is out-of-sync michael@0: * with its service, status is set to U_ENUM_OUT_OF_SYNC_ERROR and michael@0: * NULL is returned. If the native service string is a UChar* michael@0: * string, it is converted to char* with the invariant converter. michael@0: * The result is terminated by (char)0. If the conversion fails michael@0: * (because a character cannot be converted) then status is set to michael@0: * U_INVARIANT_CONVERSION_ERROR and the return value is undefined michael@0: * (but non-NULL). michael@0: * @param en the iterator object michael@0: * @param resultLength pointer to receive the length of the result michael@0: * (not including the terminating \\0). michael@0: * If the pointer is NULL it is ignored. michael@0: * @param status the error code, set to U_ENUM_OUT_OF_SYNC_ERROR if michael@0: * the iterator is out of sync with its service. Set to michael@0: * U_INVARIANT_CONVERSION_ERROR if the underlying native string is michael@0: * UChar* and conversion to char* with the invariant converter michael@0: * fails. This error pertains only to current string, so iteration michael@0: * might be able to continue successfully. michael@0: * @return a pointer to the string. The string will be michael@0: * zero-terminated. The return pointer is owned by this iterator michael@0: * and must not be deleted by the caller. The pointer is valid michael@0: * until the next call to any uenum_... method, including michael@0: * uenum_next() or uenum_unext(). When all strings have been michael@0: * traversed, returns NULL. michael@0: * @stable ICU 2.2 michael@0: */ michael@0: U_STABLE const char* U_EXPORT2 michael@0: uenum_next(UEnumeration* en, michael@0: int32_t* resultLength, michael@0: UErrorCode* status); michael@0: michael@0: /** michael@0: * Resets the iterator to the current list of service IDs. This michael@0: * re-establishes sync with the service and rewinds the iterator michael@0: * to start at the first element. michael@0: * @param en the iterator object michael@0: * @param status the error code, set to U_ENUM_OUT_OF_SYNC_ERROR if michael@0: * the iterator is out of sync with its service. michael@0: * @stable ICU 2.2 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uenum_reset(UEnumeration* en, UErrorCode* status); michael@0: michael@0: #if U_SHOW_CPLUSPLUS_API michael@0: michael@0: /** michael@0: * Given a StringEnumeration, wrap it in a UEnumeration. The michael@0: * StringEnumeration is adopted; after this call, the caller must not michael@0: * delete it (regardless of error status). michael@0: * @param adopted the C++ StringEnumeration to be wrapped in a UEnumeration. michael@0: * @param ec the error code. michael@0: * @return a UEnumeration wrapping the adopted StringEnumeration. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: U_STABLE UEnumeration* U_EXPORT2 michael@0: uenum_openFromStringEnumeration(icu::StringEnumeration* adopted, UErrorCode* ec); michael@0: michael@0: #endif michael@0: michael@0: /** michael@0: * Given an array of const UChar* strings, return a UEnumeration. String pointers from 0..count-1 must not be null. michael@0: * Do not free or modify either the string array or the characters it points to until this object has been destroyed with uenum_close. michael@0: * \snippet test/cintltst/uenumtst.c uenum_openUCharStringsEnumeration michael@0: * @param strings array of const UChar* strings (each null terminated). All storage is owned by the caller. michael@0: * @param count length of the array michael@0: * @param ec error code michael@0: * @return the new UEnumeration object. Caller is responsible for calling uenum_close to free memory. michael@0: * @see uenum_close michael@0: * @stable ICU 50 michael@0: */ michael@0: U_STABLE UEnumeration* U_EXPORT2 michael@0: uenum_openUCharStringsEnumeration(const UChar* const strings[], int32_t count, michael@0: UErrorCode* ec); michael@0: michael@0: /* Note: next function is not hidden as draft, as it is used internally (it was formerly an internal function). */ michael@0: michael@0: /** michael@0: * Given an array of const char* strings (invariant chars only), return a UEnumeration. String pointers from 0..count-1 must not be null. michael@0: * Do not free or modify either the string array or the characters it points to until this object has been destroyed with uenum_close. michael@0: * \snippet test/cintltst/uenumtst.c uenum_openCharStringsEnumeration michael@0: * @param strings array of char* strings (each null terminated). All storage is owned by the caller. michael@0: * @param count length of the array michael@0: * @param ec error code michael@0: * @return the new UEnumeration object. Caller is responsible for calling uenum_close to free memory michael@0: * @see uenum_close michael@0: * @stable ICU 50 michael@0: */ michael@0: U_STABLE UEnumeration* U_EXPORT2 michael@0: uenum_openCharStringsEnumeration(const char* const strings[], int32_t count, michael@0: UErrorCode* ec); michael@0: michael@0: #endif