Changeset 12

Show
Ignore:
Timestamp:
08/30/07 16:53:02 (1 year ago)
Author:
aarti_pl
Message:

some refactorings & cleanups

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/npo/doc/todo.txt

    r11 r12  
     1-------------------------------------------------------------------------------  
     2                        THINGS TO DO 
     3-------------------------------------------------------------------------------  
    14doost.core.Any: 
    25    - add operator: static Any oppCall()(TypeInfo type, void* data) 
    3  
    46     
    57doost.util.config.Utils: 
     
    810    - make ProgramOptions thread safe 
    911    - implement optimistic locking for backends to avoid situation where two clients overwrite their changes in backend 
    10     -  
    11      
     12 
     13 
     14 
     15-------------------------------------------------------------------------------  
     16                        THINGS TO CONSIDER 
     17------------------------------------------------------------------------------- 
     18    - it is possible to create template opIndexAssign, so it would be possible to assign values without using value!(<type>)(<val>) wrapper. 
     19      In such a case there should be special case for assigning VariableValue, which would just copy assigned value. Drawback: may be confusing and 
     20      not consistant with whole design. 
     21 
     22 
     23       
     24-------------------------------------------------------------------------------  
     25                        POSSIBLE D LANGUAGE IMPROVEMENTS 
     26-------------------------------------------------------------------------------  
     27    - referencing member objects in destructor (to allow automatic synchronization on destruction) 
     28    - typeof(this) in member classes should be of current type, not base type (would allow to remove template mixins) 
  • branches/npo/doost/sys/Environment.d

    r11 r12  
    1 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    2 // 
    3 // Created by 
    4 // (c) Marcin Kuszczak, 2006 
    5 // LICENCE: Public Domain 
    6 // 
    7 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    8  
    9  
    10 module doost.Environment; 
    11  
    12 import std.string; 
    13 import std.stdio; 
    14  
    15 extern(C) { 
    16     private extern char **environ; 
    17  
    18     private char *getenv(char *name); 
     1/******************************************************************************* 
     2 
     3        copyright:      Copyright (c) 2007 Tango. All rights reserved 
     4 
     5        license:        BSD style: $(LICENSE) 
     6 
     7        version:        Feb 2007: Initial release 
     8 
     9        author:         Deewiant, Maxter, Gregor, Kris 
     10                        hacked to work with Phobos/Doost: Aarti_Pl 
     11 
     12*******************************************************************************/ 
     13 
     14module doost.sys.Environment; 
     15 
     16import std.utf : toUtf16=toUTF16, toUtf8=toUTF8; 
     17 
     18 
     19/******************************************************************************* 
     20 
     21*******************************************************************************/ 
     22 
     23version (Windows) 
     24
     25        pragma (lib, "kernel32.lib"); 
     26 
     27        extern (Windows) 
     28        { 
     29                private void* GetEnvironmentStringsW(); 
     30                private bool FreeEnvironmentStringsW(wchar**); 
     31        } 
     32        extern (Windows) 
     33        { 
     34                private int SetEnvironmentVariableW(wchar*, wchar*); 
     35                private uint GetEnvironmentVariableW(wchar*, wchar*, uint); 
     36                private const int ERROR_ENVVAR_NOT_FOUND = 203; 
     37        } 
     38
     39else 
     40
     41    private extern (C) extern char** environ; 
     42 
     43    private char *getenv(char *name); 
    1944    private int setenv(char *envname, char *envval, int overwrite); 
    2045    private int unsetenv(char *name); 
    2146} 
    2247 
    23 class EnvException : Exception { 
    24     this(char[] e) { 
    25         super(e); 
    26     } 
    27 
    28  
    29 char[][char[]] getEnv() { 
    30     char[][char[]] result; 
    31     char** m_environment=environ; 
    32     char[] s, key, value; 
    33     uint n; 
    34  
    35     while ((*m_environment) !is null) { 
    36         s=toString((*m_environment)); 
    37         n=find(s, '='); 
    38         assert(n!=-1); 
    39  
    40         key=s[0..n]; 
    41         value=s[n+1..$]; 
    42         result[key]=value; 
    43  
    44         ++m_environment; 
    45     } 
    46     return result; 
    47 
    48  
    49 char[] getEnvVariable(char[] name) { 
    50     return ""; 
    51 
    52  
    53 void setEnvVariable(char[] name, char[] value) { 
    54 
    55  
    56 void removeEnvVariable(char[] name) { 
    57 
     48 
     49/******************************************************************************* 
     50 
     51        Exposes the system Environment settings, along with some handy 
     52        utilities 
     53 
     54*******************************************************************************/ 
     55 
     56struct Environment { 
     57        version (Win32) 
     58        { 
     59                /************************************************************** 
     60 
     61                        Returns the provided 'def' value if the variable 
     62                        does not exist 
     63 
     64                **************************************************************/ 
     65 
     66                static char[] get (char[] variable, char[] def = null) 
     67                { 
     68                        wchar[] var = toUtf16(variable) ~ "\0"; 
     69 
     70                        uint size = GetEnvironmentVariableW(var.ptr, cast(wchar*)null, 0); 
     71                        if (size is 0) 
     72                           { 
     73                           //if (SysError.lastCode is ERROR_ENVVAR_NOT_FOUND) 
     74                               return def; 
     75                           //else 
     76                           //   throw new PlatformException(SysError.lastMsg); 
     77                           } 
     78 
     79                        auto buffer = new wchar[size]; 
     80                        size = GetEnvironmentVariableW(var.ptr, buffer.ptr, size); 
     81                        if (size is 0) 
     82                            throw new Exception ("Can not read environment variable"); 
     83 
     84                        return toUtf8 (buffer[0 .. size]); 
     85                } 
     86 
     87                /************************************************************** 
     88 
     89                        clears the variable if value is null or empty 
     90 
     91                **************************************************************/ 
     92 
     93                static void set (char[] variable, char[] value = null) 
     94                { 
     95                        wchar * var, val; 
     96 
     97                        var = (toUtf16 (variable) ~ "\0").ptr; 
     98 
     99                        if (value.length > 0) 
     100                            val = (toUtf16 (value) ~ "\0").ptr; 
     101 
     102                        if (! SetEnvironmentVariableW(var, val)) 
     103                              throw new Exception ("Can not set environment variable"); 
     104                } 
     105 
     106                /************************************************************** 
     107 
     108                **************************************************************/ 
     109 
     110                static char[][char[]] get () 
     111                { 
     112                        char[][char[]] arr; 
     113 
     114                        wchar[] key = new wchar[20], 
     115                                value = new wchar[40]; 
     116 
     117                        wchar** env = cast(wchar**) GetEnvironmentStringsW(); 
     118                        scope (exit) 
     119                               FreeEnvironmentStringsW (env); 
     120 
     121                        for (wchar* str = cast(wchar*) env; *str; ++str) 
     122                            { 
     123                            size_t k = 0, v = 0; 
     124 
     125                            while (*str != '=') 
     126                                  { 
     127                                  key[k++] = *str++; 
     128 
     129                                  if (k is key.length) 
     130                                      key.length = 2 * key.length; 
     131                                  } 
     132 
     133                            ++str; 
     134 
     135                            while (*str) 
     136                                  { 
     137                                  value [v++] = *str++; 
     138 
     139                                  if (v is value.length) 
     140                                      value.length = 2 * value.length; 
     141                                  } 
     142 
     143                            arr [toUtf8(key[0 .. k])] = toUtf8(value[0 .. v]); 
     144                            } 
     145 
     146                        return arr; 
     147                } 
     148        } 
     149        else // POSIX 
     150        { 
     151                /************************************************************** 
     152 
     153                        Returns the provided 'def' value if the variable 
     154                        does not exist 
     155 
     156                **************************************************************/ 
     157 
     158                static char[] get (char[] variable, char[] def = null) 
     159                { 
     160                        char* ptr = getenv (variable.ptr); 
     161 
     162                        if (ptr is null) 
     163                            return def; 
     164 
     165                        return ptr[0 .. strlen(ptr)].dup; 
     166                } 
     167 
     168                /************************************************************** 
     169 
     170                        clears the variable, if value is null or empty 
     171 
     172                **************************************************************/ 
     173 
     174                static void set (char[] variable, char[] value = null) 
     175                { 
     176                        int result; 
     177 
     178                        if (value.length is 0) 
     179                            unsetenv ((variable ~ '\0').ptr); 
     180                        else 
     181                           result = setenv ((variable ~ '\0').ptr, (value ~ '\0').ptr, 1); 
     182 
     183                        //if (result != 0) 
     184                          //  throw new PlatformException (SysError.lastMsg); 
     185                } 
     186 
     187                /************************************************************** 
     188 
     189                **************************************************************/ 
     190 
     191                static char[][char[]] get () 
     192                { 
     193                        char[][char[]] arr; 
     194 
     195                        for (char** p = environ; *p; ++p) 
     196                            { 
     197                            size_t k = 0; 
     198                            char* str = *p; 
     199 
     200                            while (*str++ != '=') 
     201                                   ++k; 
     202                            char[] key = (*p)[0..k]; 
     203 
     204                            k = 0; 
     205                            char* val = str; 
     206                            while (*str++) 
     207                                   ++k; 
     208                            arr[key] = val[0 .. k]; 
     209                            } 
     210 
     211                        return arr; 
     212                } 
     213        } 
     214
     215 
     216debug (Environment) 
     217
     218        import tango.io.Console; 
     219 
     220 
     221        void main(char[][] args) 
     222        { 
     223        const char[] VAR = "TESTENVVAR"; 
     224        const char[] VAL1 = "VAL1"; 
     225        const char[] VAL2 = "VAL2"; 
     226 
     227        assert(Environment.get(VAR) is null); 
     228 
     229        Environment.set(VAR, VAL1); 
     230        assert(Environment.get(VAR) == VAL1); 
     231 
     232        Environment.set(VAR, VAL2); 
     233        assert(Environment.get(VAR) == VAL2); 
     234 
     235        Environment.set(VAR, null); 
     236        assert(Environment.get(VAR) is null); 
     237 
     238        Environment.set(VAR, VAL1); 
     239        Environment.set(VAR, ""); 
     240 
     241        assert(Environment.get(VAR) is null); 
     242 
     243        foreach (key, value; Environment.get) 
     244                 Cout (key) ("=") (value).newline; 
     245 
     246 
     247        } 
     248
     249 
  • branches/npo/doost/util/config/CommandLineStorage.d

    r11 r12  
    343343/******************************************************************************* 
    344344 ******************************************************************************/ 
    345 class CommandLineOptions : IOptionsDescription { 
     345class CommandLineOptions : OptionsDescription { 
    346346public: 
    347347    typeof(this) dup() { 
     
    369369    } 
    370370 
    371     IOptionsDescription[] groups() { 
     371    OptionsDescription[] groups() { 
    372372        return null; 
    373373    } 
     
    399399    /*************************************************************************** 
    400400     **************************************************************************/ 
    401     this(OptionsDescription od, char[][] args) 
     401    this(RegularOptions od, char[][] args) 
    402402    in { 
    403403        assert(od !is null); 
     
    479479        after synchronization. 
    480480     **************************************************************************/ 
    481     override void synchronize(bool nf=true) { 
     481    override void synchronize(bool nf=true) 
     482    in { 
    482483        assert(isConnected == true); 
     484    } 
     485    body { 
     486        m_collected=null; 
    483487 
    484488        OptionsMap optsMap = readPhysicallyAll; 
     
    524528        StyleParser[] style_parsers; 
    525529 
    526         //TODO: collect regexp options (zwraca wektor opcji zmatchowanych przez RegExpOption) 
    527530        if (m_style_parser) style_parsers~=m_style_parser; 
    528531        if (m_additional_parser) style_parsers~=&handleAdditionalParser; 
     
    614617    } 
    615618 
     619    /*************************************************************************** 
     620     **************************************************************************/ 
    616621    char[] consumeToken(ref char[][] args, char[] name=null) { 
    617622        char[] result; 
  • branches/npo/doost/util/config/ConfigFileStorage.d

    r11 r12  
    5757        Constructs Storage, reading content of file and parsing it 
    5858        Params: 
    59             desc = OptionsDescription object 
     59            desc = RegularOptions object 
    6060            file = file name 
    6161            codepage = codepage of file (default = unicode utf8/utf16/utf32) 
    6262     **************************************************************************/ 
    63     this(OptionsDescription desc, char[] file, int codepage=-1) 
     63    this(RegularOptions desc, char[] file, int codepage=-1) 
    6464    in { 
    6565        assert(desc !is null); 
  • branches/npo/doost/util/config/Converter.d

    r11 r12  
    7070//------------------------------------------------------------------------------ 
    7171 
    72 /* Otherwise, returns a reference to a statically allocated 
    73     empty string if 'allow_empty' and throws ValidationException 
    74     otherwise. */ 
    75  
    76 char[] getSingleString(char[] v, bool allow_empty = false) { 
    77     if (!allow_empty) { 
    78         if (v is null) throw new ValidationException("at least one value required"); 
    79     } 
    80     return v; 
    81 } 
    82  
    83 //------------------------------------------------------------------------------ 
    84  
    85 /* Throws MultipleOccurrencesException if 'value' is not empty. */ 
    86 void checkFirstOccurrence(Any value) { 
    87     if (!value.empty) 
    88         throw new MultipleOccurrencesException("multiple_occurrences"); 
    89 } 
    90  
    91 //------------------------------------------------------------------------------ 
    92  
    93 /******************************************************************************* 
    94     Validates 's' and updates 'v'. 
    95     'v' is either empty or in the state assigned by the previous 
    96     invocation of 'validate'. 
    97     The target type is specified via a parameter which has the type of 
    98     pointer to the desired type. This is workaround for compilers without 
    99     partial template ordering, just like the last 'long/int' parameter. 
    100  ******************************************************************************/ 
    101 void parseText(T)(Any v, char[] xs, char[] pattern) { 
    102     checkFirstOccurrence(v); 
    103     char[] s=getSingleString(xs).dup; 
    104  
    105     if (pattern !is null) { 
    106         auto re = std.regexp.search(s, pattern); 
    107         if (re is null) throw new InvalidOptionValueException(s, pattern); 
    108         if (re.match(0) != s) 
    109             throw new InvalidOptionValueException(s, pattern); 
    110     } 
    111  
    112     try { 
    113         v.assign(stringToType!(T)(s)); 
    114     } catch (Exception) { 
    115         throw new InvalidOptionValueException(s); 
    116     } 
    117 } 
    118  
    119 //------------------------------------------------------------------------------ 
    120  
    121 char[] stringizeValue(T)(Any value) { 
    122     static if (isAtomicType!(T)) { 
    123         return toString(value.as!(T)); 
    124     } else { 
    125         return value.as!(T).toString(); 
    126     } 
    127 } 
    128  
    129 //------------------------------------------------------------------------------ 
    130  
    13172char fromEscape(char c) { 
    13273    char result; 
     
    171112//------------------------------------------------------------------------------ 
    172113 
     114/* Otherwise, returns a reference to a statically allocated 
     115    empty string if 'allow_empty' and throws ValidationException 
     116    otherwise. */ 
     117 
     118char[] getSingleString(char[] v, bool allow_empty = false) { 
     119    if (!allow_empty) { 
     120        if (v is null) throw new ValidationException("at least one value required"); 
     121    } 
     122    return v; 
     123} 
     124 
     125//------------------------------------------------------------------------------ 
     126 
     127/******************************************************************************* 
     128    Validates 's' and updates 'v'. 
     129    'v' is either empty or in the state assigned by the previous 
     130    invocation of 'validate'. 
     131    The target type is specified via a parameter which has the type of 
     132    pointer to the desired type. This is workaround for compilers without 
     133    partial template ordering, just like the last 'long/int' parameter. 
     134 ******************************************************************************/ 
     135T parseText(T)(char[] xs, char[] pattern) { 
     136    char[] s=getSingleString(xs).dup; 
     137 
     138    if (pattern !is null) { 
     139        auto re = std.regexp.search(s, pattern); 
     140        if (re is null) throw new InvalidOptionValueException(s, pattern); 
     141        if (re.match(0) != s) 
     142            throw new InvalidOptionValueException(s, pattern); 
     143    } 
     144 
     145    try { 
     146        return stringToType!(T)(s); 
     147    } catch (Exception) { 
     148        throw new InvalidOptionValueException(s); 
     149    } 
     150} 
     151 
     152//------------------------------------------------------------------------------ 
     153 
     154/******************************************************************************* 
     155 ******************************************************************************/ 
     156char[] stringizeValue(T)(Any value) { 
     157    static if (isAtomicType!(T)) { 
     158        return toString(value.as!(T)); 
     159    } else { 
     160        return value.as!(T).toString(); 
     161    } 
     162} 
     163 
     164//------------------------------------------------------------------------------ 
     165 
    173166/******************************************************************************* 
    174167    Validates sequences. Allows multiple values per option occurrence 
     
    191184 
    192185*******************************************************************************/ 
    193 void parseText(T : T[])(Any v, char[] xs, char[] pattern) { 
    194     if (v.empty()) { 
    195         T[] t; 
    196         v=t; 
    197     } 
    198  
    199     T[] tv = v.as!(T[]); 
     186T[] parseText(T : T[])(char[] xs, char[] pattern) { 
     187    T[] tv; 
    200188 
    201189    char[] list = strip(xs); 
     
    208196 
    209197    char[][] tokens = tokenizer(list, ",;", " \t\r"); 
    210  
    211     //TODO: optimize to avoid below; parseText should not get Any as 
    212     //parameter, but return T. All code with Any should be delegated 
    213     //to ValueSemantic 
    214198    foreach(t; tokens) { 
    215         Any a = new Any
    216         parseText!(T)(a, strip(t), pattern); 
    217         tv ~= a.as!(T); 
    218     } 
    219  
    220     v.assign(tv); 
    221 
    222  
    223 //------------------------------------------------------------------------------ 
    224  
     199        tv ~= parseText!(T)(strip(t), pattern)
     200    } 
     201 
     202    return tv; 
     203
     204 
     205//------------------------------------------------------------------------------ 
     206 
     207/******************************************************************************* 
     208 ******************************************************************************/ 
    225209char[] stringizeValue(T: T[])(Any v) { 
    226210    assert(v !is null); 
     
    248232    be optional. 
    249233 ******************************************************************************/ 
    250 void parseText(T : bool)(Any v, char[] xs, char[] pattern) { 
    251     checkFirstOccurrence(v); 
     234T parseText(T : bool)(char[] xs, char[] pattern) { 
    252235    char[] s=tolower(getSingleString(xs, true).dup); 
    253236 
     
    255238        pattern = "on|yes|1|true"; 
    256239 
    257     if (s.length == 0) { 
    258         v.assign(true); 
    259         return; 
    260     } 
     240    if (s.length == 0) return true; 
    261241 
    262242    auto re = std.regexp.search(s, pattern); 
    263243    if (re !is null) { 
    264         if (re.match(0) == s) { 
    265             v.assign(true); 
    266             return; 
    267         } 
    268     } 
    269  
    270     v.assign(false); 
    271 
    272  
    273 //------------------------------------------------------------------------------ 
    274  
    275 void parseText(T : char[])(Any v, char[] xs, char[] pattern) { 
    276     checkFirstOccurrence(v); 
     244        if (re.match(0) == s) return true; 
     245    } 
     246 
     247    return false; 
     248
     249 
     250//------------------------------------------------------------------------------ 
     251 
     252/******************************************************************************* 
     253 ******************************************************************************/ 
     254T parseText(T : char[])(char[] xs, char[] pattern) { 
    277255    char[] s=getSingleString(xs).dup; 
    278256    bool skipEscapes=true; 
     
    308286    } else result = s; 
    309287 
    310     v.assign(result); 
    311 
    312  
    313 //------------------------------------------------------------------------------ 
    314  
     288    return result; 
     289
     290 
     291//------------------------------------------------------------------------------ 
     292 
     293/******************************************************************************* 
     294 ******************************************************************************/ 
    315295char[] stringizeValue(T: char[])(Any v) { 
    316296    assert(v !is null); 
     
    321301    return "\"" ~ result ~ "\""; 
    322302} 
    323  
  • branches/npo/doost/util/config/EnvironmentStorage.d

    r11 r12  
    77import doost.util.config.Option; 
    88import doost.util.config.ProgramOptions; 
     9import doost.util.config.Value; 
    910import doost.util.config.Formatter; 
    1011 
     
    1920    /*************************************************************************** 
    2021     **************************************************************************/ 
    21     this(char[] prefix,  char[] delegate(char[]) m=&nameMapper) { 
     22    //NOTE: change from function to delegate breaks compilation. Compiler bug?? 
     23 
     24    this(RegularOptions od, char[] prefix, char[] function(char[]) m = &nameMapper) 
     25    in { 
     26        assert(od !is null); 
     27    } 
     28    body { 
    2229        m_prefix=prefix; 
    2330        m_mapper=m; 
     31        m_regular = od.dup; 
     32        m_defaultSyncPolicy = SyncPolicy.Direct; 
     33        m_syncPolicy = SyncPolicy.Default; 
     34        m_persistent = false; 
    2435    } 
    2536 
     
    3445    /*************************************************************************** 
    3546     **************************************************************************/ 
    36     EnvironmentStorage prefix(char[] prefix) { 
    37         assert(m_connected == false); 
     47    typeof(this) prefix(char[] prefix) { 
     48        assert(isConnected == false); 
    3849        m_prefix = prefix; 
    3950        return this; 
     
    4253    /*************************************************************************** 
    4354     **************************************************************************/ 
    44     char[] delegate(char[]) mapper() { 
     55    char[] function(char[]) mapper() { 
    4556        return m_mapper; 
    4657    } 
     
    4859    /*************************************************************************** 
    4960     **************************************************************************/ 
    50     EnvironmentStorage mapper(char[] delegate(char[]) mp) { 
    51         assert(m_connected == false); 
     61    typeof(this) mapper(char[] function(char[]) mp) { 
     62        assert(isConnected == false); 
    5263        m_mapper = mp; 
    5364        return this; 
     
    5667protected: 
    5768    /*************************************************************************** 
     69        See: ConcreteStorage 
    5870     **************************************************************************/ 
    59     void synchronize(bool notify=true) { 
    60         char[][char[]] env=getEnv(); 
     71    override OptionsMap readPhysicallyAll() { 
     72        char[][char[]] env=Environment.get(); 
    6173        Option[] result; 
    6274 
    6375        foreach(key; env.keys) { 
    64             char[] option_name = m_mapper(key); 
     76            char[] name = m_mapper(key); 
    6577 
    66             if (option_name.length!=0) { 
    67                 auto n = new Option; 
    68                 n.string_key = option_name; 
    69                 n.value=env[key]; 
    70                 result~=n; 
     78            if (name.length!=0) { 
     79                result~=new Option(name, env[name], findOptionChecked(name)); 
    7180            } 
    7281        } 
    7382 
    74         storeOptions(result); 
     83        OptionsMap fnresult; 
     84        storeOptions(result, fnresult); 
     85        return fnresult; 
     86    } 
     87 
     88    /*************************************************************************** 
     89        See: ConcreteStorage 
     90     **************************************************************************/ 
     91     //{EMPTY, INSERTED, SYNCHRONIZED, MODIFIED, REMOVED} 
     92    override void savePhysicallyAll() { 
     93        foreach(name; m_optionStatus.keys) { 
     94            switch(getStatus(name)) { 
     95                case OStatus.REMOVED:       Environment.set(name); 
     96                                            m_optionStatus.remove(name); 
     97                                            break; 
     98                case OStatus.INSERTED:      Environment.set(name, m_prefix ~ "=" ~ m_variablesMap[name].toString); 
     99                                            setStatus(name, OStatus.SYNCHRONIZED); 
     100                                            break; 
     101                case OStatus.MODIFIED:      setStatus(name, OStatus.SYNCHRONIZED); 
     102                                            break; 
     103                default:; 
     104            } 
     105        } 
     106    } 
     107 
     108    /*************************************************************************** 
     109        See: ConcreteStorage 
     110     **************************************************************************/ 
     111    override VariableValue* readPhysicallyOne(char[] name) { 
     112        OptionDescription d; 
     113        //d = findOptionChecked(name); 
     114        Option[] result; 
     115 
     116        OptionsMap fnresult; 
     117        storeOptions(result, fnresult); 
     118        return &fnresult[name]; 
     119    } 
     120 
     121    /*************************************************************************** 
     122        See: ConcreteStorage 
     123     **************************************************************************/ 
     124    override void savePhysicallyOne(char[] name, VariableValue* value) { 
    75125    } 
    76126 
     
    85135    } 
    86136 
     137    //-------------------------------------------------------------------------- 
    87138    char[] m_prefix; 
    88     char[] delegate(char[]) m_mapper; 
     139    char[] function(char[]) m_mapper; 
    89140} 
  • branches/npo/doost/util/config/Formatter.d

    r11 r12  
    4949    /*************************************************************************** 
    5050     **************************************************************************/ 
    51     char[] makeDescription(IOptionsDescription od, IOptionsDescription od); 
     51    char[] makeDescription(OptionsDescription od, OptionsDescription od); 
    5252} 
    5353 
     
    230230    /*************************************************************************** 
    231231     **************************************************************************/ 
    232     char[] makeDescription(IOptionsDescription desc, IOptionsDescription special=null) { 
     232    char[] makeDescription(OptionsDescription desc, OptionsDescription special=null) { 
    233233        char[] result; 
    234234        if (m_addInfo !is null) result~=m_addInfo ~ ":\n"; 
  • branches/npo/doost/util/config/Option.d

    r11 r12  
    223223        to explicitly pass ownership. Unfortunately, it's often needed to 
    224224        create objects of types derived from 'ValueSemantic': 
    225            OptionsDescription d; 
     225           RegularOptions d; 
    226226           d.addOptions()("a", parameter<int>("n")->default_value(1)); 
    227227        Here, the static type returned by 'parameter' should be derived 
     
    357357    Class which provides convenient creation syntax to StandardOption. 
    358358 ******************************************************************************/ 
    359 class OptionsDescriptionEasyInit { 
    360 public: 
    361     /*************************************************************************** 
    362      **************************************************************************/ 
    363     this(OptionsDescription owner) { 
     359class RegularOptionsEasyInit { 
     360public: 
     361    /*************************************************************************** 
     362     **************************************************************************/ 
     363    this(RegularOptions owner) { 
    364364        this.owner=owner; 
    365365    } 
     
    367367    /*************************************************************************** 
    368368     **************************************************************************/ 
    369     OptionsDescriptionEasyInit opCall(char[] name, char[] description) { 
     369    typeof(this) opCall(char[] name, char[] description) { 
    370370        owner.addStandardOption(new StandardOption(name, new UntypedValue(true), description)); 
    371371        return this; 
     
    374374    /*************************************************************************** 
    375375     **************************************************************************/ 
    376     OptionsDescriptionEasyInit opCall(char[] name, ValueSemantic s) { 
     376    typeof(this) opCall(char[] name, ValueSemantic s) { 
    377377        owner.addStandardOption(new StandardOption(name, s, null)); 
    378378        return this; 
     
    381381    /*************************************************************************** 
    382382     **************************************************************************/ 
    383     OptionsDescriptionEasyInit opCall(char[] name, ValueSemantic s, char[] description) { 
     383    typeof(this) opCall(char[] name, ValueSemantic s, char[] description) { 
    384384        owner.addStandardOption(new StandardOption(name, s, description)); 
    385385        return this; 
     
    388388    /*************************************************************************** 
    389389     **************************************************************************/ 
    390     OptionsDescriptionEasyInit opCall(char[] name, char[] description, GeneralOption gso) { 
     390    typeof(this) opCall(char[] name, char[] description, GeneralOption gso) { 
    391391        gso.name = name; 
    392392        gso.semantic = new UntypedValue(true); 
     
    398398    /*************************************************************************** 
    399399     **************************************************************************/ 
    400     OptionsDescriptionEasyInit opCall(char[] name, ValueSemantic s, GeneralOption gso) { 
     400    typeof(this) opCall(char[] name, ValueSemantic s, GeneralOption gso) { 
    401401        gso.name = name; 
    402402        gso.semantic = s; 
     
    408408    /*************************************************************************** 
    409409     **************************************************************************/ 
    410     OptionsDescriptionEasyInit opCall(char[] name, ValueSemantic s, char[] description, GeneralOption gso) { 
     410    typeof(this) opCall(char[] name, ValueSemantic s, char[] description, GeneralOption gso) { 
    411411        gso.name = name; 
    412412        gso.semantic = s; 
     
    418418    /*************************************************************************** 
    419419     **************************************************************************/ 
    420     OptionsDescriptionEasyInit opCall(GeneralOption gso) { 
     420    typeof(this) opCall(GeneralOption gso) { 
    421421        gso.name = null; 
    422422        gso.semantic = null; 
     
    427427 
    428428private: 
    429     OptionsDescription owner; 
    430 } 
    431  
    432 //------------------------------------------------------------------------------ 
    433  
    434 /******************************************************************************* 
    435  ******************************************************************************/ 
    436 interface IOptionsDescription { 
     429    RegularOptions owner; 
     430} 
     431 
     432//------------------------------------------------------------------------------ 
     433 
     434/******************************************************************************* 
     435 ******************************************************************************/ 
     436interface OptionsDescription { 
    437437    /*************************************************************************** 
    438438     **************************************************************************/ 
     
    449449    /*************************************************************************** 
    450450     **************************************************************************/ 
    451     IOptionsDescription[] groups(); 
     451    OptionsDescription[] groups(); 
    452452} 
    453453 
     
    459459    for options by name. 
    460460 ******************************************************************************/ 
    461 class OptionsDescription : IOptionsDescription { 
     461class RegularOptions : OptionsDescription { 
    462462public: 
    463463    /*************************************************************************** 
     
    465465     **************************************************************************/ 
    466466    typeof(this) dup() { 
    467         auto result = new OptionsDescription
     467        auto result = new RegularOptions
    468468 
    469469        result.m_caption = m_caption.dup; 
     
    490490    /*************************************************************************** 
    491491        Creates the instance. The 'caption' parameter gives the name of 
    492         this 'OptionsDescription' instance. Primarily useful for output. 
     492        this 'RegularOptions' instance. Primarily useful for output. 
    493493     **************************************************************************/ 
    494494    this(char[] caption) { 
     
    541541    /*************************************************************************** 
    542542        Returns an object of implementation-defined type suitable for adding 
    543         options to OptionsDescription. The returned object will 
     543        options to RegularOptions. The returned object will 
    544544        have overloaded operator() with parameter type matching 
    545545        'StandardOption' constructors. Calling the operator will create 
    546546        new StandardOption instance and add it. 
    547547     **************************************************************************/ 
    548     OptionsDescriptionEasyInit addOptions() { 
    549         return new OptionsDescriptionEasyInit(this); 
     548    RegularOptionsEasyInit addOptions() { 
     549        return new RegularOptionsEasyInit(this); 
    550550    } 
    551551 
     
    570570    /*************************************************************************** 
    571571     **************************************************************************/ 
    572     IOptionsDescription[] groups() { 
     572    OptionsDescription[] groups() { 
    573573        return m_groups; 
    574574    } 
     
    584584    StandardOption[] m_standard; 
    585585    GeneralOption[] m_general; 
    586     IOptionsDescription[] m_groups; 
    587 } 
     586    OptionsDescription[] m_groups; 
     587} 
  • branches/npo/doost/util/config/ProgramOptions.d

    r11 r12  
    207207 
    208208    /*************************************************************************** 
     209        Returns all option names which are defined in current storage or 
     210        in all storages in case of ProgramOptions. 
     211 
     212        Returns: defined option names 
     213     **************************************************************************/ 
     214    char[][] definedOptions(); 
     215 
     216    /*************************************************************************** 
    209217        Returns all option names which are defined and assigned with value 
    210218        in current s