ICU 65.1  65.1
bytestriebuilder.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 * Copyright (C) 2010-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: bytestriebuilder.h
9 * encoding: UTF-8
10 * tab size: 8 (not used)
11 * indentation:4
12 *
13 * created on: 2010sep25
14 * created by: Markus W. Scherer
15 */
16 
22 #ifndef __BYTESTRIEBUILDER_H__
23 #define __BYTESTRIEBUILDER_H__
24 
25 #include "unicode/utypes.h"
26 
27 #if U_SHOW_CPLUSPLUS_API
28 
29 #include "unicode/bytestrie.h"
30 #include "unicode/stringpiece.h"
32 
33 U_NAMESPACE_BEGIN
34 
35 class BytesTrieElement;
36 class CharString;
43 class U_COMMON_API BytesTrieBuilder : public StringTrieBuilder {
44 public:
50  BytesTrieBuilder(UErrorCode &errorCode);
51 
56  virtual ~BytesTrieBuilder();
57 
72  BytesTrieBuilder &add(StringPiece s, int32_t value, UErrorCode &errorCode);
73 
92  BytesTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
93 
116  StringPiece buildStringPiece(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
117 
124  BytesTrieBuilder &clear();
125 
126 private:
127  BytesTrieBuilder(const BytesTrieBuilder &other); // no copy constructor
128  BytesTrieBuilder &operator=(const BytesTrieBuilder &other); // no assignment operator
129 
130  void buildBytes(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
131 
132  virtual int32_t getElementStringLength(int32_t i) const;
133  virtual char16_t getElementUnit(int32_t i, int32_t byteIndex) const;
134  virtual int32_t getElementValue(int32_t i) const;
135 
136  virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t byteIndex) const;
137 
138  virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t byteIndex) const;
139  virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t byteIndex, int32_t count) const;
140  virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t byteIndex, char16_t byte) const;
141 
142  virtual UBool matchNodesCanHaveValues() const { return FALSE; }
143 
144  virtual int32_t getMaxBranchLinearSubNodeLength() const { return BytesTrie::kMaxBranchLinearSubNodeLength; }
145  virtual int32_t getMinLinearMatch() const { return BytesTrie::kMinLinearMatch; }
146  virtual int32_t getMaxLinearMatchLength() const { return BytesTrie::kMaxLinearMatchLength; }
147 
151  class BTLinearMatchNode : public LinearMatchNode {
152  public:
153  BTLinearMatchNode(const char *units, int32_t len, Node *nextNode);
154  virtual UBool operator==(const Node &other) const;
155  virtual void write(StringTrieBuilder &builder);
156  private:
157  const char *s;
158  };
159 
160  virtual Node *createLinearMatchNode(int32_t i, int32_t byteIndex, int32_t length,
161  Node *nextNode) const;
162 
163  UBool ensureCapacity(int32_t length);
164  virtual int32_t write(int32_t byte);
165  int32_t write(const char *b, int32_t length);
166  virtual int32_t writeElementUnits(int32_t i, int32_t byteIndex, int32_t length);
167  virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal);
168  virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node);
169  virtual int32_t writeDeltaTo(int32_t jumpTarget);
170 
171  CharString *strings; // Pointer not object so we need not #include internal charstr.h.
172  BytesTrieElement *elements;
173  int32_t elementsCapacity;
174  int32_t elementsLength;
175 
176  // Byte serialization of the trie.
177  // Grows from the back: bytesLength measures from the end of the buffer!
178  char *bytes;
179  int32_t bytesCapacity;
180  int32_t bytesLength;
181 };
182 
183 U_NAMESPACE_END
184 
185 #endif /* U_SHOW_CPLUSPLUS_API */
186 
187 #endif // __BYTESTRIEBUILDER_H__
C++ API: Builder API for trie builders.
C++ API: Trie for mapping byte sequences to integer values.
Builder class for BytesTrie.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
Light-weight, non-const reader class for a BytesTrie.
Definition: bytestrie.h:53
C++ API: StringPiece: Read-only byte string wrapper class.
UStringTrieBuildOption
Build options for BytesTrieBuilder and CharsTrieBuilder.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
Basic definitions for ICU, for both C and C++ APIs.
#define FALSE
The FALSE value of a UBool.
Definition: umachine.h:269
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
Definition: utypes.h:300
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:60
int8_t UBool
The ICU boolean type.
Definition: umachine.h:261