Changeset 16
- Timestamp:
- 09/24/07 16:36:26 (1 year ago)
- Files:
-
- branches/npo/doost/core/Any.d (modified) (1 diff)
- branches/npo/doost/util/config/CommandLineStorage.d (modified) (27 diffs)
- branches/npo/doost/util/config/ConfigFileStorage.d (modified) (9 diffs)
- branches/npo/doost/util/config/DbStorage.d (modified) (1 diff)
- branches/npo/doost/util/config/EnvironmentStorage.d (modified) (1 diff)
- branches/npo/doost/util/config/Exception.d (modified) (1 diff)
- branches/npo/doost/util/config/Option.d (modified) (7 diffs)
- branches/npo/doost/util/config/ProgramOptions.d (modified) (1 diff)
- branches/npo/doost/util/config/Value.d (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/npo/doost/core/Any.d
r14 r16 22 22 23 23 /*************************************************************************** 24 Copy operator 24 25 **************************************************************************/ 25 26 typeof(this) dup() { branches/npo/doost/util/config/CommandLineStorage.d
r14 r16 137 137 Class thrown when there are too many positional options. 138 138 ******************************************************************************/ 139 class TooManyPositionalOptionsException : ProgramOptionsException { 140 public: 141 this(char[] what) { 142 super(what); 143 } 144 } 145 146 //------------------------------------------------------------------------------ 147 148 /******************************************************************************* 149 Class thrown when there are too few positional options. 150 ******************************************************************************/ 151 class TooFewPositionalOptionsException : ProgramOptionsException { 139 class PositionalOptionException : ProgramOptionsException { 152 140 public: 153 141 this(char[] what) { … … 172 160 class InvalidCommandLineStyleException : ProgramOptionsException { 173 161 public: 162 /*************************************************************************** 163 Constructor 164 **************************************************************************/ 174 165 this(char[] msg) { 175 166 super(msg); … … 193 184 ******************************************************************************/ 194 185 abstract class CommandLineOption : SpecialOption { 186 /*************************************************************************** 187 See: Option 188 **************************************************************************/ 195 189 typeof(this) dup(); 196 190 } … … 199 193 200 194 /******************************************************************************* 195 This class allows to get application binary path, which is passed by 196 system to binary program 201 197 ******************************************************************************/ 202 198 class SelfPath : CommandLineOption { 203 199 public: 200 /*************************************************************************** 201 Constructor 202 **************************************************************************/ 204 203 this() { 205 204 m_semantic = new TypedValue!(char[]); … … 208 207 } 209 208 209 /*************************************************************************** 210 See: Option 211 **************************************************************************/ 210 212 override typeof(this) dup() { 211 213 auto result = new typeof(this); … … 214 216 } 215 217 218 /*************************************************************************** 219 See: Option 220 **************************************************************************/ 216 221 alias Option.semantic semantic; 217 222 override void semantic(ValueSemantic s) {assert(false, "You can not change semantic for SelfPath!");} 218 223 219 224 /*************************************************************************** 220 **************************************************************************/ 221 char[] optionTypeName() { 225 See: Option 226 **************************************************************************/ 227 override char[] optionTypeName() { 222 228 return typeof(this).stringof; 223 229 } … … 227 233 228 234 /******************************************************************************* 235 This class allows to get application directory path, which is passed by 236 system to binary program 229 237 ******************************************************************************/ 230 238 class SelfDir : CommandLineOption { 231 239 public: 240 /*************************************************************************** 241 Constructor 242 **************************************************************************/ 232 243 this() { 233 244 m_semantic = new TypedValue!(char[]); … … 236 247 } 237 248 249 /*************************************************************************** 250 See: Option 251 **************************************************************************/ 238 252 override typeof(this) dup() { 239 253 auto result = new typeof(this); … … 242 256 } 243 257 258 /*************************************************************************** 259 See: Option 260 **************************************************************************/ 244 261 alias Option.semantic semantic; 245 262 override void semantic(ValueSemantic s) {assert(false, "You can not change semantic for SelfDir!");} 246 263 247 264 /*************************************************************************** 265 See: Option 248 266 **************************************************************************/ 249 267 char[] optionTypeName() { … … 255 273 256 274 /******************************************************************************* 275 This class allows to get application binary name, which is passed by 276 system to binary program 257 277 ******************************************************************************/ 258 278 class SelfName : CommandLineOption { 259 279 public: 280 /*************************************************************************** 281 Constructor 282 **************************************************************************/ 260 283 this() { 261 284 m_semantic = new TypedValue!(char[]); … … 264 287 } 265 288 289 /*************************************************************************** 290 See: Option 291 **************************************************************************/ 266 292 override typeof(this) dup() { 267 293 auto result = new typeof(this); … … 270 296 } 271 297 298 /*************************************************************************** 299 See: Option 300 **************************************************************************/ 272 301 alias Option.semantic semantic; 273 302 override void semantic(ValueSemantic s) {assert(false, "You can not change semantic for SelfName!");} 274 303 275 304 /*************************************************************************** 305 See: Option 276 306 **************************************************************************/ 277 307 char[] optionTypeName() { … … 304 334 } 305 335 336 /*************************************************************************** 337 See: Option 338 **************************************************************************/ 306 339 override typeof(this) dup() { 307 340 auto result = new typeof(this); … … 312 345 } 313 346 347 /*************************************************************************** 348 See: Option 349 **************************************************************************/ 314 350 override void description(char[] s) {assert(false);} 315 351 override char[] description() {assert(false);} 352 353 /*************************************************************************** 354 See: Option 355 **************************************************************************/ 316 356 override ValueSemantic semantic() {assert(false);} 317 357 override void semantic(ValueSemantic s) {assert(false);} 358 359 /*************************************************************************** 360 See: Option 361 **************************************************************************/ 318 362 override char[] key(char[] name) {return null;} 319 363 … … 411 455 public: 412 456 /*************************************************************************** 413 Copy operator 457 Constructor 458 **************************************************************************/ 459 this() { 460 } 461 462 /*************************************************************************** 463 Constructor 464 465 Params: 466 caption = first part of printable description of options 467 given by user 468 **************************************************************************/ 469 this(char[] caption) { 470 m_caption = caption; 471 } 472 473 /*************************************************************************** 474 See: OptonsDescription 414 475 **************************************************************************/ 415 476 typeof(this) dup() { … … 418 479 419 480 /*************************************************************************** 420 **************************************************************************/ 421 this() { 422 } 423 424 /*************************************************************************** 425 **************************************************************************/ 426 this(char[] caption) { 427 m_caption = caption; 428 } 429 430 /*************************************************************************** 481 See: OptonsDescription 431 482 **************************************************************************/ 432 483 EasyInit!(CommandLineOptions) addOptions() { … … 465 516 466 517 /******************************************************************************* 518 This storage parses array of command line arguments. Depending on style, 519 first argument can be treated as path to binary executable. 467 520 ******************************************************************************/ 468 521 class CommandLineStorage : ConcreteStorage { … … 484 537 485 538 /*************************************************************************** 486 **************************************************************************/ 487 this(RegularOptions od, char[][] args) 539 Constructor 540 541 Params: 542 ro = description of options 543 args = array of command line arguments 544 **************************************************************************/ 545 this(RegularOptions ro, char[][] args) 488 546 in { 489 assert( od!is null);547 assert(ro !is null); 490 548 assert(args !is null); 491 549 } … … 493 551 m_args = args.dup; 494 552 m_style = Style.DefaultStyle; 495 m_regular = od.dup;553 m_regular = ro.dup; 496 554 m_special = null; 497 555 m_desc = m_regular; … … 601 659 602 660 protected: 603 604 661 /*************************************************************************** 605 662 See: BaseStorage … … 655 712 656 713 if (position >= positional.maxTotalCount) 657 throw new TooManyPositionalOptionsException("too many positional options");714 throw new PositionalOptionException("Too many positional options"); 658 715 659 716 char[] name = positional.nameForPosition(position); … … 703 760 704 761 /*************************************************************************** 762 See: BaseStorage 705 763 **************************************************************************/ 706 764 override void disconnect() { … … 741 799 742 800 /*************************************************************************** 801 Parses long options: --name 743 802 **************************************************************************/ 744 803 ParsedOption[] parseLongOption(ref char[][] args) { … … 796 855 797 856 /*************************************************************************** 857 Parses short options: -n 798 858 **************************************************************************/ 799 859 ParsedOption[] parseShortOption(ref char[][] args) { … … 847 907 848 908 /*************************************************************************** 909 Parses dos options: /n 849 910 **************************************************************************/ 850 911 ParsedOption[] parseDosOption(ref char[][] args) { … … 853 914 if (args[0].length >= 2 && args[0][0] == '/') { 854 915 char[] tok = consumeToken(args); 855 char[] name = "-" ~ tok[1];916 char[] name = [tok[1]]; 856 917 char[] adjacent = tok[2..$]; 857 918 … … 931 992 } 932 993 933 // Fields994 //---------------------------- Fields -------------------------------------- 934 995 char[][] m_args; 935 996 Style m_style; branches/npo/doost/util/config/ConfigFileStorage.d
r14 r16 61 61 codepage = codepage of file (default = unicode utf8/utf16/utf32) 62 62 **************************************************************************/ 63 this(RegularOptions desc, char[] file, int codepage=-1)63 this(RegularOptions ro, char[] file, int codepage=-1) 64 64 in { 65 assert( desc!is null);65 assert(ro !is null); 66 66 assert(file != ""); 67 67 } 68 68 body { 69 69 m_file = file; 70 m_regular= desc.dup;70 m_regular=ro.dup; 71 71 m_desc = m_regular; 72 72 m_persistent = true; … … 84 84 } 85 85 body { 86 m_file = file ;86 m_file = file.dup; 87 87 return this; 88 88 } … … 107 107 108 108 /*************************************************************************** 109 See: ConcreteStorage 109 110 **************************************************************************/ 110 111 override OptionsMap readPhysicallyAll() { … … 135 136 136 137 /*************************************************************************** 138 See: ConcreteStorage 137 139 **************************************************************************/ 138 140 override Value readPhysicallyOne(char[] name) { … … 273 275 274 276 /*************************************************************************** 277 See: ConcreteStorage 275 278 **************************************************************************/ 276 279 override void savePhysicallyAll(OptionsMap map) { … … 343 346 344 347 /*************************************************************************** 348 See: ConcreteStorage 345 349 **************************************************************************/ 346 350 override void savePhysicallyOne(char[] name, in Value value) … … 436 440 if (s[0] == '[' && s[$-1] == ']') { 437 441 result.prefix = s[1..$-1]; 438 if (result.prefix[$-1] == '.') throw new Invalid SyntaxException(s, "section can not end with dot");442 if (result.prefix[$-1] == '.') throw new InvalidConfigFileSyntaxException(s, "section can not end with dot"); 439 443 } else { 440 444 //Handle typed values … … 462 466 } 463 467 464 // Fields 465 char[] m_file; 466 468 //---------------------------- Definitions --------------------------------- 467 469 struct FileLine { 468 470 char[] prefix; // "" - no prefix … … 471 473 char[] comment; // "" - option line or empty line 472 474 } 475 476 //---------------------------- Fields -------------------------------------- 477 char[] m_file; 473 478 } branches/npo/doost/util/config/DbStorage.d
r14 r16 121 121 } 122 122 123 //---------------------------- Fields -------------------------------------- 124 123 125 Database m_db; 124 126 char[] m_table; branches/npo/doost/util/config/EnvironmentStorage.d
r14 r16 24 24 25 25 /*************************************************************************** 26 Constructor 27 28 Params: 29 ro = description of options 26 30 **************************************************************************/ 27 this(RegularOptions od)31 this(RegularOptions ro) 28 32 in { 29 assert( od!is null);33 assert(ro !is null); 30 34 } 31 35 body { 32 m_regular = od.dup;36 m_regular = ro.dup; 33 37 m_desc = m_regular; 34 38 m_defaultSyncPolicy = SyncPolicy.Direct; branches/npo/doost/util/config/Exception.d
r14 r16 63 63 this(char[] type, char[] name) { 64 64 super("Duplicated '" ~ type ~ "' option definition with name: " ~ name); 65 }66 }67 68 //------------------------------------------------------------------------------69 70 /*******************************************************************************71 Class thrown when there are several option values, but72 user called a method which cannot return them all.73 ******************************************************************************/74 class MultipleValuesException : ProgramOptionsException {75 public:76 this(char[] what) {77 super(what);78 65 } 79 66 } branches/npo/doost/util/config/Option.d
r14 r16 434 434 public: 435 435 /*************************************************************************** 436 copy operator 436 437 **************************************************************************/ 437 438 typeof(this) dup(); 438 439 /***************************************************************************440 Copy operator441 **************************************************************************/442 typeof(this) duplicate(typeof(this) result) {443 result.m_caption = m_caption.dup;444 445 foreach(opt; m_options)446 result.m_options ~= opt.dup;447 448 foreach(group; m_groups)449 result.m_groups~=group.dup;450 451 foreach(opt; result.allOptions)452 register(opt, result.m_index);453 454 return result;455 }456 439 457 440 /*************************************************************************** … … 584 567 protected: 585 568 /*************************************************************************** 569 Copy operator implementation 570 **************************************************************************/ 571 typeof(this) duplicate(typeof(this) result) { 572 result.m_caption = m_caption.dup; 573 574 foreach(opt; m_options) 575 result.m_options ~= opt.dup; 576 577 foreach(group; m_groups) 578 result.m_groups~=group.dup; 579 580 foreach(opt; result.allOptions) 581 register(opt, result.m_index); 582 583 return result; 584 } 585 586 /*************************************************************************** 587 Applies given delegate for every OptionCharacteristic marked on 588 bit field 586 589 **************************************************************************/ 587 590 void apply(Option o, void delegate(OptionCharacteristic oc) dg) { … … 612 615 613 616 /*************************************************************************** 614 Below functions checks if adding new option or options description615 will not cause duplicated optionsto appear.616 617 These functions should always checkif:617 Function checks if adding new option will not cause duplicated options 618 to appear. 619 620 Function checks if: 618 621 a. there is no other same long name 619 622 b. there is no other same short name … … 626 629 identifies option. 627 630 631 Params: 632 opt - option to check 628 633 **************************************************************************/ 629 634 … … 648 653 649 654 /*************************************************************************** 655 Checks if adding given description to current description will not cause 656 options conflict (uses checkOption) 657 658 Params: 659 desc = description of options 650 660 **************************************************************************/ 651 661 void checkOptions(OptionsDescription desc) { … … 656 666 } 657 667 658 //---------------------------- ----------------------------------------------668 //---------------------------- Fields -------------------------------------- 659 669 660 670 char[] m_caption; … … 674 684 public: 675 685 /*************************************************************************** 676 C reates the instance686 Constructor 677 687 **************************************************************************/ 678 688 this() { branches/npo/doost/util/config/ProgramOptions.d
r14 r16 614 614 break; 615 615 case OAction.CLEAR: m_variablesMap.remove(name); 616 registerEvent(this, NotifyEvent.SelfRemove, name, val);617 616 break; 618 617 } branches/npo/doost/util/config/Value.d
r14 r16 15 15 16 16 /******************************************************************************* 17 Evaluates to true if given type is array 17 18 ******************************************************************************/ 18 19 template isArray( T ) { … … 26 27 27 28 /******************************************************************************* 29 Evaluates to same type as given for arrays, and to array for not-arrays, 30 char[], wchar[], dchar[]. 28 31 ******************************************************************************/ 29 32 template compositionType(T) { … … 43 46 interface ValueSemantic { 44 47 /*************************************************************************** 48 Copy operator 45 49 **************************************************************************/ 46 50 typeof(this) dup(); … … 73 77 74 78 /*************************************************************************** 75 **************************************************************************/ 76 Any compose(Any[]); 79 Composes array of values represented by Any into one array. Type of 80 resulting type is calculated by template compisitionType 81 82 Params: 83 values - array of Any 84 **************************************************************************/ 85 Any compose(Any[] values); 77 86 78 87 /*************************************************************************** … … 113 122 114 123 /*************************************************************************** 124 See: ValueSemantic 115 125 **************************************************************************/ 116 126 override typeof(this) dup() { … … 120 130 121 131 /*************************************************************************** 132 See: ValueSemantic 122 133 **************************************************************************/ 123 134 override char[] name() { … … 126 137 127 138 /*************************************************************************** 139 See: ValueSemantic 140 141 Returns: always false for UntypedValue 128 142 **************************************************************************/ 129 143 override bool isComposing() { … … 149 163 150 164 /*************************************************************************** 165 See: ValueSemantic 166 167 Returns: always null 151 168 **************************************************************************/ 152 169 override Any compose(Any[] values) { … … 155 172 156 173 /*************************************************************************** 174 See: ValueSemantic 175 176 Returns: always null 157 177 **************************************************************************/ 158 178 override ValueSemantic compositionSemantic() { … … 161 181 162 182 /*************************************************************************** 163 Does nothing. 183 See: ValueSemantic 184 185 Returns: always false 164 186 **************************************************************************/ 165 187 override bool applyDefault(ref Any b) { … … 168 190 169 191 /*************************************************************************** 170 Returns null for Untyped Value 192 See: ValueSemantic 193 194 Returns: always null 171 195 **************************************************************************/ 172 196 override TypeInfo type() { … … 175 199 176 200 /*************************************************************************** 201 See: ValueSemantic 202 203 Returns: always true 177 204 **************************************************************************/ 178 205 override bool isZeroTokens() { … … 199 226 200 227 /*************************************************************************** 228 See: ValueSemantic 201 229 **************************************************************************/ 202 230 override typeof(this) dup() { … … 212 240 /*************************************************************************** 213 241 Specifies default value, which will be used 214 if none is explicitly specified. The type 'T' should 215 provide operator<< for ostream. 242 if none is explicitly specified 216 243 **************************************************************************/ 217 244 TypedValue defaultValue(T v) { … … 222 249 223 250 /*************************************************************************** 224 Specifies default value, which will be used 225 if none is explicitly specified. Unlike the above overload, 226 the type 'T' need not provide operator<< for ostream, 227 but textual representation of default value must be provided 228 by the user. 229 **************************************************************************/ 230 TypedValue defaultValue(T v, char[] textual) { 231 m_default_value.assign(v); 232 m_default_value_as_text = textual; 233 return this; 234 } 235 236 /*************************************************************************** 237 Specifies that the value is composing. See the 'is_composing' 251 Specifies that the value is composing. See the 'isComposing' 238 252 method for explanation. 239 253 **************************************************************************/ … … 244 258 245 259 /*************************************************************************** 260 Returns true if option can be composed. If it is true, option can appear 261 many times in source and will be composed into array. 262 263 Returns: true if option is composing 246 264 **************************************************************************/ 247 265 override bool isComposing() { … … 250 268 251 269 /*************************************************************************** 270 Specifies that option have no value - just name. 271 272 Returns: this (chaining) 252 273 **************************************************************************/ 253 274 TypedValue zeroTokens() { … … 257 278 258 279 /*************************************************************************** 280 Returns true if option has only name - no value. 281 282 Returns: true if option has no value 259 283 **************************************************************************/ 260 284 override bool isZeroTokens() { … … 324 348 325 349 /*************************************************************************** 350 See: ValueSemantic 351 352 Returns: typeid of T 326 353 **************************************************************************/ 327 354 override TypeInfo type() { … … 337 364 //------------------------------------------------------------------------------ 338 365 339 /** Creates a TypedValue<T> instance. This function is the primary 340 method to create ValueSemantic instance for a specific type, which 341 can later be passed to 'StandardOption's destructor. 342 The second overload is used when it's additionally desired to store the 343 value of option into program variable. 344 */ 345 366 /******************************************************************************* 367 Creates a TypedValue!(T) instance. This function is the primary 368 method to create ValueSemantic instance for a specific type. 369 ******************************************************************************/ 346 370 TypedValue!(T, PARSER, STRINGIZER) define(T, alias PARSER = parseText, alias STRINGIZER = stringizeValue)(char[] pattern=null) { 347 371 return new TypedValue!(T, PARSER)(pattern); … … 350 374 //------------------------------------------------------------------------------ 351 375 352 /** Works the same way as the 'value<bool>' function, but the created 376 /******************************************************************************* 377 Works the same way as the 'define!(bool)' function, but the created 353 378 ValueSemantic won't accept any explicit value. So, if the option 354 379 is present on the command line, the value will be 'true'. 355 */380 ******************************************************************************/ 356 381 TypedValue!(bool) boolSwitch() { 357 382 auto r = new TypedValue!(bool)();
