ucharstriebuilder.h

Go to the documentation of this file.
00001 /*
00002 *******************************************************************************
00003 *   Copyright (C) 2010-2012, International Business Machines
00004 *   Corporation and others.  All Rights Reserved.
00005 *******************************************************************************
00006 *   file name:  ucharstriebuilder.h
00007 *   encoding:   US-ASCII
00008 *   tab size:   8 (not used)
00009 *   indentation:4
00010 *
00011 *   created on: 2010nov14
00012 *   created by: Markus W. Scherer
00013 */
00014 
00015 #ifndef __UCHARSTRIEBUILDER_H__
00016 #define __UCHARSTRIEBUILDER_H__
00017 
00018 #include "unicode/utypes.h"
00019 #include "unicode/stringtriebuilder.h"
00020 #include "unicode/ucharstrie.h"
00021 #include "unicode/unistr.h"
00022 
00028 U_NAMESPACE_BEGIN
00029 
00030 class UCharsTrieElement;
00031 
00038 class U_COMMON_API UCharsTrieBuilder : public StringTrieBuilder {
00039 public:
00045     UCharsTrieBuilder(UErrorCode &errorCode);
00046 
00051     virtual ~UCharsTrieBuilder();
00052 
00067     UCharsTrieBuilder &add(const UnicodeString &s, int32_t value, UErrorCode &errorCode);
00068 
00084     UCharsTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
00085 
00107     UnicodeString &buildUnicodeString(UStringTrieBuildOption buildOption, UnicodeString &result,
00108                                       UErrorCode &errorCode);
00109 
00116     UCharsTrieBuilder &clear() {
00117         strings.remove();
00118         elementsLength=0;
00119         ucharsLength=0;
00120         return *this;
00121     }
00122 
00123 private:
00124     UCharsTrieBuilder(const UCharsTrieBuilder &other);  // no copy constructor
00125     UCharsTrieBuilder &operator=(const UCharsTrieBuilder &other);  // no assignment operator
00126 
00127     void buildUChars(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
00128 
00129     virtual int32_t getElementStringLength(int32_t i) const;
00130     virtual UChar getElementUnit(int32_t i, int32_t unitIndex) const;
00131     virtual int32_t getElementValue(int32_t i) const;
00132 
00133     virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex) const;
00134 
00135     virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const;
00136     virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const;
00137     virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, UChar unit) const;
00138 
00139     virtual UBool matchNodesCanHaveValues() const { return TRUE; }
00140 
00141     virtual int32_t getMaxBranchLinearSubNodeLength() const { return UCharsTrie::kMaxBranchLinearSubNodeLength; }
00142     virtual int32_t getMinLinearMatch() const { return UCharsTrie::kMinLinearMatch; }
00143     virtual int32_t getMaxLinearMatchLength() const { return UCharsTrie::kMaxLinearMatchLength; }
00144 
00145 #ifndef U_HIDE_INTERNAL_API
00146     class UCTLinearMatchNode : public LinearMatchNode {
00147     public:
00148         UCTLinearMatchNode(const UChar *units, int32_t len, Node *nextNode);
00149         virtual UBool operator==(const Node &other) const;
00150         virtual void write(StringTrieBuilder &builder);
00151     private:
00152         const UChar *s;
00153     };
00154 #endif
00155 
00156     virtual Node *createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length,
00157                                         Node *nextNode) const;
00158 
00159     UBool ensureCapacity(int32_t length);
00160     virtual int32_t write(int32_t unit);
00161     int32_t write(const UChar *s, int32_t length);
00162     virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length);
00163     virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal);
00164     virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node);
00165     virtual int32_t writeDeltaTo(int32_t jumpTarget);
00166 
00167     UnicodeString strings;
00168     UCharsTrieElement *elements;
00169     int32_t elementsCapacity;
00170     int32_t elementsLength;
00171 
00172     // UChar serialization of the trie.
00173     // Grows from the back: ucharsLength measures from the end of the buffer!
00174     UChar *uchars;
00175     int32_t ucharsCapacity;
00176     int32_t ucharsLength;
00177 };
00178 
00179 U_NAMESPACE_END
00180 
00181 #endif  // __UCHARSTRIEBUILDER_H__

Generated on 25 Nov 2014 for ICU 50.1.2 by  doxygen 1.4.7