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_DICTIONARY_STRUCTURE_WITH_BUFFER_POLICY_FACTORY_H
18 #define LATINIME_DICTIONARY_STRUCTURE_WITH_BUFFER_POLICY_FACTORY_H
19 
20 #include <vector>
21 
22 #include "defines.h"
23 #include "suggest/core/policy/dictionary_header_structure_policy.h"
24 #include "suggest/core/policy/dictionary_structure_with_buffer_policy.h"
25 #include "suggest/policyimpl/dictionary/utils/format_utils.h"
26 #include "suggest/policyimpl/dictionary/utils/mmapped_buffer.h"
27 
28 namespace latinime {
29 
30 class DictionaryStructureWithBufferPolicyFactory {
31  public:
32     static DictionaryStructureWithBufferPolicy::StructurePolicyPtr
33             newPolicyForExistingDictFile(const char *const path, const int bufOffset,
34                     const int size, const bool isUpdatable);
35 
36     static DictionaryStructureWithBufferPolicy::StructurePolicyPtr
37             newPolicyForOnMemoryDict(const int formatVersion, const std::vector<int> &locale,
38                     const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap);
39 
40  private:
41     DISALLOW_IMPLICIT_CONSTRUCTORS(DictionaryStructureWithBufferPolicyFactory);
42 
43     template<class DictConstants, class DictBuffers, class DictBuffersPtr, class StructurePolicy>
44     static DictionaryStructureWithBufferPolicy::StructurePolicyPtr
45             newPolicyForOnMemoryV4Dict(const FormatUtils::FORMAT_VERSION formatVersion,
46                     const std::vector<int> &locale,
47                     const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap);
48 
49     static DictionaryStructureWithBufferPolicy::StructurePolicyPtr
50             newPolicyForDirectoryDict(const char *const path, const bool isUpdatable);
51 
52     template<class DictConstants, class DictBuffers, class DictBuffersPtr, class StructurePolicy>
53     static DictionaryStructureWithBufferPolicy::StructurePolicyPtr newPolicyForV4Dict(
54             const char *const headerFilePath, const FormatUtils::FORMAT_VERSION formatVersion,
55                     MmappedBuffer::MmappedBufferPtr &&mmappedBuffer);
56 
57     static DictionaryStructureWithBufferPolicy::StructurePolicyPtr
58             newPolicyForFileDict(const char *const path, const int bufOffset, const int size);
59 
60     static void getHeaderFilePathInDictDir(const char *const dirPath,
61             const int outHeaderFileBufSize, char *const outHeaderFilePath);
62 };
63 } // namespace latinime
64 #endif // LATINIME_DICTIONARY_STRUCTURE_WITH_BUFFER_POLICY_FACTORY_H
65