ICU 4.8.1.1
4.8.1.1
|
00001 /* 00002 ******************************************************************************* 00003 * Copyright (C) 2010-2011, International Business Machines 00004 * Corporation and others. All Rights Reserved. 00005 ******************************************************************************* 00006 * file name: bytestriebuilder.h 00007 * encoding: US-ASCII 00008 * tab size: 8 (not used) 00009 * indentation:4 00010 * 00011 * created on: 2010sep25 00012 * created by: Markus W. Scherer 00013 */ 00014 00015 #ifndef __BYTESTRIEBUILDER_H__ 00016 #define __BYTESTRIEBUILDER_H__ 00017 00018 #include "unicode/utypes.h" 00019 #include "unicode/bytestrie.h" 00020 #include "unicode/stringpiece.h" 00021 #include "unicode/stringtriebuilder.h" 00022 00023 U_NAMESPACE_BEGIN 00024 00025 class BytesTrieElement; 00026 class CharString; 00027 00034 class U_COMMON_API BytesTrieBuilder : public StringTrieBuilder { 00035 public: 00041 BytesTrieBuilder(UErrorCode &errorCode); 00042 00047 virtual ~BytesTrieBuilder(); 00048 00063 BytesTrieBuilder &add(const StringPiece &s, int32_t value, UErrorCode &errorCode); 00064 00080 BytesTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode); 00081 00101 StringPiece buildStringPiece(UStringTrieBuildOption buildOption, UErrorCode &errorCode); 00102 00109 BytesTrieBuilder &clear(); 00110 00111 private: 00112 BytesTrieBuilder(const BytesTrieBuilder &other); // no copy constructor 00113 BytesTrieBuilder &operator=(const BytesTrieBuilder &other); // no assignment operator 00114 00115 void buildBytes(UStringTrieBuildOption buildOption, UErrorCode &errorCode); 00116 00117 virtual int32_t getElementStringLength(int32_t i) const; 00118 virtual UChar getElementUnit(int32_t i, int32_t byteIndex) const; 00119 virtual int32_t getElementValue(int32_t i) const; 00120 00121 virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t byteIndex) const; 00122 00123 virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t byteIndex) const; 00124 virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t byteIndex, int32_t count) const; 00125 virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t byteIndex, UChar byte) const; 00126 00127 virtual UBool matchNodesCanHaveValues() const { return FALSE; } 00128 00129 virtual int32_t getMaxBranchLinearSubNodeLength() const { return BytesTrie::kMaxBranchLinearSubNodeLength; } 00130 virtual int32_t getMinLinearMatch() const { return BytesTrie::kMinLinearMatch; } 00131 virtual int32_t getMaxLinearMatchLength() const { return BytesTrie::kMaxLinearMatchLength; } 00132 00136 class BTLinearMatchNode : public LinearMatchNode { 00137 public: 00138 BTLinearMatchNode(const char *units, int32_t len, Node *nextNode); 00139 virtual UBool operator==(const Node &other) const; 00140 virtual void write(StringTrieBuilder &builder); 00141 private: 00142 const char *s; 00143 }; 00144 00145 virtual Node *createLinearMatchNode(int32_t i, int32_t byteIndex, int32_t length, 00146 Node *nextNode) const; 00147 00148 UBool ensureCapacity(int32_t length); 00149 virtual int32_t write(int32_t byte); 00150 int32_t write(const char *b, int32_t length); 00151 virtual int32_t writeElementUnits(int32_t i, int32_t byteIndex, int32_t length); 00152 virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal); 00153 virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node); 00154 virtual int32_t writeDeltaTo(int32_t jumpTarget); 00155 00156 CharString *strings; // Pointer not object so we need not #include internal charstr.h. 00157 BytesTrieElement *elements; 00158 int32_t elementsCapacity; 00159 int32_t elementsLength; 00160 00161 // Byte serialization of the trie. 00162 // Grows from the back: bytesLength measures from the end of the buffer! 00163 char *bytes; 00164 int32_t bytesCapacity; 00165 int32_t bytesLength; 00166 }; 00167 00168 U_NAMESPACE_END 00169 00170 #endif // __BYTESTRIEBUILDER_H__