ICU 51.2  51.2
alphaindex.h
Go to the documentation of this file.
1 /*
2 *******************************************************************************
3 *
4 * Copyright (C) 2011-2013 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 
18 #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_NORMALIZATION
19 
26 
40 
47 
57 
65 
66 
67 struct UHashtable;
69 
71 
72 // Forward Declarations
73 
74 class BucketList;
75 class Collator;
76 class RuleBasedCollator;
77 class StringEnumeration;
78 class UnicodeSet;
79 class UVector;
80 
188 public:
189 #ifdef U_HIDE_DRAFT_API
190  class Bucket;
191 #else
192 
200  class U_I18N_API Bucket : public UObject {
201  public:
206  virtual ~Bucket();
207 
214  const UnicodeString &getLabel() const { return label_; }
221  UAlphabeticIndexLabelType getLabelType() const { return labelType_; }
222 
223  private:
224  friend class AlphabeticIndex;
225  friend class BucketList;
226 
227  UnicodeString label_;
228  UnicodeString lowerBoundary_;
229  UAlphabeticIndexLabelType labelType_;
230  Bucket *displayBucket_;
231  int32_t displayIndex_;
232  UVector *records_; // Records are owned by the inputList_ vector.
233 
234  Bucket(const UnicodeString &label, // Parameter strings are copied.
235  const UnicodeString &lowerBoundary,
237  };
238 
250  public:
255  virtual ~ImmutableIndex();
256 
263  int32_t getBucketCount() const;
264 
273  int32_t getBucketIndex(const UnicodeString &name, UErrorCode &errorCode) const;
274 
282  const Bucket *getBucket(int32_t index) const;
283 
284  private:
285  friend class AlphabeticIndex;
286 
287  ImmutableIndex(BucketList *bucketList, Collator *collatorPrimaryOnly)
288  : buckets_(bucketList), collatorPrimaryOnly_(collatorPrimaryOnly) {}
289 
290  BucketList *buckets_;
291  Collator *collatorPrimaryOnly_;
292  };
293 #endif /* U_HIDE_DRAFT_API */
294 
307  AlphabeticIndex(const Locale &locale, UErrorCode &status);
308 
309 #ifndef U_HIDE_DRAFT_API
310 
324  AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status);
325 #endif /* U_HIDE_DRAFT_API */
326 
337  virtual AlphabeticIndex &addLabels(const UnicodeSet &additions, UErrorCode &status);
338 
352  virtual AlphabeticIndex &addLabels(const Locale &locale, UErrorCode &status);
353 
358  virtual ~AlphabeticIndex();
359 
360 #ifndef U_HIDE_DRAFT_API
361 
367  ImmutableIndex *buildImmutableIndex(UErrorCode &errorCode);
368 #endif /* U_HIDE_DRAFT_API */
369 
382  virtual const RuleBasedCollator &getCollator() const;
383 
384 
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 UBool operator==(const AlphabeticIndex& other) const;
664 
669  virtual UBool 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 
711  struct Record: public UMemory {
712  const UnicodeString name_;
713  const void *data_;
714  Record(const UnicodeString &name, const void *data);
715  ~Record();
716  };
717 #endif /* U_HIDE_INTERNAL_API */
718 
719 private:
720 
726  UVector *inputList_;
727 
728  int32_t labelsIterIndex_; // Index of next item to return.
729  int32_t itemsIterIndex_;
730  Bucket *currentBucket_; // While an iteration of the index in underway,
731  // point to the bucket for the current label.
732  // NULL when no iteration underway.
733 
734  int32_t maxLabelCount_; // Limit on # of labels permitted in the index.
735 
736  UnicodeSet *initialLabels_; // Initial (unprocessed) set of Labels. Union
737  // of those explicitly set by the user plus
738  // those from locales. Raw values, before
739  // crunching into bucket labels.
740 
741  UVector *firstCharsInScripts_; // The first character from each script,
742  // in collation order.
743 
744  RuleBasedCollator *collator_;
745  RuleBasedCollator *collatorPrimaryOnly_;
746 
747  // Lazy evaluated: null means that we have not built yet.
748  BucketList *buckets_;
749 
750  UnicodeString inflowLabel_;
751  UnicodeString overflowLabel_;
752  UnicodeString underflowLabel_;
753  UnicodeString overflowComparisonString_;
754 
755  UnicodeString emptyString_;
756 };
757 
759 
760 #endif /* UCONFIG_NO_COLLATION / UCONFIG_NO_NORMALIZATION */
761 #endif