annotate mde/lookup/Options.d @ 63:66d555da083e

Moved many modules/packages to better reflect usage.
author Diggory Hardy <diggory.hardy@gmail.com>
date Fri, 27 Jun 2008 18:35:33 +0100
parents mde/Options.d@960206198cbd
children cc3763817b8a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
1 /* LICENSE BLOCK
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
2 Part of mde: a Modular D game-oriented Engine
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
4
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify it under the terms
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
6 of the GNU General Public License as published by the Free Software Foundation, either
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
7 version 2 of the License, or (at your option) any later version.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
8
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
11 See the GNU General Public License for more details.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
12
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
13 You should have received a copy of the GNU General Public License
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
15
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
16 /** This module handles stored options, currently all except input maps.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
17 *
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
18 * The purpose of having all options centrally controlled is to allow generic handling by the GUI
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
19 * and ease saving and loading of values. The Options class is only really designed around handling
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
20 * small numbers of variables for now.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
21 */
63
66d555da083e Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 62
diff changeset
22 module mde.lookup.Options;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
24 import mde.exception;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
25
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
26 import mde.mergetag.Reader;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
27 import mde.mergetag.Writer;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
28 import mde.mergetag.DataSet;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
29 import mde.mergetag.exception;
63
66d555da083e Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 62
diff changeset
30 import mde.setup.paths;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
31
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
32 import tango.scrapple.text.convert.parseTo : parseTo;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
33 import tango.scrapple.text.convert.parseFrom : parseFrom;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
34
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
35 import tango.core.Exception : ArrayBoundsException;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
36 import tango.util.log.Log : Log, Logger;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
37
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
38 /** Base class for handling options.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
39 *
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
40 * This class itself handles no options and should not be instantiated, but provides a sub-classable
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
41 * base for generic options handling. Also, the static portion of this class tracks sub-class
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
42 * instances and provides loading and saving methods.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
43 *
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
44 * Each sub-class provides named variables for maximal-speed reading. Local sub-class references
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
45 * should be used for reading variables, and via the addOptionsClass() hook will be loaded from
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
46 * files during pre-init (init0 stage). Do not write changes directly to the subclasses or they will
50
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
47 * not be saved; use, for example, Options.setBool(...). Use an example like OptionsMisc as a
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
48 * template for creating a new Options sub-class.
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
49 *
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
50 * Details: Options sub-classes hold associative arrays of pointers to all option variables, with a
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
51 * char[] id. This list is used for saving, loading and to provide generic GUI options screens. The
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
52 * built-in support in Options is only for bool, int and char[] types (a float type may get added).
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
53 * Further to this, a generic class is used to store all options which have been changed, and if any
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
54 * have been changed, is merged with options from the user conf dir and saved on exit.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
55 */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
56 class Options : IDataSection
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
57 {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
58 // No actual options are stored by this class. However, much of the infrastructure is
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
59 // present since it need not be redefined in sub-classes.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
60
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
61 // The "pointer lists":
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
62 protected bool* [ID] optsBool;
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
63 protected int* [ID] optsInt;
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
64 protected double*[ID] optsDouble;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
65 protected char[]*[ID] optsCharA;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
66
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
67 //BEGIN Mergetag loading/saving code
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
68 void addTag (char[] tp, ID id, char[] dt) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
69 if (tp == "bool") {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
70 bool** p = id in optsBool;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
71 if (p !is null) **p = parseTo!(bool) (dt);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
72 } else if (tp == "char[]") {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
73 char[]** p = id in optsCharA;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
74 if (p !is null) **p = parseTo!(char[]) (dt);
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
75 } else if (tp == "double") {
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
76 double** p = id in optsDouble;
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
77 if (p !is null) **p = parseTo!(double) (dt);
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
78 } else if (tp == "int") {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
79 int** p = id in optsInt;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
80 if (p !is null) **p = parseTo!(int) (dt);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
81 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
82 }
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
83
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
84 void writeAll (ItemDelg dlg) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
85 foreach (ID id, bool* val; optsBool) dlg ("bool" , id, parseFrom!(bool ) (*val));
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
86 foreach (ID id, char[]* val; optsCharA) dlg ("char[]", id, parseFrom!(char[]) (*val));
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
87 foreach (ID id, double* val; optsDouble)dlg ("double", id, parseFrom!(double) (*val));
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
88 foreach (ID id, int* val; optsInt) dlg ("int" , id, parseFrom!(int ) (*val));
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
89 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
90 //END Mergetag loading/saving code
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
91
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
92 //BEGIN Static
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
93 /** Add an options sub-class to the list for loading and saving.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
94 *
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
95 * Call from static this() (before Init calls load()). */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
96 static void addOptionsClass (Options c, char[] i)
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
97 in { // Trap a couple of potential coding errors:
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
98 assert (c !is null); // Instance must be created before calling addOptionsClass
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
99 assert (((cast(ID) i) in subClasses) is null); // Don't allow a silent replacement
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
100 } body {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
101 subClasses[cast(ID) i] = c;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
102 subClassChanges[cast(ID) i] = new OptionsGeneric;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
103 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
104
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
105 /** Set option symbol of Options class subClass to val.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
106 *
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
107 * Due to the way options are handled generically, string IDs must be used to access the options
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
108 * via hash-maps, which is a little slower than direct access but necessary since the option
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
109 * must be changed in two separate places. */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
110 private static const ERR_MSG = "Options.setXXX called with incorrect parameters!";
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
111 static void setBool (char[] subClass, char[] symbol, bool val) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
112 changed = true; // something got set (don't bother checking this isn't what it already was)
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
113
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
114 try {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
115 *(subClasses[cast(ID) subClass].optsBool[cast(ID) symbol]) = val;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
116 subClassChanges[cast(ID) subClass].setBool (cast(ID) symbol, val);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
117 } catch (ArrayBoundsException) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
118 // log and ignore:
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
119 logger.error (ERR_MSG);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
120 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
121 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
122 static void setInt (char[] subClass, char[] symbol, int val) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
123 changed = true; // something got set (don't bother checking this isn't what it already was)
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
124
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
125 try {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
126 *(subClasses[cast(ID) subClass].optsInt[cast(ID) symbol]) = val;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
127 subClassChanges[cast(ID) subClass].setInt (cast(ID) symbol, val);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
128 } catch (ArrayBoundsException) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
129 // log and ignore:
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
130 logger.error (ERR_MSG);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
131 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
132 }
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
133 static void setDouble (char[] subClass, char[] symbol, double val) {
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
134 changed = true; // something got set (don't bother checking this isn't what it already was)
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
135
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
136 try {
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
137 *(subClasses[cast(ID) subClass].optsDouble[cast(ID) symbol]) = val;
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
138 subClassChanges[cast(ID) subClass].setDouble (cast(ID) symbol, val);
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
139 } catch (ArrayBoundsException) {
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
140 // log and ignore:
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
141 logger.error (ERR_MSG);
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
142 }
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
143 }
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
144 static void setCharA (char[] subClass, char[] symbol, char[] val) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
145 changed = true; // something got set (don't bother checking this isn't what it already was)
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
146
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
147 try {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
148 *(subClasses[cast(ID) subClass].optsCharA[cast(ID) symbol]) = val;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
149 subClassChanges[cast(ID) subClass].setCharA (cast(ID) symbol, val);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
150 } catch (ArrayBoundsException) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
151 // log and ignore:
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
152 logger.error (ERR_MSG);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
153 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
154 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
155
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
156 // Track all sections for saving/loading/other generic handling.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
157 static Options[ID] subClasses;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
158 static OptionsGeneric[ID] subClassChanges;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
159 static bool changed = false; // any changes at all, i.e. do we need to save?
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
160
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
161 /* Load/save options from file.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
162 *
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
163 * If the file doesn't exist, no reading is attempted (options are left at default values).
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
164 */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
165 private static const fileName = "options";
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
166 private static const MT_LOAD_EXC = "Loading options aborted:";
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
167 static void load () {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
168 // Check it exists (if not it should still be created on exit).
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
169 // Don't bother checking it's not a folder, because it could still be a block or something.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
170 if (!confDir.exists (fileName)) return;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
171
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
172 try {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
173 IReader reader;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
174 reader = confDir.makeMTReader (fileName, PRIORITY.LOW_HIGH);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
175 reader.dataSecCreator = delegate IDataSection(ID id) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
176 /* Recognise each defined section, and return null for unrecognised sections. */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
177 Options* p = id in subClasses;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
178 if (p !is null) return *p;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
179 else return null;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
180 };
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
181 reader.read;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
182 } catch (MTException e) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
183 logger.fatal (MT_LOAD_EXC);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
184 logger.fatal (e.msg);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
185 throw new optionsLoadException ("Mergetag exception (see above message)");
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
186 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
187 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
188 static void save () {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
189 if (!changed) return; // no changes to save
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
190
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
191 DataSet ds = new DataSet();
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
192 foreach (id, sec; subClassChanges) ds.sec[id] = sec;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
193
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
194 // Read locally-stored options
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
195 try {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
196 IReader reader;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
197 reader = confDir.makeMTReader (fileName, PRIORITY.HIGH_ONLY, ds);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
198 reader.dataSecCreator = delegate IDataSection(ID id) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
199 return null; // All recognised sections are already in the dataset.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
200 };
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
201 reader.read;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
202 } catch (MTFileIOException) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
203 // File either didn't exist or couldn't be opened.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
204 // Presuming the former, this is not a problem.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
205 } catch (MTException e) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
206 // Log a message and continue, overwriting the file:
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
207 logger.error (MT_LOAD_EXC);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
208 logger.error (e.msg);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
209 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
210
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
211 try {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
212 IWriter writer;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
213 writer = confDir.makeMTWriter (fileName, ds);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
214 writer.write();
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
215 } catch (MTException e) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
216 logger.error ("Saving options aborted! Reason:");
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
217 logger.error (e.msg);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
218 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
219 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
220
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
221 private static Logger logger;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
222 static this() {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
223 logger = Log.getLogger ("mde.options");
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
224 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
225 //END Static
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
226
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
227 //BEGIN Templates
50
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
228 private {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
229 // Return index of first comma, or halts if not found.
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
230 template cIndex(char[] A) {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
231 static if (A.length == 0)
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
232 static assert (false, "Error in implementation");
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
233 else static if (A[0] == ',')
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
234 const size_t cIndex = 0;
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
235 else
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
236 const size_t cIndex = 1 + cIndex!(A[1..$]);
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
237 }
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
238 // Return index of first semi-colon, or halts if not found.
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
239 template scIndex(char[] A) {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
240 static if (A.length == 0)
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
241 static assert (false, "Error: no trailing semi-colon");
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
242 else static if (A[0] == ';')
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
243 const size_t scIndex = 0;
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
244 else
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
245 const size_t scIndex = 1 + scIndex!(A[1..$]);
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
246 }
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
247 // Look for "type symbols;" in A and return symbols as a comma separated list of names
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
248 // (even if type is encountered more than once). Output may contain spaces and, if
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
249 // non-empty, will contain a trailing comma. Assumes scIndex always returns less than A.$.
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
250 template parseT(char[] type, char[] A) {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
251 static if (A.length < type.length + 1) // end of input, no match
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
252 const char[] parseT = "";
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
253 else static if (A[0] == ' ') // leading whitespace: skip
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
254 const char[] parseT = parseT!(type, A[1..$]);
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
255 else static if (A[0..type.length] == type && A[type.length] == ' ') // match
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
256 const char[] parseT = A[type.length+1 .. scIndex!(A)] ~ "," ~
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
257 parseT!(type, A[scIndex!(A)+1 .. $]);
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
258 else // no match
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
259 const char[] parseT = parseT!(type, A[scIndex!(A)+1 .. $]);
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
260 }
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
261 // May have a trailing comma. Assumes cIndex always returns less than A.$.
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
262 template aaVars(char[] A) {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
263 static if (A.length == 0)
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
264 const char[] aaVars = "";
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
265 else static if (A[0] == ' ')
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
266 const char[] aaVars = aaVars!(A[1..$]);
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
267 else
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
268 const char[] aaVars = "\""~A[0..cIndex!(A)]~"\"[]:&"~A[0..cIndex!(A)] ~ "," ~
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
269 aaVars!(A[cIndex!(A)+1..$]);
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
270 }
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
271 // strip Trailing Comma
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
272 template sTC(char[] A) {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
273 static if (A.length && A[$-1] == ',')
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
274 const char[] sTC = A[0..$-1];
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
275 else
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
276 const char[] sTC = A;
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
277 }
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
278 // if string is empty (other than space) return null, otherwise enclose: [A]
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
279 template listOrNull(char[] A) {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
280 static if (A.length == 0)
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
281 const char[] listOrNull = "null";
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
282 else static if (A[0] == ' ')
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
283 const char[] listOrNull = listOrNull!(A[1..$]);
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
284 else
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
285 const char[] listOrNull = "["~A~"]";
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
286 }
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
287 } protected {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
288 /** Produces the implementation code to go in the constuctor. */
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
289 template aaDefs(char[] A) {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
290 const char[] aaDefs =
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
291 "optsBool = " ~ listOrNull!(sTC!(aaVars!(parseT!("bool" , A)))) ~ ";\n" ~
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
292 "optsInt = " ~ listOrNull!(sTC!(aaVars!(parseT!("int" , A)))) ~ ";\n" ~
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
293 "optsDouble = "~ listOrNull!(sTC!(aaVars!(parseT!("double", A)))) ~ ";\n" ~
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
294 "optsCharA = " ~ listOrNull!(sTC!(aaVars!(parseT!("char[]", A)))) ~ ";\n";
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
295 }
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
296 /+/** Produces the implementation code to go in the static constuctor. */
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
297 template optClassAdd(char[] symb) {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
298 const char[] optClassAdd = symb ~ "=new "~classinfo(this).name~";\n";//Options.addOptionsClass("~symb~", );\n";
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
299 }+/
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
300 /** mixin impl("type symbol[, symbol[...]];[type symbol[...];][...]")
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
301 *
62
960206198cbd Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents: 53
diff changeset
302 * Where type is one of bool, int, double, char[]. E.g.
50
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
303 * ---
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
304 * mixin (impl ("bool a, b; int i;"));
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
305 * ---
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
306 *
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
307 * In case this() needs to be customized, mixin(impl!(A)) is equivalent to:
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
308 * ---
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
309 * mixin (A~"\nthis(){\n"~aaDefs!(A)~"}");
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
310 * ---
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
311 *
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
312 * Notes: Only use space as whitespace (no new-lines or tabs). Make sure to add a trailing
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
313 * semi-colon (;) or you'll get told off! :D
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
314 *
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
315 * In general errors aren't reported well. Trial with pragma (msg, impl!(...)); if
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
316 * necessary.
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
317 *
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
318 * Extending: mixins could also be used for the static this() {...} or even the whole
62
960206198cbd Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents: 53
diff changeset
319 * class, but doing so would rather decrease readability of any implementation. */
50
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
320 template impl(char[] A /+, char[] symb+/) {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
321 const char[] impl = A~"\nthis(){\n"~aaDefs!(A)~"}";
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
322 // ~"\nstatic this(){\n"~optClassAdd!(symb)~"}"
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
323 }
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
324 }
50
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
325 /+/** mixin impl("type symbol[, symbol[...]];[type symbol[...];][...]")
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
326 *
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
327 * E.g.
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
328 * ---
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
329 * mixin (impl ("bool a, b; int i;"));
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
330 * ---
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
331 * The parser isn't highly accurate. */
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
332 // Try using templates instead? See std.metastrings
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
333 static char[] impl (char[] A) {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
334 char[] bools;
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
335 char[] ints;
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
336
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
337 while (A.length) {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
338 // Trim whitespace
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
339 {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
340 size_t i = 0;
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
341 while (i < A.length && (A[i] == ' ' || (A[i] >= 9u && A[i] <= 0xD)))
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
342 ++i;
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
343 A = A[i..$];
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
344 }
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
345 if (A.length == 0) break;
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
346
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
347 char[] type;
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
348 for (size_t i = 0; i < A.length; ++i) {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
349 if (A[i] == ' ' || (A[i] >= 9u && A[i] <= 0xD)) {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
350 type = A[0..i];
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
351 A = A[i+1..$];
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
352 break;
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
353 }
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
354 }
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
355
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
356 char[] symbols;
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
357 for (size_t i = 0; i < A.length; ++i) {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
358 if (A[i] == ';') {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
359 symbols = A[0..i];
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
360 A = A[i+1..$];
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
361 break;
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
362 }
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
363 }
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
364
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
365 if (type == "bool") {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
366 if (bools.length)
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
367 bools = bools ~ "," ~ symbols;
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
368 else
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
369 bools = symbols;
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
370 }
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
371 else if (type == "int") {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
372 if (ints.length)
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
373 ints = ints ~ "," ~ symbols;
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
374 else
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
375 ints = symbols;
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
376 }
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
377 else {
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
378 // Unfortunately, we cannot output non-const strings (even though func is compile-time)
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
379 // We also cannot use pragma(msg) because the message gets printed even if the code isn't run.
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
380 //pragma(msg, "Warning: impl failed to parse whole input string");
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
381 // Cannot use Cout / logger either.
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
382 break;
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
383 }
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
384 }
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
385
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
386 char[] ret;
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
387 if (bools.length)
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
388 ret = "bool "~bools~";\n";
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
389 if (ints.length)
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
390 ret = ret ~ "int "~ints~";\n";
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
391
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
392
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
393
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
394 return ret;
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
395 }+/
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
396 //END Templates
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
397 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
398
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
399 /* Special class to store all locally changed options, whatever the section. */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
400 class OptionsGeneric : Options {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
401 // These store the actual values, but are never accessed directly except when initially added.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
402 // optsX store pointers to each item added along with the ID and are used for access.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
403 bool[] bools;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
404 int[] ints;
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
405 double[] doubles;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
406 char[][] strings;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
407
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
408 this () {}
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
409
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
410 void setBool (ID id, bool x) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
411 bool** p = id in optsBool;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
412 if (p !is null) **p = x;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
413 else {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
414 bools ~= x;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
415 optsBool[id] = &bools[$-1];
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
416 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
417 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
418 void setInt (ID id, int x) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
419 int** p = id in optsInt;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
420 if (p !is null) **p = x;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
421 else {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
422 ints ~= x;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
423 optsInt[id] = &ints[$-1];
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
424 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
425 }
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
426 void setDouble (ID id, double x) {
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
427 double** p = id in optsDouble;
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
428 if (p !is null) **p = x;
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
429 else {
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
430 doubles ~= x;
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
431 optsDouble[id] = &doubles[$-1];
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
432 }
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
433 }
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
434 void setCharA (ID id, char[] x) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
435 char[]** p = id in optsCharA;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
436 if (p !is null) **p = x;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
437 else {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
438 strings ~= x;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
439 optsCharA[id] = &strings[$-1];
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
440 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
441 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
442
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
443 //BEGIN Mergetag loading/saving code
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
444 // Reverse priority: only load symbols not currently existing
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
445 void addTag (char[] tp, ID id, char[] dt) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
446 if (tp == "bool") {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
447 if ((id in optsBool) is null) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
448 bools ~= parseTo!(bool) (dt);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
449 optsBool[id] = &bools[$-1];
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
450 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
451 } else if (tp == "char[]") {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
452 if ((id in optsCharA) is null) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
453 strings ~= parseTo!(char[]) (dt);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
454 optsCharA[id] = &strings[$-1];
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
455 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
456 char[]** p = id in optsCharA;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
457 if (p !is null) **p = parseTo!(char[]) (dt);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
458 } else if (tp == "int") {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
459 if ((id in optsInt) is null) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
460 ints ~= parseTo!(int) (dt);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
461 optsInt[id] = &ints[$-1];
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
462 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
463 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
464 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
465 //END Mergetag loading/saving code
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
466 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
467
63
66d555da083e Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 62
diff changeset
468 /* NOTE: Options sub-classes are expected to use a template to ease inserting contents and
66d555da083e Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 62
diff changeset
469 * hide some of the "backend" functionality. Use impl as below, or read the documentation for impl.
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
470 *
63
66d555da083e Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 62
diff changeset
471 * Each entry should have a Translation entry with humanized names and descriptions in
66d555da083e Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 62
diff changeset
472 * data/L10n/ClassName.mtt
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
473 *
63
66d555da083e Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 62
diff changeset
474 * To create a new Options sub-class, just copy, paste and adjust.
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
475 */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
476
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
477 /** A home for all miscellaneous options, at least for now. */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
478 OptionsMisc miscOpts;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
479 class OptionsMisc : Options {
53
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 50
diff changeset
480 mixin (impl!("bool useThreads, exitImmediately; int logOptions; double pollInterval; char[] L10n;"));
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
481
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
482 static this() {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
483 miscOpts = new OptionsMisc;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
484 Options.addOptionsClass (miscOpts, "misc");
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
485 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
486 }