Home | History | Annotate | Download | only in v402
      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/ver4_dict_buffers.h
     22  */
     23 
     24 #ifndef LATINIME_BACKWARD_V402_VER4_DICT_BUFFER_H
     25 #define LATINIME_BACKWARD_V402_VER4_DICT_BUFFER_H
     26 
     27 #include <memory>
     28 
     29 #include "defines.h"
     30 #include "dictionary/header/header_policy.h"
     31 #include "dictionary/structure/backward/v402/content/bigram_dict_content.h"
     32 #include "dictionary/structure/backward/v402/content/probability_dict_content.h"
     33 #include "dictionary/structure/backward/v402/content/shortcut_dict_content.h"
     34 #include "dictionary/structure/backward/v402/content/terminal_position_lookup_table.h"
     35 #include "dictionary/structure/backward/v402/ver4_dict_constants.h"
     36 #include "dictionary/utils/buffer_with_extendable_buffer.h"
     37 #include "dictionary/utils/mmapped_buffer.h"
     38 
     39 namespace latinime {
     40 namespace backward {
     41 namespace v402 {
     42 
     43 class Ver4DictBuffers {
     44  public:
     45     typedef std::unique_ptr<Ver4DictBuffers> Ver4DictBuffersPtr;
     46 
     47     static Ver4DictBuffersPtr openVer4DictBuffers(const char *const dictDirPath,
     48             MmappedBuffer::MmappedBufferPtr headerBuffer,
     49             const FormatUtils::FORMAT_VERSION formatVersion);
     50 
     51     static AK_FORCE_INLINE Ver4DictBuffersPtr createVer4DictBuffers(
     52             const HeaderPolicy *const headerPolicy, const int maxTrieSize) {
     53         return Ver4DictBuffersPtr(new Ver4DictBuffers(headerPolicy, maxTrieSize));
     54     }
     55 
     56     AK_FORCE_INLINE bool isValid() const {
     57         return mHeaderBuffer && mDictBuffer && mHeaderPolicy.isValid()
     58                 && mProbabilityDictContent.isValid() && mTerminalPositionLookupTable.isValid()
     59                 && mBigramDictContent.isValid() && mShortcutDictContent.isValid();
     60     }
     61 
     62     AK_FORCE_INLINE bool isNearSizeLimit() const {
     63         return mExpandableTrieBuffer.isNearSizeLimit()
     64                 || mTerminalPositionLookupTable.isNearSizeLimit()
     65                 || mProbabilityDictContent.isNearSizeLimit()
     66                 || mBigramDictContent.isNearSizeLimit()
     67                 || mShortcutDictContent.isNearSizeLimit();
     68     }
     69 
     70     AK_FORCE_INLINE const HeaderPolicy *getHeaderPolicy() const {
     71         return &mHeaderPolicy;
     72     }
     73 
     74     AK_FORCE_INLINE BufferWithExtendableBuffer *getWritableHeaderBuffer() {
     75         return &mExpandableHeaderBuffer;
     76     }
     77 
     78     AK_FORCE_INLINE BufferWithExtendableBuffer *getWritableTrieBuffer() {
     79         return &mExpandableTrieBuffer;
     80     }
     81 
     82     AK_FORCE_INLINE const BufferWithExtendableBuffer *getTrieBuffer() const {
     83         return &mExpandableTrieBuffer;
     84     }
     85 
     86     AK_FORCE_INLINE TerminalPositionLookupTable *getMutableTerminalPositionLookupTable() {
     87         return &mTerminalPositionLookupTable;
     88     }
     89 
     90     AK_FORCE_INLINE const TerminalPositionLookupTable *getTerminalPositionLookupTable() const {
     91         return &mTerminalPositionLookupTable;
     92     }
     93 
     94     AK_FORCE_INLINE ProbabilityDictContent *getMutableProbabilityDictContent() {
     95         return &mProbabilityDictContent;
     96     }
     97 
     98     AK_FORCE_INLINE const ProbabilityDictContent *getProbabilityDictContent() const {
     99         return &mProbabilityDictContent;
    100     }
    101 
    102     AK_FORCE_INLINE BigramDictContent *getMutableBigramDictContent() {
    103         return &mBigramDictContent;
    104     }
    105 
    106     AK_FORCE_INLINE const BigramDictContent *getBigramDictContent() const {
    107         return &mBigramDictContent;
    108     }
    109 
    110     AK_FORCE_INLINE ShortcutDictContent *getMutableShortcutDictContent() {
    111         return &mShortcutDictContent;
    112     }
    113 
    114     AK_FORCE_INLINE const ShortcutDictContent *getShortcutDictContent() const {
    115         return &mShortcutDictContent;
    116     }
    117 
    118     AK_FORCE_INLINE bool isUpdatable() const {
    119         return mIsUpdatable;
    120     }
    121 
    122     bool flush(const char *const dictDirPath) const {
    123         return flushHeaderAndDictBuffers(dictDirPath, &mExpandableHeaderBuffer);
    124     }
    125 
    126     bool flushHeaderAndDictBuffers(const char *const dictDirPath,
    127             const BufferWithExtendableBuffer *const headerBuffer) const;
    128 
    129  private:
    130     DISALLOW_COPY_AND_ASSIGN(Ver4DictBuffers);
    131 
    132     Ver4DictBuffers(const char *const dictDirPath,
    133             const MmappedBuffer::MmappedBufferPtr headerBuffer, const bool isUpdatable,
    134             const FormatUtils::FORMAT_VERSION formatVersion);
    135 
    136     Ver4DictBuffers(const HeaderPolicy *const headerPolicy, const int maxTrieSize);
    137 
    138     const MmappedBuffer::MmappedBufferPtr mHeaderBuffer;
    139     const MmappedBuffer::MmappedBufferPtr mDictBuffer;
    140     const HeaderPolicy mHeaderPolicy;
    141     BufferWithExtendableBuffer mExpandableHeaderBuffer;
    142     BufferWithExtendableBuffer mExpandableTrieBuffer;
    143     TerminalPositionLookupTable mTerminalPositionLookupTable;
    144     ProbabilityDictContent mProbabilityDictContent;
    145     BigramDictContent mBigramDictContent;
    146     ShortcutDictContent mShortcutDictContent;
    147     const int mIsUpdatable;
    148 };
    149 } // namespace v402
    150 } // namespace backward
    151 } // namespace latinime
    152 #endif /* LATINIME_BACKWARD_V402_VER4_DICT_BUFFER_H */
    153