ICU 54.1 54.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
alphaindex.h
Go to the documentation of this file.
1 /*
2 *******************************************************************************
3 *
4 * Copyright (C) 2011-2014 International Business Machines
5 * Corporation and others. All Rights Reserved.
6 *
7 *******************************************************************************
8 */
9
10 #ifndef INDEXCHARS_H
11 #define INDEXCHARS_H
12
13 #include "unicode/utypes.h"
14 #include "unicode/uobject.h"
15 #include "unicode/locid.h"
16
17 #if !UCONFIG_NO_COLLATION
18
24 U_CDECL_BEGIN
25
32 typedef enum UAlphabeticIndexLabelType {
38 U_ALPHAINDEX_NORMAL = 0,
39
45 U_ALPHAINDEX_UNDERFLOW = 1,
46
55 U_ALPHAINDEX_INFLOW = 2,
56
62 U_ALPHAINDEX_OVERFLOW = 3
63 } UAlphabeticIndexLabelType;
64
65
66 struct UHashtable;
67 U_CDECL_END
68
69 U_NAMESPACE_BEGIN
70
71 // Forward Declarations
72
73 class BucketList;
74 class Collator;
75 class RuleBasedCollator;
76 class StringEnumeration;
77 class UnicodeSet;
78 class UVector;
79
186 class U_I18N_API AlphabeticIndex: public UObject {
187 public:
196 class U_I18N_API Bucket : public UObject {
197 public:
202 virtual ~Bucket();
203
210 const UnicodeString &getLabel() const { return label_; }
217 UAlphabeticIndexLabelType getLabelType() const { return labelType_; }
218
219 private:
220 friend class AlphabeticIndex;
221 friend class BucketList;
222
223 UnicodeString label_;
224 UnicodeString lowerBoundary_;
225 UAlphabeticIndexLabelType labelType_;
226 Bucket *displayBucket_;
227 int32_t displayIndex_;
228 UVector *records_; // Records are owned by the inputList_ vector.
229
230 Bucket(const UnicodeString &label, // Parameter strings are copied.
231 const UnicodeString &lowerBoundary,
232 UAlphabeticIndexLabelType type);
233 };
234
245 class U_I18N_API ImmutableIndex : public UObject {
246 public:
251 virtual ~ImmutableIndex();
252
259 int32_t getBucketCount() const;
260
269 int32_t getBucketIndex(const UnicodeString &name, UErrorCode &errorCode) const;
270
278 const Bucket *getBucket(int32_t index) const;
279
280 private:
281 friend class AlphabeticIndex;
282
283 ImmutableIndex(BucketList *bucketList, Collator *collatorPrimaryOnly)
284 : buckets_(bucketList), collatorPrimaryOnly_(collatorPrimaryOnly) {}
285
286 BucketList *buckets_;
287 Collator *collatorPrimaryOnly_;
288 };
289
302 AlphabeticIndex(const Locale &locale, UErrorCode &status);
303
318 AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status);
319
330 virtual AlphabeticIndex &addLabels(const UnicodeSet &additions, UErrorCode &status);
331
345 virtual AlphabeticIndex &addLabels(const Locale &locale, UErrorCode &status);
346
351 virtual ~AlphabeticIndex();
352
359 ImmutableIndex *buildImmutableIndex(UErrorCode &errorCode);
360
373 virtual const RuleBasedCollator &getCollator() const;
374
375
384 virtual const UnicodeString &getInflowLabel() const;
385
397 virtual AlphabeticIndex &setInflowLabel(const UnicodeString &inflowLabel, UErrorCode &status);
398
399
407 virtual const UnicodeString &getOverflowLabel() const;
408
409
419 virtual AlphabeticIndex &setOverflowLabel(const UnicodeString &overflowLabel, UErrorCode &status);
420
428 virtual const UnicodeString &getUnderflowLabel() const;
429
439 virtual AlphabeticIndex &setUnderflowLabel(const UnicodeString &underflowLabel, UErrorCode &status);
440
441
449 virtual int32_t getMaxLabelCount() const;
450
463 virtual AlphabeticIndex &setMaxLabelCount(int32_t maxLabelCount, UErrorCode &status);
464
465
482 virtual AlphabeticIndex &addRecord(const UnicodeString &name, const void *data, UErrorCode &status);
483
492 virtual AlphabeticIndex &clearRecords(UErrorCode &status);
493
494
503 virtual int32_t getBucketCount(UErrorCode &status);
504
505
514 virtual int32_t getRecordCount(UErrorCode &status);
515
516
517
530 virtual int32_t getBucketIndex(const UnicodeString &itemName, UErrorCode &status);
531
532
539 virtual int32_t getBucketIndex() const;
540
541
553 virtual UBool nextBucket(UErrorCode &status);
554
563 virtual const UnicodeString &getBucketLabel() const;
564
572 virtual UAlphabeticIndexLabelType getBucketLabelType() const;
573
582 virtual int32_t getBucketRecordCount() const;
583
584
593 virtual AlphabeticIndex &resetBucketIterator(UErrorCode &status);
594
606 virtual UBool nextRecord(UErrorCode &status);
607
616 virtual const UnicodeString &getRecordName() const;
617
618
627 virtual const void *getRecordData() const;
628
629
636 virtual AlphabeticIndex &resetRecordIterator();
637
638 private:
643 AlphabeticIndex(const AlphabeticIndex &other);
644
648 AlphabeticIndex &operator =(const AlphabeticIndex & /*other*/) { return *this;};
649
654 virtual UBool operator==(const AlphabeticIndex& other) const;
655
660 virtual UBool operator!=(const AlphabeticIndex& other) const;
661
662 // Common initialization, for use from all constructors.
663 void init(const Locale *locale, UErrorCode &status);
664
669 void addIndexExemplars(const Locale &locale, UErrorCode &status);
673 UBool addChineseIndexCharacters(UErrorCode &errorCode);
674
675 UVector *firstStringsInScript(UErrorCode &status);
676
677 static UnicodeString separated(const UnicodeString &item);
678
684 void initLabels(UVector &indexCharacters, UErrorCode &errorCode) const;
685 BucketList *createBucketList(UErrorCode &errorCode) const;
686 void initBuckets(UErrorCode &errorCode);
687 void clearBuckets();
688 void internalResetBucketIterator();
689
690 public:
691
692 // The Record is declared public only to allow access from
693 // implementation code written in plain C.
694 // It is not intended for public use.
695
696 #ifndef U_HIDE_INTERNAL_API
697
702 struct Record: public UMemory {
703 const UnicodeString name_;
704 const void *data_;
705 Record(const UnicodeString &name, const void *data);
706 ~Record();
707 };
708 #endif /* U_HIDE_INTERNAL_API */
709
710 private:
711
717 UVector *inputList_;
718
719 int32_t labelsIterIndex_; // Index of next item to return.
720 int32_t itemsIterIndex_;
721 Bucket *currentBucket_; // While an iteration of the index in underway,
722 // point to the bucket for the current label.
723 // NULL when no iteration underway.
724
725 int32_t maxLabelCount_; // Limit on # of labels permitted in the index.
726
727 UnicodeSet *initialLabels_; // Initial (unprocessed) set of Labels. Union
728 // of those explicitly set by the user plus
729 // those from locales. Raw values, before
730 // crunching into bucket labels.
731
732 UVector *firstCharsInScripts_; // The first character from each script,
733 // in collation order.
734
735 RuleBasedCollator *collator_;
736 RuleBasedCollator *collatorPrimaryOnly_;
737
738 // Lazy evaluated: null means that we have not built yet.
739 BucketList *buckets_;
740
741 UnicodeString inflowLabel_;
742 UnicodeString overflowLabel_;
743 UnicodeString underflowLabel_;
744 UnicodeString overflowComparisonString_;
745
746 UnicodeString emptyString_;
747 };
748
749 U_NAMESPACE_END
750
751 #endif // !UCONFIG_NO_COLLATION
752 #endif