Changeset 12
- Timestamp:
- 08/30/07 16:53:02 (1 year ago)
- Files:
-
- branches/npo/doc/todo.txt (modified) (2 diffs)
- branches/npo/doost/sys/Environment.d (modified) (1 diff)
- branches/npo/doost/util/config/CommandLineStorage.d (modified) (6 diffs)
- branches/npo/doost/util/config/ConfigFileStorage.d (modified) (1 diff)
- branches/npo/doost/util/config/Converter.d (modified) (8 diffs)
- branches/npo/doost/util/config/EnvironmentStorage.d (modified) (7 diffs)
- branches/npo/doost/util/config/Formatter.d (modified) (2 diffs)
- branches/npo/doost/util/config/Option.d (modified) (17 diffs)
- branches/npo/doost/util/config/ProgramOptions.d (modified) (25 diffs)
- branches/npo/doost/util/config/Value.d (modified) (5 diffs)
- branches/npo/examples/util/config/FunctionTest.d (modified) (21 diffs)
- branches/npo/examples/util/config/util_config.cbp (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/npo/doc/todo.txt
r11 r12 1 ------------------------------------------------------------------------------- 2 THINGS TO DO 3 ------------------------------------------------------------------------------- 1 4 doost.core.Any: 2 5 - add operator: static Any oppCall()(TypeInfo type, void* data) 3 4 6 5 7 doost.util.config.Utils: … … 8 10 - make ProgramOptions thread safe 9 11 - 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 14 module doost.sys.Environment; 15 16 import std.utf : toUtf16=toUTF16, toUtf8=toUTF8; 17 18 19 /******************************************************************************* 20 21 *******************************************************************************/ 22 23 version (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 } 39 else 40 { 41 private extern (C) extern char** environ; 42 43 private char *getenv(char *name); 19 44 private int setenv(char *envname, char *envval, int overwrite); 20 45 private int unsetenv(char *name); 21 46 } 22 47 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 56 struct 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 216 debug (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 343 343 /******************************************************************************* 344 344 ******************************************************************************/ 345 class CommandLineOptions : IOptionsDescription {345 class CommandLineOptions : OptionsDescription { 346 346 public: 347 347 typeof(this) dup() { … … 369 369 } 370 370 371 IOptionsDescription[] groups() {371 OptionsDescription[] groups() { 372 372 return null; 373 373 } … … 399 399 /*************************************************************************** 400 400 **************************************************************************/ 401 this( OptionsDescriptionod, char[][] args)401 this(RegularOptions od, char[][] args) 402 402 in { 403 403 assert(od !is null); … … 479 479 after synchronization. 480 480 **************************************************************************/ 481 override void synchronize(bool nf=true) { 481 override void synchronize(bool nf=true) 482 in { 482 483 assert(isConnected == true); 484 } 485 body { 486 m_collected=null; 483 487 484 488 OptionsMap optsMap = readPhysicallyAll; … … 524 528 StyleParser[] style_parsers; 525 529 526 //TODO: collect regexp options (zwraca wektor opcji zmatchowanych przez RegExpOption)527 530 if (m_style_parser) style_parsers~=m_style_parser; 528 531 if (m_additional_parser) style_parsers~=&handleAdditionalParser; … … 614 617 } 615 618 619 /*************************************************************************** 620 **************************************************************************/ 616 621 char[] consumeToken(ref char[][] args, char[] name=null) { 617 622 char[] result; branches/npo/doost/util/config/ConfigFileStorage.d
r11 r12 57 57 Constructs Storage, reading content of file and parsing it 58 58 Params: 59 desc = OptionsDescriptionobject59 desc = RegularOptions object 60 60 file = file name 61 61 codepage = codepage of file (default = unicode utf8/utf16/utf32) 62 62 **************************************************************************/ 63 this( OptionsDescriptiondesc, char[] file, int codepage=-1)63 this(RegularOptions desc, char[] file, int codepage=-1) 64 64 in { 65 65 assert(desc !is null); branches/npo/doost/util/config/Converter.d
r11 r12 70 70 //------------------------------------------------------------------------------ 71 71 72 /* Otherwise, returns a reference to a statically allocated73 empty string if 'allow_empty' and throws ValidationException74 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 previous96 invocation of 'validate'.97 The target type is specified via a parameter which has the type of98 pointer to the desired type. This is workaround for compilers without99 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 131 72 char fromEscape(char c) { 132 73 char result; … … 171 112 //------------------------------------------------------------------------------ 172 113 114 /* Otherwise, returns a reference to a statically allocated 115 empty string if 'allow_empty' and throws ValidationException 116 otherwise. */ 117 118 char[] 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 ******************************************************************************/ 135 T 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 ******************************************************************************/ 156 char[] 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 173 166 /******************************************************************************* 174 167 Validates sequences. Allows multiple values per option occurrence … … 191 184 192 185 *******************************************************************************/ 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[]); 186 T[] parseText(T : T[])(char[] xs, char[] pattern) { 187 T[] tv; 200 188 201 189 char[] list = strip(xs); … … 208 196 209 197 char[][] tokens = tokenizer(list, ",;", " \t\r"); 210 211 //TODO: optimize to avoid below; parseText should not get Any as212 //parameter, but return T. All code with Any should be delegated213 //to ValueSemantic214 198 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 ******************************************************************************/ 225 209 char[] stringizeValue(T: T[])(Any v) { 226 210 assert(v !is null); … … 248 232 be optional. 249 233 ******************************************************************************/ 250 void parseText(T : bool)(Any v, char[] xs, char[] pattern) { 251 checkFirstOccurrence(v); 234 T parseText(T : bool)(char[] xs, char[] pattern) { 252 235 char[] s=tolower(getSingleString(xs, true).dup); 253 236 … … 255 238 pattern = "on|yes|1|true"; 256 239 257 if (s.length == 0) { 258 v.assign(true); 259 return; 260 } 240 if (s.length == 0) return true; 261 241 262 242 auto re = std.regexp.search(s, pattern); 263 243 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 ******************************************************************************/ 254 T parseText(T : char[])(char[] xs, char[] pattern) { 277 255 char[] s=getSingleString(xs).dup; 278 256 bool skipEscapes=true; … … 308 286 } else result = s; 309 287 310 v.assign(result); 311 } 312 313 //------------------------------------------------------------------------------ 314 288 return result; 289 } 290 291 //------------------------------------------------------------------------------ 292 293 /******************************************************************************* 294 ******************************************************************************/ 315 295 char[] stringizeValue(T: char[])(Any v) { 316 296 assert(v !is null); … … 321 301 return "\"" ~ result ~ "\""; 322 302 } 323 branches/npo/doost/util/config/EnvironmentStorage.d
r11 r12 7 7 import doost.util.config.Option; 8 8 import doost.util.config.ProgramOptions; 9 import doost.util.config.Value; 9 10 import doost.util.config.Formatter; 10 11 … … 19 20 /*************************************************************************** 20 21 **************************************************************************/ 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 { 22 29 m_prefix=prefix; 23 30 m_mapper=m; 31 m_regular = od.dup; 32 m_defaultSyncPolicy = SyncPolicy.Direct; 33 m_syncPolicy = SyncPolicy.Default; 34 m_persistent = false; 24 35 } 25 36 … … 34 45 /*************************************************************************** 35 46 **************************************************************************/ 36 EnvironmentStorageprefix(char[] prefix) {37 assert( m_connected == false);47 typeof(this) prefix(char[] prefix) { 48 assert(isConnected == false); 38 49 m_prefix = prefix; 39 50 return this; … … 42 53 /*************************************************************************** 43 54 **************************************************************************/ 44 char[] delegate(char[]) mapper() {55 char[] function(char[]) mapper() { 45 56 return m_mapper; 46 57 } … … 48 59 /*************************************************************************** 49 60 **************************************************************************/ 50 EnvironmentStorage mapper(char[] delegate(char[]) mp) {51 assert( m_connected == false);61 typeof(this) mapper(char[] function(char[]) mp) { 62 assert(isConnected == false); 52 63 m_mapper = mp; 53 64 return this; … … 56 67 protected: 57 68 /*************************************************************************** 69 See: ConcreteStorage 58 70 **************************************************************************/ 59 void synchronize(bool notify=true) {60 char[][char[]] env= getEnv();71 override OptionsMap readPhysicallyAll() { 72 char[][char[]] env=Environment.get(); 61 73 Option[] result; 62 74 63 75 foreach(key; env.keys) { 64 char[] option_name = m_mapper(key);76 char[] name = m_mapper(key); 65 77 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)); 71 80 } 72 81 } 73 82 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) { 75 125 } 76 126 … … 85 135 } 86 136 137 //-------------------------------------------------------------------------- 87 138 char[] m_prefix; 88 char[] delegate(char[]) m_mapper;139 char[] function(char[]) m_mapper; 89 140 } branches/npo/doost/util/config/Formatter.d
r11 r12 49 49 /*************************************************************************** 50 50 **************************************************************************/ 51 char[] makeDescription( IOptionsDescription od, IOptionsDescription od);51 char[] makeDescription(OptionsDescription od, OptionsDescription od); 52 52 } 53 53 … … 230 230 /*************************************************************************** 231 231 **************************************************************************/ 232 char[] makeDescription( IOptionsDescription desc, IOptionsDescription special=null) {232 char[] makeDescription(OptionsDescription desc, OptionsDescription special=null) { 233 233 char[] result; 234 234 if (m_addInfo !is null) result~=m_addInfo ~ ":\n"; branches/npo/doost/util/config/Option.d
r11 r12 223 223 to explicitly pass ownership. Unfortunately, it's often needed to 224 224 create objects of types derived from 'ValueSemantic': 225 OptionsDescriptiond;225 RegularOptions d; 226 226 d.addOptions()("a", parameter<int>("n")->default_value(1)); 227 227 Here, the static type returned by 'parameter' should be derived … … 357 357 Class which provides convenient creation syntax to StandardOption. 358 358 ******************************************************************************/ 359 class OptionsDescriptionEasyInit {360 public: 361 /*************************************************************************** 362 **************************************************************************/ 363 this( OptionsDescriptionowner) {359 class RegularOptionsEasyInit { 360 public: 361 /*************************************************************************** 362 **************************************************************************/ 363 this(RegularOptions owner) { 364 364 this.owner=owner; 365 365 } … … 367 367 /*************************************************************************** 368 368 **************************************************************************/ 369 OptionsDescriptionEasyInitopCall(char[] name, char[] description) {369 typeof(this) opCall(char[] name, char[] description) { 370 370 owner.addStandardOption(new StandardOption(name, new UntypedValue(true), description)); 371 371 return this; … … 374 374 /*************************************************************************** 375 375 **************************************************************************/ 376 OptionsDescriptionEasyInitopCall(char[] name, ValueSemantic s) {376 typeof(this) opCall(char[] name, ValueSemantic s) { 377 377 owner.addStandardOption(new StandardOption(name, s, null)); 378 378 return this; … … 381 381 /*************************************************************************** 382 382 **************************************************************************/ 383 OptionsDescriptionEasyInitopCall(char[] name, ValueSemantic s, char[] description) {383 typeof(this) opCall(char[] name, ValueSemantic s, char[] description) { 384 384 owner.addStandardOption(new StandardOption(name, s, description)); 385 385 return this; … … 388 388 /*************************************************************************** 389 389 **************************************************************************/ 390 OptionsDescriptionEasyInitopCall(char[] name, char[] description, GeneralOption gso) {390 typeof(this) opCall(char[] name, char[] description, GeneralOption gso) { 391 391 gso.name = name; 392 392 gso.semantic = new UntypedValue(true); … … 398 398 /*************************************************************************** 399 399 **************************************************************************/ 400 OptionsDescriptionEasyInitopCall(char[] name, ValueSemantic s, GeneralOption gso) {400 typeof(this) opCall(char[] name, ValueSemantic s, GeneralOption gso) { 401 401 gso.name = name; 402 402 gso.semantic = s; … … 408 408 /*************************************************************************** 409 409 **************************************************************************/ 410 OptionsDescriptionEasyInitopCall(char[] name, ValueSemantic s, char[] description, GeneralOption gso) {410 typeof(this) opCall(char[] name, ValueSemantic s, char[] description, GeneralOption gso) { 411 411 gso.name = name; 412 412 gso.semantic = s; … … 418 418 /*************************************************************************** 419 419 **************************************************************************/ 420 OptionsDescriptionEasyInitopCall(GeneralOption gso) {420 typeof(this) opCall(GeneralOption gso) { 421 421 gso.name = null; 422 422 gso.semantic = null; … … 427 427 428 428 private: 429 OptionsDescriptionowner;430 } 431 432 //------------------------------------------------------------------------------ 433 434 /******************************************************************************* 435 ******************************************************************************/ 436 interface IOptionsDescription {429 RegularOptions owner; 430 } 431 432 //------------------------------------------------------------------------------ 433 434 /******************************************************************************* 435 ******************************************************************************/ 436 interface OptionsDescription { 437 437 /*************************************************************************** 438 438 **************************************************************************/ … … 449 449 /*************************************************************************** 450 450 **************************************************************************/ 451 IOptionsDescription[] groups();451 OptionsDescription[] groups(); 452 452 } 453 453 … … 459 459 for options by name. 460 460 ******************************************************************************/ 461 class OptionsDescription : IOptionsDescription {461 class RegularOptions : OptionsDescription { 462 462 public: 463 463 /*************************************************************************** … … 465 465 **************************************************************************/ 466 466 typeof(this) dup() { 467 auto result = new OptionsDescription;467 auto result = new RegularOptions; 468 468 469 469 result.m_caption = m_caption.dup; … … 490 490 /*************************************************************************** 491 491 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. 493 493 **************************************************************************/ 494 494 this(char[] caption) { … … 541 541 /*************************************************************************** 542 542 Returns an object of implementation-defined type suitable for adding 543 options to OptionsDescription. The returned object will543 options to RegularOptions. The returned object will 544 544 have overloaded operator() with parameter type matching 545 545 'StandardOption' constructors. Calling the operator will create 546 546 new StandardOption instance and add it. 547 547 **************************************************************************/ 548 OptionsDescriptionEasyInit addOptions() {549 return new OptionsDescriptionEasyInit(this);548 RegularOptionsEasyInit addOptions() { 549 return new RegularOptionsEasyInit(this); 550 550 } 551 551 … … 570 570 /*************************************************************************** 571 571 **************************************************************************/ 572 IOptionsDescription[] groups() {572 OptionsDescription[] groups() { 573 573 return m_groups; 574 574 } … … 584 584 StandardOption[] m_standard; 585 585 GeneralOption[] m_general; 586 IOptionsDescription[] m_groups;587 } 586 OptionsDescription[] m_groups; 587 } branches/npo/doost/util/config/ProgramOptions.d
r11 r12 207 207 208 208 /*************************************************************************** 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 /*************************************************************************** 209 217 Returns all option names which are defined and assigned with value 210 218 in current s
