bytestriebuilder.h

Go to the documentation of this file.
00001 /*
00002 *******************************************************************************
00003 *   Copyright (C) 2010-2012, International Business Machines
00004 *   Corporation and others.  All Rights Reserved.
00005 *******************************************************************************
00006 *   file name:  bytestriebuilder.h
00007 *   encoding:   US-ASCII
00008 *   tab size:   8 (not used)
00009 *   indentation:4
00010 *
00011 *   created on: 2010sep25
00012 *   created by: Markus W. Scherer
00013 */
00014 
00020 #ifndef __BYTESTRIEBUILDER_H__
00021 #define __BYTESTRIEBUILDER_H__
00022 
00023 #include "unicode/utypes.h"
00024 #include "unicode/bytestrie.h"
00025 #include "unicode/stringpiece.h"
00026 #include "unicode/stringtriebuilder.h"
00027 
00028 U_NAMESPACE_BEGIN
00029 
00030 class BytesTrieElement;
00031 class CharString;
00032 
00039 class U_COMMON_API BytesTrieBuilder : public StringTrieBuilder {
00040 public:
00046     BytesTrieBuilder(UErrorCode &errorCode);
00047 
00052     virtual ~BytesTrieBuilder();
00053 
00068     BytesTrieBuilder &add(const StringPiece &s, int32_t value, UErrorCode &errorCode);
00069 
00085     BytesTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
00086 
00106     StringPiece buildStringPiece(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
00107 
00114     BytesTrieBuilder &clear();
00115 
00116 private:
00117     BytesTrieBuilder(const BytesTrieBuilder &other);  // no copy constructor
00118     BytesTrieBuilder &operator=(const BytesTrieBuilder &other);  // no assignment operator
00119 
00120     void buildBytes(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
00121 
00122     virtual int32_t getElementStringLength(int32_t i) const;
00123     virtual UChar getElementUnit(int32_t i, int32_t byteIndex) const;
00124     virtual int32_t getElementValue(int32_t i) const;
00125 
00126     virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t byteIndex) const;
00127 
00128     virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t byteIndex) const;
00129     virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t byteIndex, int32_t count) const;
00130     virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t byteIndex, UChar byte) const;
00131 
00132     virtual UBool matchNodesCanHaveValues() const { return FALSE; }
00133 
00134     virtual int32_t getMaxBranchLinearSubNodeLength() const { return BytesTrie::kMaxBranchLinearSubNodeLength; }
00135     virtual int32_t getMinLinearMatch() const { return BytesTrie::kMinLinearMatch; }
00136     virtual int32_t getMaxLinearMatchLength() const { return BytesTrie::kMaxLinearMatchLength; }
00137 
00138 #ifndef U_HIDE_INTERNAL_API
00139 
00142     class BTLinearMatchNode : public LinearMatchNode {
00143     public:
00144         BTLinearMatchNode(const char *units, int32_t len, Node *nextNode);
00145         virtual UBool operator==(const Node &other) const;
00146         virtual void write(StringTrieBuilder &builder);
00147     private:
00148         const char *s;
00149     };
00150 #endif  /* U_HIDE_INTERNAL_API */
00151 
00152     virtual Node *createLinearMatchNode(int32_t i, int32_t byteIndex, int32_t length,
00153                                         Node *nextNode) const;
00154 
00155     UBool ensureCapacity(int32_t length);
00156     virtual int32_t write(int32_t byte);
00157     int32_t write(const char *b, int32_t length);
00158     virtual int32_t writeElementUnits(int32_t i, int32_t byteIndex, int32_t length);
00159     virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal);
00160     virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node);
00161     virtual int32_t writeDeltaTo(int32_t jumpTarget);
00162 
00163     CharString *strings;  // Pointer not object so we need not #include internal charstr.h.
00164     BytesTrieElement *elements;
00165     int32_t elementsCapacity;
00166     int32_t elementsLength;
00167 
00168     // Byte serialization of the trie.
00169     // Grows from the back: bytesLength measures from the end of the buffer!
00170     char *bytes;
00171     int32_t bytesCapacity;
00172     int32_t bytesLength;
00173 };
00174 
00175 U_NAMESPACE_END
00176 
00177 #endif  // __BYTESTRIEBUILDER_H__

Generated on 25 Nov 2014 for ICU 50.1.2 by  doxygen 1.4.7