Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/common/unicode/bytestriebuilder.h
38827 views
/*1*******************************************************************************2* Copyright (C) 2010-2016, International Business Machines3* Corporation and others. All Rights Reserved.4*******************************************************************************5* file name: bytestriebuilder.h6* encoding: US-ASCII7* tab size: 8 (not used)8* indentation:49*10* created on: 2010sep2511* created by: Markus W. Scherer12*/1314/**15* \file16* \brief C++ API: Builder for icu::BytesTrie17*/1819#ifndef __BYTESTRIEBUILDER_H__20#define __BYTESTRIEBUILDER_H__2122#include "unicode/utypes.h"23#include "unicode/bytestrie.h"24#include "unicode/stringpiece.h"25#include "unicode/stringtriebuilder.h"2627U_NAMESPACE_BEGIN2829class BytesTrieElement;30class CharString;3132/**33* Builder class for BytesTrie.34*35* This class is not intended for public subclassing.36* @stable ICU 4.837*/38class U_COMMON_API BytesTrieBuilder : public StringTrieBuilder {39public:40/**41* Constructs an empty builder.42* @param errorCode Standard ICU error code.43* @stable ICU 4.844*/45BytesTrieBuilder(UErrorCode &errorCode);4647/**48* Destructor.49* @stable ICU 4.850*/51virtual ~BytesTrieBuilder();5253/**54* Adds a (byte sequence, value) pair.55* The byte sequence must be unique.56* The bytes will be copied; the builder does not keep57* a reference to the input StringPiece or its data().58* @param s The input byte sequence.59* @param value The value associated with this byte sequence.60* @param errorCode Standard ICU error code. Its input value must61* pass the U_SUCCESS() test, or else the function returns62* immediately. Check for U_FAILURE() on output or use with63* function chaining. (See User Guide for details.)64* @return *this65* @stable ICU 4.866*/67BytesTrieBuilder &add(const StringPiece &s, int32_t value, UErrorCode &errorCode);6869/**70* Builds a BytesTrie for the add()ed data.71* Once built, no further data can be add()ed until clear() is called.72*73* A BytesTrie cannot be empty. At least one (byte sequence, value) pair74* must have been add()ed.75*76* This method passes ownership of the builder's internal result array to the new trie object.77* Another call to any build() variant will re-serialize the trie.78* After clear() has been called, a new array will be used as well.79* @param buildOption Build option, see UStringTrieBuildOption.80* @param errorCode Standard ICU error code. Its input value must81* pass the U_SUCCESS() test, or else the function returns82* immediately. Check for U_FAILURE() on output or use with83* function chaining. (See User Guide for details.)84* @return A new BytesTrie for the add()ed data.85* @stable ICU 4.886*/87BytesTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);8889/**90* Builds a BytesTrie for the add()ed data and byte-serializes it.91* Once built, no further data can be add()ed until clear() is called.92*93* A BytesTrie cannot be empty. At least one (byte sequence, value) pair94* must have been add()ed.95*96* Multiple calls to buildStringPiece() return StringPieces referring to the97* builder's same byte array, without rebuilding.98* If buildStringPiece() is called after build(), the trie will be99* re-serialized into a new array.100* If build() is called after buildStringPiece(), the trie object will become101* the owner of the previously returned array.102* After clear() has been called, a new array will be used as well.103* @param buildOption Build option, see UStringTrieBuildOption.104* @param errorCode Standard ICU error code. Its input value must105* pass the U_SUCCESS() test, or else the function returns106* immediately. Check for U_FAILURE() on output or use with107* function chaining. (See User Guide for details.)108* @return A StringPiece which refers to the byte-serialized BytesTrie for the add()ed data.109* @stable ICU 4.8110*/111StringPiece buildStringPiece(UStringTrieBuildOption buildOption, UErrorCode &errorCode);112113/**114* Removes all (byte sequence, value) pairs.115* New data can then be add()ed and a new trie can be built.116* @return *this117* @stable ICU 4.8118*/119BytesTrieBuilder &clear();120121private:122BytesTrieBuilder(const BytesTrieBuilder &other); // no copy constructor123BytesTrieBuilder &operator=(const BytesTrieBuilder &other); // no assignment operator124125void buildBytes(UStringTrieBuildOption buildOption, UErrorCode &errorCode);126127virtual int32_t getElementStringLength(int32_t i) const;128virtual UChar getElementUnit(int32_t i, int32_t byteIndex) const;129virtual int32_t getElementValue(int32_t i) const;130131virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t byteIndex) const;132133virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t byteIndex) const;134virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t byteIndex, int32_t count) const;135virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t byteIndex, UChar byte) const;136137virtual UBool matchNodesCanHaveValues() const { return FALSE; }138139virtual int32_t getMaxBranchLinearSubNodeLength() const { return BytesTrie::kMaxBranchLinearSubNodeLength; }140virtual int32_t getMinLinearMatch() const { return BytesTrie::kMinLinearMatch; }141virtual int32_t getMaxLinearMatchLength() const { return BytesTrie::kMaxLinearMatchLength; }142143// don't use #ifndef U_HIDE_INTERNAL_API with private class members144/**145* @internal146*/147class BTLinearMatchNode : public LinearMatchNode {148public:149BTLinearMatchNode(const char *units, int32_t len, Node *nextNode);150virtual UBool operator==(const Node &other) const;151virtual void write(StringTrieBuilder &builder);152private:153const char *s;154};155156// don't use #ifndef U_HIDE_INTERNAL_API with private class members or virtual methods.157virtual Node *createLinearMatchNode(int32_t i, int32_t byteIndex, int32_t length,158Node *nextNode) const;159160UBool ensureCapacity(int32_t length);161virtual int32_t write(int32_t byte);162int32_t write(const char *b, int32_t length);163virtual int32_t writeElementUnits(int32_t i, int32_t byteIndex, int32_t length);164virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal);165virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node);166virtual int32_t writeDeltaTo(int32_t jumpTarget);167168CharString *strings; // Pointer not object so we need not #include internal charstr.h.169BytesTrieElement *elements;170int32_t elementsCapacity;171int32_t elementsLength;172173// Byte serialization of the trie.174// Grows from the back: bytesLength measures from the end of the buffer!175char *bytes;176int32_t bytesCapacity;177int32_t bytesLength;178};179180U_NAMESPACE_END181182#endif // __BYTESTRIEBUILDER_H__183184185