Changeset 1515


Ignore:
Timestamp:
24/08/10 11:23:06 (18 months ago)
Author:
Freddie Akeroyd
Message:

Update to tclap 1.2.0 from  http://tclap.sourceforge.net/
Refs #244

Location:
trunk/third_party/tclap
Files:
9 added
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/third_party/tclap/AUTHORS

    r857 r1515  
    22original author: Michael E. Smoot 
    33invaluable contributions: Daniel Aarno 
     4more contributions: Erik Zeek 
     5more contributions: Fabien Carmagnac (Tinbergen-AM) 
    46outstanding 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 * 
    45 *  file:  Arg.h 
    5  *  
     6 * 
    67 *  Copyright (c) 2003, Michael E. Smoot . 
    78 *  Copyright (c) 2004, Michael E. Smoot, Daniel Aarno . 
    89 *  All rights reverved. 
    9  *  
     10 * 
    1011 *  See the file COPYING in the top directory of this distribution for 
    1112 *  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 *****************************************************************************/ 
    2223 
    2324 
    2425#ifndef TCLAP_ARGUMENT_H 
    2526#define TCLAP_ARGUMENT_H 
     27 
     28#ifdef ___HAVE_CONFIG_H 
     29#include <config.h> 
     30#else 
     31#define HAVE_SSTREAM 
     32#endif 
    2633 
    2734#include <string> 
     
    2936#include <list> 
    3037#include <iostream> 
     38#include <iomanip> 
     39#include <cstdio> 
     40 
     41#if defined(HAVE_SSTREAM) 
     42#include <sstream> 
     43typedef std::istringstream istringstream; 
     44#elif defined(HAVE_STRSTREAM) 
     45#include <strstream> 
     46typedef std::istrstream istringstream; 
     47#else 
     48#error "Need a stringstream (sstream or strstream) to compile!" 
     49#endif 
    3150 
    3251#include <tclap/ArgException.h> 
    3352#include <tclap/Visitor.h> 
    3453#include <tclap/CmdLineInterface.h> 
     54#include <tclap/ArgTraits.h> 
     55#include <tclap/StandardTraits.h> 
    3556 
    3657namespace TCLAP { 
    3758 
    38 /**  
     59/** 
    3960 * A virtual base class that defines the essential data for all arguments. 
    4061 * This class, or one of its existing children, must be subclassed to do 
    41  * anything.  
     62 * anything. 
    4263 */ 
    4364class Arg 
    4465{ 
    45         private:  
     66        private: 
    4667 
    4768                /** 
     
    5475                 * value. 
    5576                 */ 
    56                 static char& delimiterRef() { static char delim = ' '; return delim; }  
     77                static char& delimiterRef() { static char delim = ' '; return delim; } 
    5778 
    5879        protected: 
    5980 
    60                 /**  
     81                /** 
    6182                 * 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, 
    6485                 * 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 
    6687                 * that the _flag does NOT include the dash as part of the flag. 
    6788                 */ 
     
    7091                /** 
    7192                 * 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 
    7394                 * to identify an argument on the command line.  Note that the 
    7495                 * _name does NOT include the two dashes as part of the _name. The 
     
    7899 
    79100                /** 
    80                  * Description of the argument.  
     101                 * Description of the argument. 
    81102                 */ 
    82103                std::string _description; 
    83104 
    84                 /**  
     105                /** 
    85106                 * Indicating whether the argument is required. 
    86107                 */ 
     
    88109 
    89110                /** 
    90                  * Label to be used in usage description.  Normally set to  
     111                 * Label to be used in usage description.  Normally set to 
    91112                 * "required", but can be changed when necessary. 
    92113                 */ 
     
    126147                bool _xorSet; 
    127148 
     149                bool _acceptsMultipleValues; 
     150 
    128151                /** 
    129152                 * Performs the special handling described by the Vistitor. 
     
    132155 
    133156                /** 
    134                  * Primary constructor. YOU (yes you) should NEVER construct an Arg  
     157                 * Primary constructor. YOU (yes you) should NEVER construct an Arg 
    135158                 * 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, 
    137160                 * UnlabeledValueArg, or UnlabeledMultiArg instead. 
    138161                 * 
     
    144167                 * \param v - The visitor checked by the argument. Defaults to NULL. 
    145168                 */ 
    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, 
    150173                         bool valreq, 
    151174                         Visitor* v = NULL ); 
     
    162185                 */ 
    163186                virtual void addToList( std::list<Arg*>& argList ) const; 
    164                  
     187 
    165188                /** 
    166189                 * Begin ignoring arguments since the "--" argument was specified. 
    167190                 */ 
    168191                static void beginIgnoring() { ignoreRestRef() = true; } 
    169                  
     192 
    170193                /** 
    171194                 * Whether to ignore the rest. 
     
    177200                 * value. 
    178201                 */ 
    179                 static char delimiter() { return delimiterRef(); }  
    180                  
     202                static char delimiter() { return delimiterRef(); } 
     203 
    181204                /** 
    182205                 * 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 
    188210                /** 
    189211                 * The char that indicates the beginning of a flag.  Currently '-'. 
    190212                 */ 
    191                 static const char flagStartChar() { return '-'; } 
    192                  
     213                static char flagStartChar() { return '-'; } 
     214 
    193215                /** 
    194216                 * The sting that indicates the beginning of a flag.  Currently "-". 
     
    196218                 */ 
    197219                static const std::string flagStartString() { return "-"; } 
    198                  
     220 
    199221                /** 
    200222                 * The sting that indicates the beginning of a name.  Currently "--". 
     
    216238                /** 
    217239                 * 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. 
    219241                 * \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 
    221243                 * passed in from main. 
    222244                 */ 
    223                 virtual bool processArg(int *i, std::vector<std::string>& args) = 0;  
     245                virtual bool processArg(int *i, std::vector<std::string>& args) = 0; 
    224246 
    225247                /** 
     
    228250                 * \param a - The Arg to be compared to this. 
    229251                 */ 
    230                 virtual bool operator==(const Arg& a); 
     252                virtual bool operator==(const Arg& a) const; 
    231253 
    232254                /** 
     
    274296 
    275297                /** 
    276                  * Indicates whether the argument can be ignored, if desired.  
     298                 * Indicates whether the argument can be ignored, if desired. 
    277299                 */ 
    278300                bool isIgnoreable() const; 
     
    281303                 * A method that tests whether a string matches this argument. 
    282304                 * 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 
    284306                 * arguments are specified on the command line. 
    285307                 * \param s - The string to be compared to the flag/name to determine 
     
    308330                /** 
    309331                 * 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. 
    312334                 * \param value - Where the value trimmed from the string will 
    313335                 * be stored. 
     
    330352                void setRequireLabel( const std::string& s ); 
    331353 
     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(); 
    332371}; 
    333372 
     
    347386typedef std::list<Visitor*>::iterator VisitorListIterator; 
    348387 
     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 */ 
     394template<typename T> void 
     395ExtractValue(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 */ 
     431template<typename T> void 
     432ExtractValue(T &destVal, const std::string& strVal, StringLike sl) 
     433{ 
     434    static_cast<void>(sl); // Avoid warning about unused sl 
     435    SetString(destVal, strVal); 
     436} 
    349437 
    350438////////////////////////////////////////////////////////////////////// 
     
    352440////////////////////////////////////////////////////////////////////// 
    353441 
    354 inline Arg::Arg(const std::string& flag,  
    355          const std::string& name,  
    356          const std::string& desc,  
    357          bool req,  
     442inline Arg::Arg(const std::string& flag, 
     443         const std::string& name, 
     444         const std::string& desc, 
     445         bool req, 
    358446         bool valreq, 
    359447         Visitor* v) : 
     
    367455  _visitor( v ), 
    368456  _ignoreable(true), 
    369   _xorSet(false) 
    370 { 
    371         if ( _flag.length() > 1 )  
     457  _xorSet(false), 
     458  _acceptsMultipleValues(false) 
     459{ 
     460        if ( _flag.length() > 1 ) 
    372461                throw(SpecificationException( 
    373462                                "Argument flag can only be one character long", toString() ) ); 
    374463 
    375         if ( _name != ignoreNameString() &&   
    376                  ( _flag == Arg::flagStartString() ||  
    377                    _flag == Arg::nameStartString() ||  
     464        if ( _name != ignoreNameString() && 
     465                 ( _flag == Arg::flagStartString() || 
     466                   _flag == Arg::nameStartString() || 
    378467                   _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 '" + 
    381470                                                        Arg::nameStartString() + "' or a space.", 
    382471                                                        toString() ) ); 
    383472 
    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() ) || 
    386475                 ( _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 '" + 
    389478                                                        Arg::nameStartString() + "' or space.", 
    390479                                                        toString() ) ); 
     
    403492                id = Arg::nameStartString() + _name; 
    404493 
    405         std::string delim = " ";  
    406         delim[0] = Arg::delimiter(); // ugly!!! 
    407          
    408494        if ( _valueRequired ) 
    409                 id += delim + "<" + valueId  + ">"; 
     495                id += std::string( 1, Arg::delimiter() ) + "<" + valueId  + ">"; 
    410496 
    411497        if ( !_required ) 
     
    424510 
    425511                if ( _valueRequired ) 
    426                         id += " <" + valueId + ">"; 
    427                  
     512                        id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">"; 
     513 
    428514                id += ",  "; 
    429515        } 
     
    432518 
    433519        if ( _valueRequired ) 
    434                 id += " <" + valueId + ">"; 
    435                          
     520                id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">"; 
     521 
    436522        return id; 
    437523 
    438524} 
    439525 
    440 inline bool Arg::operator==(const Arg& a) 
    441 { 
    442         if ( ( _flag != "" && _flag == a._flag ) ||  
    443                  _name == a._name ||  
    444                  _description == a._description ) 
     526inline bool Arg::operator==(const Arg& a) const 
     527{ 
     528        if ( ( _flag != "" && _flag == a._flag ) || _name == a._name) 
    445529                return true; 
    446530        else 
     
    448532} 
    449533 
    450 inline std::string Arg::getDescription() const  
     534inline std::string Arg::getDescription() const 
    451535{ 
    452536        std::string desc = ""; 
     
    454538                desc = "(" + _requireLabel + ")  "; 
    455539 
    456         if ( _valueRequired ) 
    457                 desc += "(value required)  "; 
     540//      if ( _valueRequired ) 
     541//              desc += "(value required)  "; 
    458542 
    459543        desc += _description; 
    460         return desc;  
     544        return desc; 
    461545} 
    462546 
    463547inline const std::string& Arg::getFlag() const { return _flag; } 
    464548 
    465 inline const std::string& Arg::getName() const { return _name; }  
     549inline const std::string& Arg::getName() const { return _name; } 
    466550 
    467551inline bool Arg::isRequired() const { return _required; } 
     
    469553inline bool Arg::isValueRequired() const { return _valueRequired; } 
    470554 
    471 inline bool Arg::isSet() const  
    472 {  
     555inline bool Arg::isSet() const 
     556{ 
    473557        if ( _alreadySet && !_xorSet ) 
    474558                return true; 
     
    479563inline bool Arg::isIgnoreable() const { return _ignoreable; } 
    480564 
    481 inline void Arg::setRequireLabel( const std::string& s)  
    482 {  
     565inline void Arg::setRequireLabel( const std::string& s) 
     566{ 
    483567        _requireLabel = s; 
    484568} 
     
    517601{ 
    518602        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++ ) 
    520604                if ( flag[i] == Arg::delimiter() ) 
    521605                { 
     
    537621inline bool Arg::_hasBlanks( const std::string& s ) const 
    538622{ 
    539         for ( int i = 1; (unsigned int)i < s.length(); i++ ) 
     623        for ( int i = 1; static_cast<unsigned int>(i) < s.length(); i++ ) 
    540624                if ( s[i] == Arg::blankChar() ) 
    541625                        return true; 
     
    560644inline void Arg::addToList( std::list<Arg*>& argList ) const 
    561645{ 
    562         argList.push_front( (Arg*)this ); 
     646        argList.push_front( const_cast<Arg*>(this) ); 
     647} 
     648 
     649inline bool Arg::allowMore() 
     650{ 
     651        return false; 
     652} 
     653 
     654inline bool Arg::acceptsMultipleValues() 
     655{ 
     656        return _acceptsMultipleValues; 
     657} 
     658 
     659inline void Arg::reset() 
     660{ 
     661        _xorSet = false; 
     662        _alreadySet = false; 
    563663} 
    564664 
  • trunk/third_party/tclap/ArgException.h

    r857 r1515  
     1// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 
    12 
    23/******************************************************************************  
     
    7980                const char* what() const throw()  
    8081                { 
    81                         std::string ex = _argId + " -- " + _errorText; 
     82                        static std::string ex;  
     83                        ex = _argId + " -- " + _errorText; 
    8284                        return ex.c_str(); 
    8385                } 
     
    183185}; 
    184186 
     187class ExitException { 
     188public: 
     189        ExitException(int estat) : _estat(estat) {} 
     190 
     191        int getExitStatus() const { return _estat; } 
     192 
     193private: 
     194        int _estat; 
     195}; 
     196 
    185197} // namespace TCLAP 
    186198 
  • trunk/third_party/tclap/CmdLine.h

    r857 r1515  
    1  
    2 /******************************************************************************  
    3  *  
     1// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 
     2 
     3/****************************************************************************** 
     4 * 
    45 *  file:  CmdLine.h 
    5  *  
     6 * 
    67 *  Copyright (c) 2003, Michael E. Smoot . 
    78 *  Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. 
    89 *  All rights reverved. 
    9  *  
     10 * 
    1011 *  See the file COPYING in the top directory of this distribution for 
    1112 *  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 *****************************************************************************/ 
    2223 
    2324#ifndef TCLAP_CMDLINE_H 
     
    2526 
    2627#include <tclap/SwitchArg.h> 
     28#include <tclap/MultiSwitchArg.h> 
    2729#include <tclap/UnlabeledValueArg.h> 
    2830#include <tclap/UnlabeledMultiArg.h> 
     
    3537#include <tclap/CmdLineOutput.h> 
    3638#include <tclap/StdOutput.h> 
     39 
     40#include <tclap/Constraint.h> 
     41#include <tclap/ValuesConstraint.h> 
    3742 
    3843#include <string> 
     
    4247#include <iomanip> 
    4348#include <algorithm> 
     49#include <stdlib.h> // Needed for exit(), which isn't defined in some envs. 
    4450 
    4551namespace TCLAP { 
     52 
     53template<typename T> void DelPtr(T ptr) 
     54{ 
     55        delete ptr; 
     56} 
     57 
     58template<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 
    4665 
    4766/** 
     
    7594 
    7695                /** 
    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 
    7998                 * Args added to the CmdLine object. 
    8099                 */ 
     
    82101 
    83102                /** 
    84                  * The character that is used to separate the argument flag/name  
     103                 * The character that is used to separate the argument flag/name 
    85104                 * from the value.  Defaults to ' ' (space). 
    86105                 */ 
     
    110129                 */ 
    111130                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(); 
    112141 
    113142                /** 
     
    119148                bool _emptyCombined(const std::string& s); 
    120149 
    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 
     160private: 
     161 
     162                /** 
     163                 * Encapsulates the code common to the constructors 
     164                 * (which is all of it). 
    126165                 */ 
    127166                void _constructor(); 
    128167 
    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); 
    138168 
    139169                /** 
     
    143173                bool _userSetOutput; 
    144174 
     175                /** 
     176                 * Whether or not to automatically create help and version switches. 
     177                 */ 
     178                bool _helpAndVersion; 
     179 
    145180        public: 
    146  
    147                 /** 
    148                  * Command line constructor. DEPRECATED!!!  This is here to maintain 
    149                  * backwards compatibility with earlier releases.  Note that the 
    150                  * program name will be overwritten with argv[0].  The delimiter 
    151                  * 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 the 
    155                  * --version switch. 
    156                  */ 
    157                 CmdLine(const std::string& name,  
    158                                 const std::string& message, 
    159                                 const std::string& version = "none" ); 
    160181 
    161182                /** 
     
    168189                 * \param version - The version number to be used in the 
    169190                 * --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, 
    172195                                const char delimiter = ' ', 
    173                                 const std::string& version = "none" ); 
    174                  
     196                                const std::string& version = "none", 
     197                                bool helpAndVersion = true); 
     198 
    175199                /** 
    176200                 * Deletes any resources allocated by a CmdLine object. 
     
    180204                /** 
    181205                 * 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. 
    183207                 */ 
    184208                void add( Arg& a ); 
     
    186210                /** 
    187211                 * An alternative add.  Functionally identical. 
    188                  * \param a - Argument to be added.  
     212                 * \param a - Argument to be added. 
    189213                 */ 
    190214                void add( Arg* a ); 
     
    193217                 * Add two Args that will be xor'd.  If this method is used, add does 
    194218                 * 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. 
    197221                 */ 
    198222                void xorAdd( Arg& a, Arg& b ); 
    199223 
    200224                /** 
    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, 
    202226                 * 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. 
    204228                 */ 
    205229                void xorAdd( std::vector<Arg*>& xors ); 
     
    210234                 * \param argv - Array of arguments. 
    211235                 */ 
    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); 
    213244 
    214245                /** 
     
    251282                 */ 
    252283                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 
    253310}; 
    254311 
     
    258315/////////////////////////////////////////////////////////////////////////////// 
    259316 
    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 ) 
     317inline CmdLine::CmdLine(const std::string& m, 
     318                        char delim, 
     319                        const std::string& v, 
     320                        bool help ) 
    276321: _progName("not_set_yet"), 
    277322  _message(m), 
     
    279324  _numRequired(0), 
    280325  _delimiter(delim), 
    281   _userSetOutput(false) 
     326  _handleExceptions(true), 
     327  _userSetOutput(false), 
     328  _helpAndVersion(help) 
    282329{ 
    283330        _constructor(); 
     
    286333inline CmdLine::~CmdLine() 
    287334{ 
    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 ) { 
    302339                delete _output; 
     340                _output = 0; 
     341        } 
    303342} 
    304343 
    305344inline void CmdLine::_constructor() 
    306 {  
     345{ 
    307346        _output = new StdOutput; 
    308347 
    309         Visitor *v; 
    310          
    311348        Arg::setDelimiter( _delimiter ); 
    312349 
    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.", 
    316365                                        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        } 
    328370 
    329371        v = new IgnoreRestVisitor(); 
    330         SwitchArg* ignore  = new SwitchArg(Arg::flagStartString(),  
     372        SwitchArg* ignore  = new SwitchArg(Arg::flagStartString(), 
    331373                                           Arg::ignoreNameString(), 
    332374                           "Ignores the rest of the labeled arguments following this flag.", 
     
    350392} 
    351393 
    352 inline void CmdLine::xorAdd( Arg& a, Arg& b )  
     394inline void CmdLine::xorAdd( Arg& a, Arg& b ) 
    353395{ 
    354396    std::vector<Arg*> ors; 
     
    358400} 
    359401 
    360 inline void CmdLine::add( Arg& a )  
    361 {  
     402inline void CmdLine::add( Arg& a ) 
     403{ 
    362404        add( &a ); 
    363405} 
    364406 
    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!",  
     407inline 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!", 
    371413                                        a->longID() ) ); 
    372414 
    373415        a->addToList( _argList ); 
    374416 
    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 
     422inline 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 
     433inline void CmdLine::parse(std::vector<std::string>& args) 
     434{ 
     435        bool shouldExit = false; 
     436        int estat = 0; 
     437 
    381438        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] ) ) 
    400459                                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); 
    422497} 
    423498 
    424499inline bool CmdLine::_emptyCombined(const std::string& s) 
    425500{ 
    426         if ( s[0] != Arg::flagStartChar() ) 
     501        if ( s.length() > 0 && s[0] != Arg::flagStartChar() ) 
    427502                return false; 
    428503 
    429         for ( int i = 1; (unsigned int)i < s.length(); i++ ) 
     504        for ( int i = 1; static_cast<unsigned int>(i) < s.length(); i++ ) 
    430505                if ( s[i] != Arg::blankChar() ) 
    431506                        return false; 
     
    434509} 
    435510 
     511inline 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 
    436538inline void CmdLine::deleteOnExit(Arg* ptr) 
    437539{ 
     
    483585{ 
    484586        return _message; 
     587} 
     588 
     589inline bool CmdLine::hasHelpAndVersion() 
     590{ 
     591        return _helpAndVersion; 
     592} 
     593 
     594inline void CmdLine::setExceptionHandling(const bool state) 
     595{ 
     596        _handleExceptions = state; 
     597} 
     598 
     599inline bool CmdLine::getExceptionHandling() const 
     600{ 
     601        return _handleExceptions; 
     602} 
     603 
     604inline void CmdLine::reset() 
     605{ 
     606        for( ArgListIterator it = _argList.begin(); it != _argList.end(); it++ ) 
     607        { 
     608                (*it)->reset(); 
     609        } 
     610         
     611        _progName.clear(); 
    485612} 
    486613 
     
    492619 
    493620} //namespace TCLAP 
    494 #endif  
     621#endif 
  • trunk/third_party/tclap/CmdLineInterface.h

    r857 r1515  
    8383                 * \param argv - Array of arguments. 
    8484                 */ 
    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); 
    8693 
    8794                /** 
     
    124131                 */ 
    125132                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; 
    126145}; 
    127146 
  • trunk/third_party/tclap/CmdLineOutput.h

    r857 r1515  
    4343 
    4444        public: 
     45 
     46                /** 
     47                 * Virtual destructor. 
     48                 */ 
     49                virtual ~CmdLineOutput() {} 
     50 
    4551                /** 
    4652                 * 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; -*- 
    12 
    23/******************************************************************************  
     
    7778                 */ 
    7879                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; 
    7987}; 
    8088 
     
    8997        std::list<Arg*> argList = _cmd.getArgList(); 
    9098        std::string progName = _cmd.getProgramName(); 
     99        std::string version = _cmd.getVersion(); 
     100        theDelimiter = _cmd.getDelimiter(); 
    91101        XorHandler xorHandler = _cmd.getXorHandler(); 
    92102        std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList(); 
    93  
     103        basename(progName); 
    94104 
    95105        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; 
    97107        std::cout << "\t\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\">" << std::endl << std::endl; 
    98108 
    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; 
    100122        std::cout << "<cmdsynopsis>" << std::endl; 
    101123 
    102124        std::cout << "<command>" << progName << "</command>" << std::endl; 
    103  
    104         std::string lt = "&lt;";  
    105         std::string gt = "&gt;";  
    106125 
    107126        // xor 
    108127        for ( int i = 0; (unsigned int)i < xorList.size(); i++ ) 
    109128        { 
    110                 std::cout << "<group>" << std::endl; 
     129                std::cout << "<group choice='req'>" << std::endl; 
    111130                for ( ArgVectorIterator it = xorList[i].begin();  
    112131                                                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)); 
    119133 
    120134                std::cout << "</group>" << std::endl; 
    121135        } 
    122  
     136         
     137        // rest of args 
    123138        for (ArgListIterator it = argList.begin(); it != argList.end(); it++) 
    124139                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)); 
    131141 
    132142        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; 
    134171 
    135172} 
    136173 
    137174inline void DocBookOutput::failure( CmdLineInterface& _cmd, 
    138                                                 ArgException& e )  
     175                                    ArgException& e )  
    139176{  
    140                 std::cout << e.what() << std::endl; 
     177        static_cast<void>(_cmd); // unused 
     178        std::cout << e.what() << std::endl; 
     179        throw ExitException(1); 
    141180} 
    142181 
     
    153192} 
    154193 
     194inline 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 
     203inline 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 
     212inline void DocBookOutput::printShortArg(Arg* a) 
     213{ 
     214        std::string lt = "&lt;";  
     215        std::string gt = "&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 
     252inline void DocBookOutput::printLongArg(Arg* a) 
     253{ 
     254        std::string lt = "&lt;";  
     255        std::string gt = "&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 
    155298} //namespace TCLAP 
    156299#endif  
  • trunk/third_party/tclap/HelpVisitor.h

    r857 r1515  
    6161                 * specified CmdLine. 
    6262                 */ 
    63                 void visit() { (*_out)->usage(*_cmd); exit(0); } 
     63                void visit() { (*_out)->usage(*_cmd); throw ExitException(0); } 
    6464                 
    6565}; 
  • trunk/third_party/tclap/Makefile.am

    r1251 r1515  
    1 #==================================================================== 
    2 #  NeXus - Neutron & X-ray Common Data Format 
    3  
    4 #  $Id: Makefile.am 1247 2009-04-21 18:14:24Z Freddie Akeroyd $ 
    5 # 
    6 #  Top level Makefile for coordinating NeXus build 
    7  
    8 #  Copyright (C) 2004 Freddie Akeroyd 
    9  
    10 #  This library is free software; you can redistribute it and/or 
    11 #  modify it under the terms of the GNU Lesser General Public 
    12 #  License as published by the Free Software Foundation; either 
    13 #  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 of 
    17 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
    18 #  Lesser General Public License for more details. 
    19 #  
    20 #  You should have received a copy of the GNU Lesser General Public 
    21 #  License along with this library; if not, write to the Free  
    22 #  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,  
    23 #  MA  02111-1307  USA 
    24 #              
    25 #  For further information, see <http://www.neutron.anl.gov/NeXus/> 
    26 # 
    27 #  @configure_input@ 
    28 # 
    29 #==================================================================== 
    301 
    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 
     2libtclapincludedir = $(includedir)/tclap 
     3 
     4libtclapinclude_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  
    2828 
    2929#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> 
    4431 
    4532namespace 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 to 
    56  * deal with std::string and making a specialiced function 
    57  * 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 it 
    60  * work any other way. 
    61  */ 
    62 template<class T> 
    63 class ValueExtractor  
    64 { 
    65         friend class MultiArg<T>; 
    66    
    67         private: 
    68  
    69                 /** 
    70                  * Reference to the vector of values where the result of the  
    71                  * 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 values 
    83                  * 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 #else 
    95 #error "Need a stringstream (sstream or strstream) to compile!" 
    96 #endif 
    97  
    98                         int valuesRead = 0; 
    99      
    100                         while ( is.good() )  
    101                         { 
    102                                 if ( is.peek() != EOF ) 
    103                                         is >> temp;  
    104                                 else 
    105                                         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 istringstream 
    124  * operator>> is not able to ignore spaces...  meaning -x "X Y" will only  
    125  * 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 the  
    136                  * 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 values 
    148                  * 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_HELPER 
    159  
    16033/** 
    16134 * An argument that allows multiple values of type T to be specified.  Very 
     
    16639class MultiArg : public Arg 
    16740{ 
    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, 
     41public: 
     42        typedef std::vector<T> container_type;   
     43        typedef typename container_type::iterator iterator; 
     44        typedef typename container_type::const_iterator const_iterator; 
     45 
     46protected: 
     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 
     76public: 
     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, 
    22296                  const std::string& name, 
    22397                  const std::string& desc, 
     
    226100                  Visitor* v = NULL); 
    227101 
    228                 /** 
    229                 * Constructor. 
    230                 * \param flag - The one character flag that identifies this 
    231                 * argument on the command line. 
    232                 * \param name - A one word name for the argument.  Can be 
    233                 * used as a long flag on the command line. 
    234                 * \param desc - A description of what the argument is for or 
    235                 * does. 
    236                 * \param req - Whether the argument is required on the command 
    237                 * line. 
    238                 * \param typeDesc - A short, human readable description of the 
    239                 * type that this object expects.  This is used in the generation 
    240                 * of the USAGE statement.  The goal is to be helpful to the end user 
    241                 * of the program. 
    242                 * \param parser - A CmdLine parser object to add this Arg to 
    243                 * \param v - An optional visitor.  You probably should not 
    244                 * 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,  
    247121                  const std::string& name, 
    248122                  const std::string& desc, 
     
    252126                  Visitor* v = NULL ); 
    253127 
    254                 /** 
    255                 * Constructor. 
    256                 * \param flag - The one character flag that identifies this 
    257                 * argument on the command line. 
    258                 * \param name - A one word name for the argument.  Can be 
    259                 * used as a long flag on the command line. 
    260                 * \param desc - A description of what the argument is for or 
    261                 * does. 
    262                 * \param req - Whether the argument is required on the command 
    263                 * line. 
    264                  * \param allowed - A vector of type T that where the values in the 
    265                  * vector are the only values allowed for the arg. 
    266                 * \param v - An optional visitor.  You probably should not 
    267                 * 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, 
    270144                  const std::string& name, 
    271145                  const std::string& desc, 
    272146                  bool req, 
    273                   const std::vector<T>& allowed, 
     147                  Constraint<T>* constraint, 
    274148                  Visitor* v = NULL ); 
    275149                   
    276                 /** 
    277                 * Constructor. 
    278                 * \param flag - The one character flag that identifies this 
    279                 * argument on the command line. 
    280                 * \param name - A one word name for the argument.  Can be 
    281                 * used as a long flag on the command line. 
    282                 * \param desc - A description of what the argument is for or 
    283                 * does. 
    284                 * \param req - Whether the argument is required on the command 
    285                 * line. 
    286                  * \param allowed - A vector of type T that where the values in the 
    287                  * vector are the only values allowed for the arg. 
    288                 * \param parser - A CmdLine parser object to add this Arg to 
    289                 * \param v - An optional visitor.  You probably should not 
    290                 * 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,  
    293167                  const std::string& name, 
    294168                  const std::string& desc, 
    295169                  bool req, 
    296                   const std::vector<T>& allowed, 
     170                  Constraint<T>* constraint, 
    297171                  CmdLineInterface& parser, 
    298172                  Visitor* v = NULL ); 
    299173                   
    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 
    340224}; 
    341225 
    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 #else 
    356 #error "Need a stringstream (sstream or strstream) to compile!" 
    357 #endif 
    358  
    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  */ 
    373226template<class T> 
    374227MultiArg<T>::MultiArg(const std::string& flag,  
     
    379232                      Visitor* v) 
    380233: 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} 
    383240 
    384241template<class T> 
     
    391248                      Visitor* v) 
    392249: Arg( flag, name, desc, req, true, v ), 
    393   _typeDesc( typeDesc ) 
     250  _typeDesc( typeDesc ), 
     251  _constraint( NULL ), 
     252  _allowMore(false) 
    394253{  
    395254        parser.add( this ); 
     255        _acceptsMultipleValues = true; 
    396256} 
    397257 
     
    404264                      const std::string& desc, 
    405265                      bool req, 
    406                       const std::vector<T>& allowed, 
     266                      Constraint<T>* constraint, 
    407267                      Visitor* v) 
    408268: Arg( flag, name, desc, req, true, v ), 
    409   _allowed( allowed ) 
     269  _typeDesc( constraint->shortID() ), 
     270  _constraint( constraint ), 
     271  _allowMore(false) 
    410272{  
    411         allowedInit(); 
     273        _acceptsMultipleValues = true; 
    412274} 
    413275 
     
    417279                      const std::string& desc, 
    418280                      bool req, 
    419                       const std::vector<T>& allowed, 
     281                      Constraint<T>* constraint, 
    420282                      CmdLineInterface& parser, 
    421283                      Visitor* v) 
    422284: Arg( flag, name, desc, req, true, v ), 
    423   _allowed( allowed ) 
     285  _typeDesc( constraint->shortID() ), 
     286  _constraint( constraint ), 
     287  _allowMore(false) 
    424288{  
    425         allowedInit(); 
    426289        parser.add( this ); 
    427 } 
    428  
    429 /** 
    430  * 
    431  */ 
     290        _acceptsMultipleValues = true; 
     291} 
     292 
    432293template<class T> 
    433294const std::vector<T>& MultiArg<T>::getValue() { return _values; } 
    434295 
    435 /** 
    436  * 
    437  */ 
    438296template<class T> 
    439297bool MultiArg<T>::processArg(int *i, std::vector<std::string>& args)  
     
    457315                                           toString() ) ); 
    458316 
     317                // always take the first one, regardless of start string 
    459318                if ( value == "" ) 
    460319                { 
    461320                        (*i)++; 
    462                         if ( (unsigned int)*i < args.size() ) 
     321                        if ( static_cast<unsigned int>(*i) < args.size() ) 
    463322                                _extractValue( args[*i] ); 
    464323                        else 
    465324                                throw( ArgParseException("Missing a value for this argument!", 
    466325                                         toString() ) ); 
    467                 } 
     326                }  
    468327                else 
    469328                        _extractValue( value ); 
    470329 
     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; 
    471339                _checkWithVisitor(); 
    472340 
     
    478346 
    479347/** 
    480  * Checks to see if the value parsed is in the allowed list. 
     348 * 
    481349 */ 
    482350template<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() ) ); 
     351std::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) + " ... "; 
    490355} 
    491356 
     
    494359 */ 
    495360template<class T> 
    496 std::string MultiArg<T>::shortID(const std::string& val) const 
    497 { 
    498         std::string id = Arg::shortID(_typeDesc) + " ... "; 
    499  
    500         return id; 
    501 } 
    502  
    503 /** 
    504  * 
    505  */ 
    506 template<class T> 
    507361std::string MultiArg<T>::longID(const std::string& val) const 
    508362{ 
    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)"; 
    512365} 
    513366 
     
    534387void MultiArg<T>::_extractValue( const std::string& val )  
    535388{ 
    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() ) ); 
    549403} 
    550404                 
     405template<class T> 
     406bool MultiArg<T>::allowMore() 
     407{ 
     408        bool am = _allowMore; 
     409        _allowMore = true; 
     410        return am; 
     411} 
     412 
     413template<class T> 
     414void MultiArg<T>::reset() 
     415{ 
     416        Arg::reset(); 
     417        _values.clear(); 
     418} 
    551419 
    552420} // namespace TCLAP 
  • trunk/third_party/tclap/StdOutput.h

    r1452 r1515  
     1// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 
    12 
    23/******************************************************************************  
     
    6667                 */ 
    6768                virtual void failure(CmdLineInterface& c,  
    68                                                      ArgException& e ); 
     69                                     ArgException& e ); 
    6970 
    7071        protected: 
     
    129130 
    130131inline void StdOutput::failure( CmdLineInterface& _cmd, 
    131                                                 ArgException& e )  
     132                                                                ArgException& e )  
    132133{ 
    133134        std::string progName = _cmd.getProgramName(); 
     
    136137                      << "             " << e.error() << std::endl << std::endl; 
    137138 
    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 
     155inline void  
     156StdOutput::_shortUsage( CmdLineInterface& _cmd,  
     157                                                std::ostream& os ) const 
    150158{ 
    151159        std::list<Arg*> argList = _cmd.getArgList(); 
     
    157165 
    158166        // 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                } 
    168176 
    169177        // then the rest 
     
    173181 
    174182        // 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; 
    176184        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 
     190inline void  
     191StdOutput::_longUsage( CmdLineInterface& _cmd,  
     192                                           std::ostream& os ) const 
    184193{ 
    185194        std::list<Arg*> argList = _cmd.getArgList(); 
     
    189198 
    190199        // 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                } 
    205214 
    206215        // then the rest 
    207216        for (ArgListIterator it = argList.begin(); it != argList.end(); it++) 
    208217                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                        } 
    214223 
    215224        os << std::endl; 
     
    224233                                                           int secondLineOffset ) const 
    225234{ 
    226         int len = (int)(s.length()); 
     235        int len = static_cast<int>(s.length()); 
    227236 
    228237        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--; 
    248256         
    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                { 
    260291                        for ( int i = 0; i < indentSpaces; i++ ) 
    261292                                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                } 
    287295} 
    288296 
  • trunk/third_party/tclap/SwitchArg.h

    r857 r1515  
    4646                bool _value; 
    4747 
     48                /** 
     49                 * Used to support the reset() method so that ValueArg can be 
     50                 * reset to their constructed value. 
     51                 */ 
     52        bool _default; 
    4853 
    4954        public: 
     
    6469                              const std::string& name,  
    6570                              const std::string& desc, 
    66                               bool def, 
     71                              bool def = false, 
    6772                                  Visitor* v = NULL); 
    6873 
     
    8489                              const std::string& name,  
    8590                              const std::string& desc, 
    86                               bool def, 
    8791                                  CmdLineInterface& parser, 
     92                              bool def = false, 
    8893                                  Visitor* v = NULL); 
    8994                                   
     
    109114                 */ 
    110115                bool getValue(); 
     116                 
     117                virtual void reset(); 
     118 
    111119}; 
    112120 
     
    117125                                 const std::string& name,  
    118126                                 const std::string& desc,  
    119                          bool _default, 
     127                         bool default_val, 
    120128                                         Visitor* v ) 
    121129: Arg(flag, name, desc, false, false, v),