uenum.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. *******************************************************************************
  3. *
  4. * Copyright (C) 2002-2010, International Business Machines
  5. * Corporation and others. All Rights Reserved.
  6. *
  7. *******************************************************************************
  8. * file name: uenum.h
  9. * encoding: US-ASCII
  10. * tab size: 8 (not used)
  11. * indentation:2
  12. *
  13. * created on: 2002jul08
  14. * created by: Vladimir Weinstein
  15. */
  16. #ifndef __UENUM_H
  17. #define __UENUM_H
  18. #include "unicode/utypes.h"
  19. #include "unicode/localpointer.h"
  20. #if U_SHOW_CPLUSPLUS_API
  21. #include "unicode/strenum.h"
  22. #endif
  23. /**
  24. * \file
  25. * \brief C API: String Enumeration
  26. */
  27. /**
  28. * An enumeration object.
  29. * For usage in C programs.
  30. * @stable ICU 2.2
  31. */
  32. struct UEnumeration;
  33. /** structure representing an enumeration object instance @stable ICU 2.2 */
  34. typedef struct UEnumeration UEnumeration;
  35. /**
  36. * Disposes of resources in use by the iterator. If en is NULL,
  37. * does nothing. After this call, any char* or UChar* pointer
  38. * returned by uenum_unext() or uenum_next() is invalid.
  39. * @param en UEnumeration structure pointer
  40. * @stable ICU 2.2
  41. */
  42. U_STABLE void U_EXPORT2
  43. uenum_close(UEnumeration* en);
  44. #if U_SHOW_CPLUSPLUS_API
  45. U_NAMESPACE_BEGIN
  46. /**
  47. * \class LocalUEnumerationPointer
  48. * "Smart pointer" class, closes a UEnumeration via uenum_close().
  49. * For most methods see the LocalPointerBase base class.
  50. *
  51. * @see LocalPointerBase
  52. * @see LocalPointer
  53. * @stable ICU 4.4
  54. */
  55. U_DEFINE_LOCAL_OPEN_POINTER(LocalUEnumerationPointer, UEnumeration, uenum_close);
  56. U_NAMESPACE_END
  57. #endif
  58. /**
  59. * Returns the number of elements that the iterator traverses. If
  60. * the iterator is out-of-sync with its service, status is set to
  61. * U_ENUM_OUT_OF_SYNC_ERROR.
  62. * This is a convenience function. It can end up being very
  63. * expensive as all the items might have to be pre-fetched (depending
  64. * on the type of data being traversed). Use with caution and only
  65. * when necessary.
  66. * @param en UEnumeration structure pointer
  67. * @param status error code, can be U_ENUM_OUT_OF_SYNC_ERROR if the
  68. * iterator is out of sync.
  69. * @return number of elements in the iterator
  70. * @stable ICU 2.2
  71. */
  72. U_STABLE int32_t U_EXPORT2
  73. uenum_count(UEnumeration* en, UErrorCode* status);
  74. /**
  75. * Returns the next element in the iterator's list. If there are
  76. * no more elements, returns NULL. If the iterator is out-of-sync
  77. * with its service, status is set to U_ENUM_OUT_OF_SYNC_ERROR and
  78. * NULL is returned. If the native service string is a char* string,
  79. * it is converted to UChar* with the invariant converter.
  80. * The result is terminated by (UChar)0.
  81. * @param en the iterator object
  82. * @param resultLength pointer to receive the length of the result
  83. * (not including the terminating \\0).
  84. * If the pointer is NULL it is ignored.
  85. * @param status the error code, set to U_ENUM_OUT_OF_SYNC_ERROR if
  86. * the iterator is out of sync with its service.
  87. * @return a pointer to the string. The string will be
  88. * zero-terminated. The return pointer is owned by this iterator
  89. * and must not be deleted by the caller. The pointer is valid
  90. * until the next call to any uenum_... method, including
  91. * uenum_next() or uenum_unext(). When all strings have been
  92. * traversed, returns NULL.
  93. * @stable ICU 2.2
  94. */
  95. U_STABLE const UChar* U_EXPORT2
  96. uenum_unext(UEnumeration* en,
  97. int32_t* resultLength,
  98. UErrorCode* status);
  99. /**
  100. * Returns the next element in the iterator's list. If there are
  101. * no more elements, returns NULL. If the iterator is out-of-sync
  102. * with its service, status is set to U_ENUM_OUT_OF_SYNC_ERROR and
  103. * NULL is returned. If the native service string is a UChar*
  104. * string, it is converted to char* with the invariant converter.
  105. * The result is terminated by (char)0. If the conversion fails
  106. * (because a character cannot be converted) then status is set to
  107. * U_INVARIANT_CONVERSION_ERROR and the return value is undefined
  108. * (but non-NULL).
  109. * @param en the iterator object
  110. * @param resultLength pointer to receive the length of the result
  111. * (not including the terminating \\0).
  112. * If the pointer is NULL it is ignored.
  113. * @param status the error code, set to U_ENUM_OUT_OF_SYNC_ERROR if
  114. * the iterator is out of sync with its service. Set to
  115. * U_INVARIANT_CONVERSION_ERROR if the underlying native string is
  116. * UChar* and conversion to char* with the invariant converter
  117. * fails. This error pertains only to current string, so iteration
  118. * might be able to continue successfully.
  119. * @return a pointer to the string. The string will be
  120. * zero-terminated. The return pointer is owned by this iterator
  121. * and must not be deleted by the caller. The pointer is valid
  122. * until the next call to any uenum_... method, including
  123. * uenum_next() or uenum_unext(). When all strings have been
  124. * traversed, returns NULL.
  125. * @stable ICU 2.2
  126. */
  127. U_STABLE const char* U_EXPORT2
  128. uenum_next(UEnumeration* en,
  129. int32_t* resultLength,
  130. UErrorCode* status);
  131. /**
  132. * Resets the iterator to the current list of service IDs. This
  133. * re-establishes sync with the service and rewinds the iterator
  134. * to start at the first element.
  135. * @param en the iterator object
  136. * @param status the error code, set to U_ENUM_OUT_OF_SYNC_ERROR if
  137. * the iterator is out of sync with its service.
  138. * @stable ICU 2.2
  139. */
  140. U_STABLE void U_EXPORT2
  141. uenum_reset(UEnumeration* en, UErrorCode* status);
  142. #if U_SHOW_CPLUSPLUS_API
  143. /**
  144. * Given a StringEnumeration, wrap it in a UEnumeration. The
  145. * StringEnumeration is adopted; after this call, the caller must not
  146. * delete it (regardless of error status).
  147. * @param adopted the C++ StringEnumeration to be wrapped in a UEnumeration.
  148. * @param ec the error code.
  149. * @return a UEnumeration wrapping the adopted StringEnumeration.
  150. * @draft ICU 4.2
  151. */
  152. U_CAPI UEnumeration* U_EXPORT2
  153. uenum_openFromStringEnumeration(U_NAMESPACE_QUALIFIER StringEnumeration* adopted, UErrorCode* ec);
  154. #endif
  155. #endif