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 /*
18  * !!!!! DO NOT EDIT THIS FILE !!!!!
19  *
20  * This file was generated from
21  *   dictionary/structure/v4/content/single_dict_content.h
22  */
23 
24 #ifndef LATINIME_BACKWARD_V402_SINGLE_DICT_CONTENT_H
25 #define LATINIME_BACKWARD_V402_SINGLE_DICT_CONTENT_H
26 
27 #include "defines.h"
28 #include "dictionary/structure/backward/v402/content/dict_content.h"
29 #include "dictionary/structure/backward/v402/ver4_dict_constants.h"
30 #include "dictionary/utils/buffer_with_extendable_buffer.h"
31 #include "dictionary/utils/dict_file_writing_utils.h"
32 #include "dictionary/utils/mmapped_buffer.h"
33 #include "utils/byte_array_view.h"
34 
35 namespace latinime {
36 namespace backward {
37 namespace v402 {
38 
39 class SingleDictContent : public DictContent {
40  public:
SingleDictContent(const char * const dictPath,const char * const contentFileName,const bool isUpdatable)41     SingleDictContent(const char *const dictPath, const char *const contentFileName,
42             const bool isUpdatable)
43             : mMmappedBuffer(MmappedBuffer::openBuffer(dictPath, contentFileName, isUpdatable)),
44               mExpandableContentBuffer(
45                       mMmappedBuffer ? mMmappedBuffer->getReadWriteByteArrayView() :
46                               ReadWriteByteArrayView(),
47                       BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE),
48               mIsValid(mMmappedBuffer) {}
49 
SingleDictContent()50     SingleDictContent()
51             : mMmappedBuffer(nullptr),
52               mExpandableContentBuffer(Ver4DictConstants::MAX_DICTIONARY_SIZE), mIsValid(true) {}
53 
~SingleDictContent()54     virtual ~SingleDictContent() {}
55 
isValid()56     virtual bool isValid() const {
57         return mIsValid;
58     }
59 
isNearSizeLimit()60     bool isNearSizeLimit() const {
61         return mExpandableContentBuffer.isNearSizeLimit();
62     }
63 
64  protected:
getWritableBuffer()65     BufferWithExtendableBuffer *getWritableBuffer() {
66         return &mExpandableContentBuffer;
67     }
68 
getBuffer()69     const BufferWithExtendableBuffer *getBuffer() const {
70         return &mExpandableContentBuffer;
71     }
72 
flush(const char * const dictPath,const char * const contentFileNameSuffix)73     bool flush(const char *const dictPath, const char *const contentFileNameSuffix) const {
74         return DictFileWritingUtils::flushBufferToFileWithSuffix(dictPath,
75                 contentFileNameSuffix, &mExpandableContentBuffer);
76     }
77 
78  private:
79     DISALLOW_COPY_AND_ASSIGN(SingleDictContent);
80 
81     const MmappedBuffer::MmappedBufferPtr mMmappedBuffer;
82     BufferWithExtendableBuffer mExpandableContentBuffer;
83     const bool mIsValid;
84 };
85 } // namespace v402
86 } // namespace backward
87 } // namespace latinime
88 #endif /* LATINIME_BACKWARD_V402_SINGLE_DICT_CONTENT_H */
89