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
00274 int32_t getBucketIndex(const UnicodeString &name, UErrorCode &errorCode) const;
00275
00283 const Bucket *getBucket(int32_t index) const;
00284
00285 private:
00286 friend class AlphabeticIndex;
00287
00288 ImmutableIndex(BucketList *bucketList, Collator *collatorPrimaryOnly)
00289 : buckets_(bucketList), collatorPrimaryOnly_(collatorPrimaryOnly) {}
00290
00291 BucketList *buckets_;
00292 Collator *collatorPrimaryOnly_;
00293 };
00294
00307 AlphabeticIndex(const Locale &locale, UErrorCode &status);
00308
00323 AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status);
00324
00335 virtual AlphabeticIndex &addLabels(const UnicodeSet &additions, UErrorCode &status);
00336
00350 virtual AlphabeticIndex &addLabels(const Locale &locale, UErrorCode &status);
00351
00356 virtual ~AlphabeticIndex();
00357
00364 ImmutableIndex *buildImmutableIndex(UErrorCode &errorCode);
00365
00378 virtual const RuleBasedCollator &getCollator() const;
00379
00380
00390 virtual const UnicodeString &getInflowLabel() const;
00391
00403 virtual AlphabeticIndex &setInflowLabel(const UnicodeString &inflowLabel, UErrorCode &status);
00404
00405
00413 virtual const UnicodeString &getOverflowLabel() const;
00414
00415
00425 virtual AlphabeticIndex &setOverflowLabel(const UnicodeString &overflowLabel, UErrorCode &status);
00426
00434 virtual const UnicodeString &getUnderflowLabel() const;
00435
00445 virtual AlphabeticIndex &setUnderflowLabel(const UnicodeString &underflowLabel, UErrorCode &status);
00446
00447
00455 virtual int32_t getMaxLabelCount() const;
00456
00469 virtual AlphabeticIndex &setMaxLabelCount(int32_t maxLabelCount, UErrorCode &status);
00470
00471
00488 virtual AlphabeticIndex &addRecord(const UnicodeString &name, const void *data, UErrorCode &status);
00489
00498 virtual AlphabeticIndex &clearRecords(UErrorCode &status);
00499
00500
00509 virtual int32_t getBucketCount(UErrorCode &status);
00510
00511
00520 virtual int32_t getRecordCount(UErrorCode &status);
00521
00522
00523
00536 virtual int32_t getBucketIndex(const UnicodeString &itemName, UErrorCode &status);
00537
00538
00545 virtual int32_t getBucketIndex() const;
00546
00547
00559 virtual UBool nextBucket(UErrorCode &status);
00560
00569 virtual const UnicodeString &getBucketLabel() const;
00570
00578 virtual UAlphabeticIndexLabelType getBucketLabelType() const;
00579
00588 virtual int32_t getBucketRecordCount() const;
00589
00590
00599 virtual AlphabeticIndex &resetBucketIterator(UErrorCode &status);
00600
00612 virtual UBool nextRecord(UErrorCode &status);
00613
00622 virtual const UnicodeString &getRecordName() const;
00623
00624
00633 virtual const void *getRecordData() const;
00634
00635
00642 virtual AlphabeticIndex &resetRecordIterator();
00643
00644 private:
00649 AlphabeticIndex(const AlphabeticIndex &other);
00650
00654 AlphabeticIndex &operator =(const AlphabeticIndex & ) { return *this;};
00655
00660 virtual UBool operator==(const AlphabeticIndex& other) const;
00661
00666 virtual UBool operator!=(const AlphabeticIndex& other) const;
00667
00668
00669 void init(const Locale *locale, UErrorCode &status);
00670
00675 void addIndexExemplars(const Locale &locale, UErrorCode &status);
00679 UBool addChineseIndexCharacters(UErrorCode &errorCode);
00680
00681 UVector *firstStringsInScript(UErrorCode &status);
00682
00683 static UnicodeString separated(const UnicodeString &item);
00684
00690 void initLabels(UVector &indexCharacters, UErrorCode &errorCode) const;
00691 BucketList *createBucketList(UErrorCode &errorCode) const;
00692 void initBuckets(UErrorCode &errorCode);
00693 void clearBuckets();
00694 void internalResetBucketIterator();
00695
00696 public:
00697
00698
00699
00700
00701
00702 #ifndef U_HIDE_INTERNAL_API
00703
00709 struct Record: public UMemory {
00710 const UnicodeString name_;
00711 const void *data_;
00712 Record(const UnicodeString &name, const void *data);
00713 ~Record();
00714 };
00716 #endif
00717
00718 private:
00719
00725 UVector *inputList_;
00726
00727 int32_t labelsIterIndex_;
00728 int32_t itemsIterIndex_;
00729 Bucket *currentBucket_;
00730
00731
00732
00733 int32_t maxLabelCount_;
00734
00735 UnicodeSet *initialLabels_;
00736
00737
00738
00739
00740 UVector *firstCharsInScripts_;
00741
00742
00743 RuleBasedCollator *collator_;
00744 RuleBasedCollator *collatorPrimaryOnly_;
00745
00746
00747 BucketList *buckets_;
00748
00749 UnicodeString inflowLabel_;
00750 UnicodeString overflowLabel_;
00751 UnicodeString underflowLabel_;
00752 UnicodeString overflowComparisonString_;
00753
00754 UnicodeString emptyString_;
00755 };
00756
00757 U_NAMESPACE_END
00758
00759 #endif // !UCONFIG_NO_COLLATION
00760 #endif