3 * Library to deal with pinyin.
5 * Copyright (C) 2011 Peng Wu <alexepico@gmail.com>
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.
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.
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.
22 #ifndef FACADE_CHEWING_TABLE_H
23 #define FACADE_CHEWING_TABLE_H
25 #include "novel_types.h"
26 #include "chewing_large_table.h"
30 class FacadeChewingTable{
32 ChewingLargeTable * m_system_chewing_table;
33 ChewingLargeTable * m_user_chewing_table;
36 /* constructor/destructor */
37 FacadeChewingTable() {
38 m_system_chewing_table = NULL;
39 m_user_chewing_table = NULL;
42 /* set options method */
43 bool set_options(pinyin_option_t options) {
45 if (m_system_chewing_table)
46 result = m_system_chewing_table->set_options(options) || result;
47 if (m_user_chewing_table)
48 result = m_user_chewing_table->set_options(options) || result;
52 /* load/store method */
53 bool load(pinyin_option_t options, MemoryChunk * system,
57 m_system_chewing_table = new ChewingLargeTable(options);
58 result = m_system_chewing_table->load(system) || result;
61 m_user_chewing_table = new ChewingLargeTable(options);
62 result = m_user_chewing_table->load(user) || result;
68 int search(int phrase_length, /* in */ ChewingKey keys[],
69 /* out */ PhraseIndexRanges ranges) const {
70 int result = SEARCH_NONE;
72 if (NULL != m_system_chewing_table)
73 result |= m_system_chewing_table->search
74 (phrase_length, keys, ranges);
76 if (NULL != m_user_chewing_table)
77 result |= m_user_chewing_table->search
78 (phrase_length, keys, ranges);
83 /* add/remove index method */
84 int add_index(int phrase_length, /* in */ ChewingKey keys[],
85 /* in */ phrase_token_t token) {
86 assert(NULL != m_user_chewing_table);
87 return m_user_chewing_table->add_index(phrase_length, keys, token);
90 int remove_index(int phrase_length, /* in */ ChewingKey keys[],
91 /* in */ phrase_token_t token) {
92 assert(NULL != m_user_chewing_table);
93 return m_user_chewing_table->remove_index(phrase_length, keys, token);