| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* Copyright (C) 2005 Takuro Ashie |
| 4 |
* Copyright (C) 2012 CSSlayer |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 2, or (at your option) |
| 9 |
* any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 |
*/ |
| 20 |
|
| 21 |
#ifndef __FCITX_ANTHY_STYLE_FILE_H__ |
| 22 |
#define __FCITX_ANTHY_STYLE_FILE_H__ |
| 23 |
|
| 24 |
#include <vector> |
| 25 |
#include <string> |
| 26 |
|
| 27 |
class Key2KanaTable; |
| 28 |
class StyleLine; |
| 29 |
class StyleSection; |
| 30 |
class StyleFile; |
| 31 |
|
| 32 |
typedef std::vector<StyleLine> StyleLines; |
| 33 |
typedef std::vector<StyleLines> StyleSections; |
| 34 |
typedef std::vector<StyleFile> StyleFiles; |
| 35 |
|
| 36 |
typedef enum { |
| 37 |
FCITX_ANTHY_STYLE_LINE_UNKNOWN, |
| 38 |
FCITX_ANTHY_STYLE_LINE_SPACE, |
| 39 |
FCITX_ANTHY_STYLE_LINE_COMMENT, |
| 40 |
FCITX_ANTHY_STYLE_LINE_SECTION, |
| 41 |
FCITX_ANTHY_STYLE_LINE_KEY, |
| 42 |
} StyleLineType; |
| 43 |
|
| 44 |
class StyleLine |
| 45 |
{ |
| 46 |
public: |
| 47 |
StyleLine (StyleFile *style_file, |
| 48 |
std::string line); |
| 49 |
StyleLine (StyleFile *style_file, |
| 50 |
std::string key, |
| 51 |
std::string value); |
| 52 |
StyleLine (StyleFile *style_file, |
| 53 |
std::string key, |
| 54 |
std::vector<std::string> &value); |
| 55 |
~StyleLine (); |
| 56 |
|
| 57 |
public: |
| 58 |
StyleLineType get_type (void); |
| 59 |
void get_line (std::string &line) { line = m_line; } |
| 60 |
bool get_section (std::string §ion); |
| 61 |
bool get_key (std::string &key); |
| 62 |
bool get_value (std::string &value); |
| 63 |
void set_value (std::string value); |
| 64 |
bool get_value_array (std::vector<std::string> &value); |
| 65 |
void set_value_array (std::vector<std::string> &value); |
| 66 |
|
| 67 |
private: |
| 68 |
StyleFile *m_style_file; |
| 69 |
std::string m_line; |
| 70 |
StyleLineType m_type; |
| 71 |
}; |
| 72 |
|
| 73 |
class StyleFile |
| 74 |
{ |
| 75 |
public: |
| 76 |
StyleFile (); |
| 77 |
~StyleFile (); |
| 78 |
|
| 79 |
public: |
| 80 |
bool load (const char *filename); |
| 81 |
bool save (const char *filename); |
| 82 |
|
| 83 |
std::string get_title (void); |
| 84 |
std::string get_file_name (void); |
| 85 |
|
| 86 |
bool get_section_list (StyleSections §ions); |
| 87 |
bool get_entry_list (StyleLines &lines, |
| 88 |
std::string section); |
| 89 |
bool get_key_list (std::vector<std::string> &keys, |
| 90 |
std::string section); |
| 91 |
bool get_string (std::string &value, |
| 92 |
std::string section, |
| 93 |
std::string key); |
| 94 |
bool get_string_array (std::vector<std::string> &value, |
| 95 |
std::string section, |
| 96 |
std::string key); |
| 97 |
|
| 98 |
void set_string (std::string section, |
| 99 |
std::string key, |
| 100 |
std::string value); |
| 101 |
void set_string_array (std::string section, |
| 102 |
std::string key, |
| 103 |
std::vector<std::string> &value); |
| 104 |
|
| 105 |
void delete_key (std::string section, |
| 106 |
std::string key); |
| 107 |
void delete_section (std::string section); |
| 108 |
|
| 109 |
public: // for getting specific data |
| 110 |
Key2KanaTable * |
| 111 |
get_key2kana_table (std::string section); |
| 112 |
|
| 113 |
private: |
| 114 |
void clear (void); |
| 115 |
void setup_default_entries (void); |
| 116 |
StyleLines * |
| 117 |
find_section (const std::string §ion); |
| 118 |
StyleLines & |
| 119 |
append_new_section (const std::string §ion); |
| 120 |
|
| 121 |
private: |
| 122 |
std::string m_filename; |
| 123 |
std::string m_format_version; |
| 124 |
std::string m_title; |
| 125 |
std::string m_version; |
| 126 |
|
| 127 |
StyleSections m_sections; |
| 128 |
}; |
| 129 |
|
| 130 |
#endif /* __FCITX_ANTHY_STYLE_FILE_H__ */ |