dict_file_writing_utils.h revision 6afd14dc9488aab7c2f982f9b18931c3b3a20e75
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_DICT_FILE_WRITING_UTILS_H 18#define LATINIME_DICT_FILE_WRITING_UTILS_H 19 20#include <cstdio> 21 22#include "defines.h" 23#include "suggest/policyimpl/dictionary/header/header_read_write_utils.h" 24#include "suggest/policyimpl/dictionary/utils/format_utils.h" 25 26namespace latinime { 27 28class BufferWithExtendableBuffer; 29 30class DictFileWritingUtils { 31 public: 32 static const char *const TEMP_FILE_SUFFIX_FOR_WRITING_DICT_FILE; 33 34 static bool createEmptyDictFile(const char *const filePath, const int dictVersion, 35 const std::vector<int> localeAsCodePointVector, 36 const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap); 37 38 static bool flushBufferToFileWithSuffix(const char *const basePath, const char *const suffix, 39 const BufferWithExtendableBuffer *const buffer); 40 41 private: 42 DISALLOW_IMPLICIT_CONSTRUCTORS(DictFileWritingUtils); 43 44 static bool createEmptyV401DictFile(const char *const filePath, 45 const std::vector<int> localeAsCodePointVector, 46 const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap, 47 const FormatUtils::FORMAT_VERSION formatVersion); 48 49 template<class DictConstants, class DictBuffers, class DictBuffersPtr> 50 static bool createEmptyV4DictFile(const char *const filePath, 51 const std::vector<int> localeAsCodePointVector, 52 const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap, 53 const FormatUtils::FORMAT_VERSION formatVersion); 54 55 static bool flushBufferToFile(const char *const filePath, 56 const BufferWithExtendableBuffer *const buffer); 57 58 static bool writeBufferToFile(FILE *const file, 59 const BufferWithExtendableBuffer *const buffer); 60}; 61} // namespace latinime 62#endif /* LATINIME_DICT_FILE_WRITING_UTILS_H */ 63