3 * Library to deal with pinyin.
5 * Copyright (C) 2012 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_PHRASE_TABLE2_H
23 #define FACADE_PHRASE_TABLE2_H
25 #include "phrase_large_table2.h"
32 * The facade class of phrase large table2.
36 class FacadePhraseTable2{
38 PhraseLargeTable2 * m_system_phrase_table;
39 PhraseLargeTable2 * m_user_phrase_table;
43 * FacadePhraseTable2::FacadePhraseTable2:
45 * The constructor of the FacadePhraseTable2.
48 FacadePhraseTable2() {
49 m_system_phrase_table = NULL;
50 m_user_phrase_table = NULL;
54 * FacadePhraseTable2::load:
55 * @system: the memory chunk of the system phrase table.
56 * @user: the memory chunk of the user phrase table.
57 * @returns: whether the load operation is successful.
59 * Load the system or user phrase table from the memory chunks.
62 bool load(MemoryChunk * system, MemoryChunk * user) {
65 m_system_phrase_table = new PhraseLargeTable2;
66 result = m_system_phrase_table->load(system) || result;
69 m_user_phrase_table = new PhraseLargeTable2;
70 result = m_user_phrase_table->load(user) || result;
76 * FacadePhraseTable2::store:
77 * @new_user: the memory chunk to store the user phrase table.
78 * @returns: whether the store operation is successful.
80 * Store the user phrase table to the memory chunk.
83 bool store(MemoryChunk * new_user) {
84 if (NULL == m_user_phrase_table)
86 return m_user_phrase_table->store(new_user);
90 * FacadePhraseTable2::search:
91 * @phrase_length: the length of the phrase to be searched.
92 * @phrase: the ucs4 characters of the phrase to be searched.
93 * @tokens: the GArray of tokens to store the matched phrases.
94 * @returns: the search result of enum SearchResult.
96 * Search the phrase tokens according to the ucs4 characters.
99 int search(int phrase_length, /* in */ ucs4_t phrase[],
100 /* out */ PhraseTokens tokens) const {
102 for (size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) {
104 g_array_set_size(tokens[i], 0);
107 int result = SEARCH_NONE;
109 if (NULL != m_system_phrase_table)
110 result |= m_system_phrase_table->search
111 (phrase_length, phrase, tokens);
113 if (NULL != m_user_phrase_table)
114 result |= m_user_phrase_table->search
115 (phrase_length, phrase, tokens);
121 * FacadePhraseTable2::add_index:
122 * @phrase_length: the length of the phrase to be added.
123 * @phrase: the ucs4 characters of the phrase to be added.
124 * @token: the token of the phrase to be added.
125 * @returns: the add result of enum ErrorResult.
127 * Add the phrase token to the user phrase table.
130 int add_index(int phrase_length, /* in */ ucs4_t phrase[],
131 /* in */ phrase_token_t token) {
132 if (NULL == m_user_phrase_table)
134 return m_user_phrase_table->add_index
135 (phrase_length, phrase, token);
139 * FacadePhraseTable2::remove_index:
140 * @phrase_length: the length of the phrase to be removed.
141 * @phrase: the ucs4 characters of the phrase to be removed.
142 * @token: the token of the phrase to be removed.
143 * @returns: the remove result of enum ErrorResult.
145 * Remove the phrase token from the user phrase table.
148 int remove_index(int phrase_length, /* in */ ucs4_t phrase[],
149 /* in */ phrase_token_t token) {
150 if (NULL == m_user_phrase_table)
152 return m_user_phrase_table->remove_index
153 (phrase_length, phrase, token);