ICU 57.1 57.1
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
25
64
65
66struct UHashtable;
68
70
71// Forward Declarations
72
73class BucketList;
74class Collator;
77class UnicodeSet;
78class UVector;
79
187public:
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.
233 };
234
246 public:
252
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
284 : buckets_(bucketList), collatorPrimaryOnly_(collatorPrimaryOnly) {}
285
286 BucketList *buckets_;
287 Collator *collatorPrimaryOnly_;
288 };
289
303
319
331
346
352
360
373 virtual const RuleBasedCollator &getCollator() const;
374
375
384 virtual const UnicodeString &getInflowLabel() const;
385
398
399
407 virtual const UnicodeString &getOverflowLabel() const;
408
409
420
428 virtual const UnicodeString &getUnderflowLabel() const;
429
440
441
449 virtual int32_t getMaxLabelCount() const;
450
464
465
482 virtual AlphabeticIndex &addRecord(const UnicodeString &name, const void *data, UErrorCode &status);
483
493
494
504
505
515
516
517
531
532
539 virtual int32_t getBucketIndex() const;
540
541
554
563 virtual const UnicodeString &getBucketLabel() const;
564
573
583
584
594
607
616 virtual const UnicodeString &getRecordName() const;
617
618
627 virtual const void *getRecordData() const;
628
629
637
638private:
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
690public:
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
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
710private:
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
750
751#endif // !UCONFIG_NO_COLLATION
752#endif
UAlphabeticIndexLabelType
Constants for Alphabetic Index Label Types.
Definition alphaindex.h:32
@ U_ALPHAINDEX_OVERFLOW
Overflow Label.
Definition alphaindex.h:62
@ U_ALPHAINDEX_UNDERFLOW
Undeflow Label.
Definition alphaindex.h:45
@ U_ALPHAINDEX_NORMAL
Normal Label, typically the starting letter of the names in the bucket with this label.
Definition alphaindex.h:38
@ U_ALPHAINDEX_INFLOW
Inflow Label.
Definition alphaindex.h:55
An index "bucket" with a label string and type.
Definition alphaindex.h:196
const UnicodeString & getLabel() const
Returns the label string.
Definition alphaindex.h:210
UAlphabeticIndexLabelType getLabelType() const
Returns whether this bucket is a normal, underflow, overflow, or inflow bucket.
Definition alphaindex.h:217
virtual ~Bucket()
Destructor.
Immutable, thread-safe version of AlphabeticIndex.
Definition alphaindex.h:245
const Bucket * getBucket(int32_t index) const
Returns the index-th bucket.
int32_t getBucketCount() const
Returns the number of index buckets and labels, including underflow/inflow/overflow.
int32_t getBucketIndex(const UnicodeString &name, UErrorCode &errorCode) const
Finds the index bucket for the given name and returns the number of that bucket.
virtual ~ImmutableIndex()
Destructor.
AlphabeticIndex supports the creation of a UI index appropriate for a given language.
Definition alphaindex.h:186
virtual AlphabeticIndex & setMaxLabelCount(int32_t maxLabelCount, UErrorCode &status)
Set a limit on the number of labels permitted in the index.
virtual AlphabeticIndex & setUnderflowLabel(const UnicodeString &underflowLabel, UErrorCode &status)
Set the label used for items that sort before the first normal label, and that would not otherwise ha...
virtual int32_t getRecordCount(UErrorCode &status)
Get the total number of Records in this index, that is, the number of <name, data> pairs added.
virtual AlphabeticIndex & addLabels(const Locale &locale, UErrorCode &status)
Add the index characters from a Locale to the index.
virtual AlphabeticIndex & addLabels(const UnicodeSet &additions, UErrorCode &status)
Add Labels to this Index.
virtual UBool nextRecord(UErrorCode &status)
Advance to the next record in the current Bucket.
virtual int32_t getBucketIndex() const
Get the zero based index of the current Bucket from an iteration over the Buckets of this index.
virtual int32_t getBucketIndex(const UnicodeString &itemName, UErrorCode &status)
Given the name of a record, return the zero-based index of the Bucket in which the item should appear...
virtual const RuleBasedCollator & getCollator() const
Get the Collator that establishes the ordering of the items in this index.
virtual const UnicodeString & getInflowLabel() const
Get the default label used for abbreviated buckets between other index characters.
virtual int32_t getMaxLabelCount() const
Get the limit on the number of labels permitted in the index.
virtual const UnicodeString & getOverflowLabel() const
Get the special label used for items that sort after the last normal label, and that would not otherw...
virtual int32_t getBucketCount(UErrorCode &status)
Get the number of labels in this index.
virtual ~AlphabeticIndex()
Destructor.
virtual AlphabeticIndex & resetRecordIterator()
Reset the Record iterator position to before the first Record in the current Bucket.
virtual const UnicodeString & getUnderflowLabel() const
Get the special label used for items that sort before the first normal label, and that would not othe...
virtual const UnicodeString & getBucketLabel() const
Return the name of the Label of the current bucket from an iteration over the buckets.
virtual AlphabeticIndex & setOverflowLabel(const UnicodeString &overflowLabel, UErrorCode &status)
Set the label used for items that sort after the last normal label, and that would not otherwise have...
virtual AlphabeticIndex & clearRecords(UErrorCode &status)
Remove all Records from the Index.
virtual const void * getRecordData() const
Return the data pointer of the Record currently being iterated over.
virtual AlphabeticIndex & setInflowLabel(const UnicodeString &inflowLabel, UErrorCode &status)
Set the default label used for abbreviated buckets between other index characters.
virtual AlphabeticIndex & addRecord(const UnicodeString &name, const void *data, UErrorCode &status)
Add a record to the index.
virtual AlphabeticIndex & resetBucketIterator(UErrorCode &status)
Reset the Bucket iteration for this index.
virtual UAlphabeticIndexLabelType getBucketLabelType() const
Return the type of the label for the current Bucket (selected by the iteration over Buckets....
AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status)
Construct an AlphabeticIndex that uses a specific collator.
AlphabeticIndex(const Locale &locale, UErrorCode &status)
Construct an AlphabeticIndex object for the specified locale.
virtual int32_t getBucketRecordCount() const
Get the number of <name, data> Records in the current Bucket.
ImmutableIndex * buildImmutableIndex(UErrorCode &errorCode)
Builds an immutable, thread-safe version of this instance, without data records.
virtual const UnicodeString & getRecordName() const
Get the name of the current Record.
virtual UBool nextBucket(UErrorCode &status)
Advance the iteration over the Buckets of this index.
The Collator class performs locale-sensitive string comparison.
Definition coll.h:163
"Smart pointer" base class; do not use directly: use LocalPointer etc.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:185
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables.
Definition tblcoll.h:111
Base class for 'pure' C++ implementations of uenum api.
Definition strenum.h:55
UMemory is the common ICU base class.
Definition uobject.h:110
UObject is the common ICU "boilerplate" class.
Definition uobject.h:221
A mutable set of Unicode characters and multicharacter strings.
Definition uniset.h:276
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:294
C++ API: Locale ID object.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
A (name, data) pair, to be sorted by name into one of the index buckets.
Definition alphaindex.h:702
#define U_CDECL_END
This is used to end a declaration of a library private ICU C API.
Definition umachine.h:83
int8_t UBool
The ICU boolean type.
Definition umachine.h:234
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
Definition umachine.h:82
C++ API: Common ICU base class UObject.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:476
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:358
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:129