michael@0: /*
michael@0: *******************************************************************************
michael@0: *
michael@0: * Copyright (C) 2011-2013 International Business Machines
michael@0: * Corporation and others. All Rights Reserved.
michael@0: *
michael@0: *******************************************************************************
michael@0: */
michael@0:
michael@0: #ifndef INDEXCHARS_H
michael@0: #define INDEXCHARS_H
michael@0:
michael@0: #include "unicode/utypes.h"
michael@0: #include "unicode/uobject.h"
michael@0: #include "unicode/locid.h"
michael@0:
michael@0:
michael@0: #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_NORMALIZATION
michael@0:
michael@0: /**
michael@0: * \file
michael@0: * \brief C++ API: Index Characters
michael@0: */
michael@0:
michael@0: U_CDECL_BEGIN
michael@0:
michael@0: /**
michael@0: * Constants for Alphabetic Index Label Types.
michael@0: * The form of these enum constants anticipates having a plain C API
michael@0: * for Alphabetic Indexes that will also use them.
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: typedef enum UAlphabeticIndexLabelType {
michael@0: /**
michael@0: * Normal Label, typically the starting letter of the names
michael@0: * in the bucket with this label.
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: U_ALPHAINDEX_NORMAL = 0,
michael@0:
michael@0: /**
michael@0: * Undeflow Label. The bucket with this label contains names
michael@0: * in scripts that sort before any of the bucket labels in this index.
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: U_ALPHAINDEX_UNDERFLOW = 1,
michael@0:
michael@0: /**
michael@0: * Inflow Label. The bucket with this label contains names
michael@0: * in scripts that sort between two of the bucket labels in this index.
michael@0: * Inflow labels are created when an index contains normal labels for
michael@0: * multiple scripts, and skips other scripts that sort between some of the
michael@0: * included scripts.
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: U_ALPHAINDEX_INFLOW = 2,
michael@0:
michael@0: /**
michael@0: * Overflow Label. Te bucket with this label contains names in scripts
michael@0: * that sort after all of the bucket labels in this index.
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: U_ALPHAINDEX_OVERFLOW = 3
michael@0: } UAlphabeticIndexLabelType;
michael@0:
michael@0:
michael@0: struct UHashtable;
michael@0: U_CDECL_END
michael@0:
michael@0: U_NAMESPACE_BEGIN
michael@0:
michael@0: // Forward Declarations
michael@0:
michael@0: class BucketList;
michael@0: class Collator;
michael@0: class RuleBasedCollator;
michael@0: class StringEnumeration;
michael@0: class UnicodeSet;
michael@0: class UVector;
michael@0:
michael@0: /**
michael@0: * AlphabeticIndex supports the creation of a UI index appropriate for a given language.
michael@0: * It can support either direct use, or use with a client that doesn't support localized collation.
michael@0: * The following is an example of what an index might look like in a UI:
michael@0: *
michael@0: *
michael@0: * ... A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ...
michael@0: *
michael@0: * A
michael@0: * Addison
michael@0: * Albertson
michael@0: * Azensky
michael@0: * B
michael@0: * Baker
michael@0: * ...
michael@0: *
michael@0: *
michael@0: * The class can generate a list of labels for use as a UI "index", that is, a list of
michael@0: * clickable characters (or character sequences) that allow the user to see a segment
michael@0: * (bucket) of a larger "target" list. That is, each label corresponds to a bucket in
michael@0: * the target list, where everything in the bucket is greater than or equal to the character
michael@0: * (according to the locale's collation). Strings can be added to the index;
michael@0: * they will be in sorted order in the right bucket.
michael@0: *
michael@0: * The class also supports having buckets for strings before the first (underflow),
michael@0: * after the last (overflow), and between scripts (inflow). For example, if the index
michael@0: * is constructed with labels for Russian and English, Greek characters would fall
michael@0: * into an inflow bucket between the other two scripts.
michael@0: *
michael@0: * The AlphabeticIndex class is not intended for public subclassing.
michael@0: *
michael@0: *
Note: If you expect to have a lot of ASCII or Latin characters
michael@0: * as well as characters from the user's language,
michael@0: * then it is a good idea to call addLabels(Locale::getEnglish(), status).
michael@0: *
michael@0: * Direct Use
michael@0: * The following shows an example of building an index directly.
michael@0: * The "show..." methods below are just to illustrate usage.
michael@0: *
michael@0: *
michael@0: * // Create a simple index. "Item" is assumed to be an application
michael@0: * // defined type that the application's UI and other processing knows about,
michael@0: * // and that has a name.
michael@0: *
michael@0: * UErrorCode status = U_ZERO_ERROR;
michael@0: * AlphabeticIndex index = new AlphabeticIndex(desiredLocale, status);
michael@0: * index->addLabels(additionalLocale, status);
michael@0: * for (Item *item in some source of Items ) {
michael@0: * index->addRecord(item->name(), item, status);
michael@0: * }
michael@0: * ...
michael@0: * // Show index at top. We could skip or gray out empty buckets
michael@0: *
michael@0: * while (index->nextBucket(status)) {
michael@0: * if (showAll || index->getBucketRecordCount() != 0) {
michael@0: * showLabelAtTop(UI, index->getBucketLabel());
michael@0: * }
michael@0: * }
michael@0: * ...
michael@0: * // Show the buckets with their contents, skipping empty buckets
michael@0: *
michael@0: * index->resetBucketIterator(status);
michael@0: * while (index->nextBucket(status)) {
michael@0: * if (index->getBucketRecordCount() != 0) {
michael@0: * showLabelInList(UI, index->getBucketLabel());
michael@0: * while (index->nextRecord(status)) {
michael@0: * showIndexedItem(UI, static_cast- (index->getRecordData()))
michael@0: *
michael@0: *
michael@0: * The caller can build different UIs using this class.
michael@0: * For example, an index character could be omitted or grayed-out
michael@0: * if its bucket is empty. Small buckets could also be combined based on size, such as:
michael@0: *
michael@0: *
michael@0: * ... A-F G-N O-Z ...
michael@0: *
michael@0: *
michael@0: * Client Support
michael@0: * Callers can also use the AlphabeticIndex::ImmutableIndex, or the AlphabeticIndex itself,
michael@0: * to support sorting on a client that doesn't support AlphabeticIndex functionality.
michael@0: *
michael@0: *
The ImmutableIndex is both immutable and thread-safe.
michael@0: * The corresponding AlphabeticIndex methods are not thread-safe because
michael@0: * they "lazily" build the index buckets.
michael@0: *
michael@0: * - ImmutableIndex.getBucket(index) provides random access to all
michael@0: * buckets and their labels and label types.
michael@0: *
- The AlphabeticIndex bucket iterator or ImmutableIndex.getBucket(0..getBucketCount-1)
michael@0: * can be used to get a list of the labels,
michael@0: * such as "...", "A", "B",..., and send that list to the client.
michael@0: *
- When the client has a new name, it sends that name to the server.
michael@0: * The server needs to call the following methods,
michael@0: * and communicate the bucketIndex and collationKey back to the client.
michael@0: *
michael@0: *
michael@0: * int32_t bucketIndex = index.getBucketIndex(name, status);
michael@0: * const UnicodeString &label = immutableIndex.getBucket(bucketIndex)->getLabel(); // optional
michael@0: * int32_t skLength = collator.getSortKey(name, sk, skCapacity);
michael@0: *
michael@0: *
michael@0: * - The client would put the name (and associated information) into its bucket for bucketIndex. The sort key sk is a
michael@0: * sequence of bytes that can be compared with a binary compare, and produce the right localized result.
michael@0: *
michael@0: *
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: class U_I18N_API AlphabeticIndex: public UObject {
michael@0: public:
michael@0: #ifdef U_HIDE_DRAFT_API
michael@0: class Bucket;
michael@0: #else
michael@0: /**
michael@0: * An index "bucket" with a label string and type.
michael@0: * It is referenced by getBucketIndex(),
michael@0: * and returned by ImmutableIndex.getBucket().
michael@0: *
michael@0: * The Bucket class is not intended for public subclassing.
michael@0: * @draft ICU 51
michael@0: */
michael@0: class U_I18N_API Bucket : public UObject {
michael@0: public:
michael@0: /**
michael@0: * Destructor.
michael@0: * @draft ICU 51
michael@0: */
michael@0: virtual ~Bucket();
michael@0:
michael@0: /**
michael@0: * Returns the label string.
michael@0: *
michael@0: * @return the label string for the bucket
michael@0: * @draft ICU 51
michael@0: */
michael@0: const UnicodeString &getLabel() const { return label_; }
michael@0: /**
michael@0: * Returns whether this bucket is a normal, underflow, overflow, or inflow bucket.
michael@0: *
michael@0: * @return the bucket label type
michael@0: * @draft ICU 51
michael@0: */
michael@0: UAlphabeticIndexLabelType getLabelType() const { return labelType_; }
michael@0:
michael@0: private:
michael@0: friend class AlphabeticIndex;
michael@0: friend class BucketList;
michael@0:
michael@0: UnicodeString label_;
michael@0: UnicodeString lowerBoundary_;
michael@0: UAlphabeticIndexLabelType labelType_;
michael@0: Bucket *displayBucket_;
michael@0: int32_t displayIndex_;
michael@0: UVector *records_; // Records are owned by the inputList_ vector.
michael@0:
michael@0: Bucket(const UnicodeString &label, // Parameter strings are copied.
michael@0: const UnicodeString &lowerBoundary,
michael@0: UAlphabeticIndexLabelType type);
michael@0: };
michael@0:
michael@0: /**
michael@0: * Immutable, thread-safe version of AlphabeticIndex.
michael@0: * This class provides thread-safe methods for bucketing,
michael@0: * and random access to buckets and their properties,
michael@0: * but does not offer adding records to the index.
michael@0: *
michael@0: * The ImmutableIndex class is not intended for public subclassing.
michael@0: *
michael@0: * @draft ICU 51
michael@0: */
michael@0: class U_I18N_API ImmutableIndex : public UObject {
michael@0: public:
michael@0: /**
michael@0: * Destructor.
michael@0: * @draft ICU 51
michael@0: */
michael@0: virtual ~ImmutableIndex();
michael@0:
michael@0: /**
michael@0: * Returns the number of index buckets and labels, including underflow/inflow/overflow.
michael@0: *
michael@0: * @return the number of index buckets
michael@0: * @draft ICU 51
michael@0: */
michael@0: int32_t getBucketCount() const;
michael@0:
michael@0: /**
michael@0: * Finds the index bucket for the given name and returns the number of that bucket.
michael@0: * Use getBucket() to get the bucket's properties.
michael@0: *
michael@0: * @param name the string to be sorted into an index bucket
michael@0: * @return the bucket number for the name
michael@0: * @draft ICU 51
michael@0: */
michael@0: int32_t getBucketIndex(const UnicodeString &name, UErrorCode &errorCode) const;
michael@0:
michael@0: /**
michael@0: * Returns the index-th bucket. Returns NULL if the index is out of range.
michael@0: *
michael@0: * @param index bucket number
michael@0: * @return the index-th bucket
michael@0: * @draft ICU 51
michael@0: */
michael@0: const Bucket *getBucket(int32_t index) const;
michael@0:
michael@0: private:
michael@0: friend class AlphabeticIndex;
michael@0:
michael@0: ImmutableIndex(BucketList *bucketList, Collator *collatorPrimaryOnly)
michael@0: : buckets_(bucketList), collatorPrimaryOnly_(collatorPrimaryOnly) {}
michael@0:
michael@0: BucketList *buckets_;
michael@0: Collator *collatorPrimaryOnly_;
michael@0: };
michael@0: #endif /* U_HIDE_DRAFT_API */
michael@0:
michael@0: /**
michael@0: * Construct an AlphabeticIndex object for the specified locale. If the locale's
michael@0: * data does not include index characters, a set of them will be
michael@0: * synthesized based on the locale's exemplar characters. The locale
michael@0: * determines the sorting order for both the index characters and the
michael@0: * user item names appearing under each Index character.
michael@0: *
michael@0: * @param locale the desired locale.
michael@0: * @param status Error code, will be set with the reason if the construction
michael@0: * of the AlphabeticIndex object fails.
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: AlphabeticIndex(const Locale &locale, UErrorCode &status);
michael@0:
michael@0: #ifndef U_HIDE_DRAFT_API
michael@0: /**
michael@0: * Construct an AlphabeticIndex that uses a specific collator.
michael@0: *
michael@0: * The index will be created with no labels; the addLabels() function must be called
michael@0: * after creation to add the desired labels to the index.
michael@0: *
michael@0: * The index adopts the collator, and is responsible for deleting it.
michael@0: * The caller should make no further use of the collator after creating the index.
michael@0: *
michael@0: * @param collator The collator to use to order the contents of this index.
michael@0: * @param status Error code, will be set with the reason if the
michael@0: * operation fails.
michael@0: * @draft ICU 51
michael@0: */
michael@0: AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status);
michael@0: #endif /* U_HIDE_DRAFT_API */
michael@0:
michael@0: /**
michael@0: * Add Labels to this Index. The labels are additions to those
michael@0: * that are already in the index; they do not replace the existing
michael@0: * ones.
michael@0: * @param additions The additional characters to add to the index, such as A-Z.
michael@0: * @param status Error code, will be set with the reason if the
michael@0: * operation fails.
michael@0: * @return this, for chaining
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual AlphabeticIndex &addLabels(const UnicodeSet &additions, UErrorCode &status);
michael@0:
michael@0: /**
michael@0: * Add the index characters from a Locale to the index. The labels
michael@0: * are added to those that are already in the index; they do not replace the
michael@0: * existing index characters. The collation order for this index is not
michael@0: * changed; it remains that of the locale that was originally specified
michael@0: * when creating this Index.
michael@0: *
michael@0: * @param locale The locale whose index characters are to be added.
michael@0: * @param status Error code, will be set with the reason if the
michael@0: * operation fails.
michael@0: * @return this, for chaining
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual AlphabeticIndex &addLabels(const Locale &locale, UErrorCode &status);
michael@0:
michael@0: /**
michael@0: * Destructor
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual ~AlphabeticIndex();
michael@0:
michael@0: #ifndef U_HIDE_DRAFT_API
michael@0: /**
michael@0: * Builds an immutable, thread-safe version of this instance, without data records.
michael@0: *
michael@0: * @return an immutable index instance
michael@0: * @draft ICU 51
michael@0: */
michael@0: ImmutableIndex *buildImmutableIndex(UErrorCode &errorCode);
michael@0: #endif /* U_HIDE_DRAFT_API */
michael@0:
michael@0: /**
michael@0: * Get the Collator that establishes the ordering of the items in this index.
michael@0: * Ownership of the collator remains with the AlphabeticIndex instance.
michael@0: *
michael@0: * The returned collator is a reference to the internal collator used by this
michael@0: * index. It may be safely used to compare the names of items or to get
michael@0: * sort keys for names. However if any settings need to be changed,
michael@0: * or other non-const methods called, a cloned copy must be made first.
michael@0: *
michael@0: * @return The collator
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual const RuleBasedCollator &getCollator() const;
michael@0:
michael@0:
michael@0: /**
michael@0: * Get the default label used for abbreviated buckets between other index characters.
michael@0: * For example, consider the labels when Latin and Greek are used:
michael@0: * X Y Z ... Α Β Γ.
michael@0: *
michael@0: * @return inflow label
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual const UnicodeString &getInflowLabel() const;
michael@0:
michael@0: /**
michael@0: * Set the default label used for abbreviated buckets between other index characters.
michael@0: * An inflow label will be automatically inserted if two otherwise-adjacent label characters
michael@0: * are from different scripts, e.g. Latin and Cyrillic, and a third script, e.g. Greek,
michael@0: * sorts between the two. The default inflow character is an ellipsis (...)
michael@0: *
michael@0: * @param inflowLabel the new Inflow label.
michael@0: * @param status Error code, will be set with the reason if the operation fails.
michael@0: * @return this
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual AlphabeticIndex &setInflowLabel(const UnicodeString &inflowLabel, UErrorCode &status);
michael@0:
michael@0:
michael@0: /**
michael@0: * Get the special label used for items that sort after the last normal label,
michael@0: * and that would not otherwise have an appropriate label.
michael@0: *
michael@0: * @return the overflow label
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual const UnicodeString &getOverflowLabel() const;
michael@0:
michael@0:
michael@0: /**
michael@0: * Set the label used for items that sort after the last normal label,
michael@0: * and that would not otherwise have an appropriate label.
michael@0: *
michael@0: * @param overflowLabel the new overflow label.
michael@0: * @param status Error code, will be set with the reason if the operation fails.
michael@0: * @return this
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual AlphabeticIndex &setOverflowLabel(const UnicodeString &overflowLabel, UErrorCode &status);
michael@0:
michael@0: /**
michael@0: * Get the special label used for items that sort before the first normal label,
michael@0: * and that would not otherwise have an appropriate label.
michael@0: *
michael@0: * @return underflow label
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual const UnicodeString &getUnderflowLabel() const;
michael@0:
michael@0: /**
michael@0: * Set the label used for items that sort before the first normal label,
michael@0: * and that would not otherwise have an appropriate label.
michael@0: *
michael@0: * @param underflowLabel the new underflow label.
michael@0: * @param status Error code, will be set with the reason if the operation fails.
michael@0: * @return this
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual AlphabeticIndex &setUnderflowLabel(const UnicodeString &underflowLabel, UErrorCode &status);
michael@0:
michael@0:
michael@0: /**
michael@0: * Get the limit on the number of labels permitted in the index.
michael@0: * The number does not include over, under and inflow labels.
michael@0: *
michael@0: * @return maxLabelCount maximum number of labels.
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual int32_t getMaxLabelCount() const;
michael@0:
michael@0: /**
michael@0: * Set a limit on the number of labels permitted in the index.
michael@0: * The number does not include over, under and inflow labels.
michael@0: * Currently, if the number is exceeded, then every
michael@0: * nth item is removed to bring the count down.
michael@0: * A more sophisticated mechanism may be available in the future.
michael@0: *
michael@0: * @param maxLabelCount the maximum number of labels.
michael@0: * @param status error code
michael@0: * @return This, for chaining
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual AlphabeticIndex &setMaxLabelCount(int32_t maxLabelCount, UErrorCode &status);
michael@0:
michael@0:
michael@0: /**
michael@0: * Add a record to the index. Each record will be associated with an index Bucket
michael@0: * based on the record's name. The list of records for each bucket will be sorted
michael@0: * based on the collation ordering of the names in the index's locale.
michael@0: * Records with duplicate names are permitted; they will be kept in the order
michael@0: * that they were added.
michael@0: *
michael@0: * @param name The display name for the Record. The Record will be placed in
michael@0: * a bucket based on this name.
michael@0: * @param data An optional pointer to user data associated with this
michael@0: * item. When iterating the contents of a bucket, both the
michael@0: * data pointer the name will be available for each Record.
michael@0: * @param status Error code, will be set with the reason if the operation fails.
michael@0: * @return This, for chaining.
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual AlphabeticIndex &addRecord(const UnicodeString &name, const void *data, UErrorCode &status);
michael@0:
michael@0: /**
michael@0: * Remove all Records from the Index. The set of Buckets, which define the headings under
michael@0: * which records are classified, is not altered.
michael@0: *
michael@0: * @param status Error code, will be set with the reason if the operation fails.
michael@0: * @return This, for chaining.
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual AlphabeticIndex &clearRecords(UErrorCode &status);
michael@0:
michael@0:
michael@0: /** Get the number of labels in this index.
michael@0: * Note: may trigger lazy index construction.
michael@0: *
michael@0: * @param status Error code, will be set with the reason if the operation fails.
michael@0: * @return The number of labels in this index, including any under, over or
michael@0: * in-flow labels.
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual int32_t getBucketCount(UErrorCode &status);
michael@0:
michael@0:
michael@0: /** Get the total number of Records in this index, that is, the number
michael@0: * of pairs added.
michael@0: *
michael@0: * @param status Error code, will be set with the reason if the operation fails.
michael@0: * @return The number of records in this index, that is, the total number
michael@0: * of (name, data) items added with addRecord().
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual int32_t getRecordCount(UErrorCode &status);
michael@0:
michael@0:
michael@0:
michael@0: /**
michael@0: * Given the name of a record, return the zero-based index of the Bucket
michael@0: * in which the item should appear. The name need not be in the index.
michael@0: * A Record will not be added to the index by this function.
michael@0: * Bucket numbers are zero-based, in Bucket iteration order.
michael@0: *
michael@0: * @param itemName The name whose bucket position in the index is to be determined.
michael@0: * @param status Error code, will be set with the reason if the operation fails.
michael@0: * @return The bucket number for this name.
michael@0: * @stable ICU 4.8
michael@0: *
michael@0: */
michael@0: virtual int32_t getBucketIndex(const UnicodeString &itemName, UErrorCode &status);
michael@0:
michael@0:
michael@0: /**
michael@0: * Get the zero based index of the current Bucket from an iteration
michael@0: * over the Buckets of this index. Return -1 if no iteration is in process.
michael@0: * @return the index of the current Bucket
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual int32_t getBucketIndex() const;
michael@0:
michael@0:
michael@0: /**
michael@0: * Advance the iteration over the Buckets of this index. Return FALSE if
michael@0: * there are no more Buckets.
michael@0: *
michael@0: * @param status Error code, will be set with the reason if the operation fails.
michael@0: * U_ENUM_OUT_OF_SYNC_ERROR will be reported if the index is modified while
michael@0: * an enumeration of its contents are in process.
michael@0: *
michael@0: * @return TRUE if success, FALSE if at end of iteration
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual UBool nextBucket(UErrorCode &status);
michael@0:
michael@0: /**
michael@0: * Return the name of the Label of the current bucket from an iteration over the buckets.
michael@0: * If the iteration is before the first Bucket (nextBucket() has not been called),
michael@0: * or after the last, return an empty string.
michael@0: *
michael@0: * @return the bucket label.
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual const UnicodeString &getBucketLabel() const;
michael@0:
michael@0: /**
michael@0: * Return the type of the label for the current Bucket (selected by the
michael@0: * iteration over Buckets.)
michael@0: *
michael@0: * @return the label type.
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual UAlphabeticIndexLabelType getBucketLabelType() const;
michael@0:
michael@0: /**
michael@0: * Get the number of Records in the current Bucket.
michael@0: * If the current bucket iteration position is before the first label or after the
michael@0: * last, return 0.
michael@0: *
michael@0: * @return the number of Records.
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual int32_t getBucketRecordCount() const;
michael@0:
michael@0:
michael@0: /**
michael@0: * Reset the Bucket iteration for this index. The next call to nextBucket()
michael@0: * will restart the iteration at the first label.
michael@0: *
michael@0: * @param status Error code, will be set with the reason if the operation fails.
michael@0: * @return this, for chaining.
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual AlphabeticIndex &resetBucketIterator(UErrorCode &status);
michael@0:
michael@0: /**
michael@0: * Advance to the next record in the current Bucket.
michael@0: * When nextBucket() is called, Record iteration is reset to just before the
michael@0: * first Record in the new Bucket.
michael@0: *
michael@0: * @param status Error code, will be set with the reason if the operation fails.
michael@0: * U_ENUM_OUT_OF_SYNC_ERROR will be reported if the index is modified while
michael@0: * an enumeration of its contents are in process.
michael@0: * @return TRUE if successful, FALSE when the iteration advances past the last item.
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual UBool nextRecord(UErrorCode &status);
michael@0:
michael@0: /**
michael@0: * Get the name of the current Record.
michael@0: * Return an empty string if the Record iteration position is before first
michael@0: * or after the last.
michael@0: *
michael@0: * @return The name of the current index item.
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual const UnicodeString &getRecordName() const;
michael@0:
michael@0:
michael@0: /**
michael@0: * Return the data pointer of the Record currently being iterated over.
michael@0: * Return NULL if the current iteration position before the first item in this Bucket,
michael@0: * or after the last.
michael@0: *
michael@0: * @return The current Record's data pointer.
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual const void *getRecordData() const;
michael@0:
michael@0:
michael@0: /**
michael@0: * Reset the Record iterator position to before the first Record in the current Bucket.
michael@0: *
michael@0: * @return This, for chaining.
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: virtual AlphabeticIndex &resetRecordIterator();
michael@0:
michael@0: private:
michael@0: /**
michael@0: * No Copy constructor.
michael@0: * @internal
michael@0: */
michael@0: AlphabeticIndex(const AlphabeticIndex &other);
michael@0:
michael@0: /**
michael@0: * No assignment.
michael@0: */
michael@0: AlphabeticIndex &operator =(const AlphabeticIndex & /*other*/) { return *this;};
michael@0:
michael@0: /**
michael@0: * No Equality operators.
michael@0: * @internal
michael@0: */
michael@0: virtual UBool operator==(const AlphabeticIndex& other) const;
michael@0:
michael@0: /**
michael@0: * Inequality operator.
michael@0: * @internal
michael@0: */
michael@0: virtual UBool operator!=(const AlphabeticIndex& other) const;
michael@0:
michael@0: // Common initialization, for use from all constructors.
michael@0: void init(const Locale *locale, UErrorCode &status);
michael@0:
michael@0: /**
michael@0: * This method is called to get the index exemplars. Normally these come from the locale directly,
michael@0: * but if they aren't available, we have to synthesize them.
michael@0: */
michael@0: void addIndexExemplars(const Locale &locale, UErrorCode &status);
michael@0: /**
michael@0: * Add Chinese index characters from the tailoring.
michael@0: */
michael@0: UBool addChineseIndexCharacters(UErrorCode &errorCode);
michael@0:
michael@0: UVector *firstStringsInScript(UErrorCode &status);
michael@0:
michael@0: static UnicodeString separated(const UnicodeString &item);
michael@0:
michael@0: /**
michael@0: * Determine the best labels to use.
michael@0: * This is based on the exemplars, but we also process to make sure that they are unique,
michael@0: * and sort differently, and that the overall list is small enough.
michael@0: */
michael@0: void initLabels(UVector &indexCharacters, UErrorCode &errorCode) const;
michael@0: BucketList *createBucketList(UErrorCode &errorCode) const;
michael@0: void initBuckets(UErrorCode &errorCode);
michael@0: void clearBuckets();
michael@0: void internalResetBucketIterator();
michael@0:
michael@0: public:
michael@0:
michael@0: // The Record is declared public only to allow access from
michael@0: // implementation code written in plain C.
michael@0: // It is not intended for public use.
michael@0:
michael@0: #ifndef U_HIDE_INTERNAL_API
michael@0: /**
michael@0: * A (name, data) pair, to be sorted by name into one of the index buckets.
michael@0: * The user data is not used by the index implementation.
michael@0: * @internal
michael@0: */
michael@0: struct Record: public UMemory {
michael@0: const UnicodeString name_;
michael@0: const void *data_;
michael@0: Record(const UnicodeString &name, const void *data);
michael@0: ~Record();
michael@0: };
michael@0: #endif /* U_HIDE_INTERNAL_API */
michael@0:
michael@0: private:
michael@0:
michael@0: /**
michael@0: * Holds all user records before they are distributed into buckets.
michael@0: * Type of contents is (Record *)
michael@0: * @internal
michael@0: */
michael@0: UVector *inputList_;
michael@0:
michael@0: int32_t labelsIterIndex_; // Index of next item to return.
michael@0: int32_t itemsIterIndex_;
michael@0: Bucket *currentBucket_; // While an iteration of the index in underway,
michael@0: // point to the bucket for the current label.
michael@0: // NULL when no iteration underway.
michael@0:
michael@0: int32_t maxLabelCount_; // Limit on # of labels permitted in the index.
michael@0:
michael@0: UnicodeSet *initialLabels_; // Initial (unprocessed) set of Labels. Union
michael@0: // of those explicitly set by the user plus
michael@0: // those from locales. Raw values, before
michael@0: // crunching into bucket labels.
michael@0:
michael@0: UVector *firstCharsInScripts_; // The first character from each script,
michael@0: // in collation order.
michael@0:
michael@0: RuleBasedCollator *collator_;
michael@0: RuleBasedCollator *collatorPrimaryOnly_;
michael@0:
michael@0: // Lazy evaluated: null means that we have not built yet.
michael@0: BucketList *buckets_;
michael@0:
michael@0: UnicodeString inflowLabel_;
michael@0: UnicodeString overflowLabel_;
michael@0: UnicodeString underflowLabel_;
michael@0: UnicodeString overflowComparisonString_;
michael@0:
michael@0: UnicodeString emptyString_;
michael@0: };
michael@0:
michael@0: U_NAMESPACE_END
michael@0:
michael@0: #endif /* UCONFIG_NO_COLLATION / UCONFIG_NO_NORMALIZATION */
michael@0: #endif