00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef INDEXCHARS_H
00011 #define INDEXCHARS_H
00012
00013 #include "unicode/utypes.h"
00014 #include "unicode/uobject.h"
00015 #include "unicode/locid.h"
00016
00017 #if !UCONFIG_NO_COLLATION
00018
00024 U_CDECL_BEGIN
00025
00032 typedef enum UAlphabeticIndexLabelType {
00038 U_ALPHAINDEX_NORMAL = 0,
00039
00045 U_ALPHAINDEX_UNDERFLOW = 1,
00046
00055 U_ALPHAINDEX_INFLOW = 2,
00056
00062 U_ALPHAINDEX_OVERFLOW = 3
00063 } UAlphabeticIndexLabelType;
00064
00065
00066 struct UHashtable;
00067 U_CDECL_END
00068
00069 U_NAMESPACE_BEGIN
00070
00071
00072
00073 class BucketList;
00074 class Collator;
00075 class RuleBasedCollator;
00076 class StringEnumeration;
00077 class UnicodeSet;
00078 class UVector;
00079
00186 class U_I18N_API AlphabeticIndex: public UObject {
00187 public:
00196 class U_I18N_API Bucket : public UObject {
00197 public:
00202 virtual ~Bucket();
00203
00210 const UnicodeString &getLabel() const { return label_; }
00217 UAlphabeticIndexLabelType getLabelType() const { return labelType_; }
00218
00219 private:
00220 friend class AlphabeticIndex;
00221 friend class BucketList;
00222
00223 UnicodeString label_;
00224 UnicodeString lowerBoundary_;
00225 UAlphabeticIndexLabelType labelType_;
00226 Bucket *displayBucket_;
00227 int32_t displayIndex_;
00228 UVector *records_;
00229
00230 Bucket(const UnicodeString &label,
00231 const UnicodeString &lowerBoundary,
00232 UAlphabeticIndexLabelType type);
00233 };
00234
00245 class U_I18N_API ImmutableIndex : public UObject {
00246 public:
00251 virtual ~ImmutableIndex();
00252
00259 int32_t getBucketCount() const;
00260
00269 int32_t getBucketIndex(const UnicodeString &name, UErrorCode &errorCode) const;
00270
00278 const Bucket *getBucket(int32_t index) const;
00279
00280 private:
00281 friend class AlphabeticIndex;
00282
00283 ImmutableIndex(BucketList *bucketList, Collator *collatorPrimaryOnly)
00284 : buckets_(bucketList), collatorPrimaryOnly_(collatorPrimaryOnly) {}
00285
00286 BucketList *buckets_;
00287 Collator *collatorPrimaryOnly_;
00288 };
00289
00302 AlphabeticIndex(const Locale &locale, UErrorCode &status);
00303
00318 AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status);
00319
00330 virtual AlphabeticIndex &addLabels(const UnicodeSet &additions, UErrorCode &status);
00331
00345 virtual AlphabeticIndex &addLabels(const Locale &locale, UErrorCode &status);
00346
00351 virtual ~AlphabeticIndex();
00352
00359 ImmutableIndex *buildImmutableIndex(UErrorCode &errorCode);
00360
00373 virtual const RuleBasedCollator &getCollator() const;
00374
00375
00384 virtual const UnicodeString &getInflowLabel() const;
00385
00397 virtual AlphabeticIndex &setInflowLabel(const UnicodeString &inflowLabel, UErrorCode &status);
00398
00399
00407 virtual const UnicodeString &getOverflowLabel() const;
00408
00409
00419 virtual AlphabeticIndex &setOverflowLabel(const UnicodeString &overflowLabel, UErrorCode &status);
00420
00428 virtual const UnicodeString &getUnderflowLabel() const;
00429
00439 virtual AlphabeticIndex &setUnderflowLabel(const UnicodeString &underflowLabel, UErrorCode &status);
00440
00441
00449 virtual int32_t getMaxLabelCount() const;
00450
00463 virtual AlphabeticIndex &setMaxLabelCount(int32_t maxLabelCount, UErrorCode &status);
00464
00465
00482 virtual AlphabeticIndex &addRecord(const UnicodeString &name, const void *data, UErrorCode &status);
00483
00492 virtual AlphabeticIndex &clearRecords(UErrorCode &status);
00493
00494
00503 virtual int32_t getBucketCount(UErrorCode &status);
00504
00505
00514 virtual int32_t getRecordCount(UErrorCode &status);
00515
00516
00517
00530 virtual int32_t getBucketIndex(const UnicodeString &itemName, UErrorCode &status);
00531
00532
00539 virtual int32_t getBucketIndex() const;
00540
00541
00553 virtual UBool nextBucket(UErrorCode &status);
00554
00563 virtual const UnicodeString &getBucketLabel() const;
00564
00572 virtual UAlphabeticIndexLabelType getBucketLabelType() const;
00573
00582 virtual int32_t getBucketRecordCount() const;
00583
00584
00593 virtual AlphabeticIndex &resetBucketIterator(UErrorCode &status);
00594
00606 virtual UBool nextRecord(UErrorCode &status);
00607
00616 virtual const UnicodeString &getRecordName() const;
00617
00618
00627 virtual const void *getRecordData() const;
00628
00629
00636 virtual AlphabeticIndex &resetRecordIterator();
00637
00638 private:
00643 AlphabeticIndex(const AlphabeticIndex &other);
00644
00648 AlphabeticIndex &operator =(const AlphabeticIndex & ) { return *this;};
00649
00654 virtual UBool operator==(const AlphabeticIndex& other) const;
00655
00660 virtual UBool operator!=(const AlphabeticIndex& other) const;
00661
00662
00663 void init(const Locale *locale, UErrorCode &status);
00664
00669 void addIndexExemplars(const Locale &locale, UErrorCode &status);
00673 UBool addChineseIndexCharacters(UErrorCode &errorCode);
00674
00675 UVector *firstStringsInScript(UErrorCode &status);
00676
00677 static UnicodeString separated(const UnicodeString &item);
00678
00684 void initLabels(UVector &indexCharacters, UErrorCode &errorCode) const;
00685 BucketList *createBucketList(UErrorCode &errorCode) const;
00686 void initBuckets(UErrorCode &errorCode);
00687 void clearBuckets();
00688 void internalResetBucketIterator();
00689
00690 public:
00691
00692
00693
00694
00695
00696 #ifndef U_HIDE_INTERNAL_API
00697
00702 struct Record: public UMemory {
00703 const UnicodeString name_;
00704 const void *data_;
00705 Record(const UnicodeString &name, const void *data);
00706 ~Record();
00707 };
00708 #endif
00709
00710 private:
00711
00717 UVector *inputList_;
00718
00719 int32_t labelsIterIndex_;
00720 int32_t itemsIterIndex_;
00721 Bucket *currentBucket_;
00722
00723
00724
00725 int32_t maxLabelCount_;
00726
00727 UnicodeSet *initialLabels_;
00728
00729
00730
00731
00732 UVector *firstCharsInScripts_;
00733
00734
00735 RuleBasedCollator *collator_;
00736 RuleBasedCollator *collatorPrimaryOnly_;
00737
00738
00739 BucketList *buckets_;
00740
00741 UnicodeString inflowLabel_;
00742 UnicodeString overflowLabel_;
00743 UnicodeString underflowLabel_;
00744 UnicodeString overflowComparisonString_;
00745
00746 UnicodeString emptyString_;
00747 };
00748
00749 U_NAMESPACE_END
00750
00751 #endif // !UCONFIG_NO_COLLATION
00752 #endif