ICU 4.8.1.1  4.8.1.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ucharstriebuilder.h
1 /*
2 *******************************************************************************
3 * Copyright (C) 2010-2011, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
6 * file name: ucharstriebuilder.h
7 * encoding: US-ASCII
8 * tab size: 8 (not used)
9 * indentation:4
10 *
11 * created on: 2010nov14
12 * created by: Markus W. Scherer
13 */
14 
15 #ifndef __UCHARSTRIEBUILDER_H__
16 #define __UCHARSTRIEBUILDER_H__
17 
18 #include "unicode/utypes.h"
19 #include "unicode/stringtriebuilder.h"
20 #include "unicode/ucharstrie.h"
21 #include "unicode/unistr.h"
22 
24 
25 class UCharsTrieElement;
26 
34 public:
40  UCharsTrieBuilder(UErrorCode &errorCode);
41 
46  virtual ~UCharsTrieBuilder();
47 
62  UCharsTrieBuilder &add(const UnicodeString &s, int32_t value, UErrorCode &errorCode);
63 
79  UCharsTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
80 
102  UnicodeString &buildUnicodeString(UStringTrieBuildOption buildOption, UnicodeString &result,
103  UErrorCode &errorCode);
104 
112  strings.remove();
113  elementsLength=0;
114  ucharsLength=0;
115  return *this;
116  }
117 
118 private:
119  UCharsTrieBuilder(const UCharsTrieBuilder &other); // no copy constructor
120  UCharsTrieBuilder &operator=(const UCharsTrieBuilder &other); // no assignment operator
121 
122  void buildUChars(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
123 
124  virtual int32_t getElementStringLength(int32_t i) const;
125  virtual UChar getElementUnit(int32_t i, int32_t unitIndex) const;
126  virtual int32_t getElementValue(int32_t i) const;
127 
128  virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex) const;
129 
130  virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const;
131  virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const;
132  virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, UChar unit) const;
133 
134  virtual UBool matchNodesCanHaveValues() const { return TRUE; }
135 
136  virtual int32_t getMaxBranchLinearSubNodeLength() const { return UCharsTrie::kMaxBranchLinearSubNodeLength; }
137  virtual int32_t getMinLinearMatch() const { return UCharsTrie::kMinLinearMatch; }
138  virtual int32_t getMaxLinearMatchLength() const { return UCharsTrie::kMaxLinearMatchLength; }
139 
140  class UCTLinearMatchNode : public LinearMatchNode {
141  public:
142  UCTLinearMatchNode(const UChar *units, int32_t len, Node *nextNode);
143  virtual UBool operator==(const Node &other) const;
144  virtual void write(StringTrieBuilder &builder);
145  private:
146  const UChar *s;
147  };
148 
149  virtual Node *createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length,
150  Node *nextNode) const;
151 
152  UBool ensureCapacity(int32_t length);
153  virtual int32_t write(int32_t unit);
154  int32_t write(const UChar *s, int32_t length);
155  virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length);
156  virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal);
157  virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node);
158  virtual int32_t writeDeltaTo(int32_t jumpTarget);
159 
160  UnicodeString strings;
161  UCharsTrieElement *elements;
162  int32_t elementsCapacity;
163  int32_t elementsLength;
164 
165  // UChar serialization of the trie.
166  // Grows from the back: ucharsLength measures from the end of the buffer!
167  UChar *uchars;
168  int32_t ucharsCapacity;
169  int32_t ucharsLength;
170 };
171 
173 
174 #endif // __UCHARSTRIEBUILDER_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
Light-weight, non-const reader class for a UCharsTrie.
Definition: ucharstrie.h:48
virtual int32_t getMaxLinearMatchLength() const =0
void build(UStringTrieBuildOption buildOption, int32_t elementsLength, UErrorCode &errorCode)
C++ API: Unicode String.
virtual int32_t write(int32_t unit)=0
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
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
#define TRUE
The TRUE value of a UBool.
Definition: umachine.h:232
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:188
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
Builder class for UCharsTrie.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:639
C++ API: Trie for mapping Unicode strings (or 16-bit-unit sequences) to integer values.
Basic definitions for ICU, for both C and C++ APIs.
#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
UCharsTrieBuilder & clear()
Removes all (string, value) pairs.
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