Allow libpinyin to build in cross compile mode.
[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 using namespace pinyin;
29
30 G_BEGIN_DECLS
31
32 /** @file chewing_key.h
33  *  @brief the definitions of chewing key related classes and structs.
34  */
35
36
37 /** Note: The parsed pinyins are stored in the following two
38  *          GArrays to speed up chewing table lookup.
39  *    As the chewing large table only contains information of struct ChewingKey.
40  */
41
42 struct _ChewingKey
43 {
44     guint16 m_initial : 5;
45     guint16 m_middle  : 2;
46     guint16 m_final   : 5;
47     guint16 m_tone    : 3;
48
49     _ChewingKey() {
50         m_initial = CHEWING_ZERO_INITIAL;
51         m_middle  = CHEWING_ZERO_MIDDLE;
52         m_final   = CHEWING_ZERO_FINAL;
53         m_tone    = CHEWING_ZERO_TONE;
54     }
55
56     _ChewingKey(ChewingInitial initial, ChewingMiddle middle,
57                ChewingFinal final) {
58         m_initial = initial;
59         m_middle = middle;
60         m_final = final;
61         m_tone = CHEWING_ZERO_TONE;
62     }
63
64 public:
65     gint get_table_index();
66
67     /* Note: the return value should be freed by g_free. */
68     gchar * get_pinyin_string();
69     gchar * get_shengmu_string();
70     gchar * get_yunmu_string();
71     gchar * get_chewing_string();
72 };
73
74 typedef struct _ChewingKey ChewingKey;
75
76 static inline bool operator == (ChewingKey lhs, ChewingKey rhs) {
77     if (lhs.m_initial != rhs.m_initial)
78         return false;
79     if (lhs.m_middle  != rhs.m_middle)
80         return false;
81     if (lhs.m_final   != rhs.m_final)
82         return false;
83     if (lhs.m_tone    != rhs.m_tone)
84         return false;
85     return true;
86 }
87
88 struct _ChewingKeyRest
89 {
90     /* Note: the table index is removed,
91      *   Please use get_table_index in ChewingKey.
92      */
93     guint16 m_raw_begin;           /* the begin of the raw input. */
94     guint16 m_raw_end;             /* the end of the raw input. */
95
96     _ChewingKeyRest() {
97         /* the 0th item in pinyin parser table is reserved for invalid. */
98         m_raw_begin = 0;
99         m_raw_end = 0;
100     }
101
102     guint16 length() {
103         return m_raw_end - m_raw_begin;
104     }
105 };
106
107 typedef struct _ChewingKeyRest ChewingKeyRest;
108
109 G_END_DECLS
110
111 #endif