Tizen 2.1 base
[platform/core/uifw/ise-engine-sunpinyin.git] / src / lexicon / trie_writer.h
1 // -*- mode: c++ -*-
2 #ifndef __SUNPINYIN_PYTRIE_WRITER_H__
3 #define __SUNPINYIN_PYTRIE_WRITER_H__
4
5 #include "writer.h"
6 #include "pytrie.h"
7
8 template <>
9 class OtherEndian<CPinyinTrie::TNode>
10 {
11     struct TNode_BE {
12         unsigned m_other      : 5;
13         unsigned m_bFullSyllableTransfer : 1;
14         unsigned m_csLevel    : 2;
15         unsigned m_nTransfer  : 12;
16         unsigned m_nWordId    : 12;
17     };
18
19     struct TNode_LE {
20         unsigned m_nWordId    : 12;
21         unsigned m_nTransfer  : 12;
22         unsigned m_csLevel    : 2;
23         unsigned m_bFullSyllableTransfer : 1;
24         unsigned m_other      : 5;
25     };
26 public:
27     DEFINE_OTHER_TYPE(TNode);
28
29     static TargetType create(const CPinyinTrie::TNode& from){
30         TargetType to;
31         to.m_nTransfer = from.m_nTransfer;
32         to.m_nWordId = from.m_nWordId;
33         to.m_bFullSyllableTransfer = from.m_bFullSyllableTransfer;
34         to.m_csLevel = from.m_csLevel;
35         // we don't care about m_other though
36         to.m_other = from.m_other;
37         return to;
38     }
39 };
40
41 template<>
42 class OtherEndian<TSyllable>
43 {
44     struct TSyllable_BE {
45         unsigned other    : 12;
46         unsigned initial  : 8;
47         unsigned final    : 8;
48         unsigned tone     : 4;
49     };
50
51     struct TSyllable_LE {
52         unsigned tone     : 4;
53         unsigned final    : 8;
54         unsigned initial  : 8;
55         unsigned other    : 12;
56     };
57
58 public:
59     DEFINE_OTHER_TYPE(TSyllable);
60
61     static TargetType create(const TSyllable& from){
62         TargetType to;
63         to.other = from.other;
64         to.initial = from.initial;
65         to.final = from.final;
66         to.tone = from.tone;
67         return to;
68     }
69 };
70
71 template <>
72 class OtherEndian<CPinyinTrie::TWordIdInfo>
73 {
74     struct TWordIdInfo_BE {
75         unsigned m_bSeen    : 1;
76         unsigned m_cost     : 5;
77         unsigned m_csLevel  : 2;
78         unsigned m_id       : WORD_ID_WIDTH;
79     };
80
81     struct TWordIdInfo_LE {
82         unsigned m_id       : WORD_ID_WIDTH;
83         unsigned m_csLevel  : 2;
84         unsigned m_cost     : 5;
85         unsigned m_bSeen    : 1;
86     };
87
88 public:
89     DEFINE_OTHER_TYPE(TWordIdInfo);
90
91     static TargetType create(const CPinyinTrie::TWordIdInfo& from){
92         TargetType to;
93         to.m_id = from.m_id;
94         to.m_csLevel = from.m_csLevel;
95         to.m_bSeen = from.m_bSeen;
96         to.m_cost = from.m_cost;
97         return to;
98     }
99 };
100
101 template <>
102 bool revert_write<CPinyinTrie::TTransUnit> (const CPinyinTrie::TTransUnit& t,
103                                             FILE *fp);
104
105 #endif //__SUNPINYIN_PYTRIE_WRITER_H__