diff 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
line wrap: on
line diff
--- a/mde/lookup/Options.d	Sat Jul 05 15:36:39 2008 +0100
+++ b/mde/lookup/Options.d	Sat Jul 05 18:27:46 2008 +0100
@@ -206,7 +206,7 @@
         static if (!TIsIn!(T,TYPES))
             static assert (false, "Options.set does not currently support type "~T.stringof);
         
-        mixin (`alias opts`~T.stringof~` optsVars;`);
+        mixin (`alias opts`~TName!(T)~` optsVars;`);
         
         changed = true;     // something got set (don't bother checking this isn't what it already was)
         
@@ -215,10 +215,37 @@
             optionChanges.set!(T) (cast(ID) symbol, val);
         } catch (ArrayBoundsException) {
             // log and ignore:
-            logger.error ("Options.set: unkw!");
+            logger.error ("Options.set: invalid symbol");
         }
     }
     
+    /** Get option symbol of an Options sub-class.
+     *
+     * Using this method to read an option is not necessary, but allows for generic use.  */
+    T get(T) (char[] symbol) {
+        static if (!TIsIn!(T,TYPES))
+            static assert (false, "Options.get does not currently support type "~T.stringof);
+        
+        mixin (`alias opts`~TName!(T)~` optsVars;`);
+        
+        try {
+            return *(optsVars[cast(ID) symbol]);
+        } catch (ArrayBoundsException) {
+            // log and ignore:
+            logger.error ("Options.get: invalid symbol");
+        }
+    }
+    
+    /** List the names of all options of a specific type. */
+    char[][] list(T) () {
+        static if (!TIsIn!(T,TYPES))
+            static assert (false, "Options.list does not currently support type "~T.stringof);
+        
+        mixin (`alias opts`~TName!(T)~` optsVars;`);
+        
+        return optsVars.keys;
+    }
+    
     protected {
         OptionChanges optionChanges;	// all changes to options (for saving)
     	
@@ -385,8 +412,8 @@
         static if (!TIsIn!(T,TYPES))
             static assert (false, "OptionChanges.set does not currently support type "~T.stringof);
         
-        mixin (`alias opts`~T.stringof~` optsVars;`);
-        mixin (`alias `~T.stringof~`s vars;`);
+        mixin (`alias opts`~TName!(T)~` optsVars;`);
+        mixin (`alias `~TName!(T)~`s vars;`);
         
         T** p = id in optsVars;
         if (p !is null) **p = x;
@@ -416,7 +443,7 @@
 /** A home for all miscellaneous options, at least for now. */
 OptionsMisc miscOpts;
 class OptionsMisc : Options {
-    mixin (impl!("bool useThreads, exitImmediately; int logOptions; double pollInterval; char[] L10n;"));
+    mixin (impl!("bool useThreads, exitImmediately; int logOptions; double pollInterval; char[] L10n, a,b,c;"));
     
     static this() {
         miscOpts = new OptionsMisc;