Changeset 1515
- Timestamp:
- 24/08/10 11:23:06 (18 months ago)
- Location:
- trunk/third_party/tclap
- Files:
-
- 9 added
- 18 edited
-
AUTHORS (modified) (1 diff)
-
Arg.h (modified) (31 diffs)
-
ArgException.h (modified) (3 diffs)
-
ArgTraits.h (added)
-
ChangeLog (added)
-
CmdLine.h (modified) (23 diffs)
-
CmdLineInterface.h (modified) (2 diffs)
-
CmdLineOutput.h (modified) (1 diff)
-
Constraint.h (added)
-
DocBookOutput.h (modified) (4 diffs)
-
HelpVisitor.h (modified) (1 diff)
-
Makefile.am (modified) (1 diff)
-
MultiArg.h (modified) (12 diffs)
-
MultiSwitchArg.h (added)
-
NEWS (added)
-
OptionalUnlabeledTracker.h (added)
-
StandardTraits.h (added)
-
StdOutput.h (modified) (8 diffs)
-
SwitchArg.h (modified) (10 diffs)
-
UnlabeledMultiArg.h (modified) (18 diffs)
-
UnlabeledValueArg.h (modified) (19 diffs)
-
ValueArg.h (modified) (18 diffs)
-
ValuesConstraint.h (added)
-
VersionVisitor.h (modified) (2 diffs)
-
Visitor.h (modified) (1 diff)
-
XorHandler.h (modified) (3 diffs)
-
ZshCompletionOutput.h (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/third_party/tclap/AUTHORS
r857 r1515 2 2 original author: Michael E. Smoot 3 3 invaluable contributions: Daniel Aarno 4 more contributions: Erik Zeek 5 more contributions: Fabien Carmagnac (Tinbergen-AM) 4 6 outstanding editing: Carol Smoot -
trunk/third_party/tclap/Arg.h
r857 r1515 1 2 /****************************************************************************** 3 * 1 // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 2 3 /****************************************************************************** 4 * 4 5 * file: Arg.h 5 * 6 * 6 7 * Copyright (c) 2003, Michael E. Smoot . 7 8 * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno . 8 9 * All rights reverved. 9 * 10 * 10 11 * See the file COPYING in the top directory of this distribution for 11 12 * more information. 12 * 13 * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 * DEALINGS IN THE SOFTWARE. 20 * 21 *****************************************************************************/ 13 * 14 * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 * DEALINGS IN THE SOFTWARE. 21 * 22 *****************************************************************************/ 22 23 23 24 24 25 #ifndef TCLAP_ARGUMENT_H 25 26 #define TCLAP_ARGUMENT_H 27 28 #ifdef ___HAVE_CONFIG_H 29 #include <config.h> 30 #else 31 #define HAVE_SSTREAM 32 #endif 26 33 27 34 #include <string> … … 29 36 #include <list> 30 37 #include <iostream> 38 #include <iomanip> 39 #include <cstdio> 40 41 #if defined(HAVE_SSTREAM) 42 #include <sstream> 43 typedef std::istringstream istringstream; 44 #elif defined(HAVE_STRSTREAM) 45 #include <strstream> 46 typedef std::istrstream istringstream; 47 #else 48 #error "Need a stringstream (sstream or strstream) to compile!" 49 #endif 31 50 32 51 #include <tclap/ArgException.h> 33 52 #include <tclap/Visitor.h> 34 53 #include <tclap/CmdLineInterface.h> 54 #include <tclap/ArgTraits.h> 55 #include <tclap/StandardTraits.h> 35 56 36 57 namespace TCLAP { 37 58 38 /** 59 /** 39 60 * A virtual base class that defines the essential data for all arguments. 40 61 * This class, or one of its existing children, must be subclassed to do 41 * anything. 62 * anything. 42 63 */ 43 64 class Arg 44 65 { 45 private: 66 private: 46 67 47 68 /** … … 54 75 * value. 55 76 */ 56 static char& delimiterRef() { static char delim = ' '; return delim; } 77 static char& delimiterRef() { static char delim = ' '; return delim; } 57 78 58 79 protected: 59 80 60 /** 81 /** 61 82 * The single char flag used to identify the argument. 62 * This value (preceded by a dash {-}), can be used to identify 63 * an argument on the command line. The _flag can be blank, 83 * This value (preceded by a dash {-}), can be used to identify 84 * an argument on the command line. The _flag can be blank, 64 85 * in fact this is how unlabeled args work. Unlabeled args must 65 * override appropriate functions to get correct handling. Note 86 * override appropriate functions to get correct handling. Note 66 87 * that the _flag does NOT include the dash as part of the flag. 67 88 */ … … 70 91 /** 71 92 * A single work namd indentifying the argument. 72 * This value (preceded by two dashed {--}) can also be used 93 * This value (preceded by two dashed {--}) can also be used 73 94 * to identify an argument on the command line. Note that the 74 95 * _name does NOT include the two dashes as part of the _name. The … … 78 99 79 100 /** 80 * Description of the argument. 101 * Description of the argument. 81 102 */ 82 103 std::string _description; 83 104 84 /** 105 /** 85 106 * Indicating whether the argument is required. 86 107 */ … … 88 109 89 110 /** 90 * Label to be used in usage description. Normally set to 111 * Label to be used in usage description. Normally set to 91 112 * "required", but can be changed when necessary. 92 113 */ … … 126 147 bool _xorSet; 127 148 149 bool _acceptsMultipleValues; 150 128 151 /** 129 152 * Performs the special handling described by the Vistitor. … … 132 155 133 156 /** 134 * Primary constructor. YOU (yes you) should NEVER construct an Arg 157 * Primary constructor. YOU (yes you) should NEVER construct an Arg 135 158 * directly, this is a base class that is extended by various children 136 * that are meant to be used. Use SwitchArg, ValueArg, MultiArg, 159 * that are meant to be used. Use SwitchArg, ValueArg, MultiArg, 137 160 * UnlabeledValueArg, or UnlabeledMultiArg instead. 138 161 * … … 144 167 * \param v - The visitor checked by the argument. Defaults to NULL. 145 168 */ 146 Arg( const std::string& flag, 147 const std::string& name, 148 const std::string& desc, 149 bool req, 169 Arg( const std::string& flag, 170 const std::string& name, 171 const std::string& desc, 172 bool req, 150 173 bool valreq, 151 174 Visitor* v = NULL ); … … 162 185 */ 163 186 virtual void addToList( std::list<Arg*>& argList ) const; 164 187 165 188 /** 166 189 * Begin ignoring arguments since the "--" argument was specified. 167 190 */ 168 191 static void beginIgnoring() { ignoreRestRef() = true; } 169 192 170 193 /** 171 194 * Whether to ignore the rest. … … 177 200 * value. 178 201 */ 179 static char delimiter() { return delimiterRef(); } 180 202 static char delimiter() { return delimiterRef(); } 203 181 204 /** 182 205 * The char used as a place holder when SwitchArgs are combined. 183 * Currently set to '*', which shouldn't cause many problems since 184 * *'s are expanded by most shells on the command line. 185 */ 186 static const char blankChar() { return '*'; } 187 206 * Currently set to the bell char (ASCII 7). 207 */ 208 static char blankChar() { return (char)7; } 209 188 210 /** 189 211 * The char that indicates the beginning of a flag. Currently '-'. 190 212 */ 191 static c onst char flagStartChar() { return '-'; }192 213 static char flagStartChar() { return '-'; } 214 193 215 /** 194 216 * The sting that indicates the beginning of a flag. Currently "-". … … 196 218 */ 197 219 static const std::string flagStartString() { return "-"; } 198 220 199 221 /** 200 222 * The sting that indicates the beginning of a name. Currently "--". … … 216 238 /** 217 239 * Pure virtual method meant to handle the parsing and value assignment 218 * of the string on the command line. 240 * of the string on the command line. 219 241 * \param i - Pointer the the current argument in the list. 220 * \param args - Mutable list of strings. What is 242 * \param args - Mutable list of strings. What is 221 243 * passed in from main. 222 244 */ 223 virtual bool processArg(int *i, std::vector<std::string>& args) = 0; 245 virtual bool processArg(int *i, std::vector<std::string>& args) = 0; 224 246 225 247 /** … … 228 250 * \param a - The Arg to be compared to this. 229 251 */ 230 virtual bool operator==(const Arg& a) ;252 virtual bool operator==(const Arg& a) const; 231 253 232 254 /** … … 274 296 275 297 /** 276 * Indicates whether the argument can be ignored, if desired. 298 * Indicates whether the argument can be ignored, if desired. 277 299 */ 278 300 bool isIgnoreable() const; … … 281 303 * A method that tests whether a string matches this argument. 282 304 * This is generally called by the processArg() method. This 283 * method could be re-implemented by a child to change how 305 * method could be re-implemented by a child to change how 284 306 * arguments are specified on the command line. 285 307 * \param s - The string to be compared to the flag/name to determine … … 308 330 /** 309 331 * Trims a value off of the flag. 310 * \param flag - The string from which the flag and value will be 311 * trimmed. Contains the flag once the value has been trimmed. 332 * \param flag - The string from which the flag and value will be 333 * trimmed. Contains the flag once the value has been trimmed. 312 334 * \param value - Where the value trimmed from the string will 313 335 * be stored. … … 330 352 void setRequireLabel( const std::string& s ); 331 353 354 /** 355 * Used for MultiArgs and XorHandler to determine whether args 356 * can still be set. 357 */ 358 virtual bool allowMore(); 359 360 /** 361 * Use by output classes to determine whether an Arg accepts 362 * multiple values. 363 */ 364 virtual bool acceptsMultipleValues(); 365 366 /** 367 * Clears the Arg object and allows it to be reused by new 368 * command lines. 369 */ 370 virtual void reset(); 332 371 }; 333 372 … … 347 386 typedef std::list<Visitor*>::iterator VisitorListIterator; 348 387 388 /* 389 * Extract a value of type T from it's string representation contained 390 * in strVal. The ValueLike parameter used to select the correct 391 * specialization of ExtractValue depending on the value traits of T. 392 * ValueLike traits use operator>> to assign the value from strVal. 393 */ 394 template<typename T> void 395 ExtractValue(T &destVal, const std::string& strVal, ValueLike vl) 396 { 397 static_cast<void>(vl); // Avoid warning about unused vl 398 std::istringstream is(strVal); 399 400 int valuesRead = 0; 401 while ( is.good() ) { 402 if ( is.peek() != EOF ) 403 #ifdef TCLAP_SETBASE_ZERO 404 is >> std::setbase(0) >> destVal; 405 #else 406 is >> destVal; 407 #endif 408 else 409 break; 410 411 valuesRead++; 412 } 413 414 if ( is.fail() ) 415 throw( ArgParseException("Couldn't read argument value " 416 "from string '" + strVal + "'")); 417 418 419 if ( valuesRead > 1 ) 420 throw( ArgParseException("More than one valid value parsed from " 421 "string '" + strVal + "'")); 422 423 } 424 425 /* 426 * Extract a value of type T from it's string representation contained 427 * in strVal. The ValueLike parameter used to select the correct 428 * specialization of ExtractValue depending on the value traits of T. 429 * StringLike uses assignment (operator=) to assign from strVal. 430 */ 431 template<typename T> void 432 ExtractValue(T &destVal, const std::string& strVal, StringLike sl) 433 { 434 static_cast<void>(sl); // Avoid warning about unused sl 435 SetString(destVal, strVal); 436 } 349 437 350 438 ////////////////////////////////////////////////////////////////////// … … 352 440 ////////////////////////////////////////////////////////////////////// 353 441 354 inline Arg::Arg(const std::string& flag, 355 const std::string& name, 356 const std::string& desc, 357 bool req, 442 inline Arg::Arg(const std::string& flag, 443 const std::string& name, 444 const std::string& desc, 445 bool req, 358 446 bool valreq, 359 447 Visitor* v) : … … 367 455 _visitor( v ), 368 456 _ignoreable(true), 369 _xorSet(false) 370 { 371 if ( _flag.length() > 1 ) 457 _xorSet(false), 458 _acceptsMultipleValues(false) 459 { 460 if ( _flag.length() > 1 ) 372 461 throw(SpecificationException( 373 462 "Argument flag can only be one character long", toString() ) ); 374 463 375 if ( _name != ignoreNameString() && 376 ( _flag == Arg::flagStartString() || 377 _flag == Arg::nameStartString() || 464 if ( _name != ignoreNameString() && 465 ( _flag == Arg::flagStartString() || 466 _flag == Arg::nameStartString() || 378 467 _flag == " " ) ) 379 throw(SpecificationException("Argument flag cannot be either '" + 380 Arg::flagStartString() + "' or '" + 468 throw(SpecificationException("Argument flag cannot be either '" + 469 Arg::flagStartString() + "' or '" + 381 470 Arg::nameStartString() + "' or a space.", 382 471 toString() ) ); 383 472 384 if ( ( _name. find( Arg::flagStartString(), 0 ) != std::string::npos ) ||385 ( _name. find( Arg::nameStartString(), 0 ) != std::string::npos) ||473 if ( ( _name.substr( 0, Arg::flagStartString().length() ) == Arg::flagStartString() ) || 474 ( _name.substr( 0, Arg::nameStartString().length() ) == Arg::nameStartString() ) || 386 475 ( _name.find( " ", 0 ) != std::string::npos ) ) 387 throw(SpecificationException("Argument name cannot contain either '" +388 Arg::flagStartString() + "' or '" + 476 throw(SpecificationException("Argument name begin with either '" + 477 Arg::flagStartString() + "' or '" + 389 478 Arg::nameStartString() + "' or space.", 390 479 toString() ) ); … … 403 492 id = Arg::nameStartString() + _name; 404 493 405 std::string delim = " ";406 delim[0] = Arg::delimiter(); // ugly!!!407 408 494 if ( _valueRequired ) 409 id += delim+ "<" + valueId + ">";495 id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">"; 410 496 411 497 if ( !_required ) … … 424 510 425 511 if ( _valueRequired ) 426 id += "<" + valueId + ">";427 512 id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">"; 513 428 514 id += ", "; 429 515 } … … 432 518 433 519 if ( _valueRequired ) 434 id += "<" + valueId + ">";435 520 id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">"; 521 436 522 return id; 437 523 438 524 } 439 525 440 inline bool Arg::operator==(const Arg& a) 441 { 442 if ( ( _flag != "" && _flag == a._flag ) || 443 _name == a._name || 444 _description == a._description ) 526 inline bool Arg::operator==(const Arg& a) const 527 { 528 if ( ( _flag != "" && _flag == a._flag ) || _name == a._name) 445 529 return true; 446 530 else … … 448 532 } 449 533 450 inline std::string Arg::getDescription() const 534 inline std::string Arg::getDescription() const 451 535 { 452 536 std::string desc = ""; … … 454 538 desc = "(" + _requireLabel + ") "; 455 539 456 if ( _valueRequired )457 desc += "(value required) ";540 // if ( _valueRequired ) 541 // desc += "(value required) "; 458 542 459 543 desc += _description; 460 return desc; 544 return desc; 461 545 } 462 546 463 547 inline const std::string& Arg::getFlag() const { return _flag; } 464 548 465 inline const std::string& Arg::getName() const { return _name; } 549 inline const std::string& Arg::getName() const { return _name; } 466 550 467 551 inline bool Arg::isRequired() const { return _required; } … … 469 553 inline bool Arg::isValueRequired() const { return _valueRequired; } 470 554 471 inline bool Arg::isSet() const 472 { 555 inline bool Arg::isSet() const 556 { 473 557 if ( _alreadySet && !_xorSet ) 474 558 return true; … … 479 563 inline bool Arg::isIgnoreable() const { return _ignoreable; } 480 564 481 inline void Arg::setRequireLabel( const std::string& s) 482 { 565 inline void Arg::setRequireLabel( const std::string& s) 566 { 483 567 _requireLabel = s; 484 568 } … … 517 601 { 518 602 int stop = 0; 519 for ( int i = 0; (unsigned int)i< flag.length(); i++ )603 for ( int i = 0; static_cast<unsigned int>(i) < flag.length(); i++ ) 520 604 if ( flag[i] == Arg::delimiter() ) 521 605 { … … 537 621 inline bool Arg::_hasBlanks( const std::string& s ) const 538 622 { 539 for ( int i = 1; (unsigned int)i< s.length(); i++ )623 for ( int i = 1; static_cast<unsigned int>(i) < s.length(); i++ ) 540 624 if ( s[i] == Arg::blankChar() ) 541 625 return true; … … 560 644 inline void Arg::addToList( std::list<Arg*>& argList ) const 561 645 { 562 argList.push_front( (Arg*)this ); 646 argList.push_front( const_cast<Arg*>(this) ); 647 } 648 649 inline bool Arg::allowMore() 650 { 651 return false; 652 } 653 654 inline bool Arg::acceptsMultipleValues() 655 { 656 return _acceptsMultipleValues; 657 } 658 659 inline void Arg::reset() 660 { 661 _xorSet = false; 662 _alreadySet = false; 563 663 } 564 664 -
trunk/third_party/tclap/ArgException.h
r857 r1515 1 // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 1 2 2 3 /****************************************************************************** … … 79 80 const char* what() const throw() 80 81 { 81 std::string ex = _argId + " -- " + _errorText; 82 static std::string ex; 83 ex = _argId + " -- " + _errorText; 82 84 return ex.c_str(); 83 85 } … … 183 185 }; 184 186 187 class ExitException { 188 public: 189 ExitException(int estat) : _estat(estat) {} 190 191 int getExitStatus() const { return _estat; } 192 193 private: 194 int _estat; 195 }; 196 185 197 } // namespace TCLAP 186 198 -
trunk/third_party/tclap/CmdLine.h
r857 r1515 1 2 /****************************************************************************** 3 * 1 // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 2 3 /****************************************************************************** 4 * 4 5 * file: CmdLine.h 5 * 6 * 6 7 * Copyright (c) 2003, Michael E. Smoot . 7 8 * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. 8 9 * All rights reverved. 9 * 10 * 10 11 * See the file COPYING in the top directory of this distribution for 11 12 * more information. 12 * 13 * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 * DEALINGS IN THE SOFTWARE. 20 * 21 *****************************************************************************/ 13 * 14 * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 * DEALINGS IN THE SOFTWARE. 21 * 22 *****************************************************************************/ 22 23 23 24 #ifndef TCLAP_CMDLINE_H … … 25 26 26 27 #include <tclap/SwitchArg.h> 28 #include <tclap/MultiSwitchArg.h> 27 29 #include <tclap/UnlabeledValueArg.h> 28 30 #include <tclap/UnlabeledMultiArg.h> … … 35 37 #include <tclap/CmdLineOutput.h> 36 38 #include <tclap/StdOutput.h> 39 40 #include <tclap/Constraint.h> 41 #include <tclap/ValuesConstraint.h> 37 42 38 43 #include <string> … … 42 47 #include <iomanip> 43 48 #include <algorithm> 49 #include <stdlib.h> // Needed for exit(), which isn't defined in some envs. 44 50 45 51 namespace TCLAP { 52 53 template<typename T> void DelPtr(T ptr) 54 { 55 delete ptr; 56 } 57 58 template<typename C> void ClearContainer(C &c) 59 { 60 typedef typename C::value_type value_type; 61 std::for_each(c.begin(), c.end(), DelPtr<value_type>); 62 c.clear(); 63 } 64 46 65 47 66 /** … … 75 94 76 95 /** 77 * The number of arguments that are required to be present on 78 * the command line. This is set dynamically, based on the 96 * The number of arguments that are required to be present on 97 * the command line. This is set dynamically, based on the 79 98 * Args added to the CmdLine object. 80 99 */ … … 82 101 83 102 /** 84 * The character that is used to separate the argument flag/name 103 * The character that is used to separate the argument flag/name 85 104 * from the value. Defaults to ' ' (space). 86 105 */ … … 110 129 */ 111 130 CmdLineOutput* _output; 131 132 /** 133 * Should CmdLine handle parsing exceptions internally? 134 */ 135 bool _handleExceptions; 136 137 /** 138 * Throws an exception listing the missing args. 139 */ 140 void missingArgsException(); 112 141 113 142 /** … … 119 148 bool _emptyCombined(const std::string& s); 120 149 121 private: 122 123 /** 124 * Encapsulates the code common to the constructors (which is all 125 * of it). 150 /** 151 * Perform a delete ptr; operation on ptr when this object is deleted. 152 */ 153 void deleteOnExit(Arg* ptr); 154 155 /** 156 * Perform a delete ptr; operation on ptr when this object is deleted. 157 */ 158 void deleteOnExit(Visitor* ptr); 159 160 private: 161 162 /** 163 * Encapsulates the code common to the constructors 164 * (which is all of it). 126 165 */ 127 166 void _constructor(); 128 167 129 /**130 * Perform a delete ptr; operation on ptr when this object is deleted.131 */132 void deleteOnExit(Arg* ptr);133 134 /**135 * Perform a delete ptr; operation on ptr when this object is deleted.136 */137 void deleteOnExit(Visitor* ptr);138 168 139 169 /** … … 143 173 bool _userSetOutput; 144 174 175 /** 176 * Whether or not to automatically create help and version switches. 177 */ 178 bool _helpAndVersion; 179 145 180 public: 146 147 /**148 * Command line constructor. DEPRECATED!!! This is here to maintain149 * backwards compatibility with earlier releases. Note that the150 * program name will be overwritten with argv[0]. The delimiter151 * used is ' ' (as before).152 * \param name - The program name - will be overwritten with argv[0].153 * \param message - The message to be used in the usage output.154 * \param version - The version number to be used in the155 * --version switch.156 */157 CmdLine(const std::string& name,158 const std::string& message,159 const std::string& version = "none" );160 181 161 182 /** … … 168 189 * \param version - The version number to be used in the 169 190 * --version switch. 170 */ 171 CmdLine(const std::string& message, 191 * \param helpAndVersion - Whether or not to create the Help and 192 * Version switches. Defaults to true. 193 */ 194 CmdLine(const std::string& message, 172 195 const char delimiter = ' ', 173 const std::string& version = "none" ); 174 196 const std::string& version = "none", 197 bool helpAndVersion = true); 198 175 199 /** 176 200 * Deletes any resources allocated by a CmdLine object. … … 180 204 /** 181 205 * Adds an argument to the list of arguments to be parsed. 182 * \param a - Argument to be added. 206 * \param a - Argument to be added. 183 207 */ 184 208 void add( Arg& a ); … … 186 210 /** 187 211 * An alternative add. Functionally identical. 188 * \param a - Argument to be added. 212 * \param a - Argument to be added. 189 213 */ 190 214 void add( Arg* a ); … … 193 217 * Add two Args that will be xor'd. If this method is used, add does 194 218 * not need to be called. 195 * \param a - Argument to be added and xor'd. 196 * \param b - Argument to be added and xor'd. 219 * \param a - Argument to be added and xor'd. 220 * \param b - Argument to be added and xor'd. 197 221 */ 198 222 void xorAdd( Arg& a, Arg& b ); 199 223 200 224 /** 201 * Add a list of Args that will be xor'd. If this method is used, 225 * Add a list of Args that will be xor'd. If this method is used, 202 226 * add does not need to be called. 203 * \param xors - List of Args to be added and xor'd. 227 * \param xors - List of Args to be added and xor'd. 204 228 */ 205 229 void xorAdd( std::vector<Arg*>& xors ); … … 210 234 * \param argv - Array of arguments. 211 235 */ 212 void parse(int argc, char** argv); 236 void parse(int argc, const char * const * argv); 237 238 /** 239 * Parses the command line. 240 * \param args - A vector of strings representing the args. 241 * args[0] is still the program name. 242 */ 243 void parse(std::vector<std::string>& args); 213 244 214 245 /** … … 251 282 */ 252 283 std::string& getMessage(); 284 285 /** 286 * 287 */ 288 bool hasHelpAndVersion(); 289 290 /** 291 * Disables or enables CmdLine's internal parsing exception handling. 292 * 293 * @param state Should CmdLine handle parsing exceptions internally? 294 */ 295 void setExceptionHandling(const bool state); 296 297 /** 298 * Returns the current state of the internal exception handling. 299 * 300 * @retval true Parsing exceptions are handled internally. 301 * @retval false Parsing exceptions are propagated to the caller. 302 */ 303 bool getExceptionHandling() const; 304 305 /** 306 * Allows the CmdLine object to be reused. 307 */ 308 void reset(); 309 253 310 }; 254 311 … … 258 315 /////////////////////////////////////////////////////////////////////////////// 259 316 260 inline CmdLine::CmdLine(const std::string& n, 261 const std::string& m, 262 const std::string& v ) 263 : _progName(n), 264 _message(m), 265 _version(v), 266 _numRequired(0), 267 _delimiter(' '), 268 _userSetOutput(false) 269 { 270 _constructor(); 271 } 272 273 inline CmdLine::CmdLine(const std::string& m, 274 char delim, 275 const std::string& v ) 317 inline CmdLine::CmdLine(const std::string& m, 318 char delim, 319 const std::string& v, 320 bool help ) 276 321 : _progName("not_set_yet"), 277 322 _message(m), … … 279 324 _numRequired(0), 280 325 _delimiter(delim), 281 _userSetOutput(false) 326 _handleExceptions(true), 327 _userSetOutput(false), 328 _helpAndVersion(help) 282 329 { 283 330 _constructor(); … … 286 333 inline CmdLine::~CmdLine() 287 334 { 288 ArgListIterator argIter; 289 VisitorListIterator visIter; 290 291 for( argIter = _argDeleteOnExitList.begin(); 292 argIter != _argDeleteOnExitList.end(); 293 ++argIter) 294 delete *argIter; 295 296 for( visIter = _visitorDeleteOnExitList.begin(); 297 visIter != _visitorDeleteOnExitList.end(); 298 ++visIter) 299 delete *visIter; 300 301 if ( !_userSetOutput ) 335 ClearContainer(_argDeleteOnExitList); 336 ClearContainer(_visitorDeleteOnExitList); 337 338 if ( !_userSetOutput ) { 302 339 delete _output; 340 _output = 0; 341 } 303 342 } 304 343 305 344 inline void CmdLine::_constructor() 306 { 345 { 307 346 _output = new StdOutput; 308 347 309 Visitor *v;310 311 348 Arg::setDelimiter( _delimiter ); 312 349 313 v = new HelpVisitor( this, &_output ); 314 SwitchArg* help = new SwitchArg("h","help", 315 "Displays usage information and exits.", 350 Visitor* v; 351 352 if ( _helpAndVersion ) 353 { 354 v = new HelpVisitor( this, &_output ); 355 SwitchArg* help = new SwitchArg("h","help", 356 "Displays usage information and exits.", 357 false, v); 358 add( help ); 359 deleteOnExit(help); 360 deleteOnExit(v); 361 362 v = new VersionVisitor( this, &_output ); 363 SwitchArg* vers = new SwitchArg("","version", 364 "Displays version information and exits.", 316 365 false, v); 317 add( help ); 318 deleteOnExit(help); 319 deleteOnExit(v); 320 321 v = new VersionVisitor( this, &_output ); 322 SwitchArg* vers = new SwitchArg("v","version", 323 "Displays version information and exits.", 324 false, v); 325 add( vers ); 326 deleteOnExit(vers); 327 deleteOnExit(v); 366 add( vers ); 367 deleteOnExit(vers); 368 deleteOnExit(v); 369 } 328 370 329 371 v = new IgnoreRestVisitor(); 330 SwitchArg* ignore = new SwitchArg(Arg::flagStartString(), 372 SwitchArg* ignore = new SwitchArg(Arg::flagStartString(), 331 373 Arg::ignoreNameString(), 332 374 "Ignores the rest of the labeled arguments following this flag.", … … 350 392 } 351 393 352 inline void CmdLine::xorAdd( Arg& a, Arg& b ) 394 inline void CmdLine::xorAdd( Arg& a, Arg& b ) 353 395 { 354 396 std::vector<Arg*> ors; … … 358 400 } 359 401 360 inline void CmdLine::add( Arg& a ) 361 { 402 inline void CmdLine::add( Arg& a ) 403 { 362 404 add( &a ); 363 405 } 364 406 365 inline void CmdLine::add( Arg* a ) 366 { 367 for( ArgListIterator it = _argList.begin(); it != _argList.end(); it++ ) 368 if ( *a == *(*it) ) 369 throw( SpecificationException( 370 "Argument with same flag/name already exists!", 407 inline void CmdLine::add( Arg* a ) 408 { 409 for( ArgListIterator it = _argList.begin(); it != _argList.end(); it++ ) 410 if ( *a == *(*it) ) 411 throw( SpecificationException( 412 "Argument with same flag/name already exists!", 371 413 a->longID() ) ); 372 414 373 415 a->addToList( _argList ); 374 416 375 if ( a->isRequired() ) 376 _numRequired++; 377 } 378 379 inline void CmdLine::parse(int argc, char** argv) 380 { 417 if ( a->isRequired() ) 418 _numRequired++; 419 } 420 421 422 inline void CmdLine::parse(int argc, const char * const * argv) 423 { 424 // this step is necessary so that we have easy access to 425 // mutable strings. 426 std::vector<std::string> args; 427 for (int i = 0; i < argc; i++) 428 args.push_back(argv[i]); 429 430 parse(args); 431 } 432 433 inline void CmdLine::parse(std::vector<std::string>& args) 434 { 435 bool shouldExit = false; 436 int estat = 0; 437 381 438 try { 382 383 _progName = argv[0]; 384 385 // this step is necessary so that we have easy access to mutable strings. 386 std::vector<std::string> args; 387 for (int i = 1; i < argc; i++) 388 args.push_back(argv[i]); 389 390 int requiredCount = 0; 391 392 for (int i = 0; (unsigned int)i < args.size(); i++) 393 { 394 bool matched = false; 395 for (ArgListIterator it = _argList.begin(); it != _argList.end(); it++) 396 { 397 if ( (*it)->processArg( &i, args ) ) 398 { 399 requiredCount += _xorHandler.check( *it ); 439 _progName = args.front(); 440 args.erase(args.begin()); 441 442 int requiredCount = 0; 443 444 for (int i = 0; static_cast<unsigned int>(i) < args.size(); i++) { 445 bool matched = false; 446 for (ArgListIterator it = _argList.begin(); 447 it != _argList.end(); it++) { 448 if ( (*it)->processArg( &i, args ) ) 449 { 450 requiredCount += _xorHandler.check( *it ); 451 matched = true; 452 break; 453 } 454 } 455 456 // checks to see if the argument is an empty combined 457 // switch and if so, then we've actually matched it 458 if ( !matched && _emptyCombined( args[i] ) ) 400 459 matched = true; 401 break; 402 } 403 } 404 405 // checks to see if the argument is an empty combined switch ... 406 // and if so, then we've actually matched it 407 if ( !matched && _emptyCombined( args[i] ) ) 408 matched = true; 409 410 if ( !matched && !Arg::ignoreRest() ) 411 throw(CmdLineParseException("Couldn't find match for argument", 412 args[i])); 413 } 414 415 if ( requiredCount < _numRequired ) 416 throw(CmdLineParseException("One or more required arguments missing!")); 417 418 if ( requiredCount > _numRequired ) 419 throw(CmdLineParseException("Too many arguments!")); 420 421 } catch ( ArgException e ) { _output->failure(*this,e); exit(1); } 460 461 if ( !matched && !Arg::ignoreRest() ) 462 throw(CmdLineParseException("Couldn't find match " 463 "for argument", 464 args[i])); 465 } 466 467 if ( requiredCount < _numRequired ) 468 missingArgsException(); 469 470 if ( requiredCount > _numRequired ) 471 throw(CmdLineParseException("Too many arguments!")); 472 473 } catch ( ArgException& e ) { 474 // If we're not handling the exceptions, rethrow. 475 if ( !_handleExceptions) { 476 throw; 477 } 478 479 try { 480 _output->failure(*this,e); 481 } catch ( ExitException &ee ) { 482 estat = ee.getExitStatus(); 483 shouldExit = true; 484 } 485 } catch (ExitException &ee) { 486 // If we're not handling the exceptions, rethrow. 487 if ( !_handleExceptions) { 488 throw; 489 } 490 491 estat = ee.getExitStatus(); 492 shouldExit = true; 493 } 494 495 if (shouldExit) 496 exit(estat); 422 497 } 423 498 424 499 inline bool CmdLine::_emptyCombined(const std::string& s) 425 500 { 426 if ( s [0] != Arg::flagStartChar() )501 if ( s.length() > 0 && s[0] != Arg::flagStartChar() ) 427 502 return false; 428 503 429 for ( int i = 1; (unsigned int)i< s.length(); i++ )504 for ( int i = 1; static_cast<unsigned int>(i) < s.length(); i++ ) 430 505 if ( s[i] != Arg::blankChar() ) 431 506 return false; … … 434 509 } 435 510 511 inline void CmdLine::missingArgsException() 512 { 513 int count = 0; 514 515 std::string missingArgList; 516 for (ArgListIterator it = _argList.begin(); it != _argList.end(); it++) 517 { 518 if ( (*it)->isRequired() && !(*it)->isSet() ) 519 { 520 missingArgList += (*it)->getName(); 521 missingArgList += ", "; 522 count++; 523 } 524 } 525 missingArgList = missingArgList.substr(0,missingArgList.length()-2); 526 527 std::string msg; 528 if ( count > 1 ) 529 msg = "Required arguments missing: "; 530 else 531 msg = "Required argument missing: "; 532 533 msg += missingArgList; 534 535 throw(CmdLineParseException(msg)); 536 } 537 436 538 inline void CmdLine::deleteOnExit(Arg* ptr) 437 539 { … … 483 585 { 484 586 return _message; 587 } 588 589 inline bool CmdLine::hasHelpAndVersion() 590 { 591 return _helpAndVersion; 592 } 593 594 inline void CmdLine::setExceptionHandling(const bool state) 595 { 596 _handleExceptions = state; 597 } 598 599 inline bool CmdLine::getExceptionHandling() const 600 { 601 return _handleExceptions; 602 } 603 604 inline void CmdLine::reset() 605 { 606 for( ArgListIterator it = _argList.begin(); it != _argList.end(); it++ ) 607 { 608 (*it)->reset(); 609 } 610 611 _progName.clear(); 485 612 } 486 613 … … 492 619 493 620 } //namespace TCLAP 494 #endif 621 #endif -
trunk/third_party/tclap/CmdLineInterface.h
r857 r1515 83 83 * \param argv - Array of arguments. 84 84 */ 85 virtual void parse(int argc, char** argv)=0; 85 virtual void parse(int argc, const char * const * argv)=0; 86 87 /** 88 * Parses the command line. 89 * \param args - A vector of strings representing the args. 90 * args[0] is still the program name. 91 */ 92 void parse(std::vector<std::string>& args); 86 93 87 94 /** … … 124 131 */ 125 132 virtual std::string& getMessage()=0; 133 134 /** 135 * Indicates whether or not the help and version switches were created 136 * automatically. 137 */ 138 virtual bool hasHelpAndVersion()=0; 139 140 /** 141 * Resets the instance as if it had just been constructed so that the 142 * instance can be reused. 143 */ 144 virtual void reset()=0; 126 145 }; 127 146 -
trunk/third_party/tclap/CmdLineOutput.h
r857 r1515 43 43 44 44 public: 45 46 /** 47 * Virtual destructor. 48 */ 49 virtual ~CmdLineOutput() {} 50 45 51 /** 46 52 * Generates some sort of output for the USAGE. -
trunk/third_party/tclap/DocBookOutput.h
r857 r1515 1 // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 1 2 2 3 /****************************************************************************** … … 77 78 */ 78 79 void substituteSpecialChars( std::string& s, char r, std::string& x ); 80 void removeChar( std::string& s, char r); 81 void basename( std::string& s ); 82 83 void printShortArg(Arg* it); 84 void printLongArg(Arg* it); 85 86 char theDelimiter; 79 87 }; 80 88 … … 89 97 std::list<Arg*> argList = _cmd.getArgList(); 90 98 std::string progName = _cmd.getProgramName(); 99 std::string version = _cmd.getVersion(); 100 theDelimiter = _cmd.getDelimiter(); 91 101 XorHandler xorHandler = _cmd.getXorHandler(); 92 102 std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList(); 93 103 basename(progName); 94 104 95 105 std::cout << "<?xml version='1.0'?>" << std::endl; 96 std::cout << "<!DOCTYPE book PUBLIC \"-//Norman Walsh//DTD DocBk XML V4.2//EN\"" << std::endl;106 std::cout << "<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.2//EN\"" << std::endl; 97 107 std::cout << "\t\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\">" << std::endl << std::endl; 98 108 99 std::cout << "<book>" << std::endl; 109 std::cout << "<refentry>" << std::endl; 110 111 std::cout << "<refmeta>" << std::endl; 112 std::cout << "<refentrytitle>" << progName << "</refentrytitle>" << std::endl; 113 std::cout << "<manvolnum>1</manvolnum>" << std::endl; 114 std::cout << "</refmeta>" << std::endl; 115 116 std::cout << "<refnamediv>" << std::endl; 117 std::cout << "<refname>" << progName << "</refname>" << std::endl; 118 std::cout << "<refpurpose>" << _cmd.getMessage() << "</refpurpose>" << std::endl; 119 std::cout << "</refnamediv>" << std::endl; 120 121 std::cout << "<refsynopsisdiv>" << std::endl; 100 122 std::cout << "<cmdsynopsis>" << std::endl; 101 123 102 124 std::cout << "<command>" << progName << "</command>" << std::endl; 103 104 std::string lt = "<";105 std::string gt = ">";106 125 107 126 // xor 108 127 for ( int i = 0; (unsigned int)i < xorList.size(); i++ ) 109 128 { 110 std::cout << "<group >" << std::endl;129 std::cout << "<group choice='req'>" << std::endl; 111 130 for ( ArgVectorIterator it = xorList[i].begin(); 112 131 it != xorList[i].end(); it++ ) 113 { 114 std::string id = (*it)->shortID(); 115 substituteSpecialChars(id,'<',lt); 116 substituteSpecialChars(id,'>',gt); 117 std::cout << "<arg>" << id << "</arg>" << std::endl; 118 } 132 printShortArg((*it)); 119 133 120 134 std::cout << "</group>" << std::endl; 121 135 } 122 136 137 // rest of args 123 138 for (ArgListIterator it = argList.begin(); it != argList.end(); it++) 124 139 if ( !xorHandler.contains( (*it) ) ) 125 { 126 std::string id = (*it)->shortID(); 127 substituteSpecialChars(id,'<',lt); 128 substituteSpecialChars(id,'>',gt); 129 std::cout << "<arg>" << id << "</arg>" << std::endl; 130 } 140 printShortArg((*it)); 131 141 132 142 std::cout << "</cmdsynopsis>" << std::endl; 133 std::cout << "</book>" << std::endl; 143 std::cout << "</refsynopsisdiv>" << std::endl; 144 145 std::cout << "<refsect1>" << std::endl; 146 std::cout << "<title>Description</title>" << std::endl; 147 std::cout << "<para>" << std::endl; 148 std::cout << _cmd.getMessage() << std::endl; 149 std::cout << "</para>" << std::endl; 150 std::cout << "</refsect1>" << std::endl; 151 152 std::cout << "<refsect1>" << std::endl; 153 std::cout << "<title>Options</title>" << std::endl; 154 155 std::cout << "<variablelist>" << std::endl; 156 157 for (ArgListIterator it = argList.begin(); it != argList.end(); it++) 158 printLongArg((*it)); 159 160 std::cout << "</variablelist>" << std::endl; 161 std::cout << "</refsect1>" << std::endl; 162 163 std::cout << "<refsect1>" << std::endl; 164 std::cout << "<title>Version</title>" << std::endl; 165 std::cout << "<para>" << std::endl; 166 std::cout << version << std::endl; 167 std::cout << "</para>" << std::endl; 168 std::cout << "</refsect1>" << std::endl; 169 170 std::cout << "</refentry>" << std::endl; 134 171 135 172 } 136 173 137 174 inline void DocBookOutput::failure( CmdLineInterface& _cmd, 138 ArgException& e )175 ArgException& e ) 139 176 { 140 std::cout << e.what() << std::endl; 177 static_cast<void>(_cmd); // unused 178 std::cout << e.what() << std::endl; 179 throw ExitException(1); 141 180 } 142 181 … … 153 192 } 154 193 194 inline void DocBookOutput::removeChar( std::string& s, char r) 195 { 196 size_t p; 197 while ( (p = s.find_first_of(r)) != std::string::npos ) 198 { 199 s.erase(p,1); 200 } 201 } 202 203 inline void DocBookOutput::basename( std::string& s ) 204 { 205 size_t p = s.find_last_of('/'); 206 if ( p != std::string::npos ) 207 { 208 s.erase(0, p + 1); 209 } 210 } 211 212 inline void DocBookOutput::printShortArg(Arg* a) 213 { 214 std::string lt = "<"; 215 std::string gt = ">"; 216 217 std::string id = a->shortID(); 218 substituteSpecialChars(id,'<',lt); 219 substituteSpecialChars(id,'>',gt); 220 removeChar(id,'['); 221 removeChar(id,']'); 222 223 std::string choice = "opt"; 224 if ( a->isRequired() ) 225 choice = "plain"; 226 227 std::cout << "<arg choice='" << choice << '\''; 228 if ( a->acceptsMultipleValues() ) 229 std::cout << " rep='repeat'"; 230 231 232 std::cout << '>'; 233 if ( !a->getFlag().empty() ) 234 std::cout << a->flagStartChar() << a->getFlag(); 235 else 236 std::cout << a->nameStartString() << a->getName(); 237 if ( a->isValueRequired() ) 238 { 239 std::string arg = a->shortID(); 240 removeChar(arg,'['); 241 removeChar(arg,']'); 242 removeChar(arg,'<'); 243 removeChar(arg,'>'); 244 arg.erase(0, arg.find_last_of(theDelimiter) + 1); 245 std::cout << theDelimiter; 246 std::cout << "<replaceable>" << arg << "</replaceable>"; 247 } 248 std::cout << "</arg>" << std::endl; 249 250 } 251 252 inline void DocBookOutput::printLongArg(Arg* a) 253 { 254 std::string lt = "<"; 255 std::string gt = ">"; 256 257 std::string desc = a->getDescription(); 258 substituteSpecialChars(desc,'<',lt); 259 substituteSpecialChars(desc,'>',gt); 260 261 std::cout << "<varlistentry>" << std::endl; 262 263 if ( !a->getFlag().empty() ) 264 { 265 std::cout << "<term>" << std::endl; 266 std::cout << "<option>"; 267 std::cout << a->flagStartChar() << a->getFlag(); 268 std::cout << "</option>" << std::endl; 269 std::cout << "</term>" << std::endl; 270 } 271 272 std::cout << "<term>" << std::endl; 273 std::cout << "<option>"; 274 std::cout << a->nameStartString() << a->getName(); 275 if ( a->isValueRequired() ) 276 { 277 std::string arg = a->shortID(); 278 removeChar(arg,'['); 279 removeChar(arg,']'); 280 removeChar(arg,'<'); 281 removeChar(arg,'>'); 282 arg.erase(0, arg.find_last_of(theDelimiter) + 1); 283 std::cout << theDelimiter; 284 std::cout << "<replaceable>" << arg << "</replaceable>"; 285 } 286 std::cout << "</option>" << std::endl; 287 std::cout << "</term>" << std::endl; 288 289 std::cout << "<listitem>" << std::endl; 290 std::cout << "<para>" << std::endl; 291 std::cout << desc << std::endl; 292 std::cout << "</para>" << std::endl; 293 std::cout << "</listitem>" << std::endl; 294 295 std::cout << "</varlistentry>" << std::endl; 296 } 297 155 298 } //namespace TCLAP 156 299 #endif -
trunk/third_party/tclap/HelpVisitor.h
r857 r1515 61 61 * specified CmdLine. 62 62 */ 63 void visit() { (*_out)->usage(*_cmd); exit(0); }63 void visit() { (*_out)->usage(*_cmd); throw ExitException(0); } 64 64 65 65 }; -
trunk/third_party/tclap/Makefile.am
r1251 r1515 1 #====================================================================2 # NeXus - Neutron & X-ray Common Data Format3 #4 # $Id: Makefile.am 1247 2009-04-21 18:14:24Z Freddie Akeroyd $5 #6 # Top level Makefile for coordinating NeXus build7 #8 # Copyright (C) 2004 Freddie Akeroyd9 #10 # This library is free software; you can redistribute it and/or11 # modify it under the terms of the GNU Lesser General Public12 # License as published by the Free Software Foundation; either13 # version 2 of the License, or (at your option) any later version.14 #15 # This library is distributed in the hope that it will be useful,16 # but WITHOUT ANY WARRANTY; without even the implied warranty of17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU18 # Lesser General Public License for more details.19 #20 # You should have received a copy of the GNU Lesser General Public21 # License along with this library; if not, write to the Free22 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,23 # MA 02111-1307 USA24 #25 # For further information, see <http://www.neutron.anl.gov/NeXus/>26 #27 # @configure_input@28 #29 #====================================================================30 1 31 EXTRA_DIST=README AUTHORS COPYING 32 noinst_HEADERS = Arg.h ArgException.h CmdLine.h CmdLineInterface.h \ 33 CmdLineOutput.h DocBookOutput.h HelpVisitor.h IgnoreRestVisitor.h \ 34 MultiArg.h StdOutput.h SwitchArg.h UnlabeledMultiArg.h \ 35 UnlabeledValueArg.h ValueArg.h VersionVisitor.h Visitor.h XorHandler.h 2 libtclapincludedir = $(includedir)/tclap 3 4 libtclapinclude_HEADERS = \ 5 CmdLineInterface.h \ 6 ArgException.h \ 7 CmdLine.h \ 8 XorHandler.h \ 9 MultiArg.h \ 10 UnlabeledMultiArg.h \ 11 ValueArg.h \ 12 UnlabeledValueArg.h \ 13 Visitor.h Arg.h \ 14 HelpVisitor.h \ 15 SwitchArg.h \ 16 MultiSwitchArg.h \ 17 VersionVisitor.h \ 18 IgnoreRestVisitor.h \ 19 CmdLineOutput.h \ 20 StdOutput.h \ 21 DocBookOutput.h \ 22 ZshCompletionOutput.h \ 23 OptionalUnlabeledTracker.h \ 24 Constraint.h \ 25 ValuesConstraint.h \ 26 ArgTraits.h \ 27 StandardTraits.h 28 -
trunk/third_party/tclap/MultiArg.h
r1506 r1515 28 28 29 29 #include <tclap/Arg.h> 30 31 #ifdef _____HAVE_CONFIG_H /* not needed */ 32 #include <config.h> 33 #else 34 #define HAVE_SSTREAM 35 #endif 36 37 #if defined(HAVE_SSTREAM) 38 #include <sstream> 39 #elif defined(HAVE_STRSTREAM) 40 #include <strstream> 41 #else 42 #error "Need a stringstream (sstream or strstream) to compile!" 43 #endif 30 #include <tclap/Constraint.h> 44 31 45 32 namespace TCLAP { 46 47 template<class T> class MultiArg;48 49 namespace MULTI_ARG_HELPER {50 51 enum Error_e { EXTRACT_FAILURE = 1000, EXTRACT_TOO_MANY };52 53 /**54 * This class is used to extract a value from an argument.55 * It is used because we need a special implementation to56 * deal with std::string and making a specialiced function57 * puts it in the T segment, thus generating link errors.58 * Having a specialiced class makes the symbols weak.59 * This is not pretty but I don't know how to make it60 * work any other way.61 */62 template<class T>63 class ValueExtractor64 {65 friend class MultiArg<T>;66 67 private:68 69 /**70 * Reference to the vector of values where the result of the71 * extraction will be put.72 */73 std::vector<T> &_values;74 75 /**76 * Constructor.77 * \param values - Where the values extracted will be put.78 */79 ValueExtractor(std::vector<T> &values) : _values(values) {}80 81 /**82 * Method that will attempt to parse the input stream for values83 * of type T.84 * \param val - Where the values parsed will be put.85 */86 int extractValue( const std::string& val )87 {88 T temp;89 90 #if defined(HAVE_SSTREAM)91 std::istringstream is(val);92 #elif defined(HAVE_STRSTREAM)93 std::istrstream is(val.c_str());94 #else95 #error "Need a stringstream (sstream or strstream) to compile!"96 #endif97 98 int valuesRead = 0;99 100 while ( is.good() )101 {102 if ( is.peek() != EOF )103 is >> temp;104 else105 break;106 107 valuesRead++;108 }109 110 if ( is.fail() )111 return EXTRACT_FAILURE;112 113 if ( valuesRead > 1 )114 return EXTRACT_TOO_MANY;115 116 _values.push_back(temp);117 118 return 0;119 }120 };121 122 /**123 * Specialization for string. This is necessary because istringstream124 * operator>> is not able to ignore spaces... meaning -x "X Y" will only125 * read 'X'... and thus the specialization.126 */127 template<>128 class ValueExtractor<std::string>129 {130 friend class MultiArg<std::string>;131 132 private:133 134 /**135 * Reference to the vector of strings where the result of the136 * extraction will be put.137 */138 std::vector<std::string> &_values;139 140 /**141 * Constructor.142 * \param values - Where the strings extracted will be put.143 */144 ValueExtractor(std::vector<std::string> &values) : _values(values) {}145 146 /**147 * Method that will attempt to parse the input stream for values148 * of type std::string.149 * \param val - Where the values parsed will be put.150 */151 int extractValue( const std::string& val )152 {153 _values.push_back( val );154 return 0;155 }156 };157 158 } //namespace MULTI_ARG_HELPER159 160 33 /** 161 34 * An argument that allows multiple values of type T to be specified. Very … … 166 39 class MultiArg : public Arg 167 40 { 168 protected: 169 170 /** 171 * The list of values parsed from the CmdLine. 172 */ 173 std::vector<T> _values; 174 175 /** 176 * A list of allowed values. 177 * A list of values allowed for this argument. If the value parsed 178 * for this arg is not found in this list, then an exception is 179 * thrown. If the list is empty, then any value is allowed. 180 */ 181 std::vector<T> _allowed; 182 183 /** 184 * The description of type T to be used in the usage. 185 */ 186 std::string _typeDesc; 187 188 /** 189 * Extracts the value from the string. 190 * Attempts to parse string as type T, if this fails an exception 191 * is thrown. 192 * \param val - The string to be read. 193 */ 194 void _extractValue( const std::string& val ); 195 196 /** 197 * Checks to see if parsed value is in allowed list. 198 * \param val - value parsed (only used in output). 199 */ 200 void _checkAllowed( const std::string& val ); 201 202 public: 203 204 /** 205 * Constructor. 206 * \param flag - The one character flag that identifies this 207 * argument on the command line. 208 * \param name - A one word name for the argument. Can be 209 * used as a long flag on the command line. 210 * \param desc - A description of what the argument is for or 211 * does. 212 * \param req - Whether the argument is required on the command 213 * line. 214 * \param typeDesc - A short, human readable description of the 215 * type that this object expects. This is used in the generation 216 * of the USAGE statement. The goal is to be helpful to the end user 217 * of the program. 218 * \param v - An optional visitor. You probably should not 219 * use this unless you have a very good reason. 220 */ 221 MultiArg( const std::string& flag, 41 public: 42 typedef std::vector<T> container_type; 43 typedef typename container_type::iterator iterator; 44 typedef typename container_type::const_iterator const_iterator; 45 46 protected: 47 48 /** 49 * The list of values parsed from the CmdLine. 50 */ 51 std::vector<T> _values; 52 53 /** 54 * The description of type T to be used in the usage. 55 */ 56 std::string _typeDesc; 57 58 /** 59 * A list of constraint on this Arg. 60 */ 61 Constraint<T>* _constraint; 62 63 /** 64 * Extracts the value from the string. 65 * Attempts to parse string as type T, if this fails an exception 66 * is thrown. 67 * \param val - The string to be read. 68 */ 69 void _extractValue( const std::string& val ); 70 71 /** 72 * Used by XorHandler to decide whether to keep parsing for this arg. 73 */ 74 bool _allowMore; 75 76 public: 77 78 /** 79 * Constructor. 80 * \param flag - The one character flag that identifies this 81 * argument on the command line. 82 * \param name - A one word name for the argument. Can be 83 * used as a long flag on the command line. 84 * \param desc - A description of what the argument is for or 85 * does. 86 * \param req - Whether the argument is required on the command 87 * line. 88 * \param typeDesc - A short, human readable description of the 89 * type that this object expects. This is used in the generation 90 * of the USAGE statement. The goal is to be helpful to the end user 91 * of the program. 92 * \param v - An optional visitor. You probably should not 93 * use this unless you have a very good reason. 94 */ 95 MultiArg( const std::string& flag, 222 96 const std::string& name, 223 97 const std::string& desc, … … 226 100 Visitor* v = NULL); 227 101 228 /**229 * Constructor.230 * \param flag - The one character flag that identifies this231 * argument on the command line.232 * \param name - A one word name for the argument. Can be233 * used as a long flag on the command line.234 * \param desc - A description of what the argument is for or235 * does.236 * \param req - Whether the argument is required on the command237 * line.238 * \param typeDesc - A short, human readable description of the239 * type that this object expects. This is used in the generation240 * of the USAGE statement. The goal is to be helpful to the end user241 * of the program.242 * \param parser - A CmdLine parser object to add this Arg to243 * \param v - An optional visitor. You probably should not244 * use this unless you have a very good reason.245 */246 MultiArg( const std::string& flag,102 /** 103 * Constructor. 104 * \param flag - The one character flag that identifies this 105 * argument on the command line. 106 * \param name - A one word name for the argument. Can be 107 * used as a long flag on the command line. 108 * \param desc - A description of what the argument is for or 109 * does. 110 * \param req - Whether the argument is required on the command 111 * line. 112 * \param typeDesc - A short, human readable description of the 113 * type that this object expects. This is used in the generation 114 * of the USAGE statement. The goal is to be helpful to the end user 115 * of the program. 116 * \param parser - A CmdLine parser object to add this Arg to 117 * \param v - An optional visitor. You probably should not 118 * use this unless you have a very good reason. 119 */ 120 MultiArg( const std::string& flag, 247 121 const std::string& name, 248 122 const std::string& desc, … … 252 126 Visitor* v = NULL ); 253 127 254 /**255 * Constructor.256 * \param flag - The one character flag that identifies this257 * argument on the command line.258 * \param name - A one word name for the argument. Can be259 * used as a long flag on the command line.260 * \param desc - A description of what the argument is for or261 * does.262 * \param req - Whether the argument is required on the command263 * line.264 * \param allowed - A vector of type T that where the values in the265 * vector are the only values allowed for the arg.266 * \param v - An optional visitor. You probably should not267 * use this unless you have a very good reason.268 */269 MultiArg( const std::string& flag,128 /** 129 * Constructor. 130 * \param flag - The one character flag that identifies this 131 * argument on the command line. 132 * \param name - A one word name for the argument. Can be 133 * used as a long flag on the command line. 134 * \param desc - A description of what the argument is for or 135 * does. 136 * \param req - Whether the argument is required on the command 137 * line. 138 * \param constraint - A pointer to a Constraint object used 139 * to constrain this Arg. 140 * \param v - An optional visitor. You probably should not 141 * use this unless you have a very good reason. 142 */ 143 MultiArg( const std::string& flag, 270 144 const std::string& name, 271 145 const std::string& desc, 272 146 bool req, 273 const std::vector<T>& allowed,147 Constraint<T>* constraint, 274 148 Visitor* v = NULL ); 275 149 276 /**277 * Constructor.278 * \param flag - The one character flag that identifies this279 * argument on the command line.280 * \param name - A one word name for the argument. Can be281 * used as a long flag on the command line.282 * \param desc - A description of what the argument is for or283 * does.284 * \param req - Whether the argument is required on the command285 * line.286 * \param allowed - A vector of type T that where the values in the287 * vector are the only values allowed for the arg.288 * \param parser - A CmdLine parser object to add this Arg to289 * \param v - An optional visitor. You probably should not290 * use this unless you have a very good reason.291 */292 MultiArg( const std::string& flag,150 /** 151 * Constructor. 152 * \param flag - The one character flag that identifies this 153 * argument on the command line. 154 * \param name - A one word name for the argument. Can be 155 * used as a long flag on the command line. 156 * \param desc - A description of what the argument is for or 157 * does. 158 * \param req - Whether the argument is required on the command 159 * line. 160 * \param constraint - A pointer to a Constraint object used 161 * to constrain this Arg. 162 * \param parser - A CmdLine parser object to add this Arg to 163 * \param v - An optional visitor. You probably should not 164 * use this unless you have a very good reason. 165 */ 166 MultiArg( const std::string& flag, 293 167 const std::string& name, 294 168 const std::string& desc, 295 169 bool req, 296 const std::vector<T>& allowed,170 Constraint<T>* constraint, 297 171 CmdLineInterface& parser, 298 172 Visitor* v = NULL ); 299 173 300 /** 301 * Handles the processing of the argument. 302 * This re-implements the Arg version of this method to set the 303 * _value of the argument appropriately. It knows the difference 304 * between labeled and unlabeled. 305 * \param i - Pointer the the current argument in the list. 306 * \param args - Mutable list of strings. Passed from main(). 307 */ 308 virtual bool processArg(int* i, std::vector<std::string>& args); 309 310 /** 311 * Returns a vector of type T containing the values parsed from 312 * the command line. 313 */ 314 const std::vector<T>& getValue(); 315 316 /** 317 * Returns the a short id string. Used in the usage. 318 * \param val - value to be used. 319 */ 320 virtual std::string shortID(const std::string& val="val") const; 321 322 /** 323 * Returns the a long id string. Used in the usage. 324 * \param val - value to be used. 325 */ 326 virtual std::string longID(const std::string& val="val") const; 327 328 /** 329 * Once we've matched the first value, then the arg is no longer 330 * required. 331 */ 332 virtual bool isRequired() const; 333 334 private: 335 336 /** 337 * Common initialization code for constructors with allowed vectors. 338 */ 339 void allowedInit(); 174 /** 175 * Handles the processing of the argument. 176 * This re-implements the Arg version of this method to set the 177 * _value of the argument appropriately. It knows the difference 178 * between labeled and unlabeled. 179 * \param i - Pointer the the current argument in the list. 180 * \param args - Mutable list of strings. Passed from main(). 181 */ 182 virtual bool processArg(int* i, std::vector<std::string>& args); 183 184 /** 185 * Returns a vector of type T containing the values parsed from 186 * the command line. 187 */ 188 const std::vector<T>& getValue(); 189 190 /** 191 * Returns an iterator over the values parsed from the command 192 * line. 193 */ 194 const_iterator begin() const { return _values.begin(); } 195 196 /** 197 * Returns the end of the values parsed from the command 198 * line. 199 */ 200 const_iterator end() const { return _values.end(); } 201 202 /** 203 * Returns the a short id string. Used in the usage. 204 * \param val - value to be used. 205 */ 206 virtual std::string shortID(const std::string& val="val") const; 207 208 /** 209 * Returns the a long id string. Used in the usage. 210 * \param val - value to be used. 211 */ 212 virtual std::string longID(const std::string& val="val") const; 213 214 /** 215 * Once we've matched the first value, then the arg is no longer 216 * required. 217 */ 218 virtual bool isRequired() const; 219 220 virtual bool allowMore(); 221 222 virtual void reset(); 223 340 224 }; 341 225 342 /**343 *344 */345 template<class T>346 void MultiArg<T>::allowedInit()347 {348 for ( unsigned int i = 0; i < _allowed.size(); i++ )349 {350 351 #if defined(HAVE_SSTREAM)352 std::ostringstream os;353 #elif defined(HAVE_STRSTREAM)354 std::ostrstream os;355 #else356 #error "Need a stringstream (sstream or strstream) to compile!"357 #endif358 359 os << _allowed[i];360 361 std::string temp( os.str() );362 363 if ( i > 0 )364 _typeDesc += "|";365 366 _typeDesc += temp;367 }368 }369 370 /**371 *372 */373 226 template<class T> 374 227 MultiArg<T>::MultiArg(const std::string& flag, … … 379 232 Visitor* v) 380 233 : Arg( flag, name, desc, req, true, v ), 381 _typeDesc( typeDesc ) 382 { } 234 _typeDesc( typeDesc ), 235 _constraint( NULL ), 236 _allowMore(false) 237 { 238 _acceptsMultipleValues = true; 239 } 383 240 384 241 template<class T> … … 391 248 Visitor* v) 392 249 : Arg( flag, name, desc, req, true, v ), 393 _typeDesc( typeDesc ) 250 _typeDesc( typeDesc ), 251 _constraint( NULL ), 252 _allowMore(false) 394 253 { 395 254 parser.add( this ); 255 _acceptsMultipleValues = true; 396 256 } 397 257 … … 404 264 const std::string& desc, 405 265 bool req, 406 const std::vector<T>& allowed,266 Constraint<T>* constraint, 407 267 Visitor* v) 408 268 : Arg( flag, name, desc, req, true, v ), 409 _allowed( allowed ) 269 _typeDesc( constraint->shortID() ), 270 _constraint( constraint ), 271 _allowMore(false) 410 272 { 411 allowedInit();273 _acceptsMultipleValues = true; 412 274 } 413 275 … … 417 279 const std::string& desc, 418 280 bool req, 419 const std::vector<T>& allowed,281 Constraint<T>* constraint, 420 282 CmdLineInterface& parser, 421 283 Visitor* v) 422 284 : Arg( flag, name, desc, req, true, v ), 423 _allowed( allowed ) 285 _typeDesc( constraint->shortID() ), 286 _constraint( constraint ), 287 _allowMore(false) 424 288 { 425 allowedInit();426 289 parser.add( this ); 427 } 428 429 /** 430 * 431 */ 290 _acceptsMultipleValues = true; 291 } 292 432 293 template<class T> 433 294 const std::vector<T>& MultiArg<T>::getValue() { return _values; } 434 295 435 /**436 *437 */438 296 template<class T> 439 297 bool MultiArg<T>::processArg(int *i, std::vector<std::string>& args) … … 457 315 toString() ) ); 458 316 317 // always take the first one, regardless of start string 459 318 if ( value == "" ) 460 319 { 461 320 (*i)++; 462 if ( (unsigned int)*i< args.size() )321 if ( static_cast<unsigned int>(*i) < args.size() ) 463 322 _extractValue( args[*i] ); 464 323 else 465 324 throw( ArgParseException("Missing a value for this argument!", 466 325 toString() ) ); 467 } 326 } 468 327 else 469 328 _extractValue( value ); 470 329 330 /* 331 // continuing taking the args until we hit one with a start string 332 while ( (unsigned int)(*i)+1 < args.size() && 333 args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 && 334 args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 ) 335 _extractValue( args[++(*i)] ); 336 */ 337 338 _alreadySet = true; 471 339 _checkWithVisitor(); 472 340 … … 478 346 479 347 /** 480 * Checks to see if the value parsed is in the allowed list.348 * 481 349 */ 482 350 template<class T> 483 void MultiArg<T>::_checkAllowed( const std::string& val ) 484 { 485 if ( _allowed.size() > 0 ) 486 if ( find(_allowed.begin(),_allowed.end(),_values.back()) 487 == _allowed.end() ) 488 throw( CmdLineParseException( "Couldn't find '" + val + 489 "' in allowed list.", toString() ) ); 351 std::string MultiArg<T>::shortID(const std::string& val) const 352 { 353 static_cast<void>(val); // Ignore input, don't warn 354 return Arg::shortID(_typeDesc) + " ... "; 490 355 } 491 356 … … 494 359 */ 495 360 template<class T> 496 std::string MultiArg<T>::shortID(const std::string& val) const497 {498 std::string id = Arg::shortID(_typeDesc) + " ... ";499 500 return id;501 }502 503 /**504 *505 */506 template<class T>507 361 std::string MultiArg<T>::longID(const std::string& val) const 508 362 { 509 std::string id = Arg::longID(_typeDesc) + " (accepted multiple times)"; 510 511 return id; 363 static_cast<void>(val); // Ignore input, don't warn 364 return Arg::longID(_typeDesc) + " (accepted multiple times)"; 512 365 } 513 366 … … 534 387 void MultiArg<T>::_extractValue( const std::string& val ) 535 388 { 536 MULTI_ARG_HELPER::ValueExtractor<T> ve(_values); 537 538 int err = ve.extractValue(val); 539 540 if ( err == MULTI_ARG_HELPER::EXTRACT_FAILURE ) 541 throw( ArgParseException("Couldn't read argument value " 542 "from string '" + val + "'", toString() ) ); 543 544 if(err == MULTI_ARG_HELPER::EXTRACT_TOO_MANY) 545 throw( ArgParseException("More than one valid value " 546 "parsed from string '" + val + "'", 547 toString() ) ); 548 _checkAllowed( val ); 389 try { 390 T tmp; 391 ExtractValue(tmp, val, typename ArgTraits<T>::ValueCategory()); 392 _values.push_back(tmp); 393 } catch( ArgParseException &e) { 394 throw ArgParseException(e.error(), toString()); 395 } 396 397 if ( _constraint != NULL ) 398 if ( ! _constraint->check( _values.back() ) ) 399 throw( CmdLineParseException( "Value '" + val + 400 "' does not meet constraint: " + 401 _constraint->description(), 402 toString() ) ); 549 403 } 550 404 405 template<class T> 406 bool MultiArg<T>::allowMore() 407 { 408 bool am = _allowMore; 409 _allowMore = true; 410 return am; 411 } 412 413 template<class T> 414 void MultiArg<T>::reset() 415 { 416 Arg::reset(); 417 _values.clear(); 418 } 551 419 552 420 } // namespace TCLAP -
trunk/third_party/tclap/StdOutput.h
r1452 r1515 1 // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 1 2 2 3 /****************************************************************************** … … 66 67 */ 67 68 virtual void failure(CmdLineInterface& c, 68 ArgException& e );69 ArgException& e ); 69 70 70 71 protected: … … 129 130 130 131 inline void StdOutput::failure( CmdLineInterface& _cmd, 131 ArgException& e )132 ArgException& e ) 132 133 { 133 134 std::string progName = _cmd.getProgramName(); … … 136 137 << " " << e.error() << std::endl << std::endl; 137 138 138 std::cerr << "Brief USAGE: " << std::endl; 139 140 _shortUsage( _cmd, std::cerr ); 141 142 std::cerr << std::endl << "For complete USAGE and HELP type: " 143 << std::endl << " " << progName << " --help" 144 << std::endl << std::endl; 145 146 } 147 148 inline void StdOutput::_shortUsage( CmdLineInterface& _cmd, 149 std::ostream& os ) const 139 if ( _cmd.hasHelpAndVersion() ) 140 { 141 std::cerr << "Brief USAGE: " << std::endl; 142 143 _shortUsage( _cmd, std::cerr ); 144 145 std::cerr << std::endl << "For complete USAGE and HELP type: " 146 << std::endl << " " << progName << " --help" 147 << std::endl << std::endl; 148 } 149 else 150 usage(_cmd); 151 152 throw ExitException(1); 153 } 154 155 inline void 156 StdOutput::_shortUsage( CmdLineInterface& _cmd, 157 std::ostream& os ) const 150 158 { 151 159 std::list<Arg*> argList = _cmd.getArgList(); … … 157 165 158 166 // first the xor 159 for ( int i = 0; (unsigned int)i< xorList.size(); i++ )160 {161 s += " {";162 for ( ArgVectorIterator it = xorList[i].begin();163 it != xorList[i].end(); it++ )164 s += (*it)->shortID() + "|";165 166 s[s.length()-1] = '}';167 }167 for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ ) 168 { 169 s += " {"; 170 for ( ArgVectorIterator it = xorList[i].begin(); 171 it != xorList[i].end(); it++ ) 172 s += (*it)->shortID() + "|"; 173 174 s[s.length()-1] = '}'; 175 } 168 176 169 177 // then the rest … … 173 181 174 182 // if the program name is too long, then adjust the second line offset 175 int secondLineOffset = (int)(progName.length()) + 2;183 int secondLineOffset = static_cast<int>(progName.length()) + 2; 176 184 if ( secondLineOffset > 75/2 ) 177 secondLineOffset = (int)(75/2); 178 179 spacePrint( std::cout, s, 75, 3, secondLineOffset ); 180 } 181 182 inline void StdOutput::_longUsage( CmdLineInterface& _cmd, 183 std::ostream& os ) const 185 secondLineOffset = static_cast<int>(75/2); 186 187 spacePrint( os, s, 75, 3, secondLineOffset ); 188 } 189 190 inline void 191 StdOutput::_longUsage( CmdLineInterface& _cmd, 192 std::ostream& os ) const 184 193 { 185 194 std::list<Arg*> argList = _cmd.getArgList(); … … 189 198 190 199 // first the xor 191 for ( int i = 0; (unsigned int)i< xorList.size(); i++ )192 {193 for ( ArgVectorIterator it = xorList[i].begin();194 it != xorList[i].end();195 it++ )196 {197 spacePrint( os, (*it)->longID(), 75, 3, 3 );198 spacePrint( os, (*it)->getDescription(), 75, 5, 0 );199 200 if ( it+1 != xorList[i].end() )201 spacePrint(os, "-- OR --", 75, 9, 0);202 }203 os << std::endl << std::endl;204 }200 for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ ) 201 { 202 for ( ArgVectorIterator it = xorList[i].begin(); 203 it != xorList[i].end(); 204 it++ ) 205 { 206 spacePrint( os, (*it)->longID(), 75, 3, 3 ); 207 spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); 208 209 if ( it+1 != xorList[i].end() ) 210 spacePrint(os, "-- OR --", 75, 9, 0); 211 } 212 os << std::endl << std::endl; 213 } 205 214 206 215 // then the rest 207 216 for (ArgListIterator it = argList.begin(); it != argList.end(); it++) 208 217 if ( !xorHandler.contains( (*it) ) ) 209 {210 spacePrint( os, (*it)->longID(), 75, 3, 3 );211 spacePrint( os, (*it)->getDescription(), 75, 5, 0 );212 os << std::endl;213 }218 { 219 spacePrint( os, (*it)->longID(), 75, 3, 3 ); 220 spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); 221 os << std::endl; 222 } 214 223 215 224 os << std::endl; … … 224 233 int secondLineOffset ) const 225 234 { 226 int len = (int)(s.length());235 int len = static_cast<int>(s.length()); 227 236 228 237 if ( (len + indentSpaces > maxWidth) && maxWidth > 0 ) 229 { 230 int allowedLen = maxWidth - indentSpaces; 231 int start = 0; 232 while ( start < len ) 233 { 234 // find the substring length 235 #if defined (_MSC_VER) 236 int stringLen = (std::min)( len - start, allowedLen ); 237 #else 238 int stringLen = std::min( len - start, allowedLen ); 239 #endif 240 241 // trim the length so it doesn't end in middle of a word 242 if ( stringLen == allowedLen ) 243 while ( s[stringLen+start] != ' ' && 244 s[stringLen+start] != ',' && 245 s[stringLen+start] != '|' && 246 stringLen >= 0 ) 247 stringLen--; 238 { 239 int allowedLen = maxWidth - indentSpaces; 240 int start = 0; 241 while ( start < len ) 242 { 243 // find the substring length 244 // int stringLen = std::min<int>( len - start, allowedLen ); 245 // doing it this way to support a VisualC++ 2005 bug 246 using namespace std; 247 int stringLen = min<int>( len - start, allowedLen ); 248 249 // trim the length so it doesn't end in middle of a word 250 if ( stringLen == allowedLen ) 251 while ( stringLen >= 0 && 252 s[stringLen+start] != ' ' && 253 s[stringLen+start] != ',' && 254 s[stringLen+start] != '|' ) 255 stringLen--; 248 256 249 // ok, the word is longer than the line, so just split in the 250 // wherever the line ends 251 if ( stringLen <= 0 ) 252 stringLen = allowedLen; 253 254 // check for newlines 255 for ( int i = 0; i < stringLen; i++ ) 256 if ( s[start+i] == '\n' ) 257 stringLen = i+1; 258 259 // print the indent 257 // ok, the word is longer than the line, so just split 258 // wherever the line ends 259 if ( stringLen <= 0 ) 260 stringLen = allowedLen; 261 262 // check for newlines 263 for ( int i = 0; i < stringLen; i++ ) 264 if ( s[start+i] == '\n' ) 265 stringLen = i+1; 266 267 // print the indent 268 for ( int i = 0; i < indentSpaces; i++ ) 269 os << " "; 270 271 if ( start == 0 ) 272 { 273 // handle second line offsets 274 indentSpaces += secondLineOffset; 275 276 // adjust allowed len 277 allowedLen -= secondLineOffset; 278 } 279 280 os << s.substr(start,stringLen) << std::endl; 281 282 // so we don't start a line with a space 283 while ( s[stringLen+start] == ' ' && start < len ) 284 start++; 285 286 start += stringLen; 287 } 288 } 289 else 290 { 260 291 for ( int i = 0; i < indentSpaces; i++ ) 261 292 os << " "; 262 263 if ( start == 0 ) 264 { 265 // handle second line offsets 266 indentSpaces += secondLineOffset; 267 268 // adjust allowed len 269 allowedLen -= secondLineOffset; 270 } 271 272 os << s.substr(start,stringLen) << std::endl; 273 274 // so we don't start a line with a space 275 while ( s[stringLen+start] == ' ' && start < len ) 276 start++; 277 278 start += stringLen; 279 } 280 } 281 else 282 { 283 for ( int i = 0; i < indentSpaces; i++ ) 284 os << " "; 285 os << s << std::endl; 286 } 293 os << s << std::endl; 294 } 287 295 } 288 296 -
trunk/third_party/tclap/SwitchArg.h
r857 r1515 46 46 bool _value; 47 47 48 /** 49 * Used to support the reset() method so that ValueArg can be 50 * reset to their constructed value. 51 */ 52 bool _default; 48 53 49 54 public: … … 64 69 const std::string& name, 65 70 const std::string& desc, 66 bool def ,71 bool def = false, 67 72 Visitor* v = NULL); 68 73 … … 84 89 const std::string& name, 85 90 const std::string& desc, 86 bool def,87 91 CmdLineInterface& parser, 92 bool def = false, 88 93 Visitor* v = NULL); 89 94 … … 109 114 */ 110 115 bool getValue(); 116 117 virtual void reset(); 118 111 119 }; 112 120 … … 117 125 const std::string& name, 118 126 const std::string& desc, 119 bool _default,127 bool default_val, 120 128 Visitor* v ) 121 129 : Arg(flag, name, desc, false, false, v),
