comparison mde/lookup/Options.d @ 72:159775502bb4

The first dynamically generated widget lists, based on Options, are here!
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 05 Jul 2008 18:27:46 +0100
parents 7fc0a8295c83
children 25cb7420dc91
comparison
equal deleted inserted replaced
71:77c7d3235114 72:159775502bb4
204 * must be changed in two separate places. */ 204 * must be changed in two separate places. */
205 void set(T) (char[] symbol, T val) { 205 void set(T) (char[] symbol, T val) {
206 static if (!TIsIn!(T,TYPES)) 206 static if (!TIsIn!(T,TYPES))
207 static assert (false, "Options.set does not currently support type "~T.stringof); 207 static assert (false, "Options.set does not currently support type "~T.stringof);
208 208
209 mixin (`alias opts`~T.stringof~` optsVars;`); 209 mixin (`alias opts`~TName!(T)~` optsVars;`);
210 210
211 changed = true; // something got set (don't bother checking this isn't what it already was) 211 changed = true; // something got set (don't bother checking this isn't what it already was)
212 212
213 try { 213 try {
214 *(optsVars[cast(ID) symbol]) = val; 214 *(optsVars[cast(ID) symbol]) = val;
215 optionChanges.set!(T) (cast(ID) symbol, val); 215 optionChanges.set!(T) (cast(ID) symbol, val);
216 } catch (ArrayBoundsException) { 216 } catch (ArrayBoundsException) {
217 // log and ignore: 217 // log and ignore:
218 logger.error ("Options.set: unkw!"); 218 logger.error ("Options.set: invalid symbol");
219 } 219 }
220 }
221
222 /** Get option symbol of an Options sub-class.
223 *
224 * Using this method to read an option is not necessary, but allows for generic use. */
225 T get(T) (char[] symbol) {
226 static if (!TIsIn!(T,TYPES))
227 static assert (false, "Options.get does not currently support type "~T.stringof);
228
229 mixin (`alias opts`~TName!(T)~` optsVars;`);
230
231 try {
232 return *(optsVars[cast(ID) symbol]);
233 } catch (ArrayBoundsException) {
234 // log and ignore:
235 logger.error ("Options.get: invalid symbol");
236 }
237 }
238
239 /** List the names of all options of a specific type. */
240 char[][] list(T) () {
241 static if (!TIsIn!(T,TYPES))
242 static assert (false, "Options.list does not currently support type "~T.stringof);
243
244 mixin (`alias opts`~TName!(T)~` optsVars;`);
245
246 return optsVars.keys;
220 } 247 }
221 248
222 protected { 249 protected {
223 OptionChanges optionChanges; // all changes to options (for saving) 250 OptionChanges optionChanges; // all changes to options (for saving)
224 251
383 410
384 void set(T) (ID id, T x) { 411 void set(T) (ID id, T x) {
385 static if (!TIsIn!(T,TYPES)) 412 static if (!TIsIn!(T,TYPES))
386 static assert (false, "OptionChanges.set does not currently support type "~T.stringof); 413 static assert (false, "OptionChanges.set does not currently support type "~T.stringof);
387 414
388 mixin (`alias opts`~T.stringof~` optsVars;`); 415 mixin (`alias opts`~TName!(T)~` optsVars;`);
389 mixin (`alias `~T.stringof~`s vars;`); 416 mixin (`alias `~TName!(T)~`s vars;`);
390 417
391 T** p = id in optsVars; 418 T** p = id in optsVars;
392 if (p !is null) **p = x; 419 if (p !is null) **p = x;
393 else { 420 else {
394 vars ~= x; 421 vars ~= x;
414 */ 441 */
415 442
416 /** A home for all miscellaneous options, at least for now. */ 443 /** A home for all miscellaneous options, at least for now. */
417 OptionsMisc miscOpts; 444 OptionsMisc miscOpts;
418 class OptionsMisc : Options { 445 class OptionsMisc : Options {
419 mixin (impl!("bool useThreads, exitImmediately; int logOptions; double pollInterval; char[] L10n;")); 446 mixin (impl!("bool useThreads, exitImmediately; int logOptions; double pollInterval; char[] L10n, a,b,c;"));
420 447
421 static this() { 448 static this() {
422 miscOpts = new OptionsMisc; 449 miscOpts = new OptionsMisc;
423 Options.addOptionsClass (miscOpts, "misc"); 450 Options.addOptionsClass (miscOpts, "misc");
424 } 451 }