ICU 4.8.1.1  4.8.1.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bytestriebuilder.h
1 /*
2 *******************************************************************************
3 * Copyright (C) 2010-2011, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
6 * file name: bytestriebuilder.h
7 * encoding: US-ASCII
8 * tab size: 8 (not used)
9 * indentation:4
10 *
11 * created on: 2010sep25
12 * created by: Markus W. Scherer
13 */
14 
15 #ifndef __BYTESTRIEBUILDER_H__
16 #define __BYTESTRIEBUILDER_H__
17 
18 #include "unicode/utypes.h"
19 #include "unicode/bytestrie.h"
20 #include "unicode/stringpiece.h"
21 #include "unicode/stringtriebuilder.h"
22 
24 
25 class BytesTrieElement;
26 class CharString;
27 
35 public:
41  BytesTrieBuilder(UErrorCode &errorCode);
42 
47  virtual ~BytesTrieBuilder();
48 
63  BytesTrieBuilder &add(const StringPiece &s, int32_t value, UErrorCode &errorCode);
64 
80  BytesTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
81 
101  StringPiece buildStringPiece(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
102 
109  BytesTrieBuilder &clear();
110 
111 private:
112  BytesTrieBuilder(const BytesTrieBuilder &other); // no copy constructor
113  BytesTrieBuilder &operator=(const BytesTrieBuilder &other); // no assignment operator
114 
115  void buildBytes(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
116 
117  virtual int32_t getElementStringLength(int32_t i) const;
118  virtual UChar getElementUnit(int32_t i, int32_t byteIndex) const;
119  virtual int32_t getElementValue(int32_t i) const;
120 
121  virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t byteIndex) const;
122 
123  virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t byteIndex) const;
124  virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t byteIndex, int32_t count) const;
125  virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t byteIndex, UChar byte) const;
126 
127  virtual UBool matchNodesCanHaveValues() const { return FALSE; }
128 
129  virtual int32_t getMaxBranchLinearSubNodeLength() const { return BytesTrie::kMaxBranchLinearSubNodeLength; }
130  virtual int32_t getMinLinearMatch() const { return BytesTrie::kMinLinearMatch; }
131  virtual int32_t getMaxLinearMatchLength() const { return BytesTrie::kMaxLinearMatchLength; }
132 
136  class BTLinearMatchNode : public LinearMatchNode {
137  public:
138  BTLinearMatchNode(const char *units, int32_t len, Node *nextNode);
139  virtual UBool operator==(const Node &other) const;
140  virtual void write(StringTrieBuilder &builder);
141  private:
142  const char *s;
143  };
144 
145  virtual Node *createLinearMatchNode(int32_t i, int32_t byteIndex, int32_t length,
146  Node *nextNode) const;
147 
148  UBool ensureCapacity(int32_t length);
149  virtual int32_t write(int32_t byte);
150  int32_t write(const char *b, int32_t length);
151  virtual int32_t writeElementUnits(int32_t i, int32_t byteIndex, int32_t length);
152  virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal);
153  virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node);
154  virtual int32_t writeDeltaTo(int32_t jumpTarget);
155 
156  CharString *strings; // Pointer not object so we need not #include internal charstr.h.
157  BytesTrieElement *elements;
158  int32_t elementsCapacity;
159  int32_t elementsLength;
160 
161  // Byte serialization of the trie.
162  // Grows from the back: bytesLength measures from the end of the buffer!
163  char *bytes;
164  int32_t bytesCapacity;
165  int32_t bytesLength;
166 };
167 
169 
170 #endif // __BYTESTRIEBUILDER_H__
virtual UBool matchNodesCanHaveValues() const =0
virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const =0
virtual int32_t getElementStringLength(int32_t i) const =0
virtual Node * createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length, Node *nextNode) const =0
virtual int32_t getMaxLinearMatchLength() const =0
C++ API: Trie for mapping byte sequences to integer values.
void build(UStringTrieBuildOption buildOption, int32_t elementsLength, UErrorCode &errorCode)
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:52
Builder class for BytesTrie.
virtual int32_t write(int32_t unit)=0
Light-weight, non-const reader class for a BytesTrie.
Definition: bytestrie.h:48
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex) const =0
virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length)=0
C++ API: StringPiece: Read-only byte string wrapper class.
virtual int32_t getMinLinearMatch() const =0
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal)=0
virtual int32_t getElementValue(int32_t i) const =0
virtual UChar getElementUnit(int32_t i, int32_t unitIndex) const =0
uint16_t UChar
Define UChar to be wchar_t if that is 16 bits wide; always assumed to be unsigned.
Definition: umachine.h:325
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, UChar unit) const =0
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:639
Basic definitions for ICU, for both C and C++ APIs.
#define FALSE
The FALSE value of a UBool.
Definition: umachine.h:236
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
Definition: utypes.h:520
virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const =0
Base class for string trie builder classes.
virtual int32_t writeDeltaTo(int32_t jumpTarget)=0
virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node)=0
virtual int32_t getMaxBranchLinearSubNodeLength() const =0
int8_t UBool
The ICU boolean type.
Definition: umachine.h:228