Changeset 81
- Timestamp:
- 10/15/10 09:50:50 (2 years ago)
- Files:
-
- trunk/Doost.cbp (modified) (3 diffs)
- trunk/doost/core/Any.d (modified) (1 diff)
- trunk/doost/sys/Environment.d (modified) (13 diffs)
- trunk/doost/text/ElementSet.d (modified) (3 diffs)
- trunk/doost/util/config/Exception.d (modified) (1 diff)
- trunk/doost/util/config/Formatter.d (modified) (1 diff)
- trunk/doost/util/config/Option.d (modified) (4 diffs)
- trunk/doost/util/config/PoTextArchive.d (modified) (2 diffs)
- trunk/doost/util/config/ProgramOptions.d (modified) (1 diff)
- trunk/doost/util/config/Utils.d (modified) (1 diff)
- trunk/doost/util/config/Value.d (modified) (4 diffs)
- trunk/doost/util/config/storages/CommandLineStorage.d (modified) (1 diff)
- trunk/doost/util/config/storages/ConfigFileStorage.d (modified) (23 diffs)
- trunk/doost/util/config/storages/DbStorage.d (modified) (2 diffs)
- trunk/doost/util/config/storages/EnvironmentStorage.d (modified) (7 diffs)
- trunk/doost/util/serializer/archive/TextArchive.d (modified) (3 diffs)
- trunk/examples/util/config/FunctionTest.d (modified) (71 diffs)
- trunk/examples/util/serializer/SerializerTest.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Doost.cbp
r80 r81 34 34 <Option type="1" /> 35 35 <Option compiler="dmd" /> 36 <Compiler> 37 <Add option="-unittest" /> 38 <Add option="-g" /> 39 <Add option="-debug" /> 40 </Compiler> 36 41 </Target> 37 42 </Build> … … 42 47 <Add option="-D" /> 43 48 <Add option="-Dd$(#doost)/doc/ddoc/" /> 44 <Add option="-version=ddbi_v62" />45 49 <Add directory="$(#doost)" /> 46 50 <Add directory="$(#std2)" /> … … 126 130 <Option target="AnyTest" /> 127 131 </Unit> 132 <Unit filename="examples\util\config\FunctionTest.d"> 133 <Option target="ProgramOptionsTest" /> 134 </Unit> 128 135 <Unit filename="examples\util\serializer\DataTypes.d"> 129 136 <Option target="SerializerTest" /> trunk/doost/core/Any.d
r74 r81 119 119 Allows to retrieve originall value as given type. 120 120 **************************************************************************/ 121 ValueType as(ValueType)() {121 T as(T)() { 122 122 assert(!empty, "Error: requested conversion from empty value"); 123 assert(type==typeid( ValueType), "Error: type of value (" ~ type.toString() ~124 ") is different than requested (" ~ typeid( ValueType).toString() ~ ").");125 126 auto p = cast(Holder!( ValueType))(content);123 assert(type==typeid(T), "Error: type of value (" ~ type.toString() ~ 124 ") is different than requested (" ~ typeid(T).toString() ~ ")."); 125 126 auto p = cast(Holder!(T))(content); 127 127 return p.held; 128 128 } trunk/doost/sys/Environment.d
r76 r81 31 31 private bool FreeEnvironmentStringsW(wchar**); 32 32 private int SetEnvironmentVariableW(wchar*, wchar*); 33 private uint GetEnvironmentVariableW( wchar*,wchar*, uint);33 private uint GetEnvironmentVariableW(immutable wchar*, immutable wchar*, uint); 34 34 alias uint DWORD; 35 35 DWORD GetLastError(); … … 83 83 **************************************************************/ 84 84 85 static char[] get (char[] variable, char[]def = null)85 static string get (string variable, string def = null) 86 86 { 87 87 wstring var = to!(wstring)(variable) ~ "\0"; 88 88 89 uint size = GetEnvironmentVariableW(var.ptr, cast( wchar*)null, 0);89 uint size = GetEnvironmentVariableW(var.ptr, cast(immutable wchar*)null, 0); 90 90 if (size is 0) 91 91 { … … 97 97 98 98 auto buffer = new wchar[size]; 99 size = GetEnvironmentVariableW(var.ptr, buffer.ptr, size);99 size = GetEnvironmentVariableW(var.ptr, cast(immutable wchar*)buffer.ptr, size); 100 100 if (size is 0) 101 101 throw new Exception ("Can not read environment variable"); … … 111 111 **************************************************************/ 112 112 113 static bool exists( char[]variable)114 { 115 w char[]var = toUtf16(variable) ~ "\0";113 static bool exists(string variable) 114 { 115 wstring var = toUtf16(variable) ~ "\0"; 116 116 117 117 uint size = GetEnvironmentVariableW(var.ptr, cast(wchar*)null, 0); … … 132 132 **************************************************************/ 133 133 134 static void set ( char[] variable, char[]value = null)135 { 136 wchar * var, val;134 static void set (string variable, string value = null) 135 { 136 wchar* var, val; 137 137 138 138 var = (toUtf16 (variable) ~ "\0").ptr; … … 149 149 **************************************************************/ 150 150 151 static char[][char[]] get ()152 { 153 char[][char[]] arr;154 155 w char[]key = new wchar[20],151 static string[string] get () 152 { 153 string[string] arr; 154 155 wstring key = new wchar[20], 156 156 value = new wchar[40]; 157 157 … … 176 176 while (*str) 177 177 { 178 value [v++] = *str++;178 value[v++] = *str++; 179 179 180 180 if (v is value.length) … … 198 198 **************************************************************/ 199 199 200 static bool exists( char[]variable)200 static bool exists(string variable) 201 201 { 202 202 char* ptr = getenv (variable.ptr); … … 213 213 **************************************************************/ 214 214 215 static char[] get (char[] variable, char[]def = null)215 static string get (string variable, string def = null) 216 216 { 217 217 char* ptr = getenv (variable.ptr); … … 228 228 **************************************************************/ 229 229 230 static void set ( char[] variable, char[]value = null)230 static void set (string variable, string value = null) 231 231 { 232 232 int result; … … 245 245 **************************************************************/ 246 246 247 static char[][char[]] get ()248 { 249 char[][char[]] arr;247 static string[string] get () 248 { 249 string[string] arr; 250 250 251 251 for (char** p = environ; *p; ++p) … … 256 256 while (*str++ != '=') 257 257 ++k; 258 char[]key = (*p)[0..k];258 string key = (*p)[0..k]; 259 259 260 260 k = 0; … … 275 275 276 276 277 void main( char[][] args)278 { 279 const char[]VAR = "TESTENVVAR";280 const char[]VAL1 = "VAL1";281 const char[]VAL2 = "VAL2";277 void main(string[] args) 278 { 279 string VAR = "TESTENVVAR"; 280 string VAL1 = "VAL1"; 281 string VAL2 = "VAL2"; 282 282 283 283 assert(Environment.get(VAR) is null); trunk/doost/text/ElementSet.d
r73 r81 4 4 5 5 struct ElementRange(T) { 6 private T l;7 private T r;6 private Unqual!T l; 7 private Unqual!T r; 8 8 9 9 immutable bool contains(T c) { … … 128 128 } 129 129 130 void addElement(T element) { 131 ElementRange!(T) range = {element, element}; 132 ranges = ranges ~ range; 133 } 134 130 135 immutable ElementSet!(T) dup() { 131 136 ElementSet!(T) cc; … … 134 139 cc.addRange(p.dup()); 135 140 } 136 137 141 return cc; 138 142 } trunk/doost/util/config/Exception.d
r80 r81 20 20 //------------------------------------------------------------------------------ 21 21 //String definitions for asserts (only debug version) 22 //NOTE: Asserts are used everywhere whereproblem is caused with incorrect code written22 //NOTE: Asserts are used everywhere if problem is caused with incorrect code written 23 23 //to work with ProgramOptions. It includes incorrect options definitions. 24 24 trunk/doost/util/config/Formatter.d
r80 r81 20 20 import std.string; 21 21 import std.stdio; 22 import std.algorithm : max; 23 22 24 import doost.util.config.Option; 23 import doost.util.config.Utils;24 25 25 26 //------------------------------------------------------------------------------ trunk/doost/util/config/Option.d
r76 r81 253 253 **************************************************************************/ 254 254 void name(string s) 255 in { 256 assert(s != ""); 257 } 255 //BUG-DMD: when below is turned on 256 // in { 257 // assert(s != ""); 258 // } 258 259 body { 259 string name=s .dup;260 int n = find(name, ',');260 string name=s; 261 int n = indexOf(name, ','); 261 262 262 263 assert(n != name.length-1, format(COMMA_CAN_NOT_BE_ON_LAST_POSITION, name)); … … 299 300 **************************************************************************/ 300 301 void duplicate(typeof(this) result) { 301 result.m_oAlias = m_oAlias. dup;302 result.m_oName = m_oName. dup;303 result.m_description = m_description is null ? null : m_description. dup;302 result.m_oAlias = m_oAlias.idup; 303 result.m_oName = m_oName.idup; 304 result.m_description = m_description is null ? null : m_description.idup; 304 305 result.m_semantic = m_semantic is null ? null : m_semantic.dup; 305 306 result.m_characteristics = m_characteristics; … … 761 762 **************************************************************************/ 762 763 typeof(this) duplicate(typeof(this) result) { 763 result.m_caption = m_caption. dup;764 result.m_caption = m_caption.idup; 764 765 765 766 foreach(opt; m_options) … … 892 893 **************************************************************************/ 893 894 this(string caption) { 894 m_caption=caption. dup;895 m_caption=caption.idup; 895 896 } 896 897 trunk/doost/util/config/PoTextArchive.d
r76 r81 30 30 31 31 bool start() { 32 arrayTerm.add (defArray.begin);33 arrayTerm.add (defArray.end);34 arrayTerm.add (defArray.separator);32 arrayTerm.addElement(defArray.begin); 33 arrayTerm.addElement(defArray.end); 34 arrayTerm.addElement(defArray.separator); 35 35 36 asocArrayTerm.add (defArray.begin);37 asocArrayTerm.add (defArray.end);38 asocArrayTerm.add (defArray.separator);39 asocArrayTerm.add (defArray.kvseparator);36 asocArrayTerm.addElement(defArray.begin); 37 asocArrayTerm.addElement(defArray.end); 38 asocArrayTerm.addElement(defArray.separator); 39 asocArrayTerm.addElement(defArray.kvseparator); 40 40 41 udtTerm.add (defArray.begin);42 udtTerm.add (defArray.end);43 udtTerm.add (defUdt.separator);41 udtTerm.addElement(defArray.begin); 42 udtTerm.addElement(defArray.end); 43 udtTerm.addElement(defUdt.separator); 44 44 45 45 return true; … … 53 53 } 54 54 55 arrayElementType!(VALUE) elem;55 ElementType!(VALUE) elem; 56 56 57 static if (isS tring!(typeof(elem))) {57 static if (isSomeString!(typeof(elem))) { 58 58 ElementSet!(ELEMENTTYPE) old = defString.p_allchars; 59 59 defString.p_allchars.subtract(arrayTerm); trunk/doost/util/config/ProgramOptions.d
r76 r81 336 336 be dispatched (true for notifications) 337 337 **************************************************************************/ 338 void synchronize(bool nf =true);338 void synchronize(bool nf = true); 339 339 340 340 /*************************************************************************** trunk/doost/util/config/Utils.d
r76 r81 27 27 28 28 /******************************************************************************* 29 Returns bigger of two given parameters. Type must have implemented30 comparision operator.31 32 Params: a = first value33 b = second value34 ******************************************************************************/35 T max(T)(T a, T b) {36 if (a>=b) return a;37 else return b;38 }39 40 //------------------------------------------------------------------------------41 42 /*******************************************************************************43 29 ******************************************************************************/ 44 30 string loadFileContents(string file) { trunk/doost/util/config/Value.d
r80 r81 27 27 import doost.text.Scanner; 28 28 import doost.text.Escaper; 29 import doost.text.ElementSet; 29 30 import doost.util.serializer.Serializer; 30 31 import doost.util.config.PoTextArchive; … … 39 40 static this() { 40 41 serializer = new PoSerializer; 41 serializer.global.defString.p_midchars = CharClass!(char).emptyset;42 serializer.global.defString.p_allchars = CharClass!(char).any_char;43 serializer.global.defString.p_allchars.subtract(serializer.global ().defSkip.p_skip);42 serializer.global.defString.p_midchars = cast(ElementSet!(immutable char))ElementSet!(immutable char).emptyset; 43 serializer.global.defString.p_allchars = cast(ElementSet!(immutable char))ElementSet!(immutable char).any_char; 44 serializer.global.defString.p_allchars.subtract(serializer.global.defSkip.p_skip); 44 45 } 45 46 … … 47 48 48 49 //------------------------------------------------------------------------------ 49 50 /*******************************************************************************51 Evaluates to true if given type is array52 ******************************************************************************/53 template isArray( T ) {54 static if( is( T U : U[] ) )55 const isArray = true;56 else57 const isArray = false;58 }59 60 //------------------------------------------------------------------------------61 62 /*******************************************************************************63 Evaluates to type64 ******************************************************************************/65 template arrayElementType(T) {66 static if( is( T U : U[] ) )67 alias U arrayElementType;68 else69 static assert(false);70 }71 50 72 51 /******************************************************************************* … … 347 326 if (token.length == 0 && m_zero_tokens) { 348 327 //bool switch 349 return !(m_default_value.as!(bool)); 328 value.assign(!(m_default_value.as!(bool))); 329 return; 350 330 } 351 331 } trunk/doost/util/config/storages/CommandLineStorage.d
r80 r81 1011 1011 if (args[0].length > 2 && ((args[0][0] == '-' && args[0][1] != '-') 1012 1012 || ((m_style & Style.AllowShortSlash) && args[0][0] == '/'))) { 1013 if (args[0][0]=='/') args[0][0]='-'; 1014 args[0]= '-' ~ args[0]; 1013 string line = args[0]; 1014 1015 if (line[0] == '/') line = '-' ~ line[1..$]; 1016 line = '-' ~ line; 1017 1018 args[0] = line; 1015 1019 result = parseLongOption(args); 1016 1020 } trunk/doost/util/config/storages/ConfigFileStorage.d
r80 r81 36 36 class InvalidConfigFileSyntaxException : ProgramOptionsException { 37 37 public: 38 this( char[] token, char[]msg) {38 this(string token, string msg) { 39 39 super(msg ~ " in '" ~ token ~ "'"); 40 40 } … … 74 74 Params: file = file name 75 75 **************************************************************************/ 76 this( char[]file, RegularOptions ro = null)76 this(string file, RegularOptions ro = null) 77 77 in { 78 78 assert(file != ""); … … 90 90 Params: file = file name 91 91 **************************************************************************/ 92 ConfigFileStorage file( char[]file)92 ConfigFileStorage file(string file) 93 93 in { 94 94 assert(isConnected == false, format(STACK_SHOULD_BE_DISCONNECTED, "to set config file")); … … 96 96 } 97 97 body { 98 m_file = file. dup;98 m_file = file.idup; 99 99 return this; 100 100 } … … 104 104 Returns: file name which is used for reading configuration 105 105 **************************************************************************/ 106 char[]file() {106 string file() { 107 107 return m_file; 108 108 } … … 115 115 definedPrefixes = reference to array of already used prefixes 116 116 **************************************************************************/ 117 void checkPrefixes( char[] prefix, ref bool[char[]] definedPrefixes) {117 void checkPrefixes(string prefix, ref bool[string] definedPrefixes) { 118 118 if (prefix !is null) { 119 119 if (prefix in definedPrefixes) … … 127 127 **************************************************************************/ 128 128 override OptionsMap readPhysicallyAll() { 129 char[][] lines = splitlines(loadFile(m_file));130 bool[ char[]] definedPrefixes;129 string[] lines = splitlines(loadFile(m_file)); 130 bool[string] definedPrefixes; 131 131 FileLine fl; 132 char[]lastPrefix, name, normName;132 string lastPrefix, name, normName; 133 133 OptionsMap result; 134 134 ParsedOption[] opts; … … 155 155 See: ConcreteStorage 156 156 **************************************************************************/ 157 override Value readPhysicallyOne( char[]name) {158 char[][] lines = splitlines(loadFile(m_file));159 bool[ char[]] definedPrefixes;160 char[]lastPrefix, nm;157 override Value readPhysicallyOne(string name) { 158 string[] lines = splitlines(loadFile(m_file)); 159 bool[string] definedPrefixes; 160 string lastPrefix, nm; 161 161 FileLine fl; 162 162 ParsedOption[] opts; … … 188 188 Adds new line to given string. 189 189 **************************************************************************/ 190 char[] addNewLine(char[]str) {190 string addNewLine(string str) { 191 191 if (str != "") return str~'\n'; 192 192 return str; … … 196 196 Returns: true if last line is empty 197 197 **************************************************************************/ 198 bool isLastLineEmpty( char[]contents) {198 bool isLastLineEmpty(string contents) { 199 199 if (contents.length>=2 && contents[$-2..$] == "\n\n") return true; 200 200 return false; … … 204 204 Creates line from text & comment. 205 205 **************************************************************************/ 206 char[] makeLine(char[] text, char[]comment) {207 char[]result=text;206 string makeLine(string text, string comment) { 207 string result=text; 208 208 if (comment !is null) { 209 209 uint len = text.length; … … 217 217 Creates line from name, value and comment. 218 218 **************************************************************************/ 219 char[] makeLine(char[] name, char[] value, char[]comment) {219 string makeLine(string name, string value, string comment) { 220 220 return makeLine(name ~ " = " ~ value, comment); 221 221 } … … 224 224 Prepares to add inserts to file contents. 225 225 **************************************************************************/ 226 void prepareInserts( char[] key, Value val, ref char[][char[]][char[]] insOptions) {227 char[]prefix, name, line;226 void prepareInserts(string key, Value val, ref string[string][string] insOptions) { 227 string prefix, name, line; 228 228 229 229 if (val.status == OStatus.INSERTED) { 230 230 prefix=""; 231 231 name=key; 232 int n =rfind(key, '.');232 int n = lastIndexOf(key, '.'); 233 233 if (n!=-1) { 234 234 prefix=key[0..n]; … … 243 243 Returns: line with given value. 244 244 **************************************************************************/ 245 char[]addVariableLine(FileLine fl, Value val) {245 string addVariableLine(FileLine fl, Value val) { 246 246 assert(val.semantic !is null); 247 char[]result;247 string result; 248 248 if (val !is null && val.value !is null) { 249 249 if (val.semantic.type is null) { … … 262 262 Adds end of options section. 263 263 **************************************************************************/ 264 char[] addEndOfSection(ref char[][char[]][char[]] insOptions, char[]lastPrefix) {265 char[]result;264 string addEndOfSection(ref string[string][string] insOptions, string lastPrefix) { 265 string result; 266 266 267 267 if ((lastPrefix in insOptions) is null) return result; 268 268 269 char[]name;269 string name; 270 270 foreach(name, line; insOptions[lastPrefix]) { 271 271 result~=line; … … 283 283 Adds all not used before prefixes at the end of file. 284 284 **************************************************************************/ 285 char[] addNotUsedPrefixes(char[][char[]][char[]] insOptions) {286 char[]result;285 string addNotUsedPrefixes(string[string][string] insOptions) { 286 string result; 287 287 //Add prefixes and options which were in backend 288 288 foreach(prefix, variables; insOptions) { … … 303 303 **************************************************************************/ 304 304 override void savePhysicallyAll(OptionsMap map) { 305 char[]str = loadFile(m_file);306 char[][] lines = splitlines(str);307 bool[ char[]] definedPrefixes;308 char[]contents, nm, pm, lastPrefix;309 char[][char[]][char[]] insOptions;305 string str = loadFile(m_file); 306 string[] lines = splitlines(str); 307 bool[string] definedPrefixes; 308 string contents, nm, pm, lastPrefix; 309 string[string][string] insOptions; 310 310 FileLine fl; 311 311 … … 373 373 See: ConcreteStorage 374 374 **************************************************************************/ 375 override void savePhysicallyOne( char[] name, inValue value)375 override void savePhysicallyOne(string name, Value value) 376 376 in { 377 377 assert(name != "", format(OPTION_NAME_CAN_NOT_BE_EMPTY)); … … 379 379 } 380 380 body { 381 char[]str = loadFile(m_file);382 char[][] lines = splitlines(str);383 bool[ char[]] definedPrefixes;384 char[]contents, nm, pm, lastPrefix;385 char[][char[]][char[]] insOptions;381 string str = loadFile(m_file); 382 string[] lines = splitlines(str); 383 bool[string] definedPrefixes; 384 string contents, nm, pm, lastPrefix; 385 string[string][string] insOptions; 386 386 FileLine fl; 387 387 … … 447 447 Parses one line from file. 448 448 **************************************************************************/ 449 FileLine parseLine( char[]s) {449 FileLine parseLine(string s) { 450 450 FileLine result; 451 char[]prefix;451 string prefix; 452 452 uint n; 453 453 454 if ((n = find(s, '#')) != -1) {454 if ((n = indexOf(s, '#')) != -1) { 455 455 if (n==0 || (n>0 && (s[n-1]==' ' || s[n-1]=='\t'))) { 456 456 if (n>0) n--; … … 469 469 } else { 470 470 //Handle typed values 471 if ((n = find(s, '=')) != -1) {472 if (( find(s[0..n], '.')) != -1)471 if ((n = indexOf(s, '=')) != -1) { 472 if ((indexOf(s[0..n], '.')) != -1) 473 473 throw new InvalidConfigFileSyntaxException(s, "names can not have dots in it."); 474 474 result.name = strip(s[0..n]); … … 482 482 if (s.length ==0) 483 483 throw new InvalidConfigFileSyntaxException(s, "no option name given"); 484 if (( find(s, '.')) != -1)484 if ((indexOf(s, '.')) != -1) 485 485 throw new InvalidConfigFileSyntaxException(s, "names can not have dots in it."); 486 486 result.name = s; … … 494 494 //---------------------------- Definitions --------------------------------- 495 495 struct FileLine { 496 char[]prefix; // "" - no prefix497 char[]name; // "" - comment line or empty line498 char[]value; // "" - for prefixes or comment lines499 char[]comment; // "" - option line or empty line496 string prefix; // "" - no prefix 497 string name; // "" - comment line or empty line 498 string value; // "" - for prefixes or comment lines 499 string comment; // "" - option line or empty line 500 500 } 501 501 502 502 //---------------------------- Fields -------------------------------------- 503 char[]m_file;503 string m_file; 504 504 } trunk/doost/util/config/storages/DbStorage.d
r80 r81 25 25 import doost.util.config.Value; 26 26 import doost.util.config.Formatter; 27 27 /+ 28 28 import dbi.Database; 29 29 import dbi.DBIException; … … 165 165 char[] m_table; 166 166 } 167 +/ trunk/doost/util/config/storages/EnvironmentStorage.d
r80 r81 21 21 import std.stdio; 22 22 23 import doost.sys.Environment;23 import std.process; 24 24 25 25 import doost.util.config.Option; … … 55 55 **************************************************************************/ 56 56 override OptionsMap readPhysicallyAll() { 57 char[][char[]] env=Environment.get();57 string[string] env = environment.toAA(); 58 58 OptionsMap result; 59 59 ParsedOption[] opts; … … 61 61 62 62 foreach(name, value; env) { 63 if (name =="") continue;63 if (name == "") continue; 64 64 d = findOption(name); 65 65 66 if (d !is null && Environment.exists(name)) opts~=ParsedOption(name, value, d);66 if (d !is null && name in env) opts~=ParsedOption(name, value, d); 67 67 } 68 68 … … 74 74 See: ConcreteStorage 75 75 **************************************************************************/ 76 override Value readPhysicallyOne( char[]name)76 override Value readPhysicallyOne(string name) 77 77 in { 78 78 assert(name != "", format(OPTION_NAME_CAN_NOT_BE_EMPTY)); 79 79 } 80 80 body { 81 string[string] env = environment.toAA(); 81 82 ParsedOption[] opts; 82 83 Value result; … … 85 86 //TODO: co w przypadku innych opcji? wĆ ĀaĆ Āciwie Ć Åeby obsĆ ĀuĆ ÅyĆĀ 86 87 //wyraĆ Åenia regularne, to trzeba by przejrzeĆĀ wszystkie opcje 87 if ( Environment.exists(name)) {88 opts ~= ParsedOption(name, Environment.get(name), d);88 if (name in env) { 89 opts ~= ParsedOption(name, env[name], d); 89 90 } else { 90 char[]nm = d.optionAlias;91 if (nm != "" && Environment.exists(nm)) {92 opts ~= ParsedOption(nm, Environment.get(nm), d);91 string nm = d.optionAlias; 92 if (nm != "" && name in env) { 93 opts ~= ParsedOption(nm, env[name], d); 93 94 } 94 95 } … … 109 110 See: ConcreteStorage 110 111 **************************************************************************/ 111 override void savePhysicallyOne( char[]name, Value value)112 override void savePhysicallyOne(string name, Value value) 112 113 in { 113 114 assert(name != "", format(OPTION_NAME_CAN_NOT_BE_EMPTY)); … … 115 116 } 116 117 body { 117 char[] nm = name; 118 string[string] env = environment.toAA(); 119 string nm = name; 118 120 119 if ( !Environment.exists(name)) {120 OptionSemantic d =findOption(name);121 if (d.optionAlias != "" && Environment.exists(d.optionAlias))121 if (name !in env) { 122 OptionSemantic d = findOption(name); 123 if (d.optionAlias != "" && d.optionAlias in env) 122 124 nm = d.optionAlias; 123 125 } 124 126 125 127 switch(value.status) { 126 case OStatus.REMOVED: Environment.set(nm); break;128 case OStatus.REMOVED: env[nm] = ""; break; 127 129 case OStatus.INSERTED: 128 case OStatus.MODIFIED: Environment.set(nm, value.toString); break;130 case OStatus.MODIFIED: env[nm] = value.toString; break; 129 131 default:; //EMPTY, SYNCHRONIZED 130 132 } trunk/doost/util/serializer/archive/TextArchive.d
r76 r81 326 326 throw new ParsingException("Wrong character literal in source"); 327 327 328 pragma(msg, VALUE.stringof ~ "; " ~ typeof(val[0]).stringof); 329 //FIXME: hack! 330 //value = to!(VALUE)(val[0]); 331 value = cast(VALUE)val[0]; 328 //FIXME: 127 for char, but 16384> for wchar.... 329 if (val[0] > 127) { 330 throw new SerializerException("Can not convert wide character into narrow character type."); 331 } 332 333 pragma(msg, "loadChar: " ~ VALUE.stringof ~ "; " ~ typeof(val[0]).stringof); 334 value = cast(VALUE) val[0]; 335 332 336 return true; 333 337 } … … 649 653 private: 650 654 import std.date; 651 import std.string;652 655 import std.stdio; 653 656 import std.traits; … … 710 713 //FIXME: no magic strings here 711 714 storage.put(defSkip.s_space); 712 if (value.tzcorrection >0) storage.put("+");715 if (value.tzcorrection > 0) storage.put("+"); 713 716 storage.put(format(value.tzcorrection)); 714 717 } trunk/examples/util/config/FunctionTest.d
r39 r81 21 21 import std.stdio; 22 22 import std.string; 23 import std 2.conv;23 import std.conv; 24 24 25 25 import doost.core.Any; 26 26 import doost.util.DUnit; 27 27 import doost.util.config.ProgramOptions; //Always 28 import doost.util.config. CommandLineStorage; //Only if backend is necessary29 import doost.util.config. ConfigFileStorage; //Only if backend is necessary30 import doost.util.config. EnvironmentStorage; //Only if backend is necessary31 import doost.util.config.DbStorage; //Only if backend is necessary28 import doost.util.config.storages.CommandLineStorage; //Only if backend is necessary 29 import doost.util.config.storages.ConfigFileStorage; //Only if backend is necessary 30 import doost.util.config.storages.EnvironmentStorage; //Only if backend is necessary 31 //import doost.util.config.storages.DbStorage; //Only if backend is necessary 32 32 import doost.util.config.Formatter; //Only for non-standard output 33 33 //description and for user defined 34 34 //formatters 35 36 //import doost.util.config.Value;37 38 35 version(ddbi_v62) { 39 36 import dbi.Database; … … 86 83 ("turnItOn,r", boolSwitch, "makecoffee") 87 84 ("compression,c", define!(int), "set compression level") 88 ("title,t", define!( char[]).defaultValue("title"), "set title of window")89 ("include,i", define!( char[][]).composing.defaultValue(["default1"[], "default2"]), "include paths")85 ("title,t", define!(string).defaultValue("title"), "set title of window") 86 ("include,i", define!(string[]).composing.defaultValue(["default1", "default2"]), "include paths") 90 87 ("myVal", define!(MyVal).parser(&parseMyValue), "include paths") 91 ("firstname", define!( char[][]).composing, "firstname")92 ("secondname", define!( char[][]).composing, "secondname")93 ("nickname,n", define!( char[][]).composing, "nickname")94 ("date", define!( char[])(r"\d\d\d\d-\d?\d-\d?\d"), "date of birth")95 ("regexp[ression]*,g", define!( char[]), "regular expression", new RegExpOption)88 ("firstname", define!(string[]).composing, "firstname") 89 ("secondname", define!(string[]).composing, "secondname") 90 ("nickname,n", define!(string[]).composing, "nickname") 91 ("date", define!(string)(r"\d\d\d\d-\d?\d-\d?\d"), "date of birth") 92 ("regexp[ression]*,g", define!(string), "regular expression", new RegExpOption) 96 93 ("number\\d\\d", define!(byte), "following numbers", new RegExpOption) 97 ("int,p", define!( char[])(r"\d\d\d"), new RegExpOption)98 ("string,s", define!( char[]), "text parameter")94 ("int,p", define!(string)(r"\d\d\d"), new RegExpOption) 95 ("string,s", define!(string), "text parameter") 99 96 ("other,o", define!(double), "other parameter") 100 97 //Only alias option 101 (",J", define!( char[][]), "import paths")98 (",J", define!(string[]), "import paths") 102 99 ; 103 100 });} … … 114 111 ("help,h", "produce help message") 115 112 ("compression,c", define!(uint), "compression level") 116 ("date", define!( char[]), "start date")113 ("date", define!(string), "start date") 117 114 ; 118 115 119 116 ro1 = new RegularOptions("Second group"); 120 117 ro1.options() 121 ("title,t", define!( char[]), "window title")118 ("title,t", define!(string), "window title") 122 119 ("process,p", define!(uint), "process number") 123 120 ; … … 155 152 ro2 = new RegularOptions("All options"); 156 153 ro2.options() 157 ("firstname", define!( char[][]).composing, "firstname")158 ("secondname", define!( char[][]).composing, "secondname")154 ("firstname", define!(string[]).composing, "firstname") 155 ("secondname", define!(string[]).composing, "secondname") 159 156 (ro) 160 157 (ro1); … … 177 174 "; 178 175 179 //write fln("\n", real_desc);176 //writeln("\n", real_desc); 180 177 assert(removechars(real_desc, " \t\n\r") == removechars(expc_desc, " \t\n\r")); 181 178 });} … … 203 200 ro = new RegularOptions; 204 201 ro.options() 205 ("title,t", define!( char[]), "window title")202 ("title,t", define!(string), "window title") 206 203 ("process,t", define!(uint), "process number") 207 204 ; … … 211 208 ro = new RegularOptions; 212 209 ro.options() 213 ("title", define!( char[]), "window title")210 ("title", define!(string), "window title") 214 211 ("title,t", define!(uint), "process number") 215 212 ; … … 219 216 ro = new RegularOptions; 220 217 ro.options() 221 ("title", define!( char[]), "window title")218 ("title", define!(string), "window title") 222 219 ("title,t", define!(uint), "process number") 223 220 ; … … 227 224 ro = new RegularOptions; 228 225 ro.options() 229 (".*", define!( char[]), "all other options")230 (".*", define!( char[]), "other other options")226 (".*", define!(string), "all other options") 227 (".*", define!(string), "other other options") 231 228 ; 232 229 })); … … 245 242 246 243 unittest { testCase.execute("CL Storage - lists", { 247 char[][] args;244 string[] args; 248 245 RegularOptions ro; 249 246 ProgramOptions po; … … 254 251 ro.options() 255 252 ("help,h", "produce help message") 256 ("include,i", define!( char[][]).composing.defaultValue(["default1"[], "default2"]), "include paths")257 ("firstname", define!( char[][]).composing, "firstname")258 ("secondname", define!( char[][]).composing, "secondname")259 ("nickname,n", define!( char[][]).composing, "nickname")253 ("include,i", define!(string[]).composing.defaultValue(["default1"[], "default2"]), "include paths") 254 ("firstname", define!(string[]).composing, "firstname") 255 ("secondname", define!(string[]).composing, "secondname") 256 ("nickname,n", define!(string[]).composing, "nickname") 260 257 ; 261 258 … … 268 265 assert(checkException!(UnknownOptionException)({"blah" in po; })); 269 266 270 assert(po["include"].as!( char[][]) == ["a", "b", "c"]);267 assert(po["include"].as!(string[]) == ["a", "b", "c"]); 271 268 po.disconnect; 272 269 … … 277 274 po.connect; 278 275 279 trace(po["include"].as!( char[][]));280 assert(po["include"].as!( char[][]) == ["a", "b", "c"]);281 assert(po["firstname"].as!( char[][]) == ["Anita", "Ewa Krystyna", "Paulina"]);282 trace(po["secondname"].as!( char[][]));283 assert(po["secondname"].as!( char[][]) == ["Korwin\tMikke"]);284 trace(po["nickname"].as!( char[][]));285 assert(po["nickname"].as!( char[][]) == ["Aarti", "Bono", "Bruce"]);276 trace(po["include"].as!(string[])); 277 assert(po["include"].as!(string[]) == ["a", "b", "c"]); 278 assert(po["firstname"].as!(string[]) == ["Anita", "Ewa Krystyna", "Paulina"]); 279 trace(po["secondname"].as!(string[])); 280 assert(po["secondname"].as!(string[]) == ["Korwin\tMikke"]); 281 trace(po["nickname"].as!(string[])); 282 assert(po["nickname"].as!(string[]) == ["Aarti", "Bono", "Bruce"]); 286 283 287 284 po.disconnect; … … 291 288 292 289 unittest { testCase.execute("CL Storage - long/short options", { 293 char[][] args;290 string[] args; 294 291 RegularOptions ro; 295 292 ProgramOptions po; … … 320 317 unittest { testCase.execute("CL Storage - response files", { 321 318 void[] buffer; 322 char[][] args;319 string[] args; 323 320 RegularOptions ro; 324 321 ProgramOptions po; … … 335 332 ro.options() 336 333 ("turnItOn,r", boolSwitch, "makecoffee") 337 ("date", define!( char[])(r"\d\d\d\d-\d?\d-\d?\d"), "date of birth")338 ("firstname", define!( char[][]).composing, "firstname")339 ("secondname", define!( char[][]).composing, "secondname")334 ("date", define!(string)(r"\d\d\d\d-\d?\d-\d?\d"), "date of birth") 335 ("firstname", define!(string[]).composing, "firstname") 336 ("secondname", define!(string[]).composing, "secondname") 340 337 ; 341 338 … … 347 344 348 345 assert(("turnItOn" in po) !is null); 349 assert(po["date"].as!( char[]) == "1975-07-04");350 assert(po["firstname"].as!( char[][]) == ["Ala", "Ola", "Sylwia"]);351 assert(po["secondname"].as!( char[][]) == ["Atkinson", "Bullock"]);346 assert(po["date"].as!(string) == "1975-07-04"); 347 assert(po["firstname"].as!(string[]) == ["Ala", "Ola", "Sylwia"]); 348 assert(po["secondname"].as!(string[]) == ["Atkinson", "Bullock"]); 352 349 353 350 po.disconnect; … … 357 354 358 355 unittest { testCase.execute("CL Storage - custom values", { 359 char[][] args;356 string[] args; 360 357 RegularOptions ro; 361 358 ProgramOptions po; … … 365 362 ("help,h", "produce help message") 366 363 ("compression,c", define!(int), "set compression level") 367 ("title,t", define!( char[]).defaultValue("title"), "set title of window")364 ("title,t", define!(string).defaultValue("title"), "set title of window") 368 365 ("doTheTest,d", "maketest") 369 366 ("myVal", define!(MyVal).parser(&parseMyValue), "include paths") … … 381 378 assert(po["compression"].as!(int) == 8); 382 379 assert(("title" in po) !is null); 383 assert(po["title"].as!( char[]) == "title");380 assert(po["title"].as!(string) == "title"); 384 381 assert(po["myVal"].as!(MyVal) == new MyVal(7)); 385 382 po.disconnect; … … 389 386 390 387 unittest { testCase.execute("CL Storage - self path", { 391 char[][] args;388 string[] args; 392 389 string str1, str2, str3; 393 390 RegularOptions ro; … … 428 425 po.connect; 429 426 assert(("selfpath" in po) !is null); 430 trace(po["selfpath"].as!( char[]));431 assert(po["selfpath"].as!( char[]) == str1);427 trace(po["selfpath"].as!(string)); 428 assert(po["selfpath"].as!(string) == str1); 432 429 assert(("selfdir" in po) !is null); 433 assert(po["selfdir"].as!( char[]) == str2);430 assert(po["selfdir"].as!(string) == str2); 434 431 assert(("selfname" in po) !is null); 435 assert(po["selfname"].as!( char[]) == str3);432 assert(po["selfname"].as!(string) == str3); 436 433 po.disconnect; 437 434 });} … … 440 437 441 438 unittest { testCase.execute("CL Storage - synchronization", { 442 char[][] args;439 string[] args; 443 440 RegularOptions ro; 444 441 ProgramOptions po; … … 448 445 ("help,h", "produce help message") 449 446 ("compression,c", define!(int), "set compression level") 450 ("title,t", define!( char[]).defaultValue("title"), "set title of window")447 ("title,t", define!(string).defaultValue("title"), "set title of window") 451 448 ("doTheTest,d", "maketest") 452 449 ; … … 465 462 466 463 unittest { testCase.execute("CL Storage - constraints", { 467 char[][] args;464 string[] args; 468 465 RegularOptions ro; 469 466 ProgramOptions po; … … 474 471 ro.options() 475 472 ("compression,c", define!(int), "set compression level") 476 ("title,t", define!( char[]).defaultValue("title"), "set title of window")473 ("title,t", define!(string).defaultValue("title"), "set title of window") 477 474 ("doTheTest,d", "maketest") 478 ("include,i", define!( char[][]).composing.defaultValue(["default1"[], "default2"]), "include paths")475 ("include,i", define!(string[]).composing.defaultValue(["default1"[], "default2"]), "include paths") 479 476 ("myVal", define!(MyVal).parser(&parseMyValue), "include paths") 480 ("int,p", define!( char[])(r"\d\d\d"), new RegExpOption)481 ("string,s", define!( char[]), "text parameter")482 ("firstname", define!( char[][]).composing, "firstname")483 ("secondname", define!( char[][]).composing, "secondname")484 ("nickname,n", define!( char[][]).composing, "nickname")477 ("int,p", define!(string)(r"\d\d\d"), new RegExpOption) 478 ("string,s", define!(string), "text parameter") 479 ("firstname", define!(string[]).composing, "firstname") 480 ("secondname", define!(string[]).composing, "secondname") 481 ("nickname,n", define!(string[]).composing, "nickname") 485 482 ; 486 483 … … 505 502 506 503 unittest { testCase.execute("CL Storage - input options composing", { 507 char[][] args;504 string[] args; 508 505 RegularOptions ro; 509 506 ProgramOptions po; … … 512 509 ro.options() 513 510 ("compression,c", define!(int), "set compression level") 514 ("title,t", define!( char[]).defaultValue("title"), "set title of window")511 ("title,t", define!(string).defaultValue("title"), "set title of window") 515 512 ("doTheTest,d", "maketest") 516 ("include,i", define!( char[][]).composing.defaultValue(["default1"[], "default2"]), "include paths")517 ("int,p", define!( char[])(r"\d\d\d"), new RegExpOption)518 ("string,s", define!( char[]), "text parameter")519 ("firstname", define!( char[][]).composing, "firstname")520 ("secondname", define!( char[][]).composing, "secondname")521 ("nickname,n", define!( char[][]).composing, "nickname")513 ("include,i", define!(string[]).composing.defaultValue(["default1"[], "default2"]), "include paths") 514 ("int,p", define!(string)(r"\d\d\d"), new RegExpOption) 515 ("string,s", define!(string), "text parameter") 516 ("firstname", define!(string[]).composing, "firstname") 517 ("secondname", define!(string[]).composing, "secondname") 518 ("nickname,n", define!(string[]).composing, "nickname") 522 519 ; 523 520 … … 535 532 assert(("compression" in po.storage!(CommandLineStorage)) is null); 536 533 assert(checkException!(OptionHasNoValueException)({po.storage!(CommandLineStorage)["compression"];})); 537 trace(po["include"].as!( char[][]));538 assert(po["include"].as!( char[][]) == ["/usr/local", "/usr/", "/bin/"]);534 trace(po["include"].as!(string[])); 535 assert(po["include"].as!(string[]) == ["/usr/local", "/usr/", "/bin/"]); 539 536 po.disconnect; 540 537 });} … … 543 540 544 541 unittest { testCase.execute("CL Storage - positional options", { 545 char[][] args;542 string[] args; 546 543 RegularOptions ro; 547 544 CommandLineOptions clo; … … 551 548 ro.options() 552 549 ("compression,c", define!(int), "set compression level") 553 ("title,t", define!( char[]).defaultValue("title"), "set title of window")550 ("title,t", define!(string).defaultValue("title"), "set title of window") 554 551 ("doTheTest,d", "maketest") 555 ("include,i", define!( char[][]).composing.defaultValue(["default1"[], "default2"]), "include paths")556 ("int,p", define!( char[])(r"\d\d\d"), new RegExpOption)557 ("string,s", define!( char[]), "text parameter")558 ("firstname", define!( char[][]).composing, "firstname")559 ("secondname", define!( char[][]).composing, "secondname")560 ("nickname,n", define!( char[][]).composing, "nickname")552 ("include,i", define!(string[]).composing.defaultValue(["default1"[], "default2"]), "include paths") 553 ("int,p", define!(string)(r"\d\d\d"), new RegExpOption) 554 ("string,s", define!(string), "text parameter") 555 ("firstname", define!(string[]).composing, "firstname") 556 ("secondname", define!(string[]).composing, "secondname") 557 ("nickname,n", define!(string[]).composing, "nickname") 561 558 ; 562 559 … … 573 570 574 571 po.connect; 575 assert(po["firstname"].as!( char[][]) == ["Ala", "Ola"]);576 assert(po["secondname"].as!( char[][]) == ["Kowalska", "Nowak"]);577 assert(po["nickname"].as!( char[][]) == ["Aarti_pl"]);572 assert(po["firstname"].as!(string[]) == ["Ala", "Ola"]); 573 assert(po["secondname"].as!(string[]) == ["Kowalska", "Nowak"]); 574 assert(po["nickname"].as!(string[]) == ["Aarti_pl"]); 578 575 po.disconnect; 579 576 });} … … 582 579 583 580 unittest { testCase.execute("CL Storage - regular expression options", { 584 char[][] args;581 string[] args; 585 582 RegularOptions ro; 586 583 CommandLineOptions clo; … … 598 595 ("turnItOn,r", boolSwitch, "makecoffee") 599 596 ("compression,c", define!(int), "set compression level") 600 ("title,t", define!( char[]).defaultValue("title"), "set title of window")601 ("include,i", define!( char[][]).composing.defaultValue(["default1"[], "default2"]), "include paths")602 ("firstname", define!( char[][]).composing, "firstname")603 ("secondname", define!( char[][]).composing, "secondname")604 ("nickname,n", define!( char[][]).composing, "nickname")605 ("date", define!( char[])(r"\d\d\d\d-\d?\d-\d?\d"), "date of birth")606 ("regexp[ression]*,g", define!( char[]), "regular expression", new RegExpOption)597 ("title,t", define!(string).defaultValue("title"), "set title of window") 598 ("include,i", define!(string[]).composing.defaultValue(["default1"[], "default2"]), "include paths") 599 ("firstname", define!(string[]).composing, "firstname") 600 ("secondname", define!(string[]).composing, "secondname") 601 ("nickname,n", define!(string[]).composing, "nickname") 602 ("date", define!(string)(r"\d\d\d\d-\d?\d-\d?\d"), "date of birth") 603 ("regexp[ression]*,g", define!(string), "regular expression", new RegExpOption) 607 604 ("number\\d\\d", define!(byte), "following numbers", new RegExpOption) 608 ("int,p", define!( char[])(r"\d\d\d"), new RegExpOption)609 ("string,s", define!( char[]), "text parameter")605 ("int,p", define!(string)(r"\d\d\d"), new RegExpOption) 606 ("string,s", define!(string), "text parameter") 610 607 ("other,o", define!(double), "other parameter") 611 608 //Only alias name 612 (",J", define!( char[][]), "import paths")609 (",J", define!(string[]), "import paths") 613 610 ; 614 611 … … 626 623 627 624 assert(("regexpression" in po) !is null); 628 assert(po["regexpression"].as!( char[]) == "regexpstring");625 assert(po["regexpression"].as!(string) == "regexpstring"); 629 626 assert(po["compression"].as!(int) == 8); 630 assert(po["date"].as!( char[]) == "1975-7-4");631 trace(po["string"].as!( char[]));632 assert(po["string"].as!( char[]) == "D language");627 assert(po["date"].as!(string) == "1975-7-4"); 628 trace(po["string"].as!(string)); 629 assert(po["string"].as!(string) == "D language"); 633 630 634 631 po.disconnect; … … 642 639 643 640 assert(("date" in po) !is null); 644 assert(po["date"].as!( char[]) == "1975-07-04");641 assert(po["date"].as!(string) == "1975-07-04"); 645 642 assert(("regexp" in po) !is null); 646 assert(po["regexp"].as!( char[]) == "regexpstring");643 assert(po["regexp"].as!(string) == "regexpstring"); 647 644 assert(("number00" in po) !is null); 648 645 assert(po["number00"].as!(byte) == 34); … … 652 649 assert(po["compression"].as!(int) == 5); 653 650 assert(("title" in po) !is null); 654 assert(po["title"].as!( char[]) == "title");651 assert(po["title"].as!(string) == "title"); 655 652 assert(("doTheTest" in po) !is null); 656 653 assert(("doTheCoffee" in po) !is null); … … 665 662 666 663 unittest { testCase.execute("CL Storage - option styles", { 667 char[][] args;664 string[] args; 668 665 RegularOptions ro; 669 666 ProgramOptions po; … … 682 679 ("turnItOn,r", boolSwitch, "makecoffee") 683 680 ("compression,c", define!(int), "set compression level") 684 ("title,t", define!( char[]).defaultValue("title"), "set title of window")685 ("include,i", define!( char[][]).composing.defaultValue(["default1"[], "default2"]), "include paths")686 ("firstname", define!( char[][]).composing, "firstname")687 ("secondname", define!( char[][]).composing, "secondname")688 ("nickname,n", define!( char[][]).composing, "nickname")689 ("date", define!( char[])(r"\d\d\d\d-\d?\d-\d?\d"), "date of birth")690 ("regexp[ression]*,g", define!( char[]), "regular expression", new RegExpOption)681 ("title,t", define!(string).defaultValue("title"), "set title of window") 682 ("include,i", define!(string[]).composing.defaultValue(["default1"[], "default2"]), "include paths") 683 ("firstname", define!(string[]).composing, "firstname") 684 ("secondname", define!(string[]).composing, "secondname") 685 ("nickname,n", define!(string[]).composing, "nickname") 686 ("date", define!(string)(r"\d\d\d\d-\d?\d-\d?\d"), "date of birth") 687 ("regexp[ression]*,g", define!(string), "regular expression", new RegExpOption) 691 688 ("number\\d\\d", define!(byte), "following numbers", new RegExpOption) 692 ("int,p", define!( char[])(r"\d\d\d"), new RegExpOption)693 ("string,s", define!( char[]), "text parameter")689 ("int,p", define!(string)(r"\d\d\d"), new RegExpOption) 690 ("string,s", define!(string), "text parameter") 694 691 ("other,o", define!(double), "other parameter") 695 692 //Only alias name 696 (",J", define!( char[][]), "import paths")693 (",J", define!(string[]), "import paths") 697 694 ; 698 695 … … 723 720 ("turnItOn,r", boolSwitch, "makecoffee") 724 721 ("compression,c", define!(int), "set compression level") 725 ("title,t", define!( char[]).defaultValue("title"), "set title of window")726 ("include,i", define!( char[][]).composing.defaultValue(["default1"[], "default2"]), "include paths")727 ("firstname", define!( char[][]).composing, "firstname")728 ("secondname", define!( char[][]).composing, "secondname")729 ("nickname,n", define!( char[][]).composing, "nickname")730 ("date", define!( char[])(r"\d\d\d\d-\d?\d-\d?\d"), "date of birth")731 ("regexp[ression]*,g", define!( char[]), "regular expression", new RegExpOption)722 ("title,t", define!(string).defaultValue("title"), "set title of window") 723 ("include,i", define!(string[]).composing.defaultValue(["default1"[], "default2"]), "include paths") 724 ("firstname", define!(string[]).composing, "firstname") 725 ("secondname", define!(string[]).composing, "secondname") 726 ("nickname,n", define!(string[]).composing, "nickname") 727 ("date", define!(string)(r"\d\d\d\d-\d?\d-\d?\d"), "date of birth") 728 ("regexp[ression]*,g", define!(string), "regular expression", new RegExpOption) 732 729 ("number\\d\\d", define!(byte), "following numbers", new RegExpOption) 733 ("int,p", define!( char[])(r"\d\d\d"), new RegExpOption)734 ("string,s", define!( char[]), "text parameter")730 ("int,p", define!(string)(r"\d\d\d"), new RegExpOption) 731 ("string,s", define!(string), "text parameter") 735 732 ("other,o", define!(double), "other parameter") 736 733 //Only alias name 737 (",J", define!( char[][]), "import paths")734 (",J", define!(string[]), "import paths") 738 735 ; 739 736 … … 749 746 750 747 assert(po["compression"].as!(int) == 8); 751 assert(po["title"].as!( char[]) == "1984");748 assert(po["title"].as!(string) == "1984"); 752 749 753 750 po.disconnect; … … 765 762 ro.options() 766 763 ("compression", define!(int), "set compression level") 767 ("author", define!( char[]).defaultValue("drX"), "name of author")768 ("include,i", define!( char[][]).composing, "include paths")769 ("myname", define!( char[]), "name")770 ("database.user", define!( char[]), "Database User")771 ("database.password", define!( char[]), "Database Password")772 ("database.ip", define!( char[])(r"[0|1|2]?\d?\d\.[0|1|2]?\d?\d\.[0|1|2]?\d?\d\.[0|1|2]?\d?\d"), "Database IP")764 ("author", define!(string).defaultValue("drX"), "name of author") 765 ("include,i", define!(string[]).composing, "include paths") 766 ("myname", define!(string), "name") 767 ("database.user", define!(string), "Database User") 768 ("database.password", define!(string), "Database Password") 769 ("database.ip", define!(string)(r"[0|1|2]?\d?\d\.[0|1|2]?\d?\d\.[0|1|2]?\d?\d\.[0|1|2]?\d?\d"), "Database IP") 773 770 ("interaction.help", "activate help") 774 771 ("interaction.tips", "activate tips") … … 799 796 assert(po["compression"].as!(int) == 6); 800 797 po["compression"] = any!(int)(18); 801 po["database.ip"]= any!( char[])("127.0.0.1");802 po["database.user"]= any!( char[])("marcin");803 po["database.password"]= any!( char[])("******");798 po["database.ip"]= any!(string)("127.0.0.1"); 799 po["database.user"]= any!(string)("marcin"); 800 po["database.password"]= any!(string)("******"); 804 801 assert(po["compression"].as!(int) == 18); 805 assert(po["database.ip"].as!( char[]) == "127.0.0.1"[]);802 assert(po["database.ip"].as!(string) == "127.0.0.1"[]); 806 803 807 804 po.synchronize; … … 809 806 810 807 assert(po["compression"].as!(int) == 18); 811 assert(po["database.ip"].as!( char[]) == "127.0.0.1"[]);812 assert(po["database.user"].as!( char[]) == "marcin"[]);813 assert(po["database.password"].as!( char[]) == "******"[]);808 assert(po["database.ip"].as!(string) == "127.0.0.1"[]); 809 assert(po["database.user"].as!(string) == "marcin"[]); 810 assert(po["database.password"].as!(string) == "******"[]); 814 811 assert("interaction.balloons" in po); 815 assert(po["author"].as!( char[]) == "Szklarski");816 po["author"] = any!( char[])("Niziurski");817 assert(po["author"].as!( char[]) == "Niziurski");812 assert(po["author"].as!(string) == "Szklarski"); 813 po["author"] = any!(string)("Niziurski"); 814 assert(po["author"].as!(string) == "Niziurski"); 818 815 819 816 po.syncPolicy(SyncPolicy.Cached); 820 817 821 assert(po["include"].as!( char[][]) == ["/usr/local/import/"]);822 po.storage!(ConfigFileStorage)()["include"] = any!( char[][])(["/usr/local/bin/", "/bin/", "/usr/bin/"]);818 assert(po["include"].as!(string[]) == ["/usr/local/import/"]); 819 po.storage!(ConfigFileStorage)()["include"] = any!(string[])(["/usr/local/bin/", "/bin/", "/usr/bin/"]); 823 820 824 821 po.synchronize; 825 822 826 assert(po["include"].as!( char[][]) == ["/usr/local/bin/", "/bin/", "/usr/bin/"]);827 po["myname"] = any!( char[])("Aarti_pl");823 assert(po["include"].as!(string[]) == ["/usr/local/bin/", "/bin/", "/usr/bin/"]); 824 po["myname"] = any!(string)("Aarti_pl"); 828 825 829 826 po.synchronize; 830 assert(po["myname"].as!( char[]) == "Aarti_pl");831 832 real_desc = cast( char[])std.file.read("test01.cfg");827 assert(po["myname"].as!(string) == "Aarti_pl"); 828 829 real_desc = cast(string)std.file.read("test01.cfg"); 833 830 expc_desc = 834 831 "compression = 18 # Kompresja pliku … … 852 849 po.synchronize; 853 850 854 real_desc = cast( char[])std.file.read("test01.cfg");851 real_desc = cast(string)std.file.read("test01.cfg"); 855 852 expc_desc = 856 853 "compression = 18 # Kompresja pliku … … 873 870 po.synchronize; 874 871 875 real_desc = cast( char[])std.file.read("test01.cfg");872 real_desc = cast(string)std.file.read("test01.cfg"); 876 873 expc_desc =" 877 874 compression = 18 # Kompresja pliku … … 891 888 892 889 assert(po["compression"].as!(int) == 18); 893 assert(po["myname"].as!( char[]) == "Aarti_pl");890 assert(po["myname"].as!(string) == "Aarti_pl"); 894 891 po.disconnect; 895 892 … … 933 930 934 931 po.storage!(ConfigFileStorage).remove("compression"); 935 po.storage!(ConfigFileStorage)()["author"] = any!( char[])("Nienacki");936 po["database.ip"] = any!( char[])("223.14.80.34");937 po["database.password"] = any!( char[])("***");938 po["database.user"] = any!( char[])("Magda");932 po.storage!(ConfigFileStorage)()["author"] = any!(string)("Nienacki"); 933 po["database.ip"] = any!(string)("223.14.80.34"); 934 po["database.password"] = any!(string)("***"); 935 po["database.user"] = any!(string)("Magda"); 939 936 po["interaction.help"] = any!()(); 940 937 po["interaction.tips"] = any!()(); 941 938 942 real_desc = cast( char[])std.file.read("test03.cfg");939 real_desc = cast(string)std.file.read("test03.cfg"); 943 940 expc_desc =" 944 941 author = \"Nienacki\" # Autor ksiĆ … … 960 957 po.disconnect; 961 958 962 real_desc = cast( char[])std.file.read("test03.cfg");959 real_desc = cast(string)std.file.read("test03.cfg"); 963 960 assert(removechars(real_desc, " \t\n\r") == removechars(expc_desc, " \t\n\r")); 964 961 });} … … 972 969 ro = new RegularOptions("Environment options"); 973 970 ro.options() 974 ("po_include", define!( char[][]).composing, "include paths")975 ("po_compiler", define!( char[]).defaultValue("dmd"), "default compiler")976 ("po_linker", define!( char[]).defaultValue("link"), "default linker")971 ("po_include", define!(string[]).composing, "include paths") 972 ("po_compiler", define!(string).defaultValue("dmd"), "default compiler") 973 ("po_linker", define!(string).defaultValue("link"), "default linker") 977 974 ("po_threads", define!(uint).defaultValue(3), "number of compilation threads") 978 975 ; … … 988 985 assert(!("po_include" in po)); 989 986 assert("po_compiler" in po); 990 assert(po["po_compiler"].as!( char[]) == "dmd");987 assert(po["po_compiler"].as!(string) == "dmd"); 991 988 assert("po_linker" in po); 992 assert(po["po_linker"].as!( char[]) == "link");989 assert(po["po_linker"].as!(string) == "link"); 993 990 assert("po_threads" in po); 994 991 assert(po["po_threads"].as!(uint) == 3); 995 992 996 po["po_compiler"] = any!( char[])("gdb");997 assert(po["po_compiler"].as!( char[]) == "gdb");998 po["po_linker"] = any!( char[])("gcc");999 assert(po["po_linker"].as!( char[]) == "gcc");1000 1001 po.disconnect; 1002 1003 po.connect; 1004 1005 assert(po["po_compiler"].as!( char[]) == "gdb");1006 assert(po["po_linker"].as!( char[]) == "gcc");993 po["po_compiler"] = any!(string)("gdb"); 994 assert(po["po_compiler"].as!(string) == "gdb"); 995 po["po_linker"] = any!(string)("gcc"); 996 assert(po["po_linker"].as!(string) == "gcc"); 997 998 po.disconnect; 999 1000 po.connect; 1001 1002 assert(po["po_compiler"].as!(string) == "gdb"); 1003 assert(po["po_linker"].as!(string) == "gcc"); 1007 1004 1008 1005 po.disconnect; … … 1023 1020 ("help,h", "produce help message") 1024 1021 ("compression", define!(int).defaultValue(2), "set compression level") 1025 ("title", define!( char[]).defaultValue("title"), "set title of window")1026 ("include,i", define!( char[][]).composing, "include paths")1022 ("title", define!(string).defaultValue("title"), "set title of window") 1023 ("include,i", define!(string[]).composing, "include paths") 1027 1024 ; 1028 1025 … … 1030 1027 ro1.options() 1031 1028 ("help,h", "produce help message") 1032 ("title", define!( char[]).defaultValue("title"), "set title of window")1033 ("include,i", define!( char[][]).composing, "include paths")1029 ("title", define!(string).defaultValue("title"), "set title of window") 1030 ("include,i", define!(string[]).composing, "include paths") 1034 1031 ; 1035 1032 … … 1037 1034 fil.options() 1038 1035 ("compression", define!(int), "set compression level") 1039 ("author", define!( char[]).defaultValue("drX"), "name of author")1040 ("include,i", define!( char[][]).composing, "include paths")1036 ("author", define!(string).defaultValue("drX"), "name of author") 1037 ("include,i", define!(string[]).composing, "include paths") 1041 1038 ; 1042 1039 1043 1040 fil1 = new RegularOptions("File storage 1"); 1044 1041 fil1.options() 1045 ("comment", define!( char[]).defaultValue("my comment"), "comment to last news")1042 ("comment", define!(string).defaultValue("my comment"), "comment to last news") 1046 1043 ("list,l", "list all paths") 1047 ("title", define!( char[]).defaultValue("title"), "title of window")1044 ("title", define!(string).defaultValue("title"), "title of window") 1048 1045 ; 1049 1046 … … 1093 1090 assert(("compression" in po) !is null); 1094 1091 assert(po["compression"].as!(int) == 6); 1095 assert(po["author"].as!( char[]) == "Szklarski");1096 1097 assert(po.composedOptions("include").as!( char[][]) == ["/usr/local", "/usr/", "/bin/", "/usr/local/import/"]);1098 assert(po.composedOptions("title").as!( char[][]) == ["title", "mytitle"]);1092 assert(po["author"].as!(string) == "Szklarski"); 1093 1094 assert(po.composedOptions("include").as!(string[]) == ["/usr/local", "/usr/", "/bin/", "/usr/local/import/"]); 1095 assert(po.composedOptions("title").as!(string[]) == ["title", "mytitle"]); 1099 1096 1100 1097 po.storage!(CommandLineStorage)()["compression"] = any!(int)(2); … … 1154 1151 assert(compression == 15); 1155 1152 1156 assert(po.storage!(ConfigFileStorage)().storage!(ConfigFileStorage)()["title"].as!( char[])=="mytitle");1153 assert(po.storage!(ConfigFileStorage)().storage!(ConfigFileStorage)()["title"].as!(string)=="mytitle"); 1157 1154 1158 1155 po.disconnect; … … 1211 1208 .options() 1212 1209 ("compression", define!(int), "set compression level") 1213 ("author", define!( char[]).defaultValue("drX"), "name of author")1214 ("include,i", define!( char[][]).composing, "include paths")1210 ("author", define!(string).defaultValue("drX"), "name of author") 1211 ("include,i", define!(string[]).composing, "include paths") 1215 1212 () 1216 1213 .formatter(new BasicFormatter) … … 1249 1246 fil1 = new RegularOptions("File storage 1"); 1250 1247 fil1.options() 1251 ("comment", define!( char[]).defaultValue("my comment"), "comment to last news")1248 ("comment", define!(string).defaultValue("my comment"), "comment to last news") 1252 1249 ; 1253 1250 … … 1282 1279 po.synchronize; 1283 1280 1284 real_desc = cast( char[])std.file.read("test06.cfg");1281 real_desc = cast(string)std.file.read("test06.cfg"); 1285 1282 expc_desc ="compression = 128"; 1286 1283 assert(removechars(real_desc, " \t\n\r") == removechars(expc_desc, " \t\n\r")); … … 1301 1298 ro.options() 1302 1299 ("compression", define!(int).defaultValue(2), "set compression level") 1303 ("name", define!( char[]), "name of zip")1300 ("name", define!(string), "name of zip") 1304 1301 ("help,h", "help for options") 1305 1302 (r"chanel\d", define!(int), "chanel number", new RegExpOption) … … 1309 1306 fil.options() 1310 1307 ("compression", define!(int), "set compression level") 1311 ("package", define!( char[]), "package name")1308 ("package", define!(string), "package name") 1312 1309 (r"port\d\d\d,h", boolSwitch, "port to activate", new RegExpOption) 1313 1310 ; … … 1370 1367 ro.options() 1371 1368 ("compression", define!(int).defaultValue(2), "set compression level") 1372 ("name", define!( char[]), "name of zip")1369 ("name", define!(string), "name of zip") 1373 1370 ("help,h", "help for options") 1374 1371 (r"chanel\d", define!(int), "chanel number", new RegExpOption) … … 1378 1375 fil.options() 1379 1376 ("compression", define!(int), "set compression level") 1380 ("package", define!( char[]), "package name")1377 ("package", define!(string), "package name") 1381 1378 (r"port\d\d\d,h", boolSwitch, "port to activate", new RegExpOption) 1382 1379 ; … … 1423 1420 ro.options() 1424 1421 ("compression", define!(int).defaultValue(2), "set compression level") 1425 ("name", define!( char[]), "name of zip")1422 ("name", define!(string), "name of zip") 1426 1423 ("help,h", "help for options") 1427 1424 (r"chanel\d", define!(int), "chanel number", new RegExpOption) … … 1444 1441 assert(po["compression"].as!(int) == 52); 1445 1442 1446 po["name"] = any!( char[])("Aarti_pl");1447 assert(po["name"].as!( char[]) == "Aarti_pl");1448 1449 po["name"] = any!( char[])("Wacek");1450 assert(po["name"].as!( char[]) == "Wacek");1443 po["name"] = any!(string)("Aarti_pl"); 1444 assert(po["name"].as!(string) == "Aarti_pl"); 1445 1446 po["name"] = any!(string)("Wacek"); 1447 assert(po["name"].as!(string) == "Wacek"); 1451 1448 1452 1449 //NOTE: for unknown reasons when using execute() in DbStorage below test fails … … 1471 1468 Program entry point 1472 1469 ******************************************************************************/ 1473 int main( char[][] args) {1470 int main(string[] args) { 1474 1471 try { 1475 1472 char sep = ';'; … … 1489 1486 (new EnvironmentStorage) 1490 1487 .options() 1491 ("Path,PATH", define!( char[][]).separator(sep), "paths defined in system")1488 ("Path,PATH", define!(string[]).separator(sep), "paths defined in system") 1492 1489 () 1493 1490 .next( … … 1495 1492 .options() 1496 1493 ("optimization", define!(int), "level") 1497 ("include-path", define!( char[][]), "include paths")1494 ("include-path", define!(string[]), "include paths") 1498 1495 ("compression", define!(int), "set compression level") 1499 1496 () … … 1501 1498 (new ConfigFileStorage("file2.cfg")) 1502 1499 .options() 1503 ("name", define!( char[]), "name of game")1500 ("name", define!(string), "name of game") 1504 1501 ("pi", define!(double), "value of eternity") 1505 1502 () … … 1509 1506 1510 1507 if ("help" in po) { 1511 write fln(po);1508 writeln(po); 1512 1509 return 0; 1513 1510 } 1514 1511 1515 1512 if ("compression" in po) { 1516 write fln("Compression level was set to ", po["compression"]);1513 writeln("Compression level was set to ", po["compression"]); 1517 1514 } else { 1518 write fln("Compression level was not set.");1515 writeln("Compression level was not set."); 1519 1516 } 1520 1517 1521 1518 if ("optimization" in po) { 1522 write fln("Optimization set to: ", po["optimization"]);1519 writeln("Optimization set to: ", po["optimization"]); 1523 1520 } 1524 1521 1525 1522 if ("pi" in po) { 1526 write fln("Pi set to: ", po["pi"]);1523 writeln("Pi set to: ", po["pi"]); 1527 1524 } 1528 1525 1529 1526 if ("name" in po) { 1530 write fln("Name set to: ", po["name"]);1527 writeln("Name set to: ", po["name"]); 1531 1528 } 1532 1529 1533 1530 if ("PATH" in po) { 1534 write fln("\n\nThere are following directories in your system path: \n");1535 1536 foreach(p; po["Path"].as!( char[][])) {1537 write fln(p);1531 writeln("\n\nThere are following directories in your system path: \n"); 1532 1533 foreach(p; po["Path"].as!(string[])) { 1534 writeln(p); 1538 1535 } 1539 1536 } … … 1548 1545 } 1549 1546 catch(ProgramOptionsException e) { 1550 write fln("Exception: ", e);1547 writeln("Exception: ", e); 1551 1548 return 1; 1552 1549 } trunk/examples/util/serializer/SerializerTest.d
r75 r81 18 18 import std.date; 19 19 import std.math; 20 import std.conv; 20 21 import std.string; 21 22 … … 545 546 546 547 input = new MyClass; input.x = 5; input.y = 10; input.z = 15; 547 output = serializer.dump(input); 548 trace("ch1"); 549 output = serializer.dump(input); 550 trace("ch2"); 548 551 trace(output); 549 552 assert(output == cast(serializer.STORAGETYPE)"5-10-15"); 553 trace("ch3"); 550 554 assert(serializer.load!(MyClass)(output) == input); 551 555 });} … … 921 925 922 926 mixin ArchiveTest!(TextArchive, string); 923 //mixin ArchiveTest!(TextArchiveExt, string);924 927 mixin ArchiveTest!(TextArchive, wstring); 928 //mixin ArchiveTest!(TextArchive, dstring); 929 mixin ArchiveTest!(TextArchiveExt, string); 925 930 //mixin ArchiveTest!(TextArchiveExt, wstring); 926 //mixin ArchiveTest!(TextArchive, dstring); 931 927 932 //mixin ArchiveTest!(TextArchiveExt, dstring); 928 933 929 934 mixin ArchiveTest!(JsonArchive, string); 935 //mixin ArchiveTest!(JsonArchive, wstring); 936 //mixin ArchiveTest!(JsonArchive, dstring); 930 937 //mixin ArchiveTest!(JsonArchiveExt, string); 931 //mixin ArchiveTest!(JsonArchive, wstring);932 938 //mixin ArchiveTest!(JsonArchiveExt, wstring); 933 //mixin ArchiveTest!(JsonArchive, dstring);934 939 //mixin ArchiveTest!(JsonArchiveExt, dstring); 935 940
