2 Copyright 2013 Karel Matas
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 namespace aoi_config
{
40 static const std::map
<const char*,vector
<DBTableColumn
>> db_tables
=
43 { "key", "TEXT", false , "ASC" },
44 { "val", "TEXT", false, "ASC" }
48 { "abbr", "TEXT", false, "ASC" },
49 { "desc", "TEXT", false, "ASC" }
53 { "rid", "INT", true, "ASC" },
54 { "did", "INT", true, "ASC" },
55 { "reading", "TEXT", true, "ASC" },
56 { "inf", "TEXT", false, "ASC" },
57 { "nokanji", "INT", false, "ASC" },
58 { "freq", "INT", false, "ASC" }
62 { "kid", "INT", true, "ASC" },
63 { "did", "INT", true, "ASC" },
64 { "kanji", "TEXT", true, "ASC" },
65 { "inf", "TEXT", false, "ASC" },
66 { "freq", "INT", false, "ASC" }
70 { "sid", "INT", true, "ASC" },
71 { "did", "INT", true, "ASC" },
72 { "gloss", "TEXT", false, "ASC" },
73 { "xref", "TEXT", false, "ASC" },
74 { "ant" , "TEXT", false, "ASC" },
75 { "inf", "TEXT", false, "ASC" },
76 { "pos", "TEXT", false, "ASC" },
77 { "field", "TEXT", false, "ASC" },
78 { "misc", "TEXT", false, "ASC" },
79 { "dial", "TEXT", false, "ASC" }
83 { "rid", "INT", false, "ASC" },
84 { "kid", "INT", false, "ASC" }
88 { "sid", "INT", false, "ASC" },
89 { "kid", "INT", false, "ASC" }
93 { "sid", "INT", false, "ASC" },
94 { "rid", "INT", false, "ASC" }
98 { "kanji", "TEXT", true, "ASC" },
99 { "ucs", "TEXT", false, "ASC" },
100 { "onyomi", "TEXT", false, "ASC" },
101 { "kunyomi", "TEXT", false, "ASC" },
102 { "meaning", "TEXT", false, "ASC" },
103 { "nanori", "TEXT", false, "ASC" },
104 { "flags", "TEXT", false, "ASC" },
105 { "jlpt", "INT", false, "ASC" },
106 { "grade", "INT", false, "ASC" },
107 { "freq", "INT", false, "ASC" },
108 { "strokes", "INT", false, "ASC" },
109 { "rad_classic","INT", false, "ASC" },
110 { "rad_nelson", "INT", false, "ASC" },
111 { "components", "TEXT", false, "ASC" }
115 { "component", "TEXT", false, "ASC" },
116 { "strokes", "INT", false, "ASC" }
120 { "kanji", "TEXT", true, "ASC" },
121 { "skip1", "INT", false, "ASC" },
122 { "skip2", "INT", false, "ASC" },
123 { "skip3", "INT", false, "ASC" },
124 { "misclass", "TEXT", false, "ASC" },
128 { "key", "TEXT", false, "ASC" },
129 { "val", "TEXT", false, "ASC" }
135 // bool is treated as int
139 enum ValueType
{ STRING
, INT
, BOOL
, COLOR
, FONT
};
146 std::map
<string
,Value
> data_
;
152 inline std::map
<string
,Value
> get_map () const { return data_
; };
154 // returns copy (for int, bool)
156 inline T
get ( const string
&var
)
158 if ( data_
.find(var
) == data_
.end())
159 throw std::runtime_error("Config::get(\""+var
+"\"): unknown variable");
160 std::stringstream ss
;
162 ss
<< data_
.at(var
).val
;
168 // returns reference (for string, c_char)
169 inline string
&get ( const string
&var
)
171 if ( data_
.find(var
) == data_
.end())
172 throw std::runtime_error("Config::get(\""+var
+"\"): unknown variable");
173 return data_
.at(var
).val
;
176 // C++: bool to int conversion is implicit
177 // bool: true -> 1, false -> 0
178 inline void set ( const string
&var
, int val
) { data_
.at(var
).val
= std::to_string(val
); };
179 inline void set ( const string
&var
, const string
&val
) {
180 if ( data_
.find(var
) == data_
.end())
181 throw std::runtime_error("Config::get(\""+var
+"\"): unknown variable");
182 data_
.at(var
).val
= val
;
187 } // namespace aoi_config
188 #endif // _CONFIG_HXX