Mon, 25 Mar 2013 17:04:18 +0200
Phased out FOREACH macro in favor of C++11-style for iteration.
30
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
1 | /* |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
3 | * Copyright (C) 2013 Santeri `arezey` Piippo |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
4 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
8 | * (at your option) any later version. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
9 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
13 | * GNU General Public License for more details. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
14 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
17 | */ |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
18 | |
0 | 19 | #ifndef __OPTIONS_H__ |
20 | #define __OPTIONS_H__ | |
21 | ||
22 | #include "common.h" | |
23 | #include "str.h" | |
24 | ||
25 | // ============================================================================= | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
26 | #define CONFIGFILE APPNAME ".cfg" |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
27 | #include <QString> |
0 | 28 | |
29 | #define MAX_INI_LINE 512 | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
30 | #define NUM_CONFIG (g_pConfigPointers.size ()) |
0 | 31 | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
32 | #define cfg(T, NAME, DEFAULT) \ |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
33 | T##config NAME (DEFAULT, #NAME, #T, #DEFAULT) |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
34 | |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
35 | #define extern_cfg(T, NAME) \ |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
36 | extern T##config NAME |
0 | 37 | |
38 | // ============================================================================= | |
39 | enum configtype_e { | |
40 | CONFIG_none, | |
41 | CONFIG_int, | |
42 | CONFIG_str, | |
43 | CONFIG_float, | |
44 | CONFIG_bool, | |
45 | }; | |
46 | ||
47 | // ========================================================= | |
48 | class config { | |
49 | public: | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
50 | const char* name, *typestring, *defaultstring; |
0 | 51 | |
52 | virtual configtype_e getType () { | |
53 | return CONFIG_none; | |
54 | } | |
55 | ||
56 | virtual void resetValue () {} | |
57 | ||
58 | // ------------------------------------------ | |
59 | static bool load (); | |
60 | static bool save (); | |
61 | static void reset (); | |
62 | static str dirpath (); | |
63 | static str filepath (); | |
64 | }; | |
65 | ||
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
66 | extern std::vector<config*> g_pConfigPointers; |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
67 | |
0 | 68 | // ============================================================================= |
69 | #define DEFINE_UNARY_OPERATOR(T, OP) \ | |
70 | T operator OP () { \ | |
71 | return (OP value); \ | |
72 | } \ | |
73 | ||
74 | #define DEFINE_BINARY_OPERATOR(T, OP) \ | |
75 | T operator OP (const T other) { \ | |
76 | return (value OP other); \ | |
77 | } \ | |
78 | ||
79 | #define DEFINE_ASSIGN_OPERATOR(T, OP) \ | |
80 | T& operator OP (const T other) { \ | |
81 | return (value OP other); \ | |
82 | } \ | |
83 | ||
84 | #define DEFINE_COMPARE_OPERATOR(T, OP) \ | |
85 | bool operator OP (const T other) { \ | |
86 | return (value OP other); \ | |
87 | } \ | |
88 | ||
89 | #define DEFINE_CAST_OPERATOR(T) \ | |
90 | operator T () { \ | |
91 | return (T) value; \ | |
92 | } \ | |
93 | ||
94 | #define DEFINE_ALL_COMPARE_OPERATORS(T) \ | |
95 | DEFINE_COMPARE_OPERATOR (T, ==) \ | |
96 | DEFINE_COMPARE_OPERATOR (T, !=) \ | |
97 | DEFINE_COMPARE_OPERATOR (T, >) \ | |
98 | DEFINE_COMPARE_OPERATOR (T, <) \ | |
99 | DEFINE_COMPARE_OPERATOR (T, >=) \ | |
100 | DEFINE_COMPARE_OPERATOR (T, <=) \ | |
101 | ||
102 | #define DEFINE_INCREMENT_OPERATORS(T) \ | |
103 | T operator++ () {return ++value;} \ | |
104 | T operator++ (int) {return value++;} \ | |
105 | T operator-- () {return --value;} \ | |
106 | T operator-- (int) {return value--;} | |
107 | ||
108 | #define CONFIGTYPE(T) \ | |
109 | class T##config : public config | |
110 | ||
111 | #define IMPLEMENT_CONFIG(T) \ | |
112 | T value, defval; \ | |
113 | \ | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
114 | T##config (T _defval, const char* _name, const char* _typestring, \ |
0 | 115 | const char* _defaultstring) \ |
116 | { \ | |
117 | value = defval = _defval; \ | |
118 | name = _name; \ | |
119 | typestring = _typestring; \ | |
120 | defaultstring = _defaultstring; \ | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
121 | g_pConfigPointers.push_back (this); \ |
0 | 122 | } \ |
123 | operator T () { \ | |
124 | return value; \ | |
125 | } \ | |
126 | configtype_e getType () { \ | |
127 | return CONFIG_##T; \ | |
128 | } \ | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
129 | virtual void resetValue () { \ |
0 | 130 | value = defval; \ |
131 | } | |
132 | ||
133 | // ============================================================================= | |
134 | CONFIGTYPE (int) { | |
135 | public: | |
136 | IMPLEMENT_CONFIG (int) | |
137 | ||
138 | // Int-specific operators | |
139 | DEFINE_ALL_COMPARE_OPERATORS (int) | |
140 | DEFINE_INCREMENT_OPERATORS (int) | |
141 | DEFINE_BINARY_OPERATOR (int, +) | |
142 | DEFINE_BINARY_OPERATOR (int, -) | |
143 | DEFINE_BINARY_OPERATOR (int, *) | |
144 | DEFINE_BINARY_OPERATOR (int, /) | |
145 | DEFINE_BINARY_OPERATOR (int, %) | |
146 | DEFINE_BINARY_OPERATOR (int, ^) | |
147 | DEFINE_BINARY_OPERATOR (int, |) | |
148 | DEFINE_BINARY_OPERATOR (int, &) | |
149 | DEFINE_BINARY_OPERATOR (int, >>) | |
150 | DEFINE_BINARY_OPERATOR (int, <<) | |
151 | DEFINE_UNARY_OPERATOR (int, !) | |
152 | DEFINE_UNARY_OPERATOR (int, ~) | |
153 | DEFINE_UNARY_OPERATOR (int, -) | |
154 | DEFINE_UNARY_OPERATOR (int, +) | |
155 | DEFINE_ASSIGN_OPERATOR (int, =) | |
156 | DEFINE_ASSIGN_OPERATOR (int, +=) | |
157 | DEFINE_ASSIGN_OPERATOR (int, -=) | |
158 | DEFINE_ASSIGN_OPERATOR (int, *=) | |
159 | DEFINE_ASSIGN_OPERATOR (int, /=) | |
160 | DEFINE_ASSIGN_OPERATOR (int, %=) | |
161 | DEFINE_ASSIGN_OPERATOR (int, >>=) | |
162 | DEFINE_ASSIGN_OPERATOR (int, <<=) | |
163 | }; | |
164 | ||
165 | // ============================================================================= | |
166 | CONFIGTYPE (str) { | |
167 | public: | |
168 | IMPLEMENT_CONFIG (str) | |
169 | ||
170 | DEFINE_ALL_COMPARE_OPERATORS (str) | |
171 | DEFINE_BINARY_OPERATOR (str, -) | |
172 | DEFINE_BINARY_OPERATOR (str, *) | |
173 | DEFINE_UNARY_OPERATOR (str, !) | |
174 | DEFINE_ASSIGN_OPERATOR (str, =) | |
175 | DEFINE_ASSIGN_OPERATOR (str, +=) | |
176 | DEFINE_ASSIGN_OPERATOR (str, -=) | |
177 | DEFINE_ASSIGN_OPERATOR (str, *=) | |
178 | DEFINE_CAST_OPERATOR (char*) | |
179 | ||
180 | char operator[] (size_t n) { | |
181 | return value[n]; | |
182 | } | |
183 | ||
184 | #ifdef CONFIG_WITH_QT | |
185 | operator QString () { | |
186 | return QString (value.chars()); | |
187 | } | |
188 | #endif // CONFIG_WITH_QT | |
189 | }; | |
190 | ||
191 | // ============================================================================= | |
192 | CONFIGTYPE (float) { | |
193 | public: | |
194 | IMPLEMENT_CONFIG (float) | |
195 | ||
196 | DEFINE_ALL_COMPARE_OPERATORS (float) | |
197 | DEFINE_INCREMENT_OPERATORS (float) | |
198 | DEFINE_BINARY_OPERATOR (float, +) | |
199 | DEFINE_BINARY_OPERATOR (float, -) | |
200 | DEFINE_BINARY_OPERATOR (float, *) | |
201 | DEFINE_UNARY_OPERATOR (float, !) | |
202 | DEFINE_ASSIGN_OPERATOR (float, =) | |
203 | DEFINE_ASSIGN_OPERATOR (float, +=) | |
204 | DEFINE_ASSIGN_OPERATOR (float, -=) | |
205 | DEFINE_ASSIGN_OPERATOR (float, *=) | |
206 | }; | |
207 | ||
208 | // ============================================================================= | |
209 | CONFIGTYPE (bool) { | |
210 | public: | |
211 | IMPLEMENT_CONFIG (bool) | |
212 | DEFINE_ALL_COMPARE_OPERATORS (bool) | |
213 | DEFINE_ASSIGN_OPERATOR (bool, =) | |
214 | }; | |
215 | ||
216 | #endif // __OPTIONS_H__ |