]> git.saurik.com Git - apple/icu.git/blame_incremental - icuSources/common/unicode/strenum.h
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / common / unicode / strenum.h
... / ...
CommitLineData
1/*
2*******************************************************************************
3*
4* Copyright (C) 2002, International Business Machines
5* Corporation and others. All Rights Reserved.
6*
7*******************************************************************************
8*/
9
10#ifndef STRENUM_H
11#define STRENUM_H
12
13#include "unicode/uobject.h"
14
15U_NAMESPACE_BEGIN
16
17class UnicodeString;
18
19/**
20 * Base class for 'pure' C++ implementations of uenum api. Adds a
21 * method that returns the next UnicodeString since in C++ this can
22 * be a common storage format for strings.
23 *
24 * <p>The model is that the enumeration is over strings maintained by
25 * a 'service.' At any point, the service might change, invalidating
26 * the enumerator (though this is expected to be rare). The iterator
27 * returns an error if this has occurred. Lack of the error is no
28 * guarantee that the service didn't change immediately after the
29 * call, so the returned string still might not be 'valid' on
30 * subsequent use.</p>
31 *
32 * <p>Strings may take the form of const char*, const UChar*, or const
33 * UnicodeString*. The type you get is determine by the variant of
34 * 'next' that you call. In general the StringEnumeration is
35 * optimized for one of these types, but all StringEnumerations can
36 * return all types. Returned strings are each terminated with a NUL.
37 * Depending on the service data, they might also include embedded NUL
38 * characters, so API is provided to optionally return the true
39 * length, counting the embedded NULs but not counting the terminating
40 * NUL.</p>
41 *
42 * <p>The pointers returned by next, unext, and snext become invalid
43 * upon any subsequent call to the enumeration's destructor, next,
44 * unext, snext, or reset.</p>
45 *
46 * @draft ICU 2.4
47 */
48class U_COMMON_API StringEnumeration : public UObject {
49 public:
50 /**
51 * Destructor.
52 * @draft ICU 2.4
53 */
54 virtual ~StringEnumeration();
55
56 /**
57 * <p>Return the number of elements that the iterator traverses. If
58 * the iterator is out of sync with its service, status is set to
59 * U_ENUM_OUT_OF_SYNC_ERROR, and the return value is zero.</p>
60 *
61 * <p>The return value will not change except possibly as a result of
62 * a subsequent call to reset, or if the iterator becomes out of sync.</p>
63 *
64 * <p>This is a convenience function. It can end up being very
65 * expensive as all the items might have to be pre-fetched
66 * (depending on the storage format of the data being
67 * traversed).</p>
68 *
69 * @param status the error code.
70 * @return number of elements in the iterator.
71 *
72 * @draft ICU 2.4 */
73 virtual int32_t count(UErrorCode& status) const = 0;
74
75 /**
76 * <p>Returns the next element as a NUL-terminated char*. If there
77 * are no more elements, returns NULL. If the resultLength pointer
78 * is not NULL, the length of the string (not counting the
79 * terminating NUL) is returned at that address. If an error
80 * status is returned, the value at resultLength is undefined.</p>
81 *
82 * <p>The returned pointer is owned by this iterator and must not be
83 * deleted by the caller. The pointer is valid until the next call
84 * to next, unext, snext, reset, or the enumerator's destructor.</p>
85 *
86 * <p>If the iterator is out of sync with its service, status is set
87 * to U_ENUM_OUT_OF_SYNC_ERROR and NULL is returned.</p>
88 *
89 * <p>If the native service string is a UChar* string, it is
90 * converted to char* with the invariant converter. If the
91 * conversion fails (because a character cannot be converted) then
92 * status is set to U_INVARIANT_CONVERSION_ERROR and the return
93 * value is undefined (though not NULL).</p>
94 *
95 * @param status the error code.
96 * @param resultLength a pointer to receive the length, can be NULL.
97 * @return a pointer to the string, or NULL.
98 *
99 * @draft ICU 2.4
100 */
101 virtual const char* next(int32_t *resultLength, UErrorCode& status) = 0;
102
103 /**
104 * <p>Returns the next element as a NUL-terminated UChar*. If there
105 * are no more elements, returns NULL. If the resultLength pointer
106 * is not NULL, the length of the string (not counting the
107 * terminating NUL) is returned at that address. If an error
108 * status is returned, the value at resultLength is undefined.</p>
109 *
110 * <p>The returned pointer is owned by this iterator and must not be
111 * deleted by the caller. The pointer is valid until the next call
112 * to next, unext, snext, reset, or the enumerator's destructor.</p>
113 *
114 * <p>If the iterator is out of sync with its service, status is set
115 * to U_ENUM_OUT_OF_SYNC_ERROR and NULL is returned.</p>
116 *
117 * @param status the error code.
118 * @param resultLength a ponter to receive the length, can be NULL.
119 * @return a pointer to the string, or NULL.
120 *
121 * @draft ICU 2.4
122 */
123 virtual const UChar* unext(int32_t *resultLength, UErrorCode& status) = 0;
124
125 /**
126 * <p>Returns the next element a UnicodeString*. If there are no
127 * more elements, returns NULL.</p>
128 *
129 * <p>The returned pointer is owned by this iterator and must not be
130 * deleted by the caller. The pointer is valid until the next call
131 * to next, unext, snext, reset, or the enumerator's destructor.</p>
132 *
133 * <p>If the iterator is out of sync with its service, status is set
134 * to U_ENUM_OUT_OF_SYNC_ERROR and NULL is returned.</p>
135 *
136 * @param status the error code.
137 * @return a pointer to the string, or NULL.
138 *
139 * @draft ICU 2.4
140 */
141 virtual const UnicodeString* snext(UErrorCode& status) = 0;
142
143 /**
144 * <p>Resets the iterator. This re-establishes sync with the
145 * service and rewinds the iterator to start at the first
146 * element.</p>
147 *
148 * <p>Previous pointers returned by next, unext, or snext become
149 * invalid, and the value returned by count might change.</p>
150 *
151 * @param status the error code.
152 *
153 * @draft ICU 2.4
154 */
155 virtual void reset(UErrorCode& status) = 0;
156};
157
158inline StringEnumeration::~StringEnumeration() {
159}
160
161U_NAMESPACE_END
162
163/* STRENUM_H */
164#endif