write facade chewing table
[platform/upstream/libpinyin.git] / src / storage / facade_chewing_table.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 FACADE_CHEWING_TABLE_H
23 #define FACADE_CHEWING_TABLE_H
24
25 #include "novel_types.h"
26 #include "chewing_large_table.h"
27
28 namespace pinyin{
29
30 class FacadeChewingTable{
31 private:
32     ChewingLargeTable * m_system_chewing_table;
33     ChewingLargeTable * m_user_chewing_table;
34
35 public:
36     /* constructor/destructor */
37     FacadeChewingTable() {
38         m_system_chewing_table = NULL;
39         m_user_chewing_table = NULL;
40     }
41
42     /* load/store method */
43     bool load(pinyin_option_t options, MemoryChunk * system,
44               MemoryChunk * user){
45         bool result = false;
46         if (system) {
47             m_system_chewing_table = new ChewingLargeTable(options);
48             result = m_system_chewing_table->load(system) || result;
49         }
50         if (user) {
51             m_user_chewing_table = new ChewingLargeTable(options);
52             result = m_user_chewing_table->load(user) || result;
53         }
54         return result;
55     }
56
57     /* search method */
58     int search(int phrase_length, /* in */ ChewingKey keys[],
59                /* out */ PhraseIndexRanges ranges) const {
60         int result = SEARCH_NONE;
61
62         if (NULL != m_system_chewing_table)
63             result |= m_system_chewing_table->search
64                 (phrase_length, keys, ranges);
65
66         if (NULL != m_user_chewing_table)
67             result |= m_user_chewing_table->search
68                 (phrase_length, keys, ranges);
69
70         return result;
71     }
72
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);
78     }
79
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);
84     }
85 };
86
87 };
88
89 #endif