00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef INDEXCHARS_H
00013 #define INDEXCHARS_H
00014
00015 #include "unicode/utypes.h"
00016 #include "unicode/uobject.h"
00017 #include "unicode/locid.h"
00018 #include "unicode/unistr.h"
00019
00020 #if !UCONFIG_NO_COLLATION
00021
00027 U_CDECL_BEGIN
00028
00035 typedef enum UAlphabeticIndexLabelType {
00041 U_ALPHAINDEX_NORMAL = 0,
00042
00048 U_ALPHAINDEX_UNDERFLOW = 1,
00049
00058 U_ALPHAINDEX_INFLOW = 2,
00059
00065 U_ALPHAINDEX_OVERFLOW = 3
00066 } UAlphabeticIndexLabelType;
00067
00068
00069 struct UHashtable;
00070 U_CDECL_END
00071
00072 U_NAMESPACE_BEGIN
00073
00074
00075
00076 class BucketList;
00077 class Collator;
00078 class RuleBasedCollator;
00079 class StringEnumeration;
00080 class UnicodeSet;
00081 class UVector;
00082
00189 class U_I18N_API AlphabeticIndex: public UObject {
00190 public:
00199 class U_I18N_API Bucket : public UObject {
00200 public:
00205 virtual ~Bucket();
00206
00213 const UnicodeString &getLabel() const { return label_; }
00220 UAlphabeticIndexLabelType getLabelType() const { return labelType_; }
00221
00222 private:
00223 friend class AlphabeticIndex;
00224 friend class BucketList;
00225
00226 UnicodeString label_;
00227 UnicodeString lowerBoundary_;
00228 UAlphabeticIndexLabelType labelType_;
00229 Bucket *displayBucket_;
00230 int32_t displayIndex_;
00231 UVector *records_;
00232
00233 Bucket(const UnicodeString &label,
00234 const UnicodeString &lowerBoundary,
00235 UAlphabeticIndexLabelType type);
00236 };
00237
00248 class U_I18N_API ImmutableIndex : public UObject {
00249 public:
00254 virtual ~ImmutableIndex();
00255
00262 int32_t getBucketCount() const;
00263
00272 int32_t getBucketIndex(const UnicodeString &name, UErrorCode &errorCode) const;
00273
00281 const Bucket *getBucket(int32_t index) const;
00282
00283 private:
00284 friend class AlphabeticIndex;
00285
00286 ImmutableIndex(BucketList *bucketList, Collator *collatorPrimaryOnly)
00287 : buckets_(bucketList), collatorPrimaryOnly_(collatorPrimaryOnly) {}
00288
00289 BucketList *buckets_;
00290 Collator *collatorPrimaryOnly_;
00291 };
00292
00305 AlphabeticIndex(const Locale &locale, UErrorCode &status);
00306
00321 AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status);
00322
00333 virtual AlphabeticIndex &addLabels(const UnicodeSet &additions, UErrorCode &status);
00334
00348 virtual AlphabeticIndex &addLabels(const Locale &locale, UErrorCode &status);
00349
00354 virtual ~AlphabeticIndex();
00355
00362 ImmutableIndex *buildImmutableIndex(UErrorCode &errorCode);
00363
00376 virtual const RuleBasedCollator &getCollator() const;
00377
00378
00387 virtual const UnicodeString &getInflowLabel() const;
00388
00400 virtual AlphabeticIndex &setInflowLabel(const UnicodeString &inflowLabel, UErrorCode &status);
00401
00402
00410 virtual const UnicodeString &getOverflowLabel() const;
00411
00412
00422 virtual AlphabeticIndex &setOverflowLabel(const UnicodeString &overflowLabel, UErrorCode &status);
00423
00431 virtual const UnicodeString &getUnderflowLabel() const;
00432
00442 virtual AlphabeticIndex &setUnderflowLabel(const UnicodeString &underflowLabel, UErrorCode &status);
00443
00444
00452 virtual int32_t getMaxLabelCount() const;
00453
00466 virtual AlphabeticIndex &setMaxLabelCount(int32_t maxLabelCount, UErrorCode &status);
00467
00468
00485 virtual AlphabeticIndex &addRecord(const UnicodeString &name, const void *data, UErrorCode &status);
00486
00495 virtual AlphabeticIndex &clearRecords(UErrorCode &status);
00496
00497
00506 virtual int32_t getBucketCount(UErrorCode &status);
00507
00508
00517 virtual int32_t getRecordCount(UErrorCode &status);
00518
00519
00520
00533 virtual int32_t getBucketIndex(const UnicodeString &itemName, UErrorCode &status);
00534
00535
00542 virtual int32_t getBucketIndex() const;
00543
00544
00556 virtual UBool nextBucket(UErrorCode &status);
00557
00566 virtual const UnicodeString &getBucketLabel() const;
00567
00575 virtual UAlphabeticIndexLabelType getBucketLabelType() const;
00576
00585 virtual int32_t getBucketRecordCount() const;
00586
00587
00596 virtual AlphabeticIndex &resetBucketIterator(UErrorCode &status);
00597
00609 virtual UBool nextRecord(UErrorCode &status);
00610
00619 virtual const UnicodeString &getRecordName() const;
00620
00621
00630 virtual const void *getRecordData() const;
00631
00632
00639 virtual AlphabeticIndex &resetRecordIterator();
00640
00641 private:
00646 AlphabeticIndex(const AlphabeticIndex &other);
00647
00651 AlphabeticIndex &operator =(const AlphabeticIndex & ) { return *this;};
00652
00657 virtual UBool operator==(const AlphabeticIndex& other) const;
00658
00663 virtual UBool operator!=(const AlphabeticIndex& other) const;
00664
00665
00666 void init(const Locale *locale, UErrorCode &status);
00667
00672 void addIndexExemplars(const Locale &locale, UErrorCode &status);
00676 UBool addChineseIndexCharacters(UErrorCode &errorCode);
00677
00678 UVector *firstStringsInScript(UErrorCode &status);
00679
00680 static UnicodeString separated(const UnicodeString &item);
00681
00687 void initLabels(UVector &indexCharacters, UErrorCode &errorCode) const;
00688 BucketList *createBucketList(UErrorCode &errorCode) const;
00689 void initBuckets(UErrorCode &errorCode);
00690 void clearBuckets();
00691 void internalResetBucketIterator();
00692
00693 public:
00694
00695
00696
00697
00698
00699 #ifndef U_HIDE_INTERNAL_API
00700
00705 struct Record: public UMemory {
00706 const UnicodeString name_;
00707 const void *data_;
00708 Record(const UnicodeString &name, const void *data);
00709 ~Record();
00710 };
00711 #endif
00712
00713 private:
00714
00720 UVector *inputList_;
00721
00722 int32_t labelsIterIndex_;
00723 int32_t itemsIterIndex_;
00724 Bucket *currentBucket_;
00725
00726
00727
00728 int32_t maxLabelCount_;
00729
00730 UnicodeSet *initialLabels_;
00731
00732
00733
00734
00735 UVector *firstCharsInScripts_;
00736
00737
00738 RuleBasedCollator *collator_;
00739 RuleBasedCollator *collatorPrimaryOnly_;
00740
00741
00742 BucketList *buckets_;
00743
00744 UnicodeString inflowLabel_;
00745 UnicodeString overflowLabel_;
00746 UnicodeString underflowLabel_;
00747 UnicodeString overflowComparisonString_;
00748
00749 UnicodeString emptyString_;
00750 };
00751
00752 U_NAMESPACE_END
00753
00754 #endif // !UCONFIG_NO_COLLATION
00755 #endif