Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: third_party/prediction/suggest/policyimpl/dictionary/header/header_read_write_utils.h

Issue 1247903003: Add spellcheck and word suggestion to the prediction service (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2013, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef LATINIME_HEADER_READ_WRITE_UTILS_H
18 #define LATINIME_HEADER_READ_WRITE_UTILS_H
19
20 #include <cstdint>
21
22 #include "third_party/prediction/defines.h"
23 #include "third_party/prediction/suggest/core/policy/dictionary_header_structure _policy.h"
24 #include "third_party/prediction/suggest/policyimpl/dictionary/utils/format_util s.h"
25
26 namespace latinime {
27
28 class BufferWithExtendableBuffer;
29
30 class HeaderReadWriteUtils {
31 public:
32 typedef uint16_t DictionaryFlags;
33
34 static int getHeaderSize(const uint8_t* const dictBuf);
35
36 static DictionaryFlags getFlags(const uint8_t* const dictBuf);
37
38 static AK_FORCE_INLINE int getHeaderOptionsPosition() {
39 return HEADER_MAGIC_NUMBER_SIZE + HEADER_DICTIONARY_VERSION_SIZE +
40 HEADER_FLAG_SIZE + HEADER_SIZE_FIELD_SIZE;
41 }
42
43 static DictionaryFlags createAndGetDictionaryFlagsUsingAttributeMap(
44 const DictionaryHeaderStructurePolicy::AttributeMap* const attributeMap);
45
46 static void fetchAllHeaderAttributes(
47 const uint8_t* const dictBuf,
48 DictionaryHeaderStructurePolicy::AttributeMap* const headerAttributes);
49
50 static bool writeDictionaryVersion(BufferWithExtendableBuffer* const buffer,
51 const FormatUtils::FORMAT_VERSION version,
52 int* const writingPos);
53
54 static bool writeDictionaryFlags(BufferWithExtendableBuffer* const buffer,
55 const DictionaryFlags flags,
56 int* const writingPos);
57
58 static bool writeDictionaryHeaderSize(
59 BufferWithExtendableBuffer* const buffer,
60 const int size,
61 int* const writingPos);
62
63 static bool writeHeaderAttributes(
64 BufferWithExtendableBuffer* const buffer,
65 const DictionaryHeaderStructurePolicy::AttributeMap* const
66 headerAttributes,
67 int* const writingPos);
68
69 /**
70 * Methods for header attributes.
71 */
72 static void setCodePointVectorAttribute(
73 DictionaryHeaderStructurePolicy::AttributeMap* const headerAttributes,
74 const char* const key,
75 const std::vector<int> value);
76
77 static void setBoolAttribute(
78 DictionaryHeaderStructurePolicy::AttributeMap* const headerAttributes,
79 const char* const key,
80 const bool value);
81
82 static void setIntAttribute(
83 DictionaryHeaderStructurePolicy::AttributeMap* const headerAttributes,
84 const char* const key,
85 const int value);
86
87 static const std::vector<int> readCodePointVectorAttributeValue(
88 const DictionaryHeaderStructurePolicy::AttributeMap* const
89 headerAttributes,
90 const char* const key);
91
92 static bool readBoolAttributeValue(
93 const DictionaryHeaderStructurePolicy::AttributeMap* const
94 headerAttributes,
95 const char* const key,
96 const bool defaultValue);
97
98 static int readIntAttributeValue(
99 const DictionaryHeaderStructurePolicy::AttributeMap* const
100 headerAttributes,
101 const char* const key,
102 const int defaultValue);
103
104 static void insertCharactersIntoVector(
105 const char* const characters,
106 DictionaryHeaderStructurePolicy::AttributeMap::key_type* const key);
107
108 private:
109 DISALLOW_IMPLICIT_CONSTRUCTORS(HeaderReadWriteUtils);
110
111 static const int LARGEST_INT_DIGIT_COUNT;
112 static const int MAX_ATTRIBUTE_KEY_LENGTH;
113 static const int MAX_ATTRIBUTE_VALUE_LENGTH;
114
115 static const int HEADER_MAGIC_NUMBER_SIZE;
116 static const int HEADER_DICTIONARY_VERSION_SIZE;
117 static const int HEADER_FLAG_SIZE;
118 static const int HEADER_SIZE_FIELD_SIZE;
119
120 // Value for the "flags" field. It's unused at the moment.
121 static const DictionaryFlags NO_FLAGS;
122
123 static void setIntAttributeInner(
124 DictionaryHeaderStructurePolicy::AttributeMap* const headerAttributes,
125 const DictionaryHeaderStructurePolicy::AttributeMap::key_type* const key,
126 const int value);
127
128 static int readIntAttributeValueInner(
129 const DictionaryHeaderStructurePolicy::AttributeMap* const
130 headerAttributes,
131 const DictionaryHeaderStructurePolicy::AttributeMap::key_type* const key,
132 const int defaultValue);
133 };
134 }
135 #endif /* LATINIME_HEADER_READ_WRITE_UTILS_H */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698