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 /* load/store method */
43 bool load(pinyin_option_t options, MemoryChunk * system,
47 m_system_chewing_table = new ChewingLargeTable(options);
48 result = m_system_chewing_table->load(system) || result;
51 m_user_chewing_table = new ChewingLargeTable(options);
52 result = m_user_chewing_table->load(user) || result;
58 int search(int phrase_length, /* in */ ChewingKey keys[],
59 /* out */ PhraseIndexRanges ranges) const {
60 int result = SEARCH_NONE;
62 if (NULL != m_system_chewing_table)
63 result |= m_system_chewing_table->search
64 (phrase_length, keys, ranges);
66 if (NULL != m_user_chewing_table)
67 result |= m_user_chewing_table->search
68 (phrase_length, keys, ranges);
73 /* add/remove index method */
74 int add_index(int phrase_length, /* in */ ChewingKey keys[],
75 /* in */ phrase_token_t token) {
76 assert(NULL != m_user_chewing_table);
77 return m_user_chewing_table->add_index(phrase_length, keys, token);
80 int remove_index(int phrase_length, /* in */ ChewingKey keys[],
81 /* in */ phrase_token_t token) {
82 assert(NULL != m_user_chewing_table);
83 return m_user_chewing_table->remove_index(phrase_length, keys, token);