Home | History | Annotate | Download | only in utils
      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 "dictionary/header/header_read_write_utils.h"
     24 #include "dictionary/utils/format_utils.h"
     25 
     26 namespace latinime {
     27 
     28 class BufferWithExtendableBuffer;
     29 
     30 class 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     static bool writeBufferToFileTail(FILE *const file,
     42             const BufferWithExtendableBuffer *const buffer);
     43 
     44  private:
     45     DISALLOW_IMPLICIT_CONSTRUCTORS(DictFileWritingUtils);
     46 
     47     static const int SIZE_OF_BUFFER_SIZE_FIELD;
     48 
     49     static bool createEmptyV401DictFile(const char *const filePath,
     50             const std::vector<int> localeAsCodePointVector,
     51             const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap,
     52             const FormatUtils::FORMAT_VERSION formatVersion);
     53 
     54     template<class DictConstants, class DictBuffers, class DictBuffersPtr>
     55     static bool createEmptyV4DictFile(const char *const filePath,
     56             const std::vector<int> localeAsCodePointVector,
     57             const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap,
     58             const FormatUtils::FORMAT_VERSION formatVersion);
     59 
     60     static bool flushBufferToFile(const char *const filePath,
     61             const BufferWithExtendableBuffer *const buffer);
     62 
     63     static bool writeBufferToFile(FILE *const file,
     64             const BufferWithExtendableBuffer *const buffer);
     65 };
     66 } // namespace latinime
     67 #endif /* LATINIME_DICT_FILE_WRITING_UTILS_H */
     68