fixes phrase_index.h
[platform/upstream/libpinyin.git] / src / storage / chewing_key.h
1 /* 
2  *  libpinyin
3  *  Library to deal with pinyin.
4  *  
5  *  Copyright (C) 2011 Peng Wu <alexepico@gmail.com>
6  *  
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  * 
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *  
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20  */
21
22 #ifndef CHEWING_KEY_H
23 #define CHEWING_KEY_H
24
25 #include <glib.h>
26 #include "chewing_enum.h"
27
28 /** @file chewing_key.h
29  *  @brief the definitions of chewing key related classes and structs.
30  */
31
32 namespace pinyin{
33
34
35 /**
36  * @brief enums of Double Pinyin Schemes.
37  */
38 enum DoublePinyinScheme
39 {
40     DOUBLE_PINYIN_ZRM        = 1,
41     DOUBLE_PINYIN_MS         = 2,
42     DOUBLE_PINYIN_ZIGUANG    = 3,
43     DOUBLE_PINYIN_ABC        = 4,
44     DOUBLE_PINYIN_PYJJ       = 6,
45     DOUBLE_PINYIN_XHE        = 7,
46     DOUBLE_PINYIN_CUSTOMIZED = 30,        /* for user's keyboard */
47     DOUBLE_PINYIN_DEFAULT    = DOUBLE_PINYIN_MS
48 };
49
50 /**
51  * @brief enums of Chewing Schemes.
52  */
53 enum ChewingScheme
54 {
55     CHEWING_STANDARD = 1,
56     CHEWING_IBM      = 2,
57     CHEWING_GINYIEH  = 3,
58     CHEWING_ETEN     = 4,
59     CHEWING_DEFAULT  = CHEWING_STANDARD
60 };
61
62
63 /** Note: The parsed pinyins are stored in the following two
64  *          GArrays to speed up chewing table lookup.
65  *    As the chewing large table only contains information of struct ChewingKey.
66  */
67
68 struct ChewingKey
69 {
70     guint16 m_initial : 5;
71     guint16 m_middle  : 2;
72     guint16 m_final   : 5;
73     guint16 m_tone    : 3;
74
75     ChewingKey() {
76         m_initial = CHEWING_ZERO_INITIAL;
77         m_middle  = CHEWING_ZERO_MIDDLE;
78         m_final   = CHEWING_ZERO_FINAL;
79         m_tone    = CHEWING_ZERO_TONE;
80     }
81
82     ChewingKey(ChewingInitial initial, ChewingMiddle middle,
83                ChewingFinal final) {
84         m_initial = initial;
85         m_middle = middle;
86         m_final = final;
87         m_tone = CHEWING_ZERO_TONE;
88     }
89
90 public:
91     gint get_table_index();
92
93     /* Note: the return value should be freed by g_free. */
94     gchar * get_pinyin_string();
95     gchar * get_chewing_string();
96 };
97
98 static inline bool operator == (ChewingKey lhs, ChewingKey rhs) {
99     if (lhs.m_initial != rhs.m_initial)
100         return false;
101     if (lhs.m_middle  != rhs.m_middle)
102         return false;
103     if (lhs.m_final   != rhs.m_final)
104         return false;
105     if (lhs.m_tone    != rhs.m_tone)
106         return false;
107     return true;
108 }
109
110 struct ChewingKeyRest
111 {
112     /* Note: the table index is removed,
113      *   Please use get_table_index in ChewingKey.
114      */
115     guint16 m_raw_begin;           /* the begin of the raw input. */
116     guint16 m_raw_end;             /* the end of the raw input. */
117
118     ChewingKeyRest() {
119         /* the 0th item in pinyin parser table is reserved for invalid. */
120         m_raw_begin = 0;
121         m_raw_end = 0;
122     }
123
124     guint16 length() {
125         return m_raw_end - m_raw_begin;
126     }
127 };
128
129 };
130
131 #endif