ICU 50.1.2  50.1.2
bytestriebuilder.h
Go to the documentation of this file.
1 /*
2 *******************************************************************************
3 * Copyright (C) 2010-2012, 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 
20 #ifndef __BYTESTRIEBUILDER_H__
21 #define __BYTESTRIEBUILDER_H__
22 
23 #include "unicode/utypes.h"
24 #include "unicode/bytestrie.h"
25 #include "unicode/stringpiece.h"
27 
29 
30 class BytesTrieElement;
31 class CharString;
32 
40 public:
46  BytesTrieBuilder(UErrorCode &errorCode);
47 
52  virtual ~BytesTrieBuilder();
53 
68  BytesTrieBuilder &add(const StringPiece &s, int32_t value, UErrorCode &errorCode);
69 
85  BytesTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
86 
106  StringPiece buildStringPiece(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
107 
114  BytesTrieBuilder &clear();
115 
116 private:
117  BytesTrieBuilder(const BytesTrieBuilder &other); // no copy constructor
118  BytesTrieBuilder &operator=(const BytesTrieBuilder &other); // no assignment operator
119 
120  void buildBytes(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
121 
122  virtual int32_t getElementStringLength(int32_t i) const;
123  virtual UChar getElementUnit(int32_t i, int32_t byteIndex) const;
124  virtual int32_t getElementValue(int32_t i) const;
125 
126  virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t byteIndex) const;
127 
128  virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t byteIndex) const;
129  virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t byteIndex, int32_t count) const;
130  virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t byteIndex, UChar byte) const;
131 
132  virtual UBool matchNodesCanHaveValues() const { return FALSE; }
133 
134  virtual int32_t getMaxBranchLinearSubNodeLength() const { return BytesTrie::kMaxBranchLinearSubNodeLength; }
135  virtual int32_t getMinLinearMatch() const { return BytesTrie::kMinLinearMatch; }
136  virtual int32_t getMaxLinearMatchLength() const { return BytesTrie::kMaxLinearMatchLength; }
137 
138 #ifndef U_HIDE_INTERNAL_API
139 
142  class BTLinearMatchNode : public LinearMatchNode {
143  public:
144  BTLinearMatchNode(const char *units, int32_t len, Node *nextNode);
145  virtual UBool operator==(const Node &other) const;
146  virtual void write(StringTrieBuilder &builder);
147  private:
148  const char *s;
149  };
150 #endif /* U_HIDE_INTERNAL_API */
151 
152  virtual Node *createLinearMatchNode(int32_t i, int32_t byteIndex, int32_t length,
153  Node *nextNode) const;
154 
155  UBool ensureCapacity(int32_t length);
156  virtual int32_t write(int32_t byte);
157  int32_t write(const char *b, int32_t length);
158  virtual int32_t writeElementUnits(int32_t i, int32_t byteIndex, int32_t length);
159  virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal);
160  virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node);
161  virtual int32_t writeDeltaTo(int32_t jumpTarget);
162 
163  CharString *strings; // Pointer not object so we need not #include internal charstr.h.
164  BytesTrieElement *elements;
165  int32_t elementsCapacity;
166  int32_t elementsLength;
167 
168  // Byte serialization of the trie.
169  // Grows from the back: bytesLength measures from the end of the buffer!
170  char *bytes;
171  int32_t bytesCapacity;
172  int32_t bytesLength;
173 };
174 
176 
177 #endif // __BYTESTRIEBUILDER_H__
C++ API: Builder API for trie builders.
virtual int32_t getMinLinearMatch() const =0
virtual Node * createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length, Node *nextNode) const =0
virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, UChar unit) const =0
Base class for string trie builder classes.
virtual int32_t getMaxLinearMatchLength() const =0
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.
virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const =0
virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node)=0
virtual int32_t getMaxBranchLinearSubNodeLength() const =0
virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length)=0
virtual int32_t getElementStringLength(int32_t i) const =0
Light-weight, non-const reader class for a BytesTrie.
Definition: bytestrie.h:48
virtual UChar getElementUnit(int32_t i, int32_t unitIndex) const =0
C++ API: StringPiece: Read-only byte string wrapper class.
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
virtual int32_t getElementValue(int32_t i) const =0
virtual int32_t writeDeltaTo(int32_t jumpTarget)=0
virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex) const =0
uint16_t UChar
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
Definition: umachine.h:278
UStringTrieBuildOption
Build options for BytesTrieBuilder and CharsTrieBuilder.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
void build(UStringTrieBuildOption buildOption, int32_t elementsLength, UErrorCode &errorCode)
virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal)=0
virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const =0
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
Basic definitions for ICU, for both C and C++ APIs.
#define FALSE
The FALSE value of a UBool.
Definition: umachine.h:208
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
Definition: utypes.h:357
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:52
virtual UBool matchNodesCanHaveValues() const =0
virtual int32_t write(int32_t unit)=0
int8_t UBool
The ICU boolean type.
Definition: umachine.h:200