ICU 58.2  58.2
alphaindex.h
Go to the documentation of this file.
1 // Copyright (C) 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 
19 #if !UCONFIG_NO_COLLATION
20 
27 
41 
48 
58 
66 
67 
68 struct UHashtable;
70 
72 
73 // Forward Declarations
74 
75 class BucketList;
76 class Collator;
77 class RuleBasedCollator;
78 class StringEnumeration;
79 class UnicodeSet;
80 class UVector;
81 
189 public:
198  class U_I18N_API Bucket : public UObject {
199  public:
204  virtual ~Bucket();
205 
212  const UnicodeString &getLabel() const { return label_; }
219  UAlphabeticIndexLabelType getLabelType() const { return labelType_; }
220 
221  private:
222  friend class AlphabeticIndex;
223  friend class BucketList;
224 
225  UnicodeString label_;
226  UnicodeString lowerBoundary_;
227  UAlphabeticIndexLabelType labelType_;
228  Bucket *displayBucket_;
229  int32_t displayIndex_;
230  UVector *records_; // Records are owned by the inputList_ vector.
231 
232  Bucket(const UnicodeString &label, // Parameter strings are copied.
233  const UnicodeString &lowerBoundary,
235  };
236 
248  public:
253  virtual ~ImmutableIndex();
254 
261  int32_t getBucketCount() const;
262 
271  int32_t getBucketIndex(const UnicodeString &name, UErrorCode &errorCode) const;
272 
280  const Bucket *getBucket(int32_t index) const;
281 
282  private:
283  friend class AlphabeticIndex;
284 
285  ImmutableIndex(BucketList *bucketList, Collator *collatorPrimaryOnly)
286  : buckets_(bucketList), collatorPrimaryOnly_(collatorPrimaryOnly) {}
287 
288  BucketList *buckets_;
289  Collator *collatorPrimaryOnly_;
290  };
291 
304  AlphabeticIndex(const Locale &locale, UErrorCode &status);
305 
320  AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status);
321 
332  virtual AlphabeticIndex &addLabels(const UnicodeSet &additions, UErrorCode &status);
333 
347  virtual AlphabeticIndex &addLabels(const Locale &locale, UErrorCode &status);
348 
353  virtual ~AlphabeticIndex();
354 
361  ImmutableIndex *buildImmutableIndex(UErrorCode &errorCode);
362 
375  virtual const RuleBasedCollator &getCollator() const;
376 
377 
386  virtual const UnicodeString &getInflowLabel() const;
387 
399  virtual AlphabeticIndex &setInflowLabel(const UnicodeString &inflowLabel, UErrorCode &status);
400 
401 
409  virtual const UnicodeString &getOverflowLabel() const;
410 
411 
421  virtual AlphabeticIndex &setOverflowLabel(const UnicodeString &overflowLabel, UErrorCode &status);
422 
430  virtual const UnicodeString &getUnderflowLabel() const;
431 
441  virtual AlphabeticIndex &setUnderflowLabel(const UnicodeString &underflowLabel, UErrorCode &status);
442 
443 
451  virtual int32_t getMaxLabelCount() const;
452 
465  virtual AlphabeticIndex &setMaxLabelCount(int32_t maxLabelCount, UErrorCode &status);
466 
467 
484  virtual AlphabeticIndex &addRecord(const UnicodeString &name, const void *data, UErrorCode &status);
485 
494  virtual AlphabeticIndex &clearRecords(UErrorCode &status);
495 
496 
505  virtual int32_t getBucketCount(UErrorCode &status);
506 
507 
516  virtual int32_t getRecordCount(UErrorCode &status);
517 
518 
519 
532  virtual int32_t getBucketIndex(const UnicodeString &itemName, UErrorCode &status);
533 
534 
541  virtual int32_t getBucketIndex() const;
542 
543 
555  virtual UBool nextBucket(UErrorCode &status);
556 
565  virtual const UnicodeString &getBucketLabel() const;
566 
574  virtual UAlphabeticIndexLabelType getBucketLabelType() const;
575 
584  virtual int32_t getBucketRecordCount() const;
585 
586 
595  virtual AlphabeticIndex &resetBucketIterator(UErrorCode &status);
596 
608  virtual UBool nextRecord(UErrorCode &status);
609 
618  virtual const UnicodeString &getRecordName() const;
619 
620 
629  virtual const void *getRecordData() const;
630 
631 
638  virtual AlphabeticIndex &resetRecordIterator();
639 
640 private:
645  AlphabeticIndex(const AlphabeticIndex &other);
646 
650  AlphabeticIndex &operator =(const AlphabeticIndex & /*other*/) { return *this;};
651 
656  virtual UBool operator==(const AlphabeticIndex& other) const;
657 
662  virtual UBool operator!=(const AlphabeticIndex& other) const;
663 
664  // Common initialization, for use from all constructors.
665  void init(const Locale *locale, UErrorCode &status);
666 
671  void addIndexExemplars(const Locale &locale, UErrorCode &status);
675  UBool addChineseIndexCharacters(UErrorCode &errorCode);
676 
677  UVector *firstStringsInScript(UErrorCode &status);
678 
679  static UnicodeString separated(const UnicodeString &item);
680 
686  void initLabels(UVector &indexCharacters, UErrorCode &errorCode) const;
687  BucketList *createBucketList(UErrorCode &errorCode) const;
688  void initBuckets(UErrorCode &errorCode);
689  void clearBuckets();
690  void internalResetBucketIterator();
691 
692 public:
693 
694  // The Record is declared public only to allow access from
695  // implementation code written in plain C.
696  // It is not intended for public use.
697 
698 #ifndef U_HIDE_INTERNAL_API
699 
704  struct Record: public UMemory {
705  const UnicodeString name_;
706  const void *data_;
707  Record(const UnicodeString &name, const void *data);
708  ~Record();
709  };
710 #endif /* U_HIDE_INTERNAL_API */
711 
712 private:
713 
719  UVector *inputList_;
720 
721  int32_t labelsIterIndex_; // Index of next item to return.
722  int32_t itemsIterIndex_;
723  Bucket *currentBucket_; // While an iteration of the index in underway,
724  // point to the bucket for the current label.
725  // NULL when no iteration underway.
726 
727  int32_t maxLabelCount_; // Limit on # of labels permitted in the index.
728 
729  UnicodeSet *initialLabels_; // Initial (unprocessed) set of Labels. Union
730  // of those explicitly set by the user plus
731  // those from locales. Raw values, before
732  // crunching into bucket labels.
733 
734  UVector *firstCharsInScripts_; // The first character from each script,
735  // in collation order.
736 
737  RuleBasedCollator *collator_;
738  RuleBasedCollator *collatorPrimaryOnly_;
739 
740  // Lazy evaluated: null means that we have not built yet.
741  BucketList *buckets_;
742 
743  UnicodeString inflowLabel_;
744  UnicodeString overflowLabel_;
745  UnicodeString underflowLabel_;
746  UnicodeString overflowComparisonString_;
747 
748  UnicodeString emptyString_;
749 };
750 
752 
753 #endif // !UCONFIG_NO_COLLATION
754 #endif
The Collator class performs locale-sensitive string comparison.
Definition: coll.h:165
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
Inflow Label.
Definition: alphaindex.h:57
Normal Label, typically the starting letter of the names in the bucket with this label.
Definition: alphaindex.h:40
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
Definition: umachine.h:107
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:360
An index "bucket" with a label string and type.
Definition: alphaindex.h:198
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
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:219
Immutable, thread-safe version of AlphabeticIndex.
Definition: alphaindex.h:247
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:220
A mutable set of Unicode characters and multicharacter strings.
Definition: uniset.h:278
A (name, data) pair, to be sorted by name into one of the index buckets.
Definition: alphaindex.h:704
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:108
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
AlphabeticIndex supports the creation of a UI index appropriate for a given language.
Definition: alphaindex.h:188
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
Overflow Label.
Definition: alphaindex.h:64
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:212
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
Undeflow Label.
Definition: alphaindex.h:47
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:259
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:187
UAlphabeticIndexLabelType
Constants for Alphabetic Index Label Types.
Definition: alphaindex.h:34