diff mde/lookup/Options.d @ 82:ac1e3fd07275

New ssi file format. (De)serializer now supports non-ascii wide characters (encoded to UTF-8) and no longer supports non-ascii 8-bit chars which would result in bad UTF-8. Moved/renamed a few things left over from the last commit.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 30 Aug 2008 09:37:35 +0100
parents d8fccaa45d5f
children e0f1ec7fe73a
line wrap: on
line diff
--- a/mde/lookup/Options.d	Fri Aug 29 11:59:43 2008 +0100
+++ b/mde/lookup/Options.d	Sat Aug 30 09:37:35 2008 +0100
@@ -182,13 +182,27 @@
     
         private Logger logger;
         static this() {
-            logger = Log.getLogger ("mde.options");
+            logger = Log.getLogger ("mde.lookup.Options");
         }
     }
     //END Static
     
     
     //BEGIN Non-static
+    /+ NOTE: according to spec: "Templates cannot be used to add non-static members or virtual
+    functions to classes." However, this appears to work (but linking problems did occur).
+    Alternative: use mixins. From OptionsChanges:
+        // setT (used to be a template, but:
+        // Templates cannot be used to add non-static members or virtual functions to classes. )
+        template setMixin(A...) {
+            static if (A.length) {
+                const char[] setMixin = `void set`~TName!(A[0])~` (ID id, `~A[0].stringof~` x) {
+                    `~TName!(T)~`s[id] = x;
+                }
+                ` ~ setMixin!(A[1..$]);
+            } else
+                const char[] setMixin = ``;
+        }+/
     /** Set option symbol of an Options sub-class to val.
      *
      * Due to the way options are handled generically, string IDs must be used to access the options
@@ -197,13 +211,11 @@
     void set(T) (char[] symbol, T val) {
         static assert (TIsIn!(T,TYPES), "Options does not support type "~T.stringof);
         
-        mixin (`alias opts`~TName!(T)~` optsVars;`);
-        
         changed = true;     // something got set (don't bother checking this isn't what it already was)
         
         try {
-            *(optsVars[cast(ID) symbol]) = val;
-            optionChanges.set!(T) (cast(ID) symbol, val);
+            mixin (`*(opts`~TName!(T)~`[cast(ID) symbol]) = val;`);
+            mixin (`optionChanges.`~TName!(T)~`s[symbol] = val;`);
         } catch (ArrayBoundsException) {
             // log and ignore:
             logger.error ("Options.set: invalid symbol");
@@ -398,7 +410,6 @@
             } else
                 const char[] writeAllMixin = ``;
         }
-        
     }
     //END Templates
     // These store the actual values, but are never accessed directly except when initially added.
@@ -407,13 +418,6 @@
     
     this () {}
     
-    void set(T) (ID id, T x) {
-        static assert (Options.TIsIn!(T,TYPES), "Options does not support type "~T.stringof);
-        
-        mixin (`alias `~TName!(T)~`s vars;`);
-        vars[id] = x;
-    }
-    
     //BEGIN Mergetag loading/saving code
     // HIGH_LOW priority: only load symbols not currently existing
     void addTag (char[] tp, ID id, char[] dt) {