1 /* 2 * Copyright 2011 kubtek <kubtek@mail.com> 3 * 4 * This file is part of StarDict. 5 * 6 * StarDict 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 3 of the License, or 9 * (at your option) any later version. 10 * 11 * StarDict 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 StarDict. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef _IFO_FILE_H_ 21 #define _IFO_FILE_H_ 22 23 #include <glib.h> 24 #include <list> 25 #include <string> 26 #include "libcommon.h" 27 28 #define GET_METHOD_TEMPL(type, field) \ 29 type get_##field(void) const \ 30 { \ 31 return field; \ 32 } 33 34 #define SET_METHOD_TEMPL(type, field) \ 35 void set_##field(type field) \ 36 { \ 37 this->field = field; \ 38 this->f_##field = true; \ 39 } 40 41 #define UNSET_METHOD_TEMPL(type, field, default_val) \ 42 void unset_##field(void) \ 43 { \ 44 this->f_##field = false; \ 45 this->field = default_val; \ 46 } 47 48 #define IS_METHOD_TEMPL(type, field) \ 49 bool is_##field(void) const \ 50 { \ 51 return f_##field; \ 52 } 53 54 #define ALL_METHOD_TEMPL(type, field, default_val) \ 55 GET_METHOD_TEMPL(type, field) \ 56 SET_METHOD_TEMPL(type, field) \ 57 UNSET_METHOD_TEMPL(type, field, default_val) \ 58 IS_METHOD_TEMPL(type, field) 59 60 enum DictInfoType { 61 DictInfoType_NormDict, 62 DictInfoType_TreeDict, 63 DictInfoType_ResDb 64 }; 65 66 // This structure contains all information about dictionary or Resource Storage 67 // database. 68 struct DictInfo { 69 /* in file name encoding */ 70 std::string ifo_file_name; 71 72 DictInfo(void); 73 /* ifofilename in file name encoding */ 74 bool load_from_ifo_file(const std::string& ifofilename, DictInfoType infotype); 75 bool save_ifo_file(void) const; 76 void clear(void); 77 DictInfo& operator=(const DictInfo& dict_info); 78 79 ALL_METHOD_TEMPL(guint32, wordcount, 0) 80 ALL_METHOD_TEMPL(guint32, filecount, 0) 81 ALL_METHOD_TEMPL(guint32, synwordcount, 0) 82 ALL_METHOD_TEMPL(const std::string&, bookname, "") 83 ALL_METHOD_TEMPL(const std::string&, author, "") 84 ALL_METHOD_TEMPL(const std::string&, email, "") 85 ALL_METHOD_TEMPL(const std::string&, website, "") 86 ALL_METHOD_TEMPL(const std::string&, date, "") 87 ALL_METHOD_TEMPL(const std::string&, description, "") 88 ALL_METHOD_TEMPL(guint32, index_file_size, 0) 89 ALL_METHOD_TEMPL(const std::string&, sametypesequence, "") 90 ALL_METHOD_TEMPL(const std::string&, dicttype, "") 91 ALL_METHOD_TEMPL(const std::string&, version, "") 92 ALL_METHOD_TEMPL(DictInfoType, infotype, DictInfoType_NormDict) 93 private: 94 const char* get_key_value(const char *p1, std::string& key, 95 std::string& value); 96 bool check_option_duplicate(bool& flag, const char* option); 97 int lineno; 98 // flags. true if corresponding item is set 99 bool f_wordcount; 100 bool f_filecount; 101 bool f_synwordcount; 102 bool f_bookname; 103 bool f_author; 104 bool f_email; 105 bool f_website; 106 bool f_date; 107 bool f_description; 108 bool f_index_file_size; 109 bool f_sametypesequence; 110 bool f_dicttype; 111 bool f_version; 112 bool f_idxoffsetbits; 113 bool f_infotype; 114 115 /* other strings in utf-8 */ 116 guint32 wordcount; 117 guint32 filecount; 118 guint32 synwordcount; 119 std::string bookname; 120 std::string author; 121 std::string email; 122 std::string website; 123 std::string date; 124 std::string description; 125 guint32 index_file_size; 126 std::string sametypesequence; 127 std::string dicttype; 128 std::string version; 129 DictInfoType infotype; 130 }; 131 132 #undef GET_METHOD_TEMPL 133 #undef SET_METHOD_TEMPL 134 #undef UNSET_METHOD_TEMPL 135 #undef IS_METHOD_TEMPL 136 #undef ALL_METHOD_TEMPL 137 138 #endif//!_IFO_FILE_H_ 139