ICU 62.1 62.1
alphaindex.h
Go to the documentation of this file.
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3/*
4*******************************************************************************
5*
6* Copyright (C) 2011-2014 International Business Machines
7* Corporation and others. All Rights Reserved.
8*
9*******************************************************************************
10*/
11
12#ifndef INDEXCHARS_H
13#define INDEXCHARS_H
14
15#include "unicode/utypes.h"
16#include "unicode/uobject.h"
17#include "unicode/locid.h"
18#include "unicode/unistr.h"
19
20#if !UCONFIG_NO_COLLATION
21
28
67
68
69struct UHashtable;
71
73
74// Forward Declarations
75
76class BucketList;
77class Collator;
78class RuleBasedCollator;
79class StringEnumeration;
80class UnicodeSet;
81class UVector;
82
190public:
199 class U_I18N_API Bucket : public UObject {
200 public:
205 virtual ~Bucket();
206
213 const UnicodeString &getLabel() const { return label_; }
220 UAlphabeticIndexLabelType getLabelType() const { return labelType_; }
221
222 private:
223 friend class AlphabeticIndex;
224 friend class BucketList;
225
226 UnicodeString label_;
227 UnicodeString lowerBoundary_;
228 UAlphabeticIndexLabelType labelType_;
229 Bucket *displayBucket_;
230 int32_t displayIndex_;
231 UVector *records_; // Records are owned by the inputList_ vector.
232
233 Bucket(const UnicodeString &label, // Parameter strings are copied.
236 };
237
249 public:
255
262 int32_t getBucketCount() const;
263
272 int32_t getBucketIndex(const UnicodeString &name, UErrorCode &errorCode) const;
273
281 const Bucket *getBucket(int32_t index) const;
282
283 private:
284 friend class AlphabeticIndex;
285
287 : buckets_(bucketList), collatorPrimaryOnly_(collatorPrimaryOnly) {}
288
289 BucketList *buckets_;
290 Collator *collatorPrimaryOnly_;
291 };
292
306
322
334
349
355
363
376 virtual const RuleBasedCollator &getCollator() const;
377
378
387 virtual const UnicodeString &getInflowLabel() const;
388
401
402
410 virtual const UnicodeString &getOverflowLabel() const;
411
412
423
431 virtual const UnicodeString &getUnderflowLabel() const;
432
443
444
452 virtual int32_t getMaxLabelCount() const;
453
467
468
485 virtual AlphabeticIndex &addRecord(const UnicodeString &name, const void *data, UErrorCode &status);
486
496
497
507
508
518
519
520
534
535
542 virtual int32_t getBucketIndex() const;
543
544
557
566 virtual const UnicodeString &getBucketLabel() const;
567
576
585 virtual int32_t getBucketRecordCount() const;
586
587
597
610
619 virtual const UnicodeString &getRecordName() const;
620
621
630 virtual const void *getRecordData() const;
631
632
640
641private:
647
651 AlphabeticIndex &operator =(const AlphabeticIndex & /*other*/) { return *this;};
652
657 virtual UBool operator==(const AlphabeticIndex& other) const;
658
663 virtual UBool operator!=(const AlphabeticIndex& other) const;
664
665 // Common initialization, for use from all constructors.
666 void init(const Locale *locale, UErrorCode &status);
667
672 void addIndexExemplars(const Locale &locale, UErrorCode &status);
676 UBool addChineseIndexCharacters(UErrorCode &errorCode);
677
678 UVector *firstStringsInScript(UErrorCode &status);
679
680 static UnicodeString separated(const UnicodeString &item);
681
687 void initLabels(UVector &indexCharacters, UErrorCode &errorCode) const;
688 BucketList *createBucketList(UErrorCode &errorCode) const;
689 void initBuckets(UErrorCode &errorCode);
690 void clearBuckets();
691 void internalResetBucketIterator();
692
693public:
694
695 // The Record is declared public only to allow access from
696 // implementation code written in plain C.
697 // It is not intended for public use.
698
699#ifndef U_HIDE_INTERNAL_API
705 struct Record: public UMemory {
706 const UnicodeString name_;
707 const void *data_;
708 Record(const UnicodeString &name, const void *data);
709 ~Record();
710 };
711#endif /* U_HIDE_INTERNAL_API */
712
713private:
714
720 UVector *inputList_;
721
722 int32_t labelsIterIndex_; // Index of next item to return.
723 int32_t itemsIterIndex_;
724 Bucket *currentBucket_; // While an iteration of the index in underway,
725 // point to the bucket for the current label.
726 // NULL when no iteration underway.
727
728 int32_t maxLabelCount_; // Limit on # of labels permitted in the index.
729
730 UnicodeSet *initialLabels_; // Initial (unprocessed) set of Labels. Union
731 // of those explicitly set by the user plus
732 // those from locales. Raw values, before
733 // crunching into bucket labels.
734
735 UVector *firstCharsInScripts_; // The first character from each script,
736 // in collation order.
737
738 RuleBasedCollator *collator_;
739 RuleBasedCollator *collatorPrimaryOnly_;
740
741 // Lazy evaluated: null means that we have not built yet.
742 BucketList *buckets_;
743
744 UnicodeString inflowLabel_;
745 UnicodeString overflowLabel_;
746 UnicodeString underflowLabel_;
747 UnicodeString overflowComparisonString_;
748
749 UnicodeString emptyString_;
750};
751
753
754#endif // !UCONFIG_NO_COLLATION
755#endif
UAlphabeticIndexLabelType
Constants for Alphabetic Index Label Types.
Definition alphaindex.h:35
@ U_ALPHAINDEX_OVERFLOW
Overflow Label.
Definition alphaindex.h:65
@ U_ALPHAINDEX_UNDERFLOW
Undeflow Label.
Definition alphaindex.h:48
@ U_ALPHAINDEX_NORMAL
Normal Label, typically the starting letter of the names in the bucket with this label.
Definition alphaindex.h:41
@ U_ALPHAINDEX_INFLOW
Inflow Label.
Definition alphaindex.h:58
An index "bucket" with a label string and type.
Definition alphaindex.h:199
UAlphabeticIndexLabelType getLabelType() const
Returns whether this bucket is a normal, underflow, overflow, or inflow bucket.
Definition alphaindex.h:220
const UnicodeString & getLabel() const
Returns the label string.
Definition alphaindex.h:213
virtual ~Bucket()
Destructor.
Immutable, thread-safe version of AlphabeticIndex.
Definition alphaindex.h:248
int32_t getBucketCount() const
Returns the number of index buckets and labels, including underflow/inflow/overflow.
const Bucket * getBucket(int32_t index) const
Returns the index-th bucket.
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:189
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 const void * getRecordData() const
Return the data pointer of the Record currently being iterated over.
virtual UBool nextRecord(UErrorCode &status)
Advance to the next record in the current Bucket.
virtual const RuleBasedCollator & getCollator() const
Get the Collator that establishes the ordering of the items in this index.
virtual AlphabeticIndex & addLabels(const UnicodeSet &additions, UErrorCode &status)
Add Labels to this Index.
AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status)
Construct an AlphabeticIndex that uses a specific collator.
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()
Destructor.
virtual AlphabeticIndex & addRecord(const UnicodeString &name, const void *data, UErrorCode &status)
Add a record to the index.
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 AlphabeticIndex & resetRecordIterator()
Reset the Record iterator position to before the first Record in the current Bucket.
virtual const UnicodeString & getBucketLabel() const
Return the name of the Label of the current bucket from an iteration over the buckets.
virtual const UnicodeString & getRecordName() const
Get the name of the current Record.
virtual const UnicodeString & getInflowLabel() const
Get the default label used for abbreviated buckets between other index characters.
virtual UBool nextBucket(UErrorCode &status)
Advance the iteration over the Buckets of this index.
AlphabeticIndex(const Locale &locale, UErrorCode &status)
Construct an AlphabeticIndex object for the specified locale.
virtual AlphabeticIndex & clearRecords(UErrorCode &status)
Remove all Records from the Index.
ImmutableIndex * buildImmutableIndex(UErrorCode &errorCode)
Builds an immutable, thread-safe version of this instance, without data records.
virtual AlphabeticIndex & setInflowLabel(const UnicodeString &inflowLabel, UErrorCode &status)
Set the default label used for abbreviated buckets between other index characters.
virtual AlphabeticIndex & setMaxLabelCount(int32_t maxLabelCount, UErrorCode &status)
Set a limit on the number of labels permitted in the 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 int32_t getBucketIndex() const
Get the zero based index of the current Bucket from an iteration over the Buckets of this index.
virtual AlphabeticIndex & addLabels(const Locale &locale, UErrorCode &status)
Add the index characters from a Locale to 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 AlphabeticIndex & resetBucketIterator(UErrorCode &status)
Reset the Bucket iteration for this 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 getBucketRecordCount() const
Get the number of <name, data> Records in the current Bucket.
virtual int32_t getBucketCount(UErrorCode &status)
Get the number of labels in this index.
virtual UAlphabeticIndexLabelType getBucketLabelType() const
Return the type of the label for the current Bucket (selected by the iteration over Buckets....
virtual int32_t getMaxLabelCount() const
Get the limit on the number of labels permitted in the index.
The Collator class performs locale-sensitive string comparison.
Definition coll.h:165
"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:188
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables.
Definition tblcoll.h:113
UMemory is the common ICU base class.
Definition uobject.h:112
UObject is the common ICU "boilerplate" class.
Definition uobject.h:223
A mutable set of Unicode characters and multicharacter strings.
Definition uniset.h:278
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:287
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:705
#define U_CDECL_END
This is used to end a declaration of a library private ICU C API.
Definition umachine.h:85
int8_t UBool
The ICU boolean type.
Definition umachine.h:236
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
Definition umachine.h:84
C++ API: Unicode String.
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:396
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:360
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:138
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:137