ICU 68.2  68.2
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:
51 
56  virtual ~BytesTrieBuilder();
57 
72  BytesTrieBuilder &add(StringPiece s, int32_t value, UErrorCode &errorCode);
73 
92  BytesTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
93 
118 
126 
127 private:
128  BytesTrieBuilder(const BytesTrieBuilder &other); // no copy constructor
129  BytesTrieBuilder &operator=(const BytesTrieBuilder &other); // no assignment operator
130 
131  void buildBytes(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
132 
133  virtual int32_t getElementStringLength(int32_t i) const;
134  virtual char16_t getElementUnit(int32_t i, int32_t byteIndex) const;
135  virtual int32_t getElementValue(int32_t i) const;
136 
137  virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t byteIndex) const;
138 
139  virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t byteIndex) const;
140  virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t byteIndex, int32_t count) const;
141  virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t byteIndex, char16_t byte) const;
142 
143  virtual UBool matchNodesCanHaveValues() const { return false; }
144 
145  virtual int32_t getMaxBranchLinearSubNodeLength() const { return BytesTrie::kMaxBranchLinearSubNodeLength; }
146  virtual int32_t getMinLinearMatch() const { return BytesTrie::kMinLinearMatch; }
147  virtual int32_t getMaxLinearMatchLength() const { return BytesTrie::kMaxLinearMatchLength; }
148 
152  class BTLinearMatchNode : public LinearMatchNode {
153  public:
154  BTLinearMatchNode(const char *units, int32_t len, Node *nextNode);
155  virtual UBool operator==(const Node &other) const;
156  virtual void write(StringTrieBuilder &builder);
157  private:
158  const char *s;
159  };
160 
161  virtual Node *createLinearMatchNode(int32_t i, int32_t byteIndex, int32_t length,
162  Node *nextNode) const;
163 
164  UBool ensureCapacity(int32_t length);
165  virtual int32_t write(int32_t byte);
166  int32_t write(const char *b, int32_t length);
167  virtual int32_t writeElementUnits(int32_t i, int32_t byteIndex, int32_t length);
168  virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal);
169  virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node);
170  virtual int32_t writeDeltaTo(int32_t jumpTarget);
171 
172  CharString *strings; // Pointer not object so we need not #include internal charstr.h.
173  BytesTrieElement *elements;
174  int32_t elementsCapacity;
175  int32_t elementsLength;
176 
177  // Byte serialization of the trie.
178  // Grows from the back: bytesLength measures from the end of the buffer!
179  char *bytes;
180  int32_t bytesCapacity;
181  int32_t bytesLength;
182 };
183 
184 U_NAMESPACE_END
185 
186 #endif /* U_SHOW_CPLUSPLUS_API */
187 
188 #endif // __BYTESTRIEBUILDER_H__
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::BytesTrieBuilder::build
BytesTrie * build(UStringTrieBuildOption buildOption, UErrorCode &errorCode)
Builds a BytesTrie for the add()ed data.
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
stringtriebuilder.h
C++ API: Builder API for trie builders.
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
UStringTrieBuildOption
UStringTrieBuildOption
Build options for BytesTrieBuilder and CharsTrieBuilder.
Definition: stringtriebuilder.h:41
U_COMMON_API
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition: utypes.h:300
stringpiece.h
C++ API: StringPiece: Read-only byte string wrapper class.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
icu::BytesTrieBuilder::buildStringPiece
StringPiece buildStringPiece(UStringTrieBuildOption buildOption, UErrorCode &errorCode)
Builds a BytesTrie for the add()ed data and byte-serializes it.
icu::BytesTrieBuilder::clear
BytesTrieBuilder & clear()
Removes all (byte sequence, value) pairs.
icu::BytesTrieBuilder::~BytesTrieBuilder
virtual ~BytesTrieBuilder()
Destructor.
icu::BytesTrie
Light-weight, non-const reader class for a BytesTrie.
Definition: bytestrie.h:53
icu::BytesTrieBuilder::BytesTrieBuilder
BytesTrieBuilder(UErrorCode &errorCode)
Constructs an empty builder.
icu::BytesTrieBuilder
Builder class for BytesTrie.
Definition: bytestriebuilder.h:43
icu::BytesTrieBuilder::add
BytesTrieBuilder & add(StringPiece s, int32_t value, UErrorCode &errorCode)
Adds a (byte sequence, value) pair.
bytestrie.h
C++ API: Trie for mapping byte sequences to integer values.
icu::StringPiece
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:60