bytestriebuilder.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
* Copyright (C) 2010-2016, International Business Machines
* Corporation and others. All Rights Reserved.
*******************************************************************************
* file name: bytestriebuilder.h
* encoding: UTF-8
* tab size: 8 (not used)
* indentation:4
*
* created on: 2010sep25
* created by: Markus W. Scherer
*/
#ifndef __BYTESTRIEBUILDER_H__
#define __BYTESTRIEBUILDER_H__
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#include "unicode/bytestrie.h"
#include "unicode/stringpiece.h"
#include "unicode/stringtriebuilder.h"
class BytesTrieTest;
U_NAMESPACE_BEGIN
class BytesTrieElement;
class CharString;
class U_COMMON_API BytesTrieBuilder : public StringTrieBuilder {
public:
BytesTrieBuilder(UErrorCode &errorCode);
virtual ~BytesTrieBuilder();
BytesTrieBuilder &add(StringPiece s, int32_t value, UErrorCode &errorCode);
BytesTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
StringPiece buildStringPiece(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
BytesTrieBuilder &clear();
private:
friend class ::BytesTrieTest;
BytesTrieBuilder(const BytesTrieBuilder &other) = delete; // no copy constructor
BytesTrieBuilder &operator=(const BytesTrieBuilder &other) = delete; // no assignment operator
void buildBytes(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
virtual int32_t getElementStringLength(int32_t i) const override;
virtual char16_t getElementUnit(int32_t i, int32_t byteIndex) const override;
virtual int32_t getElementValue(int32_t i) const override;
virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t byteIndex) const override;
virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t byteIndex) const override;
virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t byteIndex, int32_t count) const override;
virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t byteIndex, char16_t byte) const override;
virtual UBool matchNodesCanHaveValues() const override { return false; }
virtual int32_t getMaxBranchLinearSubNodeLength() const override { return BytesTrie::kMaxBranchLinearSubNodeLength; }
virtual int32_t getMinLinearMatch() const override { return BytesTrie::kMinLinearMatch; }
virtual int32_t getMaxLinearMatchLength() const override { return BytesTrie::kMaxLinearMatchLength; }
class BTLinearMatchNode : public LinearMatchNode {
public:
BTLinearMatchNode(const char *units, int32_t len, Node *nextNode);
virtual bool operator==(const Node &other) const override;
virtual void write(StringTrieBuilder &builder) override;
private:
const char *s;
};
virtual Node *createLinearMatchNode(int32_t i, int32_t byteIndex, int32_t length,
Node *nextNode) const override;
UBool ensureCapacity(int32_t length);
virtual int32_t write(int32_t byte) override;
int32_t write(const char *b, int32_t length);
virtual int32_t writeElementUnits(int32_t i, int32_t byteIndex, int32_t length) override;
virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal) override;
virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node) override;
virtual int32_t writeDeltaTo(int32_t jumpTarget) override;
static int32_t internalEncodeDelta(int32_t i, char intBytes[]);
CharString *strings; // Pointer not object so we need not #include internal charstr.h.
BytesTrieElement *elements;
int32_t elementsCapacity;
int32_t elementsLength;
// Byte serialization of the trie.
// Grows from the back: bytesLength measures from the end of the buffer!
char *bytes;
int32_t bytesCapacity;
int32_t bytesLength;
};
U_NAMESPACE_END
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // __BYTESTRIEBUILDER_H__
bytestrie.h
C++ API: Trie for mapping byte sequences to integer values.
icu::BytesTrieBuilder
Builder class for BytesTrie.
Definition: bytestriebuilder.h:45
icu::BytesTrieBuilder::buildStringPiece
StringPiece buildStringPiece(UStringTrieBuildOption buildOption, UErrorCode &errorCode)
Builds a BytesTrie for the add()ed data and byte-serializes it.
icu::BytesTrieBuilder::BytesTrieBuilder
BytesTrieBuilder(UErrorCode &errorCode)
Constructs an empty builder.
icu::BytesTrieBuilder::~BytesTrieBuilder
virtual ~BytesTrieBuilder()
Destructor.
icu::BytesTrieBuilder::clear
BytesTrieBuilder & clear()
Removes all (byte sequence, value) pairs.
icu::BytesTrieBuilder::add
BytesTrieBuilder & add(StringPiece s, int32_t value, UErrorCode &errorCode)
Adds a (byte sequence, value) pair.
icu::BytesTrieBuilder::build
BytesTrie * build(UStringTrieBuildOption buildOption, UErrorCode &errorCode)
Builds a BytesTrie for the add()ed data.
icu::BytesTrie
Light-weight, non-const reader class for a BytesTrie.
Definition: bytestrie.h:55
icu::StringPiece
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:61
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
stringpiece.h
C++ API: StringPiece: Read-only byte string wrapper class.
stringtriebuilder.h
C++ API: Builder API for trie builders.
UStringTrieBuildOption
UStringTrieBuildOption
Build options for BytesTrieBuilder and CharsTrieBuilder.
Definition: stringtriebuilder.h:41
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:430
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:315