ICU 50.2 50.2
ucharstriebuilder.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: 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"
20#include "unicode/ucharstrie.h"
21#include "unicode/unistr.h"
22
27
29
30class UCharsTrieElement;
31
39public:
46
52
67 UCharsTrieBuilder &add(const UnicodeString &s, int32_t value, UErrorCode &errorCode);
68
85
108 UErrorCode &errorCode);
109
117 strings.remove();
118 elementsLength=0;
119 ucharsLength=0;
120 return *this;
121 }
122
123private:
124 UCharsTrieBuilder(const UCharsTrieBuilder &other); // no copy constructor
125 UCharsTrieBuilder &operator=(const UCharsTrieBuilder &other); // no assignment operator
126
127 void buildUChars(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
128
129 virtual int32_t getElementStringLength(int32_t i) const;
130 virtual UChar getElementUnit(int32_t i, int32_t unitIndex) const;
131 virtual int32_t getElementValue(int32_t i) const;
132
133 virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex) const;
134
135 virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const;
136 virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const;
137 virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, UChar unit) const;
138
139 virtual UBool matchNodesCanHaveValues() const { return TRUE; }
140
141 virtual int32_t getMaxBranchLinearSubNodeLength() const { return UCharsTrie::kMaxBranchLinearSubNodeLength; }
142 virtual int32_t getMinLinearMatch() const { return UCharsTrie::kMinLinearMatch; }
143 virtual int32_t getMaxLinearMatchLength() const { return UCharsTrie::kMaxLinearMatchLength; }
144
145#ifndef U_HIDE_INTERNAL_API
146 class UCTLinearMatchNode : public LinearMatchNode {
147 public:
148 UCTLinearMatchNode(const UChar *units, int32_t len, Node *nextNode);
149 virtual UBool operator==(const Node &other) const;
150 virtual void write(StringTrieBuilder &builder);
151 private:
152 const UChar *s;
153 };
154#endif
155
156 virtual Node *createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length,
157 Node *nextNode) const;
158
159 UBool ensureCapacity(int32_t length);
160 virtual int32_t write(int32_t unit);
161 int32_t write(const UChar *s, int32_t length);
162 virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length);
163 virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal);
164 virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node);
165 virtual int32_t writeDeltaTo(int32_t jumpTarget);
166
167 UnicodeString strings;
168 UCharsTrieElement *elements;
169 int32_t elementsCapacity;
170 int32_t elementsLength;
171
172 // UChar serialization of the trie.
173 // Grows from the back: ucharsLength measures from the end of the buffer!
174 UChar *uchars;
175 int32_t ucharsCapacity;
176 int32_t ucharsLength;
177};
178
180
181#endif // __UCHARSTRIEBUILDER_H__
virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const =0
virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const =0
virtual int32_t getMaxBranchLinearSubNodeLength() const =0
virtual int32_t write(int32_t unit)=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
virtual int32_t getMinLinearMatch() const =0
virtual int32_t getElementValue(int32_t i) const =0
virtual int32_t getElementStringLength(int32_t i) const =0
virtual UChar getElementUnit(int32_t i, int32_t unitIndex) const =0
virtual UBool matchNodesCanHaveValues() const =0
virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal)=0
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 writeDeltaTo(int32_t jumpTarget)=0
virtual int32_t getMaxLinearMatchLength() const =0
virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node)=0
Builder class for UCharsTrie.
UCharsTrie * build(UStringTrieBuildOption buildOption, UErrorCode &errorCode)
Builds a UCharsTrie for the add()ed data.
virtual ~UCharsTrieBuilder()
Destructor.
UCharsTrieBuilder & clear()
Removes all (string, value) pairs.
UCharsTrieBuilder(UErrorCode &errorCode)
Constructs an empty builder.
UnicodeString & buildUnicodeString(UStringTrieBuildOption buildOption, UnicodeString &result, UErrorCode &errorCode)
Builds a UCharsTrie for the add()ed data and UChar-serializes it.
UCharsTrieBuilder & add(const UnicodeString &s, int32_t value, UErrorCode &errorCode)
Adds a (string, value) pair.
Light-weight, non-const reader class for a UCharsTrie.
Definition ucharstrie.h:48
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:247
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
C++ API: Builder API for trie builders.
UStringTrieBuildOption
Build options for BytesTrieBuilder and CharsTrieBuilder.
C++ API: Trie for mapping Unicode strings (or 16-bit-unit sequences) to integer values.
int8_t UBool
The ICU boolean type.
Definition umachine.h:200
#define TRUE
The TRUE value of a UBool.
Definition umachine.h:204
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
C++ API: Unicode String.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:476
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition utypes.h:357
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:129