add get_shengmu/yunmu_string
[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_shengmu_string();
96     gchar * get_yunmu_string();
97     gchar * get_chewing_string();
98 };
99
100 static inline bool operator == (ChewingKey lhs, ChewingKey rhs) {
101     if (lhs.m_initial != rhs.m_initial)
102         return false;
103     if (lhs.m_middle  != rhs.m_middle)
104         return false;
105     if (lhs.m_final   != rhs.m_final)
106         return false;
107     if (lhs.m_tone    != rhs.m_tone)
108         return false;
109     return true;
110 }
111
112 struct ChewingKeyRest
113 {
114     /* Note: the table index is removed,
115      *   Please use get_table_index in ChewingKey.
116      */
117     guint16 m_raw_begin;           /* the begin of the raw input. */
118     guint16 m_raw_end;             /* the end of the raw input. */
119
120     ChewingKeyRest() {
121         /* the 0th item in pinyin parser table is reserved for invalid. */
122         m_raw_begin = 0;
123         m_raw_end = 0;
124     }
125
126     guint16 length() {
127         return m_raw_end - m_raw_begin;
128     }
129 };
130
131 };
132
133 #endif