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_BIGRAM_ENTRY_H
18#define LATINIME_BIGRAM_ENTRY_H
19
20#include "defines.h"
21#include "suggest/policyimpl/dictionary/structure/v4/ver4_dict_constants.h"
22#include "suggest/policyimpl/dictionary/utils/historical_info.h"
23
24namespace latinime {
25
26class BigramEntry {
27 public:
28    BigramEntry(const BigramEntry& bigramEntry)
29            : mHasNext(bigramEntry.mHasNext), mProbability(bigramEntry.mProbability),
30              mHistoricalInfo(), mTargetTerminalId(bigramEntry.mTargetTerminalId) {}
31
32    // Entry with historical information.
33    BigramEntry(const bool hasNext, const int probability, const int targetTerminalId)
34            : mHasNext(hasNext), mProbability(probability), mHistoricalInfo(),
35              mTargetTerminalId(targetTerminalId) {}
36
37    // Entry with historical information.
38    BigramEntry(const bool hasNext, const int probability,
39            const HistoricalInfo *const historicalInfo, const int targetTerminalId)
40            : mHasNext(hasNext), mProbability(probability), mHistoricalInfo(*historicalInfo),
41              mTargetTerminalId(targetTerminalId) {}
42
43    const BigramEntry getInvalidatedEntry() const {
44        return updateTargetTerminalIdAndGetEntry(Ver4DictConstants::NOT_A_TERMINAL_ID);
45    }
46
47    const BigramEntry updateHasNextAndGetEntry(const bool hasNext) const {
48        return BigramEntry(hasNext, mProbability, &mHistoricalInfo, mTargetTerminalId);
49    }
50
51    const BigramEntry updateTargetTerminalIdAndGetEntry(const int newTargetTerminalId) const {
52        return BigramEntry(mHasNext, mProbability, &mHistoricalInfo, newTargetTerminalId);
53    }
54
55    const BigramEntry updateProbabilityAndGetEntry(const int probability) const {
56        return BigramEntry(mHasNext, probability, &mHistoricalInfo, mTargetTerminalId);
57    }
58
59    const BigramEntry updateHistoricalInfoAndGetEntry(
60            const HistoricalInfo *const historicalInfo) const {
61        return BigramEntry(mHasNext, mProbability, historicalInfo, mTargetTerminalId);
62    }
63
64    bool isValid() const {
65        return mTargetTerminalId != Ver4DictConstants::NOT_A_TERMINAL_ID;
66    }
67
68    bool hasNext() const {
69        return mHasNext;
70    }
71
72    int getProbability() const {
73        return mProbability;
74    }
75
76    bool hasHistoricalInfo() const {
77        return mHistoricalInfo.isValid();
78    }
79
80    const HistoricalInfo *getHistoricalInfo() const {
81        return &mHistoricalInfo;
82    }
83
84    int getTargetTerminalId() const {
85        return mTargetTerminalId;
86    }
87
88 private:
89    // Copy constructor is public to use this class as a type of return value.
90    DISALLOW_DEFAULT_CONSTRUCTOR(BigramEntry);
91    DISALLOW_ASSIGNMENT_OPERATOR(BigramEntry);
92
93    const bool mHasNext;
94    const int mProbability;
95    const HistoricalInfo mHistoricalInfo;
96    const int mTargetTerminalId;
97};
98} // namespace latinime
99#endif /* LATINIME_BIGRAM_ENTRY_H */
100