summaryrefslogtreecommitdiffstats
path: root/src/storage/table_info.h
blob: bc3837ffe7130bccbd30b129e25140141a2fe704 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* 
 *  libpinyin
 *  Library to deal with pinyin.
 *  
 *  Copyright (C) 2013 Peng Wu <alexepico@gmail.com>
 *  
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef TABLE_INFO_H
#define TABLE_INFO_H

#include "novel_types.h"


namespace pinyin{

typedef enum {
    PINYIN_TABLE,                 /* use pinyin. */
    ZHUYIN_TABLE,                 /* use zhuyin. */
} TABLE_PHONETIC_TYPE;

typedef enum {
    DEFAULT_TABLE,
    ADDON_TABLE,
} TABLE_TARGET;

typedef enum {
    NOT_USED,                /* not used. */
    SYSTEM_FILE,             /* system phrase file. */
    DICTIONARY,              /* professional dictionary. */
    USER_FILE,               /* user only phrase file. */
} PHRASE_FILE_TYPE;

typedef struct {
    guint8 m_dict_index; /* for assert purpose. */
    const gchar * m_table_filename;
    const gchar * m_system_filename;
    const gchar * m_user_filename;
    PHRASE_FILE_TYPE m_file_type;
} pinyin_table_info_t;


class UserTableInfo;

class SystemTableInfo2{
    friend class UserTableInfo;
private:
    int m_binary_format_version;
    int m_model_data_version;
    gfloat m_lambda;

    TABLE_PHONETIC_TYPE m_table_phonetic_type;

    pinyin_table_info_t m_default_tables[PHRASE_INDEX_LIBRARY_COUNT];

    pinyin_table_info_t m_addon_tables[PHRASE_INDEX_LIBRARY_COUNT];

private:
    void reset();

public:
    SystemTableInfo2();

    ~SystemTableInfo2();

    bool load(const char * filename);

    const pinyin_table_info_t * get_default_tables();

    const pinyin_table_info_t * get_addon_tables();

    gfloat get_lambda();

    TABLE_PHONETIC_TYPE get_table_phonetic_type();
};

class UserTableInfo{
private:
    int m_binary_format_version;
    int m_model_data_version;

private:
    void reset();

public:
    UserTableInfo();

    bool load(const char * filename);

    bool save(const char * filename);

    bool is_conform(const SystemTableInfo2 * sysinfo);

    bool make_conform(const SystemTableInfo2 * sysinfo);
};

};


#endif