ICU 56.1: alphaindex.h Source File

ICU 56.1 56.1

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

- File List
- Globals

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
icu::Collator
The Collator class performs locale-sensitive string comparison.
Definition: coll.h:163
icu::AlphabeticIndex::Bucket::getLabel
const UnicodeString & getLabel() const
Returns the label string.
Definition: alphaindex.h:210
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
U_ALPHAINDEX_INFLOW
Inflow Label.
Definition: alphaindex.h:55
U_ALPHAINDEX_NORMAL
Normal Label, typically the starting letter of the names in the bucket with this label.
Definition: alphaindex.h:38
U_CDECL_BEGIN
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
Definition: umachine.h:82
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:358
icu::AlphabeticIndex::Bucket
An index "bucket" with a label string and type.
Definition: alphaindex.h:196
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
icu::RuleBasedCollator
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables...
Definition: tblcoll.h:111
icu::AlphabeticIndex::ImmutableIndex
Immutable, thread-safe version of AlphabeticIndex.
Definition: alphaindex.h:245
icu::operator!=
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
icu::UnicodeSet
A mutable set of Unicode characters and multicharacter strings.
Definition: uniset.h:276
icu::AlphabeticIndex::Record
A (name, data) pair, to be sorted by name into one of the index buckets.
Definition: alphaindex.h:702
uobject.h
C++ API: Common ICU base class UObject.
U_CDECL_END
#define U_CDECL_END
This is used to end a declaration of a library private ICU C API.
Definition: umachine.h:83
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
icu::AlphabeticIndex
AlphabeticIndex supports the creation of a UI index appropriate for a given language.
Definition: alphaindex.h:186
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
U_ALPHAINDEX_OVERFLOW
Overflow Label.
Definition: alphaindex.h:62
locid.h
C++ API: Locale ID object.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:293
icu::AlphabeticIndex::Bucket::getLabelType
UAlphabeticIndexLabelType getLabelType() const
Returns whether this bucket is a normal, underflow, overflow, or inflow bucket.
Definition: alphaindex.h:217
U_ALPHAINDEX_UNDERFLOW
Undeflow Label.
Definition: alphaindex.h:45
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:221
icu::UMemory
UMemory is the common ICU base class.
Definition: uobject.h:110
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185
UAlphabeticIndexLabelType
UAlphabeticIndexLabelType
Constants for Alphabetic Index Label Types.
Definition: alphaindex.h:32