ICU 64.2  64.2
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 
42 
49 
59 
67 
68 
69 struct UHashtable;
71 
73 
74 // Forward Declarations
75 
76 class BucketList;
77 class Collator;
78 class RuleBasedCollator;
79 class StringEnumeration;
80 class UnicodeSet;
81 class UVector;
82 
190 public:
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.
234  const UnicodeString &lowerBoundary,
236  };
237 
249  public:
254  virtual ~ImmutableIndex();
255 
262  int32_t getBucketCount() const;
263 
274  int32_t getBucketIndex(const UnicodeString &name, UErrorCode &errorCode) const;
275 
283  const Bucket *getBucket(int32_t index) const;
284 
285  private:
286  friend class AlphabeticIndex;
287 
288  ImmutableIndex(BucketList *bucketList, Collator *collatorPrimaryOnly)
289  : buckets_(bucketList), collatorPrimaryOnly_(collatorPrimaryOnly) {}
290 
291  BucketList *buckets_;
292  Collator *collatorPrimaryOnly_;
293  };
294 
307  AlphabeticIndex(const Locale &locale, UErrorCode &status);
308 
323  AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status);
324 
335  virtual AlphabeticIndex &addLabels(const UnicodeSet &additions, UErrorCode &status);
336 
350  virtual AlphabeticIndex &addLabels(const Locale &locale, UErrorCode &status);
351 
356  virtual ~AlphabeticIndex();
357 
364  ImmutableIndex *buildImmutableIndex(UErrorCode &errorCode);
365 
378  virtual const RuleBasedCollator &getCollator() const;
379 
380 
390  virtual const UnicodeString &getInflowLabel() const;
391 
403  virtual AlphabeticIndex &setInflowLabel(const UnicodeString &inflowLabel, UErrorCode &status);
404 
405 
413  virtual const UnicodeString &getOverflowLabel() const;
414 
415 
425  virtual AlphabeticIndex &setOverflowLabel(const UnicodeString &overflowLabel, UErrorCode &status);
426 
434  virtual const UnicodeString &getUnderflowLabel() const;
435 
445  virtual AlphabeticIndex &setUnderflowLabel(const UnicodeString &underflowLabel, UErrorCode &status);
446 
447 
455  virtual int32_t getMaxLabelCount() const;
456 
469  virtual AlphabeticIndex &setMaxLabelCount(int32_t maxLabelCount, UErrorCode &status);
470 
471 
488  virtual AlphabeticIndex &addRecord(const UnicodeString &name, const void *data, UErrorCode &status);
489 
498  virtual AlphabeticIndex &clearRecords(UErrorCode &status);
499 
500 
509  virtual int32_t getBucketCount(UErrorCode &status);
510 
511 
520  virtual int32_t getRecordCount(UErrorCode &status);
521 
522 
523 
536  virtual int32_t getBucketIndex(const UnicodeString &itemName, UErrorCode &status);
537 
538 
545  virtual int32_t getBucketIndex() const;
546 
547 
559  virtual UBool nextBucket(UErrorCode &status);
560 
569  virtual const UnicodeString &getBucketLabel() const;
570 
578  virtual UAlphabeticIndexLabelType getBucketLabelType() const;
579 
588  virtual int32_t getBucketRecordCount() const;
589 
590 
599  virtual AlphabeticIndex &resetBucketIterator(UErrorCode &status);
600 
612  virtual UBool nextRecord(UErrorCode &status);
613 
622  virtual const UnicodeString &getRecordName() const;
623 
624 
633  virtual const void *getRecordData() const;
634 
635 
642  virtual AlphabeticIndex &resetRecordIterator();
643 
644 private:
649  AlphabeticIndex(const AlphabeticIndex &other);
650 
654  AlphabeticIndex &operator =(const AlphabeticIndex & /*other*/) { return *this;}
655 
660  virtual UBool operator==(const AlphabeticIndex& other) const;
661 
666  virtual UBool operator!=(const AlphabeticIndex& other) const;
667 
668  // Common initialization, for use from all constructors.
669  void init(const Locale *locale, UErrorCode &status);
670 
675  void addIndexExemplars(const Locale &locale, UErrorCode &status);
679  UBool addChineseIndexCharacters(UErrorCode &errorCode);
680 
681  UVector *firstStringsInScript(UErrorCode &status);
682 
683  static UnicodeString separated(const UnicodeString &item);
684 
690  void initLabels(UVector &indexCharacters, UErrorCode &errorCode) const;
691  BucketList *createBucketList(UErrorCode &errorCode) const;
692  void initBuckets(UErrorCode &errorCode);
693  void clearBuckets();
694  void internalResetBucketIterator();
695 
696 public:
697 
698  // The Record is declared public only to allow access from
699  // implementation code written in plain C.
700  // It is not intended for public use.
701 
702 #ifndef U_HIDE_INTERNAL_API
703 
709  struct Record: public UMemory {
710  const UnicodeString name_;
711  const void *data_;
712  Record(const UnicodeString &name, const void *data);
713  ~Record();
714  };
716 #endif /* U_HIDE_INTERNAL_API */
717 
718 private:
719 
725  UVector *inputList_;
726 
727  int32_t labelsIterIndex_; // Index of next item to return.
728  int32_t itemsIterIndex_;
729  Bucket *currentBucket_; // While an iteration of the index in underway,
730  // point to the bucket for the current label.
731  // NULL when no iteration underway.
732 
733  int32_t maxLabelCount_; // Limit on # of labels permitted in the index.
734 
735  UnicodeSet *initialLabels_; // Initial (unprocessed) set of Labels. Union
736  // of those explicitly set by the user plus
737  // those from locales. Raw values, before
738  // crunching into bucket labels.
739 
740  UVector *firstCharsInScripts_; // The first character from each script,
741  // in collation order.
742 
743  RuleBasedCollator *collator_;
744  RuleBasedCollator *collatorPrimaryOnly_;
745 
746  // Lazy evaluated: null means that we have not built yet.
747  BucketList *buckets_;
748 
749  UnicodeString inflowLabel_;
750  UnicodeString overflowLabel_;
751  UnicodeString underflowLabel_;
752  UnicodeString overflowComparisonString_;
753 
754  UnicodeString emptyString_;
755 };
756 
758 
759 #endif // !UCONFIG_NO_COLLATION
760 #endif
struct UHashtable UHashtable
Definition: msgfmt.h:41
The Collator class performs locale-sensitive string comparison.
Definition: coll.h:165
C++ API: Unicode String.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
Inflow Label.
Definition: alphaindex.h:58
Normal Label, typically the starting letter of the names in the bucket with this label.
Definition: alphaindex.h:41
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
Definition: umachine.h:84
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
An index "bucket" with a label string and type.
Definition: alphaindex.h:199
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables...
Definition: tblcoll.h:113
UAlphabeticIndexLabelType getLabelType() const
Returns whether this bucket is a normal, underflow, overflow, or inflow bucket.
Definition: alphaindex.h:220
Immutable, thread-safe version of AlphabeticIndex.
Definition: alphaindex.h:248
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
A mutable set of Unicode characters and multicharacter strings.
Definition: uniset.h:277
C++ API: Common ICU base class UObject.
#define U_CDECL_END
This is used to end a declaration of a library private ICU C API.
Definition: umachine.h:85
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
AlphabeticIndex supports the creation of a UI index appropriate for a given language.
Definition: alphaindex.h:189
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:401
Overflow Label.
Definition: alphaindex.h:65
C++ API: Locale ID object.
Basic definitions for ICU, for both C and C++ APIs.
const UnicodeString & getLabel() const
Returns the label string.
Definition: alphaindex.h:213
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:289
Undeflow Label.
Definition: alphaindex.h:48
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
UMemory is the common ICU base class.
Definition: uobject.h:112
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:192
UAlphabeticIndexLabelType
Constants for Alphabetic Index Label Types.
Definition: alphaindex.h:35