1 /*
2  * Copyright (C) 2014 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_TOOLKIT_OFFDEVICE_INTERMEDIATE_DICT_PT_NODE_H
18 #define LATINIME_DICT_TOOLKIT_OFFDEVICE_INTERMEDIATE_DICT_PT_NODE_H
19 
20 #include <memory>
21 
22 #include "dict_toolkit_defines.h"
23 #include "offdevice_intermediate_dict/offdevice_intermediate_dict_pt_node_array.h"
24 #include "dictionary/property/word_property.h"
25 #include "utils/int_array_view.h"
26 
27 namespace latinime {
28 namespace dicttoolkit {
29 
30 class OffdeviceIntermediateDictPtNode final {
31  public:
32     // Non-terminal
OffdeviceIntermediateDictPtNode(const CodePointArrayView ptNodeCodePoints)33     OffdeviceIntermediateDictPtNode(const CodePointArrayView ptNodeCodePoints)
34             : mPtNodeCodePoints(ptNodeCodePoints.toVector()), mChildrenPtNodeArray(),
35               mWortProperty(nullptr) {}
36 
37     // Terminal
OffdeviceIntermediateDictPtNode(const CodePointArrayView ptNodeCodePoints,const WordProperty & wordProperty)38     OffdeviceIntermediateDictPtNode(const CodePointArrayView ptNodeCodePoints,
39             const WordProperty &wordProperty)
40              : mPtNodeCodePoints(ptNodeCodePoints.toVector()), mChildrenPtNodeArray(),
41                mWortProperty(new WordProperty(wordProperty)) {}
42 
43     // Replacing PtNodeCodePoints.
OffdeviceIntermediateDictPtNode(const CodePointArrayView ptNodeCodePoints,const OffdeviceIntermediateDictPtNode & ptNode)44     OffdeviceIntermediateDictPtNode(const CodePointArrayView ptNodeCodePoints,
45             const OffdeviceIntermediateDictPtNode &ptNode)
46             : mPtNodeCodePoints(ptNodeCodePoints.toVector()),
47               mChildrenPtNodeArray(ptNode.mChildrenPtNodeArray),
48               mWortProperty(new WordProperty(*ptNode.mWortProperty)) {}
49 
50     // Replacing WordProperty.
OffdeviceIntermediateDictPtNode(const WordProperty & wordProperty,const OffdeviceIntermediateDictPtNode & ptNode)51     OffdeviceIntermediateDictPtNode(const WordProperty &wordProperty,
52             const OffdeviceIntermediateDictPtNode &ptNode)
53             : mPtNodeCodePoints(ptNode.mPtNodeCodePoints),
54               mChildrenPtNodeArray(ptNode.mChildrenPtNodeArray),
55               mWortProperty(new WordProperty(wordProperty)) {}
56 
getWordProperty()57     const WordProperty *getWordProperty() const {
58         return mWortProperty.get();
59     }
60 
getPtNodeCodePoints()61     const CodePointArrayView getPtNodeCodePoints() const {
62         return CodePointArrayView(mPtNodeCodePoints);
63     }
64 
getChildrenPtNodeArray()65     OffdeviceIntermediateDictPtNodeArray &getChildrenPtNodeArray() {
66         return mChildrenPtNodeArray;
67     }
68 
69  private:
70     DISALLOW_COPY_AND_ASSIGN(OffdeviceIntermediateDictPtNode);
71 
72     const std::vector<int> mPtNodeCodePoints;
73     OffdeviceIntermediateDictPtNodeArray mChildrenPtNodeArray;
74     const std::unique_ptr<WordProperty> mWortProperty;
75 };
76 
77 } // namespace dicttoolkit
78 } // namespace latinime
79 #endif // LATINIME_DICT_TOOLKIT_OFFDEVICE_INTERMEDIATE_DICT_PT_NODE_H
80