1 /*
2  * Copyright (C) 2012 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_DIC_NODE_STATE_H
18 #define LATINIME_DIC_NODE_STATE_H
19 
20 #include "defines.h"
21 #include "suggest/core/dicnode/internal/dic_node_state_input.h"
22 #include "suggest/core/dicnode/internal/dic_node_state_output.h"
23 #include "suggest/core/dicnode/internal/dic_node_state_scoring.h"
24 
25 namespace latinime {
26 
27 class DicNodeState {
28  public:
29     DicNodeStateInput mDicNodeStateInput;
30     DicNodeStateOutput mDicNodeStateOutput;
31     DicNodeStateScoring mDicNodeStateScoring;
32 
DicNodeState()33     AK_FORCE_INLINE DicNodeState()
34             : mDicNodeStateInput(), mDicNodeStateOutput(), mDicNodeStateScoring() {}
35 
~DicNodeState()36     ~DicNodeState() {}
37 
38     DicNodeState &operator=(const DicNodeState& src) {
39         initByCopy(&src);
40         return *this;
41     }
42 
DicNodeState(const DicNodeState & src)43     DicNodeState(const DicNodeState& src)
44             : mDicNodeStateInput(), mDicNodeStateOutput(), mDicNodeStateScoring() {
45         initByCopy(&src);
46     }
47 
48     // Init for root
init()49     void init() {
50         mDicNodeStateInput.init();
51         mDicNodeStateOutput.init();
52         mDicNodeStateScoring.init();
53     }
54 
55     // Init with previous word.
initAsRootWithPreviousWord(const DicNodeState * prevWordDicNodeState,const int prevWordCodePointCount)56     void initAsRootWithPreviousWord(const DicNodeState *prevWordDicNodeState,
57             const int prevWordCodePointCount) {
58         mDicNodeStateOutput.init(&prevWordDicNodeState->mDicNodeStateOutput);
59         mDicNodeStateInput.init(
60                 &prevWordDicNodeState->mDicNodeStateInput, true /* resetTerminalDiffCost */);
61         mDicNodeStateScoring.initByCopy(&prevWordDicNodeState->mDicNodeStateScoring);
62     }
63 
64     // Init by copy
initByCopy(const DicNodeState * const src)65     AK_FORCE_INLINE void initByCopy(const DicNodeState *const src) {
66         mDicNodeStateInput.initByCopy(&src->mDicNodeStateInput);
67         mDicNodeStateOutput.initByCopy(&src->mDicNodeStateOutput);
68         mDicNodeStateScoring.initByCopy(&src->mDicNodeStateScoring);
69     }
70 
71     // Init by copy and adding merged node code points.
init(const DicNodeState * const src,const uint16_t mergedNodeCodePointCount,const int * const mergedNodeCodePoints)72     void init(const DicNodeState *const src, const uint16_t mergedNodeCodePointCount,
73             const int *const mergedNodeCodePoints) {
74         initByCopy(src);
75         mDicNodeStateOutput.addMergedNodeCodePoints(
76                 mergedNodeCodePointCount, mergedNodeCodePoints);
77     }
78 };
79 } // namespace latinime
80 #endif // LATINIME_DIC_NODE_STATE_H
81