add set options method to 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     /* set options method */
43     bool set_options(pinyin_option_t options) {
44         bool result = false;
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;
49         return result;
50     }
51
52     /* load/store method */
53     bool load(pinyin_option_t options, MemoryChunk * system,
54               MemoryChunk * user){
55         bool result = false;
56         if (system) {
57             m_system_chewing_table = new ChewingLargeTable(options);
58             result = m_system_chewing_table->load(system) || result;
59         }
60         if (user) {
61             m_user_chewing_table = new ChewingLargeTable(options);
62             result = m_user_chewing_table->load(user) || result;
63         }
64         return result;
65     }
66
67     /* search method */
68     int search(int phrase_length, /* in */ ChewingKey keys[],
69                /* out */ PhraseIndexRanges ranges) const {
70         int result = SEARCH_NONE;
71
72         if (NULL != m_system_chewing_table)
73             result |= m_system_chewing_table->search
74                 (phrase_length, keys, ranges);
75
76         if (NULL != m_user_chewing_table)
77             result |= m_user_chewing_table->search
78                 (phrase_length, keys, ranges);
79
80         return result;
81     }
82
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);
88     }
89
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);
94     }
95 };
96
97 };
98
99 #endif