ICU 71.1 71.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
17 #if U_SHOW_CPLUSPLUS_API
18
19 #include "unicode/uobject.h"
20 #include "unicode/locid.h"
21 #include "unicode/unistr.h"
22
23 #if !UCONFIG_NO_COLLATION
24
30 U_CDECL_BEGIN
31
38 typedef enum UAlphabeticIndexLabelType {
44 U_ALPHAINDEX_NORMAL = 0,
45
51 U_ALPHAINDEX_UNDERFLOW = 1,
52
61 U_ALPHAINDEX_INFLOW = 2,
62
68 U_ALPHAINDEX_OVERFLOW = 3
69 } UAlphabeticIndexLabelType;
70
71
72 struct UHashtable;
73 U_CDECL_END
74
75 U_NAMESPACE_BEGIN
76
77 // Forward Declarations
78
79 class BucketList;
80 class Collator;
81 class RuleBasedCollator;
82 class StringEnumeration;
83 class UnicodeSet;
84 class UVector;
85
192 class U_I18N_API AlphabeticIndex: public UObject {
193 public:
202 class U_I18N_API Bucket : public UObject {
203 public:
208 virtual ~Bucket();
209
216 const UnicodeString &getLabel() const { return label_; }
223 UAlphabeticIndexLabelType getLabelType() const { return labelType_; }
224
225 private:
226 friend class AlphabeticIndex;
227 friend class BucketList;
228
229 UnicodeString label_;
230 UnicodeString lowerBoundary_;
231 UAlphabeticIndexLabelType labelType_;
232 Bucket *displayBucket_;
233 int32_t displayIndex_;
234 UVector *records_; // Records are owned by the inputList_ vector.
235
236 Bucket(const UnicodeString &label, // Parameter strings are copied.
237 const UnicodeString &lowerBoundary,
238 UAlphabeticIndexLabelType type);
239 };
240
251 class U_I18N_API ImmutableIndex : public UObject {
252 public:
257 virtual ~ImmutableIndex();
258
265 int32_t getBucketCount() const;
266
277 int32_t getBucketIndex(const UnicodeString &name, UErrorCode &errorCode) const;
278
286 const Bucket *getBucket(int32_t index) const;
287
288 private:
289 friend class AlphabeticIndex;
290
291 ImmutableIndex(BucketList *bucketList, Collator *collatorPrimaryOnly)
292 : buckets_(bucketList), collatorPrimaryOnly_(collatorPrimaryOnly) {}
293
294 BucketList *buckets_;
295 Collator *collatorPrimaryOnly_;
296 };
297
310 AlphabeticIndex(const Locale &locale, UErrorCode &status);
311
326 AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status);
327
338 virtual AlphabeticIndex &addLabels(const UnicodeSet &additions, UErrorCode &status);
339
353 virtual AlphabeticIndex &addLabels(const Locale &locale, UErrorCode &status);
354
359 virtual ~AlphabeticIndex();
360
367 ImmutableIndex *buildImmutableIndex(UErrorCode &errorCode);
368
381 virtual const RuleBasedCollator &getCollator() const;
382
383
393 virtual const UnicodeString &getInflowLabel() const;
394
406 virtual AlphabeticIndex &setInflowLabel(const UnicodeString &inflowLabel, UErrorCode &status);
407
408
416 virtual const UnicodeString &getOverflowLabel() const;
417
418
428 virtual AlphabeticIndex &setOverflowLabel(const UnicodeString &overflowLabel, UErrorCode &status);
429
437 virtual const UnicodeString &getUnderflowLabel() const;
438
448 virtual AlphabeticIndex &setUnderflowLabel(const UnicodeString &underflowLabel, UErrorCode &status);
449
450
458 virtual int32_t getMaxLabelCount() const;
459
472 virtual AlphabeticIndex &setMaxLabelCount(int32_t maxLabelCount, UErrorCode &status);
473
474
491 virtual AlphabeticIndex &addRecord(const UnicodeString &name, const void *data, UErrorCode &status);
492
501 virtual AlphabeticIndex &clearRecords(UErrorCode &status);
502
503
512 virtual int32_t getBucketCount(UErrorCode &status);
513
514
523 virtual int32_t getRecordCount(UErrorCode &status);
524
525
526
539 virtual int32_t getBucketIndex(const UnicodeString &itemName, UErrorCode &status);
540
541
548 virtual int32_t getBucketIndex() const;
549
550
562 virtual UBool nextBucket(UErrorCode &status);
563
572 virtual const UnicodeString &getBucketLabel() const;
573
581 virtual UAlphabeticIndexLabelType getBucketLabelType() const;
582
591 virtual int32_t getBucketRecordCount() const;
592
593
602 virtual AlphabeticIndex &resetBucketIterator(UErrorCode &status);
603
615 virtual UBool nextRecord(UErrorCode &status);
616
625 virtual const UnicodeString &getRecordName() const;
626
627
636 virtual const void *getRecordData() const;
637
638
645 virtual AlphabeticIndex &resetRecordIterator();
646
647 private:
652 AlphabeticIndex(const AlphabeticIndex &other);
653
657 AlphabeticIndex &operator =(const AlphabeticIndex & /*other*/) { return *this;}
658
663 virtual bool operator==(const AlphabeticIndex& other) const;
664
669 virtual bool operator!=(const AlphabeticIndex& other) const;
670
671 // Common initialization, for use from all constructors.
672 void init(const Locale *locale, UErrorCode &status);
673
678 void addIndexExemplars(const Locale &locale, UErrorCode &status);
682 UBool addChineseIndexCharacters(UErrorCode &errorCode);
683
684 UVector *firstStringsInScript(UErrorCode &status);
685
686 static UnicodeString separated(const UnicodeString &item);
687
693 void initLabels(UVector &indexCharacters, UErrorCode &errorCode) const;
694 BucketList *createBucketList(UErrorCode &errorCode) const;
695 void initBuckets(UErrorCode &errorCode);
696 void clearBuckets();
697 void internalResetBucketIterator();
698
699 public:
700
701 // The Record is declared public only to allow access from
702 // implementation code written in plain C.
703 // It is not intended for public use.
704
705 #ifndef U_HIDE_INTERNAL_API
706
712 struct Record: public UMemory {
713 const UnicodeString name_;
714 const void *data_;
715 Record(const UnicodeString &name, const void *data);
716 ~Record();
717 };
719 #endif /* U_HIDE_INTERNAL_API */
720
721 private:
722
728 UVector *inputList_;
729
730 int32_t labelsIterIndex_; // Index of next item to return.
731 int32_t itemsIterIndex_;
732 Bucket *currentBucket_; // While an iteration of the index in underway,
733 // point to the bucket for the current label.
734 // NULL when no iteration underway.
735
736 int32_t maxLabelCount_; // Limit on # of labels permitted in the index.
737
738 UnicodeSet *initialLabels_; // Initial (unprocessed) set of Labels. Union
739 // of those explicitly set by the user plus
740 // those from locales. Raw values, before
741 // crunching into bucket labels.
742
743 UVector *firstCharsInScripts_; // The first character from each script,
744 // in collation order.
745
746 RuleBasedCollator *collator_;
747 RuleBasedCollator *collatorPrimaryOnly_;
748
749 // Lazy evaluated: null means that we have not built yet.
750 BucketList *buckets_;
751
752 UnicodeString inflowLabel_;
753 UnicodeString overflowLabel_;
754 UnicodeString underflowLabel_;
755 UnicodeString overflowComparisonString_;
756
757 UnicodeString emptyString_;
758 };
759
760 U_NAMESPACE_END
761
762 #endif // !UCONFIG_NO_COLLATION
763
764 #endif /* U_SHOW_CPLUSPLUS_API */
765
766 #endif
icu::AlphabeticIndex::Bucket::getLabelType
UAlphabeticIndexLabelType getLabelType() const
Returns whether this bucket is a normal, underflow, overflow, or inflow bucket.
Definition: alphaindex.h:223
UHashtable
struct UHashtable UHashtable
Definition: msgfmt.h:43
icu::AlphabeticIndex::Bucket::getLabel
const UnicodeString & getLabel() const
Returns the label string.
Definition: alphaindex.h:216
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::UnicodeSet
A mutable set of Unicode characters and multicharacter strings.
Definition: uniset.h:285
UAlphabeticIndexLabelType
UAlphabeticIndexLabelType
Constants for Alphabetic Index Label Types.
Definition: alphaindex.h:38
U_I18N_API
#define U_I18N_API
Definition: utypes.h:301
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
icu::Collator
The Collator class performs locale-sensitive string comparison.
Definition: coll.h:167
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
U_ALPHAINDEX_NORMAL
@ U_ALPHAINDEX_NORMAL
Normal Label, typically the starting letter of the names in the bucket with this label.
Definition: alphaindex.h:44
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
icu::UMemory
UMemory is the common ICU base class.
Definition: uobject.h:115
icu::RuleBasedCollator
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables.
Definition: tblcoll.h:115
U_ALPHAINDEX_INFLOW
@ U_ALPHAINDEX_INFLOW
Inflow Label.
Definition: alphaindex.h:61
U_CDECL_END
#define U_CDECL_END
Definition: umachine.h:86
U_CDECL_BEGIN
#define U_CDECL_BEGIN
Definition: umachine.h:85
icu::operator!=
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:335
icu::AlphabeticIndex::ImmutableIndex
Immutable, thread-safe version of AlphabeticIndex.
Definition: alphaindex.h:251
U_ALPHAINDEX_OVERFLOW
@ U_ALPHAINDEX_OVERFLOW
Overflow Label.
Definition: alphaindex.h:68
U_ALPHAINDEX_UNDERFLOW
@ U_ALPHAINDEX_UNDERFLOW
Underflow Label.
Definition: alphaindex.h:51
locid.h
C++ API: Locale ID object.
uobject.h
C++ API: Common ICU base class UObject.
icu::AlphabeticIndex
AlphabeticIndex supports the creation of a UI index appropriate for a given language.
Definition: alphaindex.h:192
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::AlphabeticIndex::Bucket
An index "bucket" with a label string and type.
Definition: alphaindex.h:202
unistr.h
C++ API: Unicode String.