aboutsummaryrefslogtreecommitdiffstats
path: root/native/jni/src/dictionary/utils/dict_file_writing_utils.h
blob: 102a89da405184f296072149d5b99e23089ea215 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * Copyright (C) 2013, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef LATINIME_DICT_FILE_WRITING_UTILS_H
#define LATINIME_DICT_FILE_WRITING_UTILS_H

#include <cstdio>

#include "defines.h"
#include "dictionary/header/header_read_write_utils.h"
#include "dictionary/utils/format_utils.h"

namespace latinime {

class BufferWithExtendableBuffer;

class DictFileWritingUtils {
 public:
    static const char *const TEMP_FILE_SUFFIX_FOR_WRITING_DICT_FILE;

    static bool createEmptyDictFile(const char *const filePath, const int dictVersion,
            const std::vector<int> localeAsCodePointVector,
            const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap);

    static bool flushBufferToFileWithSuffix(const char *const basePath, const char *const suffix,
            const BufferWithExtendableBuffer *const buffer);

    static bool writeBufferToFileTail(FILE *const file,
            const BufferWithExtendableBuffer *const buffer);

 private:
    DISALLOW_IMPLICIT_CONSTRUCTORS(DictFileWritingUtils);

    static const int SIZE_OF_BUFFER_SIZE_FIELD;

    static bool createEmptyV401DictFile(const char *const filePath,
            const std::vector<int> localeAsCodePointVector,
            const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap,
            const FormatUtils::FORMAT_VERSION formatVersion);

    template<class DictConstants, class DictBuffers, class DictBuffersPtr>
    static bool createEmptyV4DictFile(const char *const filePath,
            const std::vector<int> localeAsCodePointVector,
            const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap,
            const FormatUtils::FORMAT_VERSION formatVersion);

    static bool flushBufferToFile(const char *const filePath,
            const BufferWithExtendableBuffer *const buffer);

    static bool writeBufferToFile(FILE *const file,
            const BufferWithExtendableBuffer *const buffer);
};
} // namespace latinime
#endif /* LATINIME_DICT_FILE_WRITING_UTILS_H */