ICU-1972 implementation and data structure for enumeration wrapper

X-SVN-Rev: 9067
This commit is contained in:
Vladimir Weinstein 2002-07-09 06:15:34 +00:00
parent 4fc8030dfe
commit 47e06cbfe8
3 changed files with 159 additions and 87 deletions

View file

@ -1,97 +1,41 @@
/*
*******************************************************************************
*
* Copyright (C) 2002, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
* file name: uenum.cpp
* encoding: US-ASCII
* tab size: 8 (not used)
* indentation:2
*
* created on: 2002jul08
* created by: Vladimir Weinstein
*/
#include "uenumimp.h"
/**
* Disposes of resources in use by the iterator. If en is NULL,
* does nothing. After this call, any char* or UChar* pointer
* returned by uenum_unext() or uenum_next() is invalid.
* @param en UEnumeration structure pointer
*/
void uenum_close(UEnumeration* en) {
en->close(en);
}
/**
* Returns the number of elements that the iterator traverses. If
* the iterator is out-of-sync with its service, status is set to
* U_ENUM_OUT_OF_SYNC_ERROR.
* This is a convenience function. It can end up being very
* expensive as all the items might have to be pre-fetched (depending
* on the type of data being traversed). Use with caution and only
* when necessary.
* @param en UEnumeration structure pointer
* @param status error code, can be U_ENUM_OUT_OF_SYNC_ERROR if the
* iterator is out of sync.
* @return number of elements in the iterator
*/
int32_t uenum_count(UEnumeration* en, UErrorCode* status) {
return 0;
return en->count(en, status);
}
/**
* Returns the next element in the iterator's list. If there are
* no more elements, returns NULL. If the iterator is out-of-sync
* with its service, status is set to U_ENUM_OUT_OF_SYNC_ERROR and
* NULL is returned. If the native service string is a char* string,
* it is converted to UChar* with the invariant converter.
* The result is terminated by (UChar)0.
* @param en the iterator object
* @param resultLength pointer to return result to receive
* the length of the result. If the pointer is NULL it is
* ignored.
* @param status the error code, set to U_ENUM_OUT_OF_SYNC_ERROR if
* the iterator is out of sync with its service.
* @return a pointer to the string. The string will be
* zero-terminated. The return pointer is owned by this iterator
* and must not be deleted by the caller. The pointer is valid
* until the next call to any uenum_... method, including
* uenum_next() or uenum_unext(). When all strings have been
* traversed, returns NULL.
*/
const UChar* uenum_unext(UEnumeration* en,
int32_t* resultLength,
UErrorCode* status) {
return NULL;
return en->uNext(en, resultLength, status);
}
/**
* Returns the next element in the iterator's list. If there are
* no more elements, returns NULL. If the iterator is out-of-sync
* with its service, status is set to U_ENUM_OUT_OF_SYNC_ERROR and
* NULL is returned. If the native service string is a UChar*
* string, it is converted to char* with the invariant converter.
* The result is terminated by (char)0. If the conversion fails
* (because a character cannot be converted) then status is set to
* U_INVARIANT_CONVERSION_ERROR and the return value is undefined
* (but non-NULL).
* @param en the iterator object
* @param resultLength pointer to return result to receive
* the length of the result. If the pointer is NULL it is
* ignored.
* @param status the error code, set to U_ENUM_OUT_OF_SYNC_ERROR if
* the iterator is out of sync with its service. Set to
* U_INVARIANT_CONVERSION_ERROR if the underlying native string is
* UChar* and conversion to char* with the invariant converter
* fails. This error pertains only to current string, so iteration
* might be able to continue successfully.
* @return a pointer to the string. The string will be
* zero-terminated. The return pointer is owned by this iterator
* and must not be deleted by the caller. The pointer is valid
* until the next call to any uenum_... method, including
* uenum_next() or uenum_unext(). When all strings have been
* traversed, returns NULL.
*/
const char* uenum_next(UEnumeration* en,
int32_t* resultLength,
UErrorCode* status) {
return NULL;
return en->next(en, resultLength, status);
}
/**
* Resets the iterator to the current list of service IDs. This
* re-establishes sync with the service and rewinds the iterator
* to start at the first element.
* @param en the iterator object
* @param status the error code, set to U_ENUM_OUT_OF_SYNC_ERROR if
* the iterator is out of sync with its service.
*/
void uenum_reset(UErrorCode* status) {
void uenum_reset(UEnumeration* en, UErrorCode* status) {
en->reset(en, status);
}

View file

@ -1,9 +1,116 @@
/*
*******************************************************************************
*
* Copyright (C) 2002, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
* file name: uenumimp.h
* encoding: US-ASCII
* tab size: 8 (not used)
* indentation:2
*
* created on: 2002jul08
* created by: Vladimir Weinstein
*/
#ifndef __UENUMIMP_H
#define __UENUMIMP_H
#include "unicode/uenum.h"
/**
* Function type declaration for uenum_close().
*
* This function should cleanup the enumerator object
*
* @param en enumeration to be closed
*/
typedef void U_CALLCONV
UEnumClose(UEnumeration *en);
/**
* Function type declaration for uenum_count().
*
* This function should count the number of elements
* in this enumeration
*
* @param en enumeration to be counted
* @param status pointer to UErrorCode variable
* @return number of elements in enumeration
*/
typedef int32_t U_CALLCONV
UEnumCount(UEnumeration *en, UErrorCode *status);
/**
* Function type declaration for uenum_unext().
*
* This function should return the next element
* as a UChar *
*
* @param en enumeration
* @param resultLength pointer to result length
* @param status pointer to UErrorCode variable
* @return next element as UChar *
*/
typedef const UChar* U_CALLCONV
UEnumUNext(UEnumeration* en,
int32_t* resultLength,
UErrorCode* status);
/**
* Function type declaration for uenum_next().
*
* This function should return the next element
* as a char *
*
* @param en enumeration
* @param resultLength pointer to result length
* @param status pointer to UErrorCode variable
* @return next element as char *
*/
typedef const char* U_CALLCONV
UEnumNext(UEnumeration* en,
int32_t* resultLength,
UErrorCode* status);
/**
* Function type declaration for uenum_reset().
*
* This function should reset the enumeration
* object
*
* @param en enumeration
* @param status pointer to UErrorCode variable
*/
typedef void U_CALLCONV
UEnumReset(UEnumeration* en,
UErrorCode* status);
struct UEnumeration {
UChar *currentUChar;
char *currentChar;
void *context1;
void *context2;
int32_t int1;
int32_t int2;
/* these are functions that will
* be used for APIs
*/
/* called from uenum_close */
UEnumClose *close;
/* called from uenum_count */
UEnumCount *count;
/* called from uenum_unext */
UEnumUNext *uNext;
/* called from uenum_next */
UEnumNext *next;
/* called from uenum_reset */
UEnumReset *reset;
};
#endif

View file

@ -1,6 +1,22 @@
#ifndef __UENUM_H
#define __UENUM_H
/*
*******************************************************************************
*
* Copyright (C) 2002, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
* file name: uenum.h
* encoding: US-ASCII
* tab size: 8 (not used)
* indentation:2
*
* created on: 2002jul08
* created by: Vladimir Weinstein
*/
#include "unicode/utypes.h"
/** A collator.
@ -16,7 +32,8 @@ typedef struct UEnumeration UEnumeration;
* returned by uenum_unext() or uenum_next() is invalid.
* @param en UEnumeration structure pointer
*/
void uenum_close(UEnumeration* en);
U_CAPI void U_EXPORT2
uenum_close(UEnumeration* en);
/**
* Returns the number of elements that the iterator traverses. If
@ -31,7 +48,8 @@ void uenum_close(UEnumeration* en);
* iterator is out of sync.
* @return number of elements in the iterator
*/
int32_t uenum_count(UEnumeration* en, UErrorCode* status);
U_CAPI int32_t U_EXPORT2
uenum_count(UEnumeration* en, UErrorCode* status);
/**
* Returns the next element in the iterator's list. If there are
@ -53,9 +71,10 @@ int32_t uenum_count(UEnumeration* en, UErrorCode* status);
* uenum_next() or uenum_unext(). When all strings have been
* traversed, returns NULL.
*/
const UChar* uenum_unext(UEnumeration* en,
int32_t* resultLength,
UErrorCode* status);
U_CAPI const UChar* U_EXPORT2
uenum_unext(UEnumeration* en,
int32_t* resultLength,
UErrorCode* status);
/**
* Returns the next element in the iterator's list. If there are
@ -84,9 +103,10 @@ const UChar* uenum_unext(UEnumeration* en,
* uenum_next() or uenum_unext(). When all strings have been
* traversed, returns NULL.
*/
const char* uenum_next(UEnumeration* en,
int32_t* resultLength,
UErrorCode* status);
U_CAPI const char* U_EXPORT2
uenum_next(UEnumeration* en,
int32_t* resultLength,
UErrorCode* status);
/**
* Resets the iterator to the current list of service IDs. This
@ -96,6 +116,7 @@ const char* uenum_next(UEnumeration* en,
* @param status the error code, set to U_ENUM_OUT_OF_SYNC_ERROR if
* the iterator is out of sync with its service.
*/
void uenum_reset(UErrorCode* status);
U_CAPI void U_EXPORT2
uenum_reset(UEnumeration* en, UErrorCode* status);
#endif