| @@ -1,26 +1,25 @@ | |||
| // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- | |||
| /****************************************************************************** | |||
| * | |||
| /****************************************************************************** | |||
| * | |||
| * file: ArgException.h | |||
| * | |||
| * | |||
| * Copyright (c) 2003, Michael E. Smoot . | |||
| * Copyright (c) 2017 Google LLC | |||
| * All rights reserved. | |||
| * | |||
| * | |||
| * See the file COPYING in the top directory of this distribution for | |||
| * more information. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| #ifndef TCLAP_ARG_EXCEPTION_H | |||
| #define TCLAP_ARG_EXCEPTION_H | |||
| @@ -28,186 +27,180 @@ | |||
| #include <string> | |||
| #include <exception> | |||
| namespace TCLAP { | |||
| /** | |||
| * A simple class that defines and argument exception. Should be caught | |||
| * whenever a CmdLine is created and parsed. | |||
| */ | |||
| class ArgException : public std::exception | |||
| { | |||
| public: | |||
| /** | |||
| * Constructor. | |||
| * \param text - The text of the exception. | |||
| * \param id - The text identifying the argument source. | |||
| * \param td - Text describing the type of ArgException it is. | |||
| * of the exception. | |||
| */ | |||
| ArgException( const std::string& text = "undefined exception", | |||
| const std::string& id = "undefined", | |||
| const std::string& td = "Generic ArgException") | |||
| : std::exception(), | |||
| _errorText(text), | |||
| _argId( id ), | |||
| _typeDescription(td) | |||
| { } | |||
| /** | |||
| * Destructor. | |||
| */ | |||
| virtual ~ArgException() throw() { } | |||
| /** | |||
| * Returns the error text. | |||
| */ | |||
| std::string error() const { return ( _errorText ); } | |||
| /** | |||
| * Returns the argument id. | |||
| */ | |||
| std::string argId() const | |||
| { | |||
| if ( _argId == "undefined" ) | |||
| return " "; | |||
| else | |||
| return ( "Argument: " + _argId ); | |||
| } | |||
| /** | |||
| * Returns the arg id and error text. | |||
| */ | |||
| const char* what() const throw() | |||
| { | |||
| static std::string ex; | |||
| ex = _argId + " -- " + _errorText; | |||
| return ex.c_str(); | |||
| } | |||
| /** | |||
| * Returns the type of the exception. Used to explain and distinguish | |||
| * between different child exceptions. | |||
| */ | |||
| std::string typeDescription() const | |||
| { | |||
| return _typeDescription; | |||
| } | |||
| private: | |||
| /** | |||
| * The text of the exception message. | |||
| */ | |||
| std::string _errorText; | |||
| /** | |||
| * The argument related to this exception. | |||
| */ | |||
| std::string _argId; | |||
| /** | |||
| * Describes the type of the exception. Used to distinguish | |||
| * between different child exceptions. | |||
| */ | |||
| std::string _typeDescription; | |||
| }; | |||
| /** | |||
| * Thrown from within the child Arg classes when it fails to properly | |||
| * parse the argument it has been passed. | |||
| */ | |||
| class ArgParseException : public ArgException | |||
| { | |||
| public: | |||
| /** | |||
| * Constructor. | |||
| * \param text - The text of the exception. | |||
| * \param id - The text identifying the argument source | |||
| * of the exception. | |||
| */ | |||
| ArgParseException( const std::string& text = "undefined exception", | |||
| const std::string& id = "undefined" ) | |||
| : ArgException( text, | |||
| id, | |||
| std::string( "Exception found while parsing " ) + | |||
| std::string( "the value the Arg has been passed." )) | |||
| { } | |||
| }; | |||
| /** | |||
| * Thrown from CmdLine when the arguments on the command line are not | |||
| * properly specified, e.g. too many arguments, required argument missing, etc. | |||
| */ | |||
| class CmdLineParseException : public ArgException | |||
| namespace TCLAP | |||
| { | |||
| public: | |||
| /** | |||
| * Constructor. | |||
| * \param text - The text of the exception. | |||
| * \param id - The text identifying the argument source | |||
| * of the exception. | |||
| */ | |||
| CmdLineParseException( const std::string& text = "undefined exception", | |||
| const std::string& id = "undefined" ) | |||
| : ArgException( text, | |||
| id, | |||
| std::string( "Exception found when the values ") + | |||
| std::string( "on the command line do not meet ") + | |||
| std::string( "the requirements of the defined ") + | |||
| std::string( "Args." )) | |||
| { } | |||
| }; | |||
| /** | |||
| * Thrown from Arg and CmdLine when an Arg is improperly specified, e.g. | |||
| * same flag as another Arg, same name, etc. | |||
| */ | |||
| class SpecificationException : public ArgException | |||
| { | |||
| public: | |||
| /** | |||
| * Constructor. | |||
| * \param text - The text of the exception. | |||
| * \param id - The text identifying the argument source | |||
| * of the exception. | |||
| */ | |||
| SpecificationException( const std::string& text = "undefined exception", | |||
| const std::string& id = "undefined" ) | |||
| : ArgException( text, | |||
| id, | |||
| std::string("Exception found when an Arg object ")+ | |||
| std::string("is improperly defined by the ") + | |||
| std::string("developer." )) | |||
| { } | |||
| }; | |||
| /** | |||
| * Thrown when TCLAP thinks the program should exit. | |||
| * | |||
| * For example after parse error this exception will be thrown (and | |||
| * normally caught). This allows any resource to be clened properly | |||
| * before exit. | |||
| * | |||
| * If exception handling is disabled (CmdLine::setExceptionHandling), | |||
| * this exception will propagate to the call site, allowing the | |||
| * program to catch it and avoid program termination, or do it's own | |||
| * cleanup. See for example, https://sourceforge.net/p/tclap/bugs/29. | |||
| */ | |||
| class ExitException { | |||
| public: | |||
| ExitException(int estat) : _estat(estat) {} | |||
| int getExitStatus() const { return _estat; } | |||
| private: | |||
| int _estat; | |||
| }; | |||
| } // namespace TCLAP | |||
| #endif | |||
| /** | |||
| * A simple class that defines and argument exception. Should be caught | |||
| * whenever a CmdLine is created and parsed. | |||
| */ | |||
| class ArgException : public std::exception | |||
| { | |||
| public: | |||
| /** | |||
| * Constructor. | |||
| * \param text - The text of the exception. | |||
| * \param id - The text identifying the argument source. | |||
| * \param td - Text describing the type of ArgException it is. | |||
| * of the exception. | |||
| */ | |||
| ArgException(const std::string& text = "undefined exception", const std::string& id = "undefined", const std::string& td = "Generic ArgException") : | |||
| std::exception(), | |||
| _errorText(text), | |||
| _argId(id), | |||
| _typeDescription(td) | |||
| { | |||
| } | |||
| /** | |||
| * Destructor. | |||
| */ | |||
| virtual ~ArgException() throw() | |||
| { | |||
| } | |||
| /** | |||
| * Returns the error text. | |||
| */ | |||
| std::string error() const | |||
| { | |||
| return (_errorText); | |||
| } | |||
| /** | |||
| * Returns the argument id. | |||
| */ | |||
| std::string argId() const | |||
| { | |||
| if (_argId == "undefined") | |||
| return " "; | |||
| else | |||
| return ("Argument: " + _argId); | |||
| } | |||
| /** | |||
| * Returns the arg id and error text. | |||
| */ | |||
| const char* what() const throw() | |||
| { | |||
| static std::string ex; | |||
| ex = _argId + " -- " + _errorText; | |||
| return ex.c_str(); | |||
| } | |||
| /** | |||
| * Returns the type of the exception. Used to explain and distinguish | |||
| * between different child exceptions. | |||
| */ | |||
| std::string typeDescription() const | |||
| { | |||
| return _typeDescription; | |||
| } | |||
| private: | |||
| /** | |||
| * The text of the exception message. | |||
| */ | |||
| std::string _errorText; | |||
| /** | |||
| * The argument related to this exception. | |||
| */ | |||
| std::string _argId; | |||
| /** | |||
| * Describes the type of the exception. Used to distinguish | |||
| * between different child exceptions. | |||
| */ | |||
| std::string _typeDescription; | |||
| }; | |||
| /** | |||
| * Thrown from within the child Arg classes when it fails to properly | |||
| * parse the argument it has been passed. | |||
| */ | |||
| class ArgParseException : public ArgException | |||
| { | |||
| public: | |||
| /** | |||
| * Constructor. | |||
| * \param text - The text of the exception. | |||
| * \param id - The text identifying the argument source | |||
| * of the exception. | |||
| */ | |||
| ArgParseException(const std::string& text = "undefined exception", const std::string& id = "undefined") : | |||
| ArgException(text, id, std::string("Exception found while parsing ") + std::string("the value the Arg has been passed.")) | |||
| { | |||
| } | |||
| }; | |||
| /** | |||
| * Thrown from CmdLine when the arguments on the command line are not | |||
| * properly specified, e.g. too many arguments, required argument missing, etc. | |||
| */ | |||
| class CmdLineParseException : public ArgException | |||
| { | |||
| public: | |||
| /** | |||
| * Constructor. | |||
| * \param text - The text of the exception. | |||
| * \param id - The text identifying the argument source | |||
| * of the exception. | |||
| */ | |||
| CmdLineParseException(const std::string& text = "undefined exception", const std::string& id = "undefined") : | |||
| ArgException(text, id, std::string("Exception found when the values ") + std::string("on the command line do not meet ") + std::string("the requirements of the defined ") + std::string("Args.")) | |||
| { | |||
| } | |||
| }; | |||
| /** | |||
| * Thrown from Arg and CmdLine when an Arg is improperly specified, e.g. | |||
| * same flag as another Arg, same name, etc. | |||
| */ | |||
| class SpecificationException : public ArgException | |||
| { | |||
| public: | |||
| /** | |||
| * Constructor. | |||
| * \param text - The text of the exception. | |||
| * \param id - The text identifying the argument source | |||
| * of the exception. | |||
| */ | |||
| SpecificationException(const std::string& text = "undefined exception", const std::string& id = "undefined") : | |||
| ArgException(text, id, std::string("Exception found when an Arg object ") + std::string("is improperly defined by the ") + std::string("developer.")) | |||
| { | |||
| } | |||
| }; | |||
| /** | |||
| * Thrown when TCLAP thinks the program should exit. | |||
| * | |||
| * For example after parse error this exception will be thrown (and | |||
| * normally caught). This allows any resource to be clened properly | |||
| * before exit. | |||
| * | |||
| * If exception handling is disabled (CmdLine::setExceptionHandling), | |||
| * this exception will propagate to the call site, allowing the | |||
| * program to catch it and avoid program termination, or do it's own | |||
| * cleanup. See for example, https://sourceforge.net/p/tclap/bugs/29. | |||
| */ | |||
| class ExitException | |||
| { | |||
| public: | |||
| ExitException(int estat) : | |||
| _estat(estat) | |||
| { | |||
| } | |||
| int getExitStatus() const | |||
| { | |||
| return _estat; | |||
| } | |||
| private: | |||
| int _estat; | |||
| }; | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -27,96 +27,113 @@ | |||
| #ifndef TCLAP_ARGTRAITS_H | |||
| #define TCLAP_ARGTRAITS_H | |||
| namespace TCLAP { | |||
| // We use two empty structs to get compile type specialization | |||
| // function to work | |||
| /** | |||
| * A value like argument value type is a value that can be set using | |||
| * operator>>. This is the default value type. | |||
| */ | |||
| struct ValueLike { | |||
| typedef ValueLike ValueCategory; | |||
| virtual ~ValueLike() {} | |||
| }; | |||
| /** | |||
| * A string like argument value type is a value that can be set using | |||
| * operator=(string). Useful if the value type contains spaces which | |||
| * will be broken up into individual tokens by operator>>. | |||
| */ | |||
| struct StringLike { | |||
| virtual ~StringLike() {} | |||
| }; | |||
| /** | |||
| * A class can inherit from this object to make it have string like | |||
| * traits. This is a compile time thing and does not add any overhead | |||
| * to the inherenting class. | |||
| */ | |||
| struct StringLikeTrait { | |||
| typedef StringLike ValueCategory; | |||
| virtual ~StringLikeTrait() {} | |||
| }; | |||
| /** | |||
| * A class can inherit from this object to make it have value like | |||
| * traits. This is a compile time thing and does not add any overhead | |||
| * to the inherenting class. | |||
| */ | |||
| struct ValueLikeTrait { | |||
| typedef ValueLike ValueCategory; | |||
| virtual ~ValueLikeTrait() {} | |||
| }; | |||
| /** | |||
| * Arg traits are used to get compile type specialization when parsing | |||
| * argument values. Using an ArgTraits you can specify the way that | |||
| * values gets assigned to any particular type during parsing. The two | |||
| * supported types are StringLike and ValueLike. ValueLike is the | |||
| * default and means that operator>> will be used to assign values to | |||
| * the type. | |||
| */ | |||
| template<typename T> | |||
| class ArgTraits { | |||
| // This is a bit silly, but what we want to do is: | |||
| // 1) If there exists a specialization of ArgTraits for type X, | |||
| // use it. | |||
| // | |||
| // 2) If no specialization exists but X has the typename | |||
| // X::ValueCategory, use the specialization for X::ValueCategory. | |||
| // | |||
| // 3) If neither (1) nor (2) defines the trait, use the default | |||
| // which is ValueLike. | |||
| // This is the "how": | |||
| // | |||
| // test<T>(0) (where 0 is the NULL ptr) will match | |||
| // test(typename C::ValueCategory*) iff type T has the | |||
| // corresponding typedef. If it does not test(...) will be | |||
| // matched. This allows us to determine if T::ValueCategory | |||
| // exists by checking the sizeof for the test function (return | |||
| // value must have different sizeof). | |||
| template<typename C> static short test(typename C::ValueCategory*); | |||
| template<typename C> static long test(...); | |||
| static const bool hasTrait = sizeof(test<T>(0)) == sizeof(short); | |||
| template <typename C, bool> | |||
| struct DefaultArgTrait { | |||
| typedef ValueLike ValueCategory; | |||
| }; | |||
| template <typename C> | |||
| struct DefaultArgTrait<C, true> { | |||
| typedef typename C::ValueCategory ValueCategory; | |||
| }; | |||
| public: | |||
| typedef typename DefaultArgTrait<T, hasTrait>::ValueCategory ValueCategory; | |||
| }; | |||
| } // namespace | |||
| namespace TCLAP | |||
| { | |||
| // We use two empty structs to get compile type specialization | |||
| // function to work | |||
| /** | |||
| * A value like argument value type is a value that can be set using | |||
| * operator>>. This is the default value type. | |||
| */ | |||
| struct ValueLike | |||
| { | |||
| typedef ValueLike ValueCategory; | |||
| virtual ~ValueLike() | |||
| { | |||
| } | |||
| }; | |||
| /** | |||
| * A string like argument value type is a value that can be set using | |||
| * operator=(string). Useful if the value type contains spaces which | |||
| * will be broken up into individual tokens by operator>>. | |||
| */ | |||
| struct StringLike | |||
| { | |||
| virtual ~StringLike() | |||
| { | |||
| } | |||
| }; | |||
| /** | |||
| * A class can inherit from this object to make it have string like | |||
| * traits. This is a compile time thing and does not add any overhead | |||
| * to the inherenting class. | |||
| */ | |||
| struct StringLikeTrait | |||
| { | |||
| typedef StringLike ValueCategory; | |||
| virtual ~StringLikeTrait() | |||
| { | |||
| } | |||
| }; | |||
| /** | |||
| * A class can inherit from this object to make it have value like | |||
| * traits. This is a compile time thing and does not add any overhead | |||
| * to the inherenting class. | |||
| */ | |||
| struct ValueLikeTrait | |||
| { | |||
| typedef ValueLike ValueCategory; | |||
| virtual ~ValueLikeTrait() | |||
| { | |||
| } | |||
| }; | |||
| /** | |||
| * Arg traits are used to get compile type specialization when parsing | |||
| * argument values. Using an ArgTraits you can specify the way that | |||
| * values gets assigned to any particular type during parsing. The two | |||
| * supported types are StringLike and ValueLike. ValueLike is the | |||
| * default and means that operator>> will be used to assign values to | |||
| * the type. | |||
| */ | |||
| template<typename T> | |||
| class ArgTraits | |||
| { | |||
| // This is a bit silly, but what we want to do is: | |||
| // 1) If there exists a specialization of ArgTraits for type X, | |||
| // use it. | |||
| // | |||
| // 2) If no specialization exists but X has the typename | |||
| // X::ValueCategory, use the specialization for X::ValueCategory. | |||
| // | |||
| // 3) If neither (1) nor (2) defines the trait, use the default | |||
| // which is ValueLike. | |||
| // This is the "how": | |||
| // | |||
| // test<T>(0) (where 0 is the NULL ptr) will match | |||
| // test(typename C::ValueCategory*) iff type T has the | |||
| // corresponding typedef. If it does not test(...) will be | |||
| // matched. This allows us to determine if T::ValueCategory | |||
| // exists by checking the sizeof for the test function (return | |||
| // value must have different sizeof). | |||
| template<typename C> | |||
| static short test(typename C::ValueCategory*); | |||
| template<typename C> | |||
| static long test(...); | |||
| static const bool hasTrait = sizeof(test<T>(0)) == sizeof(short); | |||
| template<typename C, bool> | |||
| struct DefaultArgTrait | |||
| { | |||
| typedef ValueLike ValueCategory; | |||
| }; | |||
| template<typename C> | |||
| struct DefaultArgTrait<C, true> | |||
| { | |||
| typedef typename C::ValueCategory ValueCategory; | |||
| }; | |||
| public: | |||
| typedef typename DefaultArgTrait<T, hasTrait>::ValueCategory ValueCategory; | |||
| }; | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -1,10 +1,9 @@ | |||
| // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- | |||
| /****************************************************************************** | |||
| * | |||
| /****************************************************************************** | |||
| * | |||
| * file: CmdLineInterface.h | |||
| * | |||
| * | |||
| * Copyright (c) 2003, Michael E. Smoot . | |||
| * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. | |||
| * Copyright (c) 2017, Google LLC | |||
| @@ -12,16 +11,16 @@ | |||
| * | |||
| * See the file COPYING in the top directory of this distribution for | |||
| * more information. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| #ifndef TCLAP_COMMANDLINE_INTERFACE_H | |||
| #define TCLAP_COMMANDLINE_INTERFACE_H | |||
| @@ -32,122 +31,122 @@ | |||
| #include <iostream> | |||
| #include <algorithm> | |||
| namespace TCLAP | |||
| { | |||
| class Arg; | |||
| class CmdLineOutput; | |||
| class XorHandler; | |||
| /** | |||
| * The base class that manages the command line definition and passes | |||
| * along the parsing to the appropriate Arg classes. | |||
| */ | |||
| class CmdLineInterface | |||
| { | |||
| public: | |||
| /** | |||
| * Destructor | |||
| */ | |||
| virtual ~CmdLineInterface() | |||
| { | |||
| } | |||
| namespace TCLAP { | |||
| class Arg; | |||
| class CmdLineOutput; | |||
| class XorHandler; | |||
| /** | |||
| * Adds an argument to the list of arguments to be parsed. | |||
| * \param a - Argument to be added. | |||
| */ | |||
| virtual void add(Arg& a) = 0; | |||
| /** | |||
| * The base class that manages the command line definition and passes | |||
| * along the parsing to the appropriate Arg classes. | |||
| */ | |||
| class CmdLineInterface | |||
| { | |||
| public: | |||
| /** | |||
| * Destructor | |||
| */ | |||
| virtual ~CmdLineInterface() {} | |||
| /** | |||
| * Adds an argument to the list of arguments to be parsed. | |||
| * \param a - Argument to be added. | |||
| */ | |||
| virtual void add( Arg& a )=0; | |||
| /** | |||
| * An alternative add. Functionally identical. | |||
| * \param a - Argument to be added. | |||
| */ | |||
| virtual void add( Arg* a )=0; | |||
| /** | |||
| * Add two Args that will be xor'd. | |||
| * If this method is used, add does | |||
| * not need to be called. | |||
| * \param a - Argument to be added and xor'd. | |||
| * \param b - Argument to be added and xor'd. | |||
| */ | |||
| virtual void xorAdd( Arg& a, Arg& b )=0; | |||
| /** | |||
| * Add a list of Args that will be xor'd. If this method is used, | |||
| * add does not need to be called. | |||
| * \param xors - List of Args to be added and xor'd. | |||
| */ | |||
| virtual void xorAdd( const std::vector<Arg*>& xors )=0; | |||
| /** | |||
| * Parses the command line. | |||
| * \param argc - Number of arguments. | |||
| * \param argv - Array of arguments. | |||
| */ | |||
| virtual void parse(int argc, const char * const * argv)=0; | |||
| /** | |||
| * An alternative add. Functionally identical. | |||
| * \param a - Argument to be added. | |||
| */ | |||
| virtual void add(Arg* a) = 0; | |||
| /** | |||
| * Add two Args that will be xor'd. | |||
| * If this method is used, add does | |||
| * not need to be called. | |||
| * \param a - Argument to be added and xor'd. | |||
| * \param b - Argument to be added and xor'd. | |||
| */ | |||
| virtual void xorAdd(Arg& a, Arg& b) = 0; | |||
| /** | |||
| * Add a list of Args that will be xor'd. If this method is used, | |||
| * add does not need to be called. | |||
| * \param xors - List of Args to be added and xor'd. | |||
| */ | |||
| virtual void xorAdd(const std::vector<Arg*>& xors) = 0; | |||
| /** | |||
| * Parses the command line. | |||
| * \param argc - Number of arguments. | |||
| * \param argv - Array of arguments. | |||
| */ | |||
| virtual void parse(int argc, const char* const* argv) = 0; | |||
| /** | |||
| * Parses the command line. | |||
| * \param args - A vector of strings representing the args. | |||
| * \param args - A vector of strings representing the args. | |||
| * args[0] is still the program name. | |||
| */ | |||
| void parse(std::vector<std::string>& args); | |||
| /** | |||
| * Returns the CmdLineOutput object. | |||
| */ | |||
| virtual CmdLineOutput* getOutput()=0; | |||
| /** | |||
| * \param co - CmdLineOutput object that we want to use instead. | |||
| */ | |||
| virtual void setOutput(CmdLineOutput* co)=0; | |||
| /** | |||
| * Returns the version string. | |||
| */ | |||
| virtual std::string& getVersion()=0; | |||
| /** | |||
| * Returns the program name string. | |||
| */ | |||
| virtual std::string& getProgramName()=0; | |||
| /** | |||
| * Returns the argList. | |||
| */ | |||
| virtual std::list<Arg*>& getArgList()=0; | |||
| /** | |||
| * Returns the XorHandler. | |||
| */ | |||
| virtual XorHandler& getXorHandler()=0; | |||
| /** | |||
| * Returns the delimiter string. | |||
| */ | |||
| virtual char getDelimiter()=0; | |||
| /** | |||
| * Returns the message string. | |||
| */ | |||
| virtual std::string& getMessage()=0; | |||
| /** | |||
| * Indicates whether or not the help and version switches were created | |||
| * automatically. | |||
| */ | |||
| virtual bool hasHelpAndVersion()=0; | |||
| /** | |||
| * Resets the instance as if it had just been constructed so that the | |||
| * instance can be reused. | |||
| */ | |||
| virtual void reset()=0; | |||
| }; | |||
| } //namespace | |||
| #endif | |||
| /** | |||
| * Returns the CmdLineOutput object. | |||
| */ | |||
| virtual CmdLineOutput* getOutput() = 0; | |||
| /** | |||
| * \param co - CmdLineOutput object that we want to use instead. | |||
| */ | |||
| virtual void setOutput(CmdLineOutput* co) = 0; | |||
| /** | |||
| * Returns the version string. | |||
| */ | |||
| virtual std::string& getVersion() = 0; | |||
| /** | |||
| * Returns the program name string. | |||
| */ | |||
| virtual std::string& getProgramName() = 0; | |||
| /** | |||
| * Returns the argList. | |||
| */ | |||
| virtual std::list<Arg*>& getArgList() = 0; | |||
| /** | |||
| * Returns the XorHandler. | |||
| */ | |||
| virtual XorHandler& getXorHandler() = 0; | |||
| /** | |||
| * Returns the delimiter string. | |||
| */ | |||
| virtual char getDelimiter() = 0; | |||
| /** | |||
| * Returns the message string. | |||
| */ | |||
| virtual std::string& getMessage() = 0; | |||
| /** | |||
| * Indicates whether or not the help and version switches were created | |||
| * automatically. | |||
| */ | |||
| virtual bool hasHelpAndVersion() = 0; | |||
| /** | |||
| * Resets the instance as if it had just been constructed so that the | |||
| * instance can be reused. | |||
| */ | |||
| virtual void reset() = 0; | |||
| }; | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -1,27 +1,25 @@ | |||
| // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- | |||
| /****************************************************************************** | |||
| * | |||
| /****************************************************************************** | |||
| * | |||
| * file: CmdLineOutput.h | |||
| * | |||
| * | |||
| * Copyright (c) 2004, Michael E. Smoot | |||
| * Copyright (c) 2017, Google LLC | |||
| * All rights reserved. | |||
| * | |||
| * | |||
| * See the file COPYING in the top directory of this distribution for | |||
| * more information. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| #ifndef TCLAP_CMDLINEOUTPUT_H | |||
| #define TCLAP_CMDLINEOUTPUT_H | |||
| @@ -33,45 +31,44 @@ | |||
| #include <iomanip> | |||
| #include <algorithm> | |||
| namespace TCLAP { | |||
| class CmdLineInterface; | |||
| class ArgException; | |||
| /** | |||
| * The interface that any output object must implement. | |||
| */ | |||
| class CmdLineOutput | |||
| namespace TCLAP | |||
| { | |||
| public: | |||
| /** | |||
| * Virtual destructor. | |||
| */ | |||
| virtual ~CmdLineOutput() {} | |||
| class CmdLineInterface; | |||
| class ArgException; | |||
| /** | |||
| * Generates some sort of output for the USAGE. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| */ | |||
| virtual void usage(CmdLineInterface& c)=0; | |||
| /** | |||
| * The interface that any output object must implement. | |||
| */ | |||
| class CmdLineOutput | |||
| { | |||
| public: | |||
| /** | |||
| * Virtual destructor. | |||
| */ | |||
| virtual ~CmdLineOutput() | |||
| { | |||
| } | |||
| /** | |||
| * Generates some sort of output for the version. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| */ | |||
| virtual void version(CmdLineInterface& c)=0; | |||
| /** | |||
| * Generates some sort of output for the USAGE. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| */ | |||
| virtual void usage(CmdLineInterface& c) = 0; | |||
| /** | |||
| * Generates some sort of output for a failure. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| * \param e - The ArgException that caused the failure. | |||
| */ | |||
| virtual void failure( CmdLineInterface& c, | |||
| ArgException& e )=0; | |||
| /** | |||
| * Generates some sort of output for the version. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| */ | |||
| virtual void version(CmdLineInterface& c) = 0; | |||
| }; | |||
| /** | |||
| * Generates some sort of output for a failure. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| * \param e - The ArgException that caused the failure. | |||
| */ | |||
| virtual void failure(CmdLineInterface& c, ArgException& e) = 0; | |||
| }; | |||
| } //namespace TCLAP | |||
| #endif | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -1,6 +1,5 @@ | |||
| // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- | |||
| /****************************************************************************** | |||
| * | |||
| * file: Constraint.h | |||
| @@ -33,46 +32,50 @@ | |||
| #include <algorithm> | |||
| #include <stdexcept> | |||
| namespace TCLAP { | |||
| /** | |||
| * The interface that defines the interaction between the Arg and Constraint. | |||
| */ | |||
| template<class T> | |||
| class Constraint | |||
| namespace TCLAP | |||
| { | |||
| public: | |||
| /** | |||
| * Returns a description of the Constraint. | |||
| */ | |||
| virtual std::string description() const =0; | |||
| /** | |||
| * The interface that defines the interaction between the Arg and Constraint. | |||
| */ | |||
| template<class T> | |||
| class Constraint | |||
| { | |||
| public: | |||
| /** | |||
| * Returns a description of the Constraint. | |||
| */ | |||
| virtual std::string description() const = 0; | |||
| /** | |||
| * Returns the short ID for the Constraint. | |||
| */ | |||
| virtual std::string shortID() const =0; | |||
| /** | |||
| * Returns the short ID for the Constraint. | |||
| */ | |||
| virtual std::string shortID() const = 0; | |||
| /** | |||
| * The method used to verify that the value parsed from the command | |||
| * line meets the constraint. | |||
| * \param value - The value that will be checked. | |||
| */ | |||
| virtual bool check(const T& value) const =0; | |||
| /** | |||
| * The method used to verify that the value parsed from the command | |||
| * line meets the constraint. | |||
| * \param value - The value that will be checked. | |||
| */ | |||
| virtual bool check(const T& value) const = 0; | |||
| /** | |||
| * Destructor. | |||
| * Silences warnings about Constraint being a base class with virtual | |||
| * functions but without a virtual destructor. | |||
| */ | |||
| virtual ~Constraint() { ; } | |||
| /** | |||
| * Destructor. | |||
| * Silences warnings about Constraint being a base class with virtual | |||
| * functions but without a virtual destructor. | |||
| */ | |||
| virtual ~Constraint() | |||
| { | |||
| ; | |||
| } | |||
| static std::string shortID(Constraint<T> *constraint) { | |||
| if (!constraint) | |||
| throw std::logic_error("Cannot create a ValueArg with a NULL constraint"); | |||
| return constraint->shortID(); | |||
| } | |||
| }; | |||
| static std::string shortID(Constraint<T>* constraint) | |||
| { | |||
| if (!constraint) | |||
| throw std::logic_error("Cannot create a ValueArg with a NULL constraint"); | |||
| return constraint->shortID(); | |||
| } | |||
| }; | |||
| } //namespace TCLAP | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -1,25 +1,25 @@ | |||
| // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- | |||
| /****************************************************************************** | |||
| * | |||
| /****************************************************************************** | |||
| * | |||
| * file: DocBookOutput.h | |||
| * | |||
| * | |||
| * Copyright (c) 2004, Michael E. Smoot | |||
| * Copyright (c) 2017, Google LLC | |||
| * All rights reserved. | |||
| * | |||
| * | |||
| * See the file COPYING in the top directory of this distribution for | |||
| * more information. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| #ifndef TCLAP_DOCBOOKOUTPUT_H | |||
| #define TCLAP_DOCBOOKOUTPUT_H | |||
| @@ -35,269 +35,265 @@ | |||
| #include <tclap/XorHandler.h> | |||
| #include <tclap/Arg.h> | |||
| namespace TCLAP { | |||
| /** | |||
| * A class that generates DocBook output for usage() method for the | |||
| * given CmdLine and its Args. | |||
| */ | |||
| class DocBookOutput : public CmdLineOutput | |||
| namespace TCLAP | |||
| { | |||
| public: | |||
| /** | |||
| * Prints the usage to stdout. Can be overridden to | |||
| * produce alternative behavior. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| */ | |||
| virtual void usage(CmdLineInterface& c); | |||
| /** | |||
| * Prints the version to stdout. Can be overridden | |||
| * to produce alternative behavior. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| */ | |||
| virtual void version(CmdLineInterface& c); | |||
| /** | |||
| * Prints (to stderr) an error message, short usage | |||
| * Can be overridden to produce alternative behavior. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| * \param e - The ArgException that caused the failure. | |||
| */ | |||
| virtual void failure(CmdLineInterface& c, | |||
| ArgException& e ); | |||
| DocBookOutput() : theDelimiter('=') {} | |||
| protected: | |||
| /** | |||
| * Substitutes the char r for string x in string s. | |||
| * \param s - The string to operate on. | |||
| * \param r - The char to replace. | |||
| * \param x - What to replace r with. | |||
| */ | |||
| void substituteSpecialChars( std::string& s, char r, std::string& x ); | |||
| void removeChar( std::string& s, char r); | |||
| void basename( std::string& s ); | |||
| void printShortArg(Arg* it); | |||
| void printLongArg(Arg* it); | |||
| char theDelimiter; | |||
| }; | |||
| inline void DocBookOutput::version(CmdLineInterface& _cmd) | |||
| { | |||
| std::cout << _cmd.getVersion() << std::endl; | |||
| } | |||
| inline void DocBookOutput::usage(CmdLineInterface& _cmd ) | |||
| { | |||
| std::list<Arg*> argList = _cmd.getArgList(); | |||
| std::string progName = _cmd.getProgramName(); | |||
| std::string xversion = _cmd.getVersion(); | |||
| theDelimiter = _cmd.getDelimiter(); | |||
| XorHandler xorHandler = _cmd.getXorHandler(); | |||
| const std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList(); | |||
| basename(progName); | |||
| std::cout << "<?xml version='1.0'?>" << std::endl; | |||
| std::cout << "<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.2//EN\"" << std::endl; | |||
| std::cout << "\t\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\">" << std::endl << std::endl; | |||
| std::cout << "<refentry>" << std::endl; | |||
| std::cout << "<refmeta>" << std::endl; | |||
| std::cout << "<refentrytitle>" << progName << "</refentrytitle>" << std::endl; | |||
| std::cout << "<manvolnum>1</manvolnum>" << std::endl; | |||
| std::cout << "</refmeta>" << std::endl; | |||
| std::cout << "<refnamediv>" << std::endl; | |||
| std::cout << "<refname>" << progName << "</refname>" << std::endl; | |||
| std::cout << "<refpurpose>" << _cmd.getMessage() << "</refpurpose>" << std::endl; | |||
| std::cout << "</refnamediv>" << std::endl; | |||
| std::cout << "<refsynopsisdiv>" << std::endl; | |||
| std::cout << "<cmdsynopsis>" << std::endl; | |||
| std::cout << "<command>" << progName << "</command>" << std::endl; | |||
| // xor | |||
| for ( int i = 0; (unsigned int)i < xorList.size(); i++ ) | |||
| { | |||
| std::cout << "<group choice='req'>" << std::endl; | |||
| for ( ArgVectorIterator it = xorList[i].begin(); | |||
| it != xorList[i].end(); it++ ) | |||
| printShortArg((*it)); | |||
| std::cout << "</group>" << std::endl; | |||
| } | |||
| // rest of args | |||
| for (ArgListIterator it = argList.begin(); it != argList.end(); it++) | |||
| if ( !xorHandler.contains( (*it) ) ) | |||
| printShortArg((*it)); | |||
| std::cout << "</cmdsynopsis>" << std::endl; | |||
| std::cout << "</refsynopsisdiv>" << std::endl; | |||
| std::cout << "<refsect1>" << std::endl; | |||
| std::cout << "<title>Description</title>" << std::endl; | |||
| std::cout << "<para>" << std::endl; | |||
| std::cout << _cmd.getMessage() << std::endl; | |||
| std::cout << "</para>" << std::endl; | |||
| std::cout << "</refsect1>" << std::endl; | |||
| std::cout << "<refsect1>" << std::endl; | |||
| std::cout << "<title>Options</title>" << std::endl; | |||
| std::cout << "<variablelist>" << std::endl; | |||
| for (ArgListIterator it = argList.begin(); it != argList.end(); it++) | |||
| printLongArg((*it)); | |||
| std::cout << "</variablelist>" << std::endl; | |||
| std::cout << "</refsect1>" << std::endl; | |||
| std::cout << "<refsect1>" << std::endl; | |||
| std::cout << "<title>Version</title>" << std::endl; | |||
| std::cout << "<para>" << std::endl; | |||
| std::cout << xversion << std::endl; | |||
| std::cout << "</para>" << std::endl; | |||
| std::cout << "</refsect1>" << std::endl; | |||
| std::cout << "</refentry>" << std::endl; | |||
| } | |||
| inline void DocBookOutput::failure( CmdLineInterface& _cmd, | |||
| ArgException& e ) | |||
| { | |||
| static_cast<void>(_cmd); // unused | |||
| std::cout << e.what() << std::endl; | |||
| throw ExitException(1); | |||
| } | |||
| inline void DocBookOutput::substituteSpecialChars( std::string& s, | |||
| char r, | |||
| std::string& x ) | |||
| { | |||
| size_t p; | |||
| while ( (p = s.find_first_of(r)) != std::string::npos ) | |||
| { | |||
| s.erase(p,1); | |||
| s.insert(p,x); | |||
| } | |||
| } | |||
| inline void DocBookOutput::removeChar( std::string& s, char r) | |||
| { | |||
| size_t p; | |||
| while ( (p = s.find_first_of(r)) != std::string::npos ) | |||
| { | |||
| s.erase(p,1); | |||
| } | |||
| } | |||
| inline void DocBookOutput::basename( std::string& s ) | |||
| { | |||
| size_t p = s.find_last_of('/'); | |||
| if ( p != std::string::npos ) | |||
| { | |||
| s.erase(0, p + 1); | |||
| } | |||
| } | |||
| inline void DocBookOutput::printShortArg(Arg* a) | |||
| { | |||
| std::string lt = "<"; | |||
| std::string gt = ">"; | |||
| std::string id = a->shortID(); | |||
| substituteSpecialChars(id,'<',lt); | |||
| substituteSpecialChars(id,'>',gt); | |||
| removeChar(id,'['); | |||
| removeChar(id,']'); | |||
| std::string choice = "opt"; | |||
| if ( a->isRequired() ) | |||
| choice = "plain"; | |||
| std::cout << "<arg choice='" << choice << '\''; | |||
| if ( a->acceptsMultipleValues() ) | |||
| std::cout << " rep='repeat'"; | |||
| std::cout << '>'; | |||
| if ( !a->getFlag().empty() ) | |||
| std::cout << a->flagStartChar() << a->getFlag(); | |||
| else | |||
| std::cout << a->nameStartString() << a->getName(); | |||
| if ( a->isValueRequired() ) | |||
| { | |||
| std::string arg = a->shortID(); | |||
| removeChar(arg,'['); | |||
| removeChar(arg,']'); | |||
| removeChar(arg,'<'); | |||
| removeChar(arg,'>'); | |||
| removeChar(arg,'.'); | |||
| arg.erase(0, arg.find_last_of(theDelimiter) + 1); | |||
| std::cout << theDelimiter; | |||
| std::cout << "<replaceable>" << arg << "</replaceable>"; | |||
| } | |||
| std::cout << "</arg>" << std::endl; | |||
| } | |||
| inline void DocBookOutput::printLongArg(Arg* a) | |||
| { | |||
| std::string lt = "<"; | |||
| std::string gt = ">"; | |||
| std::string desc = a->getDescription(); | |||
| substituteSpecialChars(desc,'<',lt); | |||
| substituteSpecialChars(desc,'>',gt); | |||
| std::cout << "<varlistentry>" << std::endl; | |||
| if ( !a->getFlag().empty() ) | |||
| { | |||
| std::cout << "<term>" << std::endl; | |||
| std::cout << "<option>"; | |||
| std::cout << a->flagStartChar() << a->getFlag(); | |||
| std::cout << "</option>" << std::endl; | |||
| std::cout << "</term>" << std::endl; | |||
| } | |||
| std::cout << "<term>" << std::endl; | |||
| std::cout << "<option>"; | |||
| std::cout << a->nameStartString() << a->getName(); | |||
| if ( a->isValueRequired() ) | |||
| { | |||
| std::string arg = a->shortID(); | |||
| removeChar(arg,'['); | |||
| removeChar(arg,']'); | |||
| removeChar(arg,'<'); | |||
| removeChar(arg,'>'); | |||
| removeChar(arg,'.'); | |||
| arg.erase(0, arg.find_last_of(theDelimiter) + 1); | |||
| std::cout << theDelimiter; | |||
| std::cout << "<replaceable>" << arg << "</replaceable>"; | |||
| } | |||
| std::cout << "</option>" << std::endl; | |||
| std::cout << "</term>" << std::endl; | |||
| std::cout << "<listitem>" << std::endl; | |||
| std::cout << "<para>" << std::endl; | |||
| std::cout << desc << std::endl; | |||
| std::cout << "</para>" << std::endl; | |||
| std::cout << "</listitem>" << std::endl; | |||
| std::cout << "</varlistentry>" << std::endl; | |||
| } | |||
| } //namespace TCLAP | |||
| #endif | |||
| /** | |||
| * A class that generates DocBook output for usage() method for the | |||
| * given CmdLine and its Args. | |||
| */ | |||
| class DocBookOutput : public CmdLineOutput | |||
| { | |||
| public: | |||
| /** | |||
| * Prints the usage to stdout. Can be overridden to | |||
| * produce alternative behavior. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| */ | |||
| virtual void usage(CmdLineInterface& c); | |||
| /** | |||
| * Prints the version to stdout. Can be overridden | |||
| * to produce alternative behavior. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| */ | |||
| virtual void version(CmdLineInterface& c); | |||
| /** | |||
| * Prints (to stderr) an error message, short usage | |||
| * Can be overridden to produce alternative behavior. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| * \param e - The ArgException that caused the failure. | |||
| */ | |||
| virtual void failure(CmdLineInterface& c, ArgException& e); | |||
| DocBookOutput() : | |||
| theDelimiter('=') | |||
| { | |||
| } | |||
| protected: | |||
| /** | |||
| * Substitutes the char r for string x in string s. | |||
| * \param s - The string to operate on. | |||
| * \param r - The char to replace. | |||
| * \param x - What to replace r with. | |||
| */ | |||
| void substituteSpecialChars(std::string& s, char r, std::string& x); | |||
| void removeChar(std::string& s, char r); | |||
| void basename(std::string& s); | |||
| void printShortArg(Arg* it); | |||
| void printLongArg(Arg* it); | |||
| char theDelimiter; | |||
| }; | |||
| inline void DocBookOutput::version(CmdLineInterface& _cmd) | |||
| { | |||
| std::cout << _cmd.getVersion() << std::endl; | |||
| } | |||
| inline void DocBookOutput::usage(CmdLineInterface& _cmd) | |||
| { | |||
| std::list<Arg*> argList = _cmd.getArgList(); | |||
| std::string progName = _cmd.getProgramName(); | |||
| std::string xversion = _cmd.getVersion(); | |||
| theDelimiter = _cmd.getDelimiter(); | |||
| XorHandler xorHandler = _cmd.getXorHandler(); | |||
| const std::vector<std::vector<Arg*>> xorList = xorHandler.getXorList(); | |||
| basename(progName); | |||
| std::cout << "<?xml version='1.0'?>" << std::endl; | |||
| std::cout << "<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.2//EN\"" << std::endl; | |||
| std::cout << "\t\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\">" << std::endl | |||
| << std::endl; | |||
| std::cout << "<refentry>" << std::endl; | |||
| std::cout << "<refmeta>" << std::endl; | |||
| std::cout << "<refentrytitle>" << progName << "</refentrytitle>" << std::endl; | |||
| std::cout << "<manvolnum>1</manvolnum>" << std::endl; | |||
| std::cout << "</refmeta>" << std::endl; | |||
| std::cout << "<refnamediv>" << std::endl; | |||
| std::cout << "<refname>" << progName << "</refname>" << std::endl; | |||
| std::cout << "<refpurpose>" << _cmd.getMessage() << "</refpurpose>" << std::endl; | |||
| std::cout << "</refnamediv>" << std::endl; | |||
| std::cout << "<refsynopsisdiv>" << std::endl; | |||
| std::cout << "<cmdsynopsis>" << std::endl; | |||
| std::cout << "<command>" << progName << "</command>" << std::endl; | |||
| // xor | |||
| for (int i = 0; (unsigned int)i < xorList.size(); i++) | |||
| { | |||
| std::cout << "<group choice='req'>" << std::endl; | |||
| for (ArgVectorIterator it = xorList[i].begin(); | |||
| it != xorList[i].end(); | |||
| it++) | |||
| printShortArg((*it)); | |||
| std::cout << "</group>" << std::endl; | |||
| } | |||
| // rest of args | |||
| for (ArgListIterator it = argList.begin(); it != argList.end(); it++) | |||
| if (!xorHandler.contains((*it))) | |||
| printShortArg((*it)); | |||
| std::cout << "</cmdsynopsis>" << std::endl; | |||
| std::cout << "</refsynopsisdiv>" << std::endl; | |||
| std::cout << "<refsect1>" << std::endl; | |||
| std::cout << "<title>Description</title>" << std::endl; | |||
| std::cout << "<para>" << std::endl; | |||
| std::cout << _cmd.getMessage() << std::endl; | |||
| std::cout << "</para>" << std::endl; | |||
| std::cout << "</refsect1>" << std::endl; | |||
| std::cout << "<refsect1>" << std::endl; | |||
| std::cout << "<title>Options</title>" << std::endl; | |||
| std::cout << "<variablelist>" << std::endl; | |||
| for (ArgListIterator it = argList.begin(); it != argList.end(); it++) | |||
| printLongArg((*it)); | |||
| std::cout << "</variablelist>" << std::endl; | |||
| std::cout << "</refsect1>" << std::endl; | |||
| std::cout << "<refsect1>" << std::endl; | |||
| std::cout << "<title>Version</title>" << std::endl; | |||
| std::cout << "<para>" << std::endl; | |||
| std::cout << xversion << std::endl; | |||
| std::cout << "</para>" << std::endl; | |||
| std::cout << "</refsect1>" << std::endl; | |||
| std::cout << "</refentry>" << std::endl; | |||
| } | |||
| inline void DocBookOutput::failure(CmdLineInterface& _cmd, ArgException& e) | |||
| { | |||
| static_cast<void>(_cmd); // unused | |||
| std::cout << e.what() << std::endl; | |||
| throw ExitException(1); | |||
| } | |||
| inline void DocBookOutput::substituteSpecialChars(std::string& s, char r, std::string& x) | |||
| { | |||
| size_t p; | |||
| while ((p = s.find_first_of(r)) != std::string::npos) | |||
| { | |||
| s.erase(p, 1); | |||
| s.insert(p, x); | |||
| } | |||
| } | |||
| inline void DocBookOutput::removeChar(std::string& s, char r) | |||
| { | |||
| size_t p; | |||
| while ((p = s.find_first_of(r)) != std::string::npos) | |||
| { | |||
| s.erase(p, 1); | |||
| } | |||
| } | |||
| inline void DocBookOutput::basename(std::string& s) | |||
| { | |||
| size_t p = s.find_last_of('/'); | |||
| if (p != std::string::npos) | |||
| { | |||
| s.erase(0, p + 1); | |||
| } | |||
| } | |||
| inline void DocBookOutput::printShortArg(Arg* a) | |||
| { | |||
| std::string lt = "<"; | |||
| std::string gt = ">"; | |||
| std::string id = a->shortID(); | |||
| substituteSpecialChars(id, '<', lt); | |||
| substituteSpecialChars(id, '>', gt); | |||
| removeChar(id, '['); | |||
| removeChar(id, ']'); | |||
| std::string choice = "opt"; | |||
| if (a->isRequired()) | |||
| choice = "plain"; | |||
| std::cout << "<arg choice='" << choice << '\''; | |||
| if (a->acceptsMultipleValues()) | |||
| std::cout << " rep='repeat'"; | |||
| std::cout << '>'; | |||
| if (!a->getFlag().empty()) | |||
| std::cout << a->flagStartChar() << a->getFlag(); | |||
| else | |||
| std::cout << a->nameStartString() << a->getName(); | |||
| if (a->isValueRequired()) | |||
| { | |||
| std::string arg = a->shortID(); | |||
| removeChar(arg, '['); | |||
| removeChar(arg, ']'); | |||
| removeChar(arg, '<'); | |||
| removeChar(arg, '>'); | |||
| removeChar(arg, '.'); | |||
| arg.erase(0, arg.find_last_of(theDelimiter) + 1); | |||
| std::cout << theDelimiter; | |||
| std::cout << "<replaceable>" << arg << "</replaceable>"; | |||
| } | |||
| std::cout << "</arg>" << std::endl; | |||
| } | |||
| inline void DocBookOutput::printLongArg(Arg* a) | |||
| { | |||
| std::string lt = "<"; | |||
| std::string gt = ">"; | |||
| std::string desc = a->getDescription(); | |||
| substituteSpecialChars(desc, '<', lt); | |||
| substituteSpecialChars(desc, '>', gt); | |||
| std::cout << "<varlistentry>" << std::endl; | |||
| if (!a->getFlag().empty()) | |||
| { | |||
| std::cout << "<term>" << std::endl; | |||
| std::cout << "<option>"; | |||
| std::cout << a->flagStartChar() << a->getFlag(); | |||
| std::cout << "</option>" << std::endl; | |||
| std::cout << "</term>" << std::endl; | |||
| } | |||
| std::cout << "<term>" << std::endl; | |||
| std::cout << "<option>"; | |||
| std::cout << a->nameStartString() << a->getName(); | |||
| if (a->isValueRequired()) | |||
| { | |||
| std::string arg = a->shortID(); | |||
| removeChar(arg, '['); | |||
| removeChar(arg, ']'); | |||
| removeChar(arg, '<'); | |||
| removeChar(arg, '>'); | |||
| removeChar(arg, '.'); | |||
| arg.erase(0, arg.find_last_of(theDelimiter) + 1); | |||
| std::cout << theDelimiter; | |||
| std::cout << "<replaceable>" << arg << "</replaceable>"; | |||
| } | |||
| std::cout << "</option>" << std::endl; | |||
| std::cout << "</term>" << std::endl; | |||
| std::cout << "<listitem>" << std::endl; | |||
| std::cout << "<para>" << std::endl; | |||
| std::cout << desc << std::endl; | |||
| std::cout << "</para>" << std::endl; | |||
| std::cout << "</listitem>" << std::endl; | |||
| std::cout << "</varlistentry>" << std::endl; | |||
| } | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -1,25 +1,24 @@ | |||
| // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- | |||
| /****************************************************************************** | |||
| * | |||
| /****************************************************************************** | |||
| * | |||
| * file: HelpVisitor.h | |||
| * | |||
| * | |||
| * Copyright (c) 2003, Michael E. Smoot . | |||
| * All rights reserved. | |||
| * | |||
| * | |||
| * See the file COPYING in the top directory of this distribution for | |||
| * more information. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| #ifndef TCLAP_HELP_VISITOR_H | |||
| #define TCLAP_HELP_VISITOR_H | |||
| @@ -28,51 +27,57 @@ | |||
| #include <tclap/CmdLineOutput.h> | |||
| #include <tclap/Visitor.h> | |||
| namespace TCLAP { | |||
| /** | |||
| * A Visitor object that calls the usage method of the given CmdLineOutput | |||
| * object for the specified CmdLine object. | |||
| */ | |||
| class HelpVisitor: public Visitor | |||
| namespace TCLAP | |||
| { | |||
| private: | |||
| /** | |||
| * Prevent accidental copying. | |||
| */ | |||
| HelpVisitor(const HelpVisitor& rhs); | |||
| HelpVisitor& operator=(const HelpVisitor& rhs); | |||
| protected: | |||
| /** | |||
| * The CmdLine the output will be generated for. | |||
| */ | |||
| CmdLineInterface* _cmd; | |||
| /** | |||
| * A Visitor object that calls the usage method of the given CmdLineOutput | |||
| * object for the specified CmdLine object. | |||
| */ | |||
| class HelpVisitor : public Visitor | |||
| { | |||
| private: | |||
| /** | |||
| * Prevent accidental copying. | |||
| */ | |||
| HelpVisitor(const HelpVisitor& rhs); | |||
| HelpVisitor& operator=(const HelpVisitor& rhs); | |||
| /** | |||
| * The output object. | |||
| */ | |||
| CmdLineOutput** _out; | |||
| protected: | |||
| /** | |||
| * The CmdLine the output will be generated for. | |||
| */ | |||
| CmdLineInterface* _cmd; | |||
| public: | |||
| /** | |||
| * The output object. | |||
| */ | |||
| CmdLineOutput** _out; | |||
| /** | |||
| * Constructor. | |||
| * \param cmd - The CmdLine the output will be generated for. | |||
| * \param out - The type of output. | |||
| */ | |||
| HelpVisitor(CmdLineInterface* cmd, CmdLineOutput** out) | |||
| : Visitor(), _cmd( cmd ), _out( out ) { } | |||
| public: | |||
| /** | |||
| * Constructor. | |||
| * \param cmd - The CmdLine the output will be generated for. | |||
| * \param out - The type of output. | |||
| */ | |||
| HelpVisitor(CmdLineInterface* cmd, CmdLineOutput** out) : | |||
| Visitor(), | |||
| _cmd(cmd), | |||
| _out(out) | |||
| { | |||
| } | |||
| /** | |||
| * Calls the usage method of the CmdLineOutput for the | |||
| * specified CmdLine. | |||
| */ | |||
| void visit() { (*_out)->usage(*_cmd); throw ExitException(0); } | |||
| }; | |||
| /** | |||
| * Calls the usage method of the CmdLineOutput for the | |||
| * specified CmdLine. | |||
| */ | |||
| void visit() | |||
| { | |||
| (*_out)->usage(*_cmd); | |||
| throw ExitException(0); | |||
| } | |||
| }; | |||
| } | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -1,26 +1,24 @@ | |||
| // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- | |||
| /****************************************************************************** | |||
| * | |||
| /****************************************************************************** | |||
| * | |||
| * file: IgnoreRestVisitor.h | |||
| * | |||
| * | |||
| * Copyright (c) 2003, Michael E. Smoot . | |||
| * All rights reserved. | |||
| * | |||
| * | |||
| * See the file COPYING in the top directory of this distribution for | |||
| * more information. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| #ifndef TCLAP_IGNORE_REST_VISITOR_H | |||
| #define TCLAP_IGNORE_REST_VISITOR_H | |||
| @@ -28,27 +26,33 @@ | |||
| #include <tclap/Visitor.h> | |||
| #include <tclap/Arg.h> | |||
| namespace TCLAP { | |||
| /** | |||
| * A Visitor that tells the CmdLine to begin ignoring arguments after | |||
| * this one is parsed. | |||
| */ | |||
| class IgnoreRestVisitor: public Visitor | |||
| namespace TCLAP | |||
| { | |||
| public: | |||
| /** | |||
| * Constructor. | |||
| */ | |||
| IgnoreRestVisitor() : Visitor() {} | |||
| /** | |||
| * Sets Arg::_ignoreRest. | |||
| */ | |||
| void visit() { Arg::beginIgnoring(); } | |||
| }; | |||
| } | |||
| /** | |||
| * A Visitor that tells the CmdLine to begin ignoring arguments after | |||
| * this one is parsed. | |||
| */ | |||
| class IgnoreRestVisitor : public Visitor | |||
| { | |||
| public: | |||
| /** | |||
| * Constructor. | |||
| */ | |||
| IgnoreRestVisitor() : | |||
| Visitor() | |||
| { | |||
| } | |||
| /** | |||
| * Sets Arg::_ignoreRest. | |||
| */ | |||
| void visit() | |||
| { | |||
| Arg::beginIgnoring(); | |||
| } | |||
| }; | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -1,28 +1,27 @@ | |||
| // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- | |||
| /****************************************************************************** | |||
| * | |||
| /****************************************************************************** | |||
| * | |||
| * file: MultiArg.h | |||
| * | |||
| * | |||
| * Copyright (c) 2003, Michael E. Smoot . | |||
| * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. | |||
| * Copyright (c) 2017, Google LLC | |||
| * All rights reserved. | |||
| * | |||
| * | |||
| * See the file COPYING in the top directory of this distribution for | |||
| * more information. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| #ifndef TCLAP_MULTIPLE_ARGUMENT_H | |||
| #define TCLAP_MULTIPLE_ARGUMENT_H | |||
| @@ -32,402 +31,364 @@ | |||
| #include <tclap/Arg.h> | |||
| #include <tclap/Constraint.h> | |||
| namespace TCLAP { | |||
| /** | |||
| * An argument that allows multiple values of type T to be specified. Very | |||
| * similar to a ValueArg, except a vector of values will be returned | |||
| * instead of just one. | |||
| */ | |||
| template<class T> | |||
| class MultiArg : public Arg | |||
| { | |||
| public: | |||
| typedef std::vector<T> container_type; | |||
| typedef typename container_type::iterator iterator; | |||
| typedef typename container_type::const_iterator const_iterator; | |||
| protected: | |||
| /** | |||
| * The list of values parsed from the CmdLine. | |||
| */ | |||
| std::vector<T> _values; | |||
| /** | |||
| * The description of type T to be used in the usage. | |||
| */ | |||
| std::string _typeDesc; | |||
| /** | |||
| * A list of constraint on this Arg. | |||
| */ | |||
| Constraint<T>* _constraint; | |||
| /** | |||
| * Extracts the value from the string. | |||
| * Attempts to parse string as type T, if this fails an exception | |||
| * is thrown. | |||
| * \param val - The string to be read. | |||
| */ | |||
| void _extractValue( const std::string& val ); | |||
| /** | |||
| * Used by XorHandler to decide whether to keep parsing for this arg. | |||
| */ | |||
| bool _allowMore; | |||
| public: | |||
| /** | |||
| * Constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param typeDesc - A short, human readable description of the | |||
| * type that this object expects. This is used in the generation | |||
| * of the USAGE statement. The goal is to be helpful to the end user | |||
| * of the program. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| MultiArg( const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| const std::string& typeDesc, | |||
| Visitor* v = NULL); | |||
| /** | |||
| * Constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param typeDesc - A short, human readable description of the | |||
| * type that this object expects. This is used in the generation | |||
| * of the USAGE statement. The goal is to be helpful to the end user | |||
| * of the program. | |||
| * \param parser - A CmdLine parser object to add this Arg to | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| MultiArg( const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| const std::string& typeDesc, | |||
| CmdLineInterface& parser, | |||
| Visitor* v = NULL ); | |||
| /** | |||
| * Constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param constraint - A pointer to a Constraint object used | |||
| * to constrain this Arg. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| MultiArg( const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| Constraint<T>* constraint, | |||
| Visitor* v = NULL ); | |||
| /** | |||
| * Constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param constraint - A pointer to a Constraint object used | |||
| * to constrain this Arg. | |||
| * \param parser - A CmdLine parser object to add this Arg to | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| MultiArg( const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| Constraint<T>* constraint, | |||
| CmdLineInterface& parser, | |||
| Visitor* v = NULL ); | |||
| /** | |||
| * Handles the processing of the argument. | |||
| * This re-implements the Arg version of this method to set the | |||
| * _value of the argument appropriately. It knows the difference | |||
| * between labeled and unlabeled. | |||
| * \param i - Pointer the the current argument in the list. | |||
| * \param args - Mutable list of strings. Passed from main(). | |||
| */ | |||
| virtual bool processArg(int* i, std::vector<std::string>& args); | |||
| /** | |||
| * Returns a vector of type T containing the values parsed from | |||
| * the command line. | |||
| */ | |||
| const std::vector<T>& getValue() const { return _values; } | |||
| /** | |||
| * Returns an iterator over the values parsed from the command | |||
| * line. | |||
| */ | |||
| const_iterator begin() const { return _values.begin(); } | |||
| /** | |||
| * Returns the end of the values parsed from the command | |||
| * line. | |||
| */ | |||
| const_iterator end() const { return _values.end(); } | |||
| /** | |||
| * Returns the a short id string. Used in the usage. | |||
| * \param val - value to be used. | |||
| */ | |||
| virtual std::string shortID(const std::string& val="val") const; | |||
| /** | |||
| * Returns the a long id string. Used in the usage. | |||
| * \param val - value to be used. | |||
| */ | |||
| virtual std::string longID(const std::string& val="val") const; | |||
| /** | |||
| * Once we've matched the first value, then the arg is no longer | |||
| * required. | |||
| */ | |||
| virtual bool isRequired() const; | |||
| virtual bool allowMore(); | |||
| virtual void reset(); | |||
| private: | |||
| /** | |||
| * Prevent accidental copying | |||
| */ | |||
| MultiArg<T>(const MultiArg<T>& rhs); | |||
| MultiArg<T>& operator=(const MultiArg<T>& rhs); | |||
| }; | |||
| template<class T> | |||
| MultiArg<T>::MultiArg(const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| const std::string& typeDesc, | |||
| Visitor* v) : | |||
| Arg( flag, name, desc, req, true, v ), | |||
| _values(std::vector<T>()), | |||
| _typeDesc( typeDesc ), | |||
| _constraint( NULL ), | |||
| _allowMore(false) | |||
| { | |||
| _acceptsMultipleValues = true; | |||
| } | |||
| template<class T> | |||
| MultiArg<T>::MultiArg(const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| const std::string& typeDesc, | |||
| CmdLineInterface& parser, | |||
| Visitor* v) | |||
| : Arg( flag, name, desc, req, true, v ), | |||
| _values(std::vector<T>()), | |||
| _typeDesc( typeDesc ), | |||
| _constraint( NULL ), | |||
| _allowMore(false) | |||
| { | |||
| parser.add( this ); | |||
| _acceptsMultipleValues = true; | |||
| } | |||
| /** | |||
| * | |||
| */ | |||
| template<class T> | |||
| MultiArg<T>::MultiArg(const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| Constraint<T>* constraint, | |||
| Visitor* v) | |||
| : Arg( flag, name, desc, req, true, v ), | |||
| _values(std::vector<T>()), | |||
| _typeDesc( Constraint<T>::shortID(constraint) ), | |||
| _constraint( constraint ), | |||
| _allowMore(false) | |||
| { | |||
| _acceptsMultipleValues = true; | |||
| } | |||
| template<class T> | |||
| MultiArg<T>::MultiArg(const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| Constraint<T>* constraint, | |||
| CmdLineInterface& parser, | |||
| Visitor* v) | |||
| : Arg( flag, name, desc, req, true, v ), | |||
| _values(std::vector<T>()), | |||
| _typeDesc( Constraint<T>::shortID(constraint) ), | |||
| _constraint( constraint ), | |||
| _allowMore(false) | |||
| { | |||
| parser.add( this ); | |||
| _acceptsMultipleValues = true; | |||
| } | |||
| template<class T> | |||
| bool MultiArg<T>::processArg(int *i, std::vector<std::string>& args) | |||
| namespace TCLAP | |||
| { | |||
| if ( _ignoreable && Arg::ignoreRest() ) | |||
| return false; | |||
| if ( _hasBlanks( args[*i] ) ) | |||
| return false; | |||
| std::string flag = args[*i]; | |||
| std::string value = ""; | |||
| trimFlag( flag, value ); | |||
| if ( argMatches( flag ) ) | |||
| { | |||
| if ( Arg::delimiter() != ' ' && value == "" ) | |||
| throw( ArgParseException( | |||
| "Couldn't find delimiter for this argument!", | |||
| toString() ) ); | |||
| // always take the first one, regardless of start string | |||
| if ( value == "" ) | |||
| { | |||
| (*i)++; | |||
| if ( static_cast<unsigned int>(*i) < args.size() ) | |||
| _extractValue( args[*i] ); | |||
| else | |||
| throw( ArgParseException("Missing a value for this argument!", | |||
| toString() ) ); | |||
| } | |||
| else | |||
| _extractValue( value ); | |||
| /* | |||
| // continuing taking the args until we hit one with a start string | |||
| while ( (unsigned int)(*i)+1 < args.size() && | |||
| args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 && | |||
| args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 ) | |||
| _extractValue( args[++(*i)] ); | |||
| */ | |||
| _alreadySet = true; | |||
| _checkWithVisitor(); | |||
| return true; | |||
| } | |||
| else | |||
| return false; | |||
| } | |||
| /** | |||
| * | |||
| */ | |||
| template<class T> | |||
| std::string MultiArg<T>::shortID(const std::string& val) const | |||
| { | |||
| static_cast<void>(val); // Ignore input, don't warn | |||
| return Arg::shortID(_typeDesc) + " ..."; | |||
| } | |||
| /** | |||
| * An argument that allows multiple values of type T to be specified. Very | |||
| * similar to a ValueArg, except a vector of values will be returned | |||
| * instead of just one. | |||
| */ | |||
| template<class T> | |||
| class MultiArg : public Arg | |||
| { | |||
| public: | |||
| typedef std::vector<T> container_type; | |||
| typedef typename container_type::iterator iterator; | |||
| typedef typename container_type::const_iterator const_iterator; | |||
| protected: | |||
| /** | |||
| * The list of values parsed from the CmdLine. | |||
| */ | |||
| std::vector<T> _values; | |||
| /** | |||
| * The description of type T to be used in the usage. | |||
| */ | |||
| std::string _typeDesc; | |||
| /** | |||
| * A list of constraint on this Arg. | |||
| */ | |||
| Constraint<T>* _constraint; | |||
| /** | |||
| * Extracts the value from the string. | |||
| * Attempts to parse string as type T, if this fails an exception | |||
| * is thrown. | |||
| * \param val - The string to be read. | |||
| */ | |||
| void _extractValue(const std::string& val); | |||
| /** | |||
| * Used by XorHandler to decide whether to keep parsing for this arg. | |||
| */ | |||
| bool _allowMore; | |||
| public: | |||
| /** | |||
| * Constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param typeDesc - A short, human readable description of the | |||
| * type that this object expects. This is used in the generation | |||
| * of the USAGE statement. The goal is to be helpful to the end user | |||
| * of the program. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| MultiArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, const std::string& typeDesc, Visitor* v = NULL); | |||
| /** | |||
| * Constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param typeDesc - A short, human readable description of the | |||
| * type that this object expects. This is used in the generation | |||
| * of the USAGE statement. The goal is to be helpful to the end user | |||
| * of the program. | |||
| * \param parser - A CmdLine parser object to add this Arg to | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| MultiArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, const std::string& typeDesc, CmdLineInterface& parser, Visitor* v = NULL); | |||
| /** | |||
| * Constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param constraint - A pointer to a Constraint object used | |||
| * to constrain this Arg. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| MultiArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, Constraint<T>* constraint, Visitor* v = NULL); | |||
| /** | |||
| * Constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param constraint - A pointer to a Constraint object used | |||
| * to constrain this Arg. | |||
| * \param parser - A CmdLine parser object to add this Arg to | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| MultiArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, Constraint<T>* constraint, CmdLineInterface& parser, Visitor* v = NULL); | |||
| /** | |||
| * Handles the processing of the argument. | |||
| * This re-implements the Arg version of this method to set the | |||
| * _value of the argument appropriately. It knows the difference | |||
| * between labeled and unlabeled. | |||
| * \param i - Pointer the the current argument in the list. | |||
| * \param args - Mutable list of strings. Passed from main(). | |||
| */ | |||
| virtual bool processArg(int* i, std::vector<std::string>& args); | |||
| /** | |||
| * Returns a vector of type T containing the values parsed from | |||
| * the command line. | |||
| */ | |||
| const std::vector<T>& getValue() const | |||
| { | |||
| return _values; | |||
| } | |||
| /** | |||
| * Returns an iterator over the values parsed from the command | |||
| * line. | |||
| */ | |||
| const_iterator begin() const | |||
| { | |||
| return _values.begin(); | |||
| } | |||
| /** | |||
| * Returns the end of the values parsed from the command | |||
| * line. | |||
| */ | |||
| const_iterator end() const | |||
| { | |||
| return _values.end(); | |||
| } | |||
| /** | |||
| * Returns the a short id string. Used in the usage. | |||
| * \param val - value to be used. | |||
| */ | |||
| virtual std::string shortID(const std::string& val = "val") const; | |||
| /** | |||
| * Returns the a long id string. Used in the usage. | |||
| * \param val - value to be used. | |||
| */ | |||
| virtual std::string longID(const std::string& val = "val") const; | |||
| /** | |||
| * Once we've matched the first value, then the arg is no longer | |||
| * required. | |||
| */ | |||
| virtual bool isRequired() const; | |||
| virtual bool allowMore(); | |||
| virtual void reset(); | |||
| private: | |||
| /** | |||
| * Prevent accidental copying | |||
| */ | |||
| MultiArg<T>(const MultiArg<T>& rhs); | |||
| MultiArg<T>& operator=(const MultiArg<T>& rhs); | |||
| }; | |||
| template<class T> | |||
| MultiArg<T>::MultiArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, const std::string& typeDesc, Visitor* v) : | |||
| Arg(flag, name, desc, req, true, v), | |||
| _values(std::vector<T>()), | |||
| _typeDesc(typeDesc), | |||
| _constraint(NULL), | |||
| _allowMore(false) | |||
| { | |||
| _acceptsMultipleValues = true; | |||
| } | |||
| /** | |||
| * | |||
| */ | |||
| template<class T> | |||
| std::string MultiArg<T>::longID(const std::string& val) const | |||
| { | |||
| static_cast<void>(val); // Ignore input, don't warn | |||
| return Arg::longID(_typeDesc) + " (accepted multiple times)"; | |||
| } | |||
| /** | |||
| * Once we've matched the first value, then the arg is no longer | |||
| * required. | |||
| */ | |||
| template<class T> | |||
| bool MultiArg<T>::isRequired() const | |||
| { | |||
| if ( _required ) | |||
| { | |||
| if ( _values.size() > 1 ) | |||
| return false; | |||
| else | |||
| return true; | |||
| } | |||
| else | |||
| return false; | |||
| } | |||
| template<class T> | |||
| void MultiArg<T>::_extractValue( const std::string& val ) | |||
| { | |||
| try { | |||
| T tmp; | |||
| ExtractValue(tmp, val, typename ArgTraits<T>::ValueCategory()); | |||
| _values.push_back(tmp); | |||
| } catch( ArgParseException &e) { | |||
| throw ArgParseException(e.error(), toString()); | |||
| template<class T> | |||
| MultiArg<T>::MultiArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, const std::string& typeDesc, CmdLineInterface& parser, Visitor* v) : | |||
| Arg(flag, name, desc, req, true, v), | |||
| _values(std::vector<T>()), | |||
| _typeDesc(typeDesc), | |||
| _constraint(NULL), | |||
| _allowMore(false) | |||
| { | |||
| parser.add(this); | |||
| _acceptsMultipleValues = true; | |||
| } | |||
| if ( _constraint != NULL ) | |||
| if ( ! _constraint->check( _values.back() ) ) | |||
| throw( CmdLineParseException( "Value '" + val + | |||
| "' does not meet constraint: " + | |||
| _constraint->description(), | |||
| toString() ) ); | |||
| } | |||
| template<class T> | |||
| bool MultiArg<T>::allowMore() | |||
| { | |||
| bool am = _allowMore; | |||
| _allowMore = true; | |||
| return am; | |||
| } | |||
| /** | |||
| * | |||
| */ | |||
| template<class T> | |||
| MultiArg<T>::MultiArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, Constraint<T>* constraint, Visitor* v) : | |||
| Arg(flag, name, desc, req, true, v), | |||
| _values(std::vector<T>()), | |||
| _typeDesc(Constraint<T>::shortID(constraint)), | |||
| _constraint(constraint), | |||
| _allowMore(false) | |||
| { | |||
| _acceptsMultipleValues = true; | |||
| } | |||
| template<class T> | |||
| void MultiArg<T>::reset() | |||
| { | |||
| Arg::reset(); | |||
| _values.clear(); | |||
| } | |||
| template<class T> | |||
| MultiArg<T>::MultiArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, Constraint<T>* constraint, CmdLineInterface& parser, Visitor* v) : | |||
| Arg(flag, name, desc, req, true, v), | |||
| _values(std::vector<T>()), | |||
| _typeDesc(Constraint<T>::shortID(constraint)), | |||
| _constraint(constraint), | |||
| _allowMore(false) | |||
| { | |||
| parser.add(this); | |||
| _acceptsMultipleValues = true; | |||
| } | |||
| template<class T> | |||
| bool MultiArg<T>::processArg(int* i, std::vector<std::string>& args) | |||
| { | |||
| if (_ignoreable && Arg::ignoreRest()) | |||
| return false; | |||
| if (_hasBlanks(args[*i])) | |||
| return false; | |||
| std::string flag = args[*i]; | |||
| std::string value = ""; | |||
| trimFlag(flag, value); | |||
| if (argMatches(flag)) | |||
| { | |||
| if (Arg::delimiter() != ' ' && value == "") | |||
| throw(ArgParseException( | |||
| "Couldn't find delimiter for this argument!", | |||
| toString() | |||
| )); | |||
| // always take the first one, regardless of start string | |||
| if (value == "") | |||
| { | |||
| (*i)++; | |||
| if (static_cast<unsigned int>(*i) < args.size()) | |||
| _extractValue(args[*i]); | |||
| else | |||
| throw(ArgParseException("Missing a value for this argument!", toString())); | |||
| } | |||
| else | |||
| _extractValue(value); | |||
| /* | |||
| // continuing taking the args until we hit one with a start string | |||
| while ( (unsigned int)(*i)+1 < args.size() && | |||
| args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 && | |||
| args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 ) | |||
| _extractValue( args[++(*i)] ); | |||
| */ | |||
| _alreadySet = true; | |||
| _checkWithVisitor(); | |||
| return true; | |||
| } | |||
| else | |||
| return false; | |||
| } | |||
| /** | |||
| * | |||
| */ | |||
| template<class T> | |||
| std::string MultiArg<T>::shortID(const std::string& val) const | |||
| { | |||
| static_cast<void>(val); // Ignore input, don't warn | |||
| return Arg::shortID(_typeDesc) + " ..."; | |||
| } | |||
| /** | |||
| * | |||
| */ | |||
| template<class T> | |||
| std::string MultiArg<T>::longID(const std::string& val) const | |||
| { | |||
| static_cast<void>(val); // Ignore input, don't warn | |||
| return Arg::longID(_typeDesc) + " (accepted multiple times)"; | |||
| } | |||
| /** | |||
| * Once we've matched the first value, then the arg is no longer | |||
| * required. | |||
| */ | |||
| template<class T> | |||
| bool MultiArg<T>::isRequired() const | |||
| { | |||
| if (_required) | |||
| { | |||
| if (_values.size() > 1) | |||
| return false; | |||
| else | |||
| return true; | |||
| } | |||
| else | |||
| return false; | |||
| } | |||
| template<class T> | |||
| void MultiArg<T>::_extractValue(const std::string& val) | |||
| { | |||
| try | |||
| { | |||
| T tmp; | |||
| ExtractValue(tmp, val, typename ArgTraits<T>::ValueCategory()); | |||
| _values.push_back(tmp); | |||
| } | |||
| catch (ArgParseException& e) | |||
| { | |||
| throw ArgParseException(e.error(), toString()); | |||
| } | |||
| if (_constraint != NULL) | |||
| if (!_constraint->check(_values.back())) | |||
| throw(CmdLineParseException("Value '" + val + "' does not meet constraint: " + _constraint->description(), toString())); | |||
| } | |||
| template<class T> | |||
| bool MultiArg<T>::allowMore() | |||
| { | |||
| bool am = _allowMore; | |||
| _allowMore = true; | |||
| return am; | |||
| } | |||
| template<class T> | |||
| void MultiArg<T>::reset() | |||
| { | |||
| Arg::reset(); | |||
| _values.clear(); | |||
| } | |||
| } // namespace TCLAP | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -1,29 +1,27 @@ | |||
| // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- | |||
| /****************************************************************************** | |||
| * | |||
| * file: MultiSwitchArg.h | |||
| * | |||
| * Copyright (c) 2003, Michael E. Smoot . | |||
| * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. | |||
| * Copyright (c) 2005, Michael E. Smoot, Daniel Aarno, Erik Zeek. | |||
| * Copyright (c) 2017, Google LLC | |||
| * All rights reserved. | |||
| * | |||
| * See the file COPYING in the top directory of this distribution for | |||
| * more information. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| /****************************************************************************** | |||
| * | |||
| * file: MultiSwitchArg.h | |||
| * | |||
| * Copyright (c) 2003, Michael E. Smoot . | |||
| * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. | |||
| * Copyright (c) 2005, Michael E. Smoot, Daniel Aarno, Erik Zeek. | |||
| * Copyright (c) 2017, Google LLC | |||
| * All rights reserved. | |||
| * | |||
| * See the file COPYING in the top directory of this distribution for | |||
| * more information. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| #ifndef TCLAP_MULTI_SWITCH_ARG_H | |||
| #define TCLAP_MULTI_SWITCH_ARG_H | |||
| @@ -33,185 +31,167 @@ | |||
| #include <tclap/SwitchArg.h> | |||
| namespace TCLAP { | |||
| /** | |||
| * A multiple switch argument. If the switch is set on the command line, then | |||
| * the getValue method will return the number of times the switch appears. | |||
| */ | |||
| class MultiSwitchArg : public SwitchArg | |||
| namespace TCLAP | |||
| { | |||
| protected: | |||
| /** | |||
| * The value of the switch. | |||
| */ | |||
| int _value; | |||
| /** | |||
| * Used to support the reset() method so that ValueArg can be | |||
| * reset to their constructed value. | |||
| */ | |||
| int _default; | |||
| public: | |||
| /** | |||
| * MultiSwitchArg constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param init - Optional. The initial/default value of this Arg. | |||
| * Defaults to 0. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| MultiSwitchArg(const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| int init = 0, | |||
| Visitor* v = NULL); | |||
| /** | |||
| * MultiSwitchArg constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param parser - A CmdLine parser object to add this Arg to | |||
| * \param init - Optional. The initial/default value of this Arg. | |||
| * Defaults to 0. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| MultiSwitchArg(const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| CmdLineInterface& parser, | |||
| int init = 0, | |||
| Visitor* v = NULL); | |||
| /** | |||
| * Handles the processing of the argument. | |||
| * This re-implements the SwitchArg version of this method to set the | |||
| * _value of the argument appropriately. | |||
| * \param i - Pointer the the current argument in the list. | |||
| * \param args - Mutable list of strings. Passed | |||
| * in from main(). | |||
| */ | |||
| virtual bool processArg(int* i, std::vector<std::string>& args); | |||
| /** | |||
| * Returns int, the number of times the switch has been set. | |||
| */ | |||
| int getValue() const { return _value; } | |||
| /** | |||
| * Returns the shortID for this Arg. | |||
| */ | |||
| std::string shortID(const std::string& val) const; | |||
| /** | |||
| * Returns the longID for this Arg. | |||
| */ | |||
| std::string longID(const std::string& val) const; | |||
| void reset(); | |||
| }; | |||
| ////////////////////////////////////////////////////////////////////// | |||
| //BEGIN MultiSwitchArg.cpp | |||
| ////////////////////////////////////////////////////////////////////// | |||
| inline MultiSwitchArg::MultiSwitchArg(const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| int init, | |||
| Visitor* v ) | |||
| : SwitchArg(flag, name, desc, false, v), | |||
| _value( init ), | |||
| _default( init ) | |||
| { } | |||
| inline MultiSwitchArg::MultiSwitchArg(const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| CmdLineInterface& parser, | |||
| int init, | |||
| Visitor* v ) | |||
| : SwitchArg(flag, name, desc, false, v), | |||
| _value( init ), | |||
| _default( init ) | |||
| { | |||
| parser.add( this ); | |||
| } | |||
| inline bool MultiSwitchArg::processArg(int *i, std::vector<std::string>& args) | |||
| { | |||
| if ( _ignoreable && Arg::ignoreRest() ) | |||
| return false; | |||
| if ( argMatches( args[*i] )) | |||
| { | |||
| // so the isSet() method will work | |||
| _alreadySet = true; | |||
| // Matched argument: increment value. | |||
| ++_value; | |||
| _checkWithVisitor(); | |||
| return true; | |||
| } | |||
| else if ( combinedSwitchesMatch( args[*i] ) ) | |||
| { | |||
| // so the isSet() method will work | |||
| _alreadySet = true; | |||
| // Matched argument: increment value. | |||
| ++_value; | |||
| // Check for more in argument and increment value. | |||
| while ( combinedSwitchesMatch( args[*i] ) ) | |||
| ++_value; | |||
| _checkWithVisitor(); | |||
| return false; | |||
| } | |||
| else | |||
| return false; | |||
| } | |||
| inline std::string | |||
| MultiSwitchArg::shortID(const std::string& val) const | |||
| { | |||
| return Arg::shortID(val) + " ..."; | |||
| } | |||
| inline std::string | |||
| MultiSwitchArg::longID(const std::string& val) const | |||
| { | |||
| return Arg::longID(val) + " (accepted multiple times)"; | |||
| } | |||
| inline void | |||
| MultiSwitchArg::reset() | |||
| { | |||
| MultiSwitchArg::_value = MultiSwitchArg::_default; | |||
| } | |||
| ////////////////////////////////////////////////////////////////////// | |||
| //END MultiSwitchArg.cpp | |||
| ////////////////////////////////////////////////////////////////////// | |||
| } //namespace TCLAP | |||
| /** | |||
| * A multiple switch argument. If the switch is set on the command line, then | |||
| * the getValue method will return the number of times the switch appears. | |||
| */ | |||
| class MultiSwitchArg : public SwitchArg | |||
| { | |||
| protected: | |||
| /** | |||
| * The value of the switch. | |||
| */ | |||
| int _value; | |||
| /** | |||
| * Used to support the reset() method so that ValueArg can be | |||
| * reset to their constructed value. | |||
| */ | |||
| int _default; | |||
| public: | |||
| /** | |||
| * MultiSwitchArg constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param init - Optional. The initial/default value of this Arg. | |||
| * Defaults to 0. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| MultiSwitchArg(const std::string& flag, const std::string& name, const std::string& desc, int init = 0, Visitor* v = NULL); | |||
| /** | |||
| * MultiSwitchArg constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param parser - A CmdLine parser object to add this Arg to | |||
| * \param init - Optional. The initial/default value of this Arg. | |||
| * Defaults to 0. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| MultiSwitchArg(const std::string& flag, const std::string& name, const std::string& desc, CmdLineInterface& parser, int init = 0, Visitor* v = NULL); | |||
| /** | |||
| * Handles the processing of the argument. | |||
| * This re-implements the SwitchArg version of this method to set the | |||
| * _value of the argument appropriately. | |||
| * \param i - Pointer the the current argument in the list. | |||
| * \param args - Mutable list of strings. Passed | |||
| * in from main(). | |||
| */ | |||
| virtual bool processArg(int* i, std::vector<std::string>& args); | |||
| /** | |||
| * Returns int, the number of times the switch has been set. | |||
| */ | |||
| int getValue() const | |||
| { | |||
| return _value; | |||
| } | |||
| /** | |||
| * Returns the shortID for this Arg. | |||
| */ | |||
| std::string shortID(const std::string& val) const; | |||
| /** | |||
| * Returns the longID for this Arg. | |||
| */ | |||
| std::string longID(const std::string& val) const; | |||
| void reset(); | |||
| }; | |||
| ////////////////////////////////////////////////////////////////////// | |||
| // BEGIN MultiSwitchArg.cpp | |||
| ////////////////////////////////////////////////////////////////////// | |||
| inline MultiSwitchArg::MultiSwitchArg(const std::string& flag, const std::string& name, const std::string& desc, int init, Visitor* v) : | |||
| SwitchArg(flag, name, desc, false, v), | |||
| _value(init), | |||
| _default(init) | |||
| { | |||
| } | |||
| inline MultiSwitchArg::MultiSwitchArg(const std::string& flag, const std::string& name, const std::string& desc, CmdLineInterface& parser, int init, Visitor* v) : | |||
| SwitchArg(flag, name, desc, false, v), | |||
| _value(init), | |||
| _default(init) | |||
| { | |||
| parser.add(this); | |||
| } | |||
| inline bool MultiSwitchArg::processArg(int* i, std::vector<std::string>& args) | |||
| { | |||
| if (_ignoreable && Arg::ignoreRest()) | |||
| return false; | |||
| if (argMatches(args[*i])) | |||
| { | |||
| // so the isSet() method will work | |||
| _alreadySet = true; | |||
| // Matched argument: increment value. | |||
| ++_value; | |||
| _checkWithVisitor(); | |||
| return true; | |||
| } | |||
| else if (combinedSwitchesMatch(args[*i])) | |||
| { | |||
| // so the isSet() method will work | |||
| _alreadySet = true; | |||
| // Matched argument: increment value. | |||
| ++_value; | |||
| // Check for more in argument and increment value. | |||
| while (combinedSwitchesMatch(args[*i])) | |||
| ++_value; | |||
| _checkWithVisitor(); | |||
| return false; | |||
| } | |||
| else | |||
| return false; | |||
| } | |||
| inline std::string | |||
| MultiSwitchArg::shortID(const std::string& val) const | |||
| { | |||
| return Arg::shortID(val) + " ..."; | |||
| } | |||
| inline std::string | |||
| MultiSwitchArg::longID(const std::string& val) const | |||
| { | |||
| return Arg::longID(val) + " (accepted multiple times)"; | |||
| } | |||
| inline void | |||
| MultiSwitchArg::reset() | |||
| { | |||
| MultiSwitchArg::_value = MultiSwitchArg::_default; | |||
| } | |||
| ////////////////////////////////////////////////////////////////////// | |||
| // END MultiSwitchArg.cpp | |||
| ////////////////////////////////////////////////////////////////////// | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -1,64 +1,68 @@ | |||
| // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- | |||
| /****************************************************************************** | |||
| * | |||
| /****************************************************************************** | |||
| * | |||
| * file: OptionalUnlabeledTracker.h | |||
| * | |||
| * | |||
| * Copyright (c) 2005, Michael E. Smoot . | |||
| * All rights reserved. | |||
| * | |||
| * | |||
| * See the file COPYING in the top directory of this distribution for | |||
| * more information. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| #ifndef TCLAP_OPTIONAL_UNLABELED_TRACKER_H | |||
| #define TCLAP_OPTIONAL_UNLABELED_TRACKER_H | |||
| #include <string> | |||
| namespace TCLAP { | |||
| class OptionalUnlabeledTracker | |||
| namespace TCLAP | |||
| { | |||
| public: | |||
| static void check( bool req, const std::string& argName ); | |||
| static void gotOptional() { alreadyOptionalRef() = true; } | |||
| static bool& alreadyOptional() { return alreadyOptionalRef(); } | |||
| private: | |||
| static bool& alreadyOptionalRef() { static bool ct = false; return ct; } | |||
| }; | |||
| inline void OptionalUnlabeledTracker::check( bool req, const std::string& argName ) | |||
| { | |||
| if ( OptionalUnlabeledTracker::alreadyOptional() ) | |||
| throw( SpecificationException( | |||
| "You can't specify ANY Unlabeled Arg following an optional Unlabeled Arg", | |||
| argName ) ); | |||
| if ( !req ) | |||
| OptionalUnlabeledTracker::gotOptional(); | |||
| } | |||
| } // namespace TCLAP | |||
| class OptionalUnlabeledTracker | |||
| { | |||
| public: | |||
| static void check(bool req, const std::string& argName); | |||
| static void gotOptional() | |||
| { | |||
| alreadyOptionalRef() = true; | |||
| } | |||
| static bool& alreadyOptional() | |||
| { | |||
| return alreadyOptionalRef(); | |||
| } | |||
| private: | |||
| static bool& alreadyOptionalRef() | |||
| { | |||
| static bool ct = false; | |||
| return ct; | |||
| } | |||
| }; | |||
| inline void OptionalUnlabeledTracker::check(bool req, const std::string& argName) | |||
| { | |||
| if (OptionalUnlabeledTracker::alreadyOptional()) | |||
| throw(SpecificationException( | |||
| "You can't specify ANY Unlabeled Arg following an optional Unlabeled Arg", | |||
| argName | |||
| )); | |||
| if (!req) | |||
| OptionalUnlabeledTracker::gotOptional(); | |||
| } | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -28,10 +28,10 @@ | |||
| #define TCLAP_STANDARD_TRAITS_H | |||
| #ifdef HAVE_CONFIG_H | |||
| #include <config.h> // To check for long long | |||
| #include <config.h> // To check for long long | |||
| #endif | |||
| // If Microsoft has already typedef'd wchar_t as an unsigned | |||
| // If Microsoft has already typedef'd wchar_t as an unsigned | |||
| // short, then compiles will break because it's as if we're | |||
| // creating ArgTraits twice for unsigned short. Thus... | |||
| #ifdef _MSC_VER | |||
| @@ -40,24 +40,25 @@ | |||
| #endif | |||
| #endif | |||
| namespace TCLAP { | |||
| namespace TCLAP | |||
| { | |||
| // Integer types (signed, unsigned and bool) and floating point types all | |||
| // have value-like semantics. | |||
| // Integer types (signed, unsigned and bool) and floating point types all | |||
| // have value-like semantics. | |||
| // Strings have string like argument traits. | |||
| template<> | |||
| struct ArgTraits<std::string> { | |||
| typedef StringLike ValueCategory; | |||
| }; | |||
| // Strings have string like argument traits. | |||
| template<> | |||
| struct ArgTraits<std::string> | |||
| { | |||
| typedef StringLike ValueCategory; | |||
| }; | |||
| template<typename T> | |||
| void SetString(T &dst, const std::string &src) | |||
| { | |||
| dst = src; | |||
| } | |||
| template<typename T> | |||
| void SetString(T& dst, const std::string& src) | |||
| { | |||
| dst = src; | |||
| } | |||
| } // namespace | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -1,25 +1,25 @@ | |||
| // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- | |||
| /****************************************************************************** | |||
| * | |||
| /****************************************************************************** | |||
| * | |||
| * file: StdOutput.h | |||
| * | |||
| * | |||
| * Copyright (c) 2004, Michael E. Smoot | |||
| * Copyright (c) 2017, Google LLC | |||
| * All rights reserved. | |||
| * | |||
| * | |||
| * See the file COPYING in the top directory of this distribution for | |||
| * more information. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| #ifndef TCLAP_STDCMDLINEOUTPUT_H | |||
| #define TCLAP_STDCMDLINEOUTPUT_H | |||
| @@ -35,266 +35,262 @@ | |||
| #include <tclap/XorHandler.h> | |||
| #include <tclap/Arg.h> | |||
| namespace TCLAP { | |||
| /** | |||
| * A class that isolates any output from the CmdLine object so that it | |||
| * may be easily modified. | |||
| */ | |||
| class StdOutput : public CmdLineOutput | |||
| namespace TCLAP | |||
| { | |||
| public: | |||
| /** | |||
| * Prints the usage to stdout. Can be overridden to | |||
| * produce alternative behavior. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| */ | |||
| virtual void usage(CmdLineInterface& c); | |||
| /** | |||
| * Prints the version to stdout. Can be overridden | |||
| * to produce alternative behavior. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| */ | |||
| virtual void version(CmdLineInterface& c); | |||
| /** | |||
| * Prints (to stderr) an error message, short usage | |||
| * Can be overridden to produce alternative behavior. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| * \param e - The ArgException that caused the failure. | |||
| */ | |||
| virtual void failure(CmdLineInterface& c, | |||
| ArgException& e ); | |||
| protected: | |||
| /** | |||
| * A class that isolates any output from the CmdLine object so that it | |||
| * may be easily modified. | |||
| */ | |||
| class StdOutput : public CmdLineOutput | |||
| { | |||
| public: | |||
| /** | |||
| * Writes a brief usage message with short args. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| * \param os - The stream to write the message to. | |||
| * Prints the usage to stdout. Can be overridden to | |||
| * produce alternative behavior. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| */ | |||
| void _shortUsage( CmdLineInterface& c, std::ostream& os ) const; | |||
| virtual void usage(CmdLineInterface& c); | |||
| /** | |||
| * Writes a longer usage message with long and short args, | |||
| * provides descriptions and prints message. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| * \param os - The stream to write the message to. | |||
| */ | |||
| void _longUsage( CmdLineInterface& c, std::ostream& os ) const; | |||
| /** | |||
| * This function inserts line breaks and indents long strings | |||
| * according the params input. It will only break lines at spaces, | |||
| * commas and pipes. | |||
| * \param os - The stream to be printed to. | |||
| * \param s - The string to be printed. | |||
| * \param maxWidth - The maxWidth allowed for the output line. | |||
| * \param indentSpaces - The number of spaces to indent the first line. | |||
| * \param secondLineOffset - The number of spaces to indent the second | |||
| * and all subsequent lines in addition to indentSpaces. | |||
| */ | |||
| void spacePrint( std::ostream& os, | |||
| const std::string& s, | |||
| int maxWidth, | |||
| int indentSpaces, | |||
| int secondLineOffset ) const; | |||
| }; | |||
| inline void StdOutput::version(CmdLineInterface& _cmd) | |||
| { | |||
| std::string progName = _cmd.getProgramName(); | |||
| std::string xversion = _cmd.getVersion(); | |||
| std::cout << std::endl << progName << " version: " | |||
| << xversion << std::endl << std::endl; | |||
| } | |||
| inline void StdOutput::usage(CmdLineInterface& _cmd ) | |||
| { | |||
| std::cout << std::endl << "USAGE: " << std::endl << std::endl; | |||
| _shortUsage( _cmd, std::cout ); | |||
| std::cout << std::endl << std::endl << "Where: " << std::endl << std::endl; | |||
| _longUsage( _cmd, std::cout ); | |||
| std::cout << std::endl; | |||
| } | |||
| inline void StdOutput::failure( CmdLineInterface& _cmd, | |||
| ArgException& e ) | |||
| { | |||
| std::string progName = _cmd.getProgramName(); | |||
| std::cerr << "PARSE ERROR: " << e.argId() << std::endl | |||
| << " " << e.error() << std::endl << std::endl; | |||
| if ( _cmd.hasHelpAndVersion() ) | |||
| { | |||
| std::cerr << "Brief USAGE: " << std::endl; | |||
| * Prints the version to stdout. Can be overridden | |||
| * to produce alternative behavior. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| */ | |||
| virtual void version(CmdLineInterface& c); | |||
| _shortUsage( _cmd, std::cerr ); | |||
| /** | |||
| * Prints (to stderr) an error message, short usage | |||
| * Can be overridden to produce alternative behavior. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| * \param e - The ArgException that caused the failure. | |||
| */ | |||
| virtual void failure(CmdLineInterface& c, ArgException& e); | |||
| std::cerr << std::endl << "For complete USAGE and HELP type: " | |||
| << std::endl << " " << progName << " " | |||
| << Arg::nameStartString() << "help" | |||
| << std::endl << std::endl; | |||
| } | |||
| else | |||
| usage(_cmd); | |||
| protected: | |||
| /** | |||
| * Writes a brief usage message with short args. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| * \param os - The stream to write the message to. | |||
| */ | |||
| void _shortUsage(CmdLineInterface& c, std::ostream& os) const; | |||
| throw ExitException(1); | |||
| } | |||
| /** | |||
| * Writes a longer usage message with long and short args, | |||
| * provides descriptions and prints message. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| * \param os - The stream to write the message to. | |||
| */ | |||
| void _longUsage(CmdLineInterface& c, std::ostream& os) const; | |||
| inline void | |||
| StdOutput::_shortUsage( CmdLineInterface& _cmd, | |||
| std::ostream& os ) const | |||
| { | |||
| std::list<Arg*> argList = _cmd.getArgList(); | |||
| std::string progName = _cmd.getProgramName(); | |||
| XorHandler xorHandler = _cmd.getXorHandler(); | |||
| std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList(); | |||
| std::string s = progName + " "; | |||
| // first the xor | |||
| for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ ) | |||
| { | |||
| s += " {"; | |||
| for ( ArgVectorIterator it = xorList[i].begin(); | |||
| it != xorList[i].end(); it++ ) | |||
| s += (*it)->shortID() + "|"; | |||
| s[s.length()-1] = '}'; | |||
| } | |||
| // then the rest | |||
| for (ArgListIterator it = argList.begin(); it != argList.end(); it++) | |||
| if ( !xorHandler.contains( (*it) ) ) | |||
| s += " " + (*it)->shortID(); | |||
| // if the program name is too long, then adjust the second line offset | |||
| int secondLineOffset = static_cast<int>(progName.length()) + 2; | |||
| if ( secondLineOffset > 75/2 ) | |||
| secondLineOffset = static_cast<int>(75/2); | |||
| spacePrint( os, s, 75, 3, secondLineOffset ); | |||
| } | |||
| inline void | |||
| StdOutput::_longUsage( CmdLineInterface& _cmd, | |||
| std::ostream& os ) const | |||
| { | |||
| std::list<Arg*> argList = _cmd.getArgList(); | |||
| std::string message = _cmd.getMessage(); | |||
| XorHandler xorHandler = _cmd.getXorHandler(); | |||
| std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList(); | |||
| // first the xor | |||
| for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ ) | |||
| { | |||
| for ( ArgVectorIterator it = xorList[i].begin(); | |||
| it != xorList[i].end(); | |||
| it++ ) | |||
| { | |||
| spacePrint( os, (*it)->longID(), 75, 3, 3 ); | |||
| spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); | |||
| if ( it+1 != xorList[i].end() ) | |||
| spacePrint(os, "-- OR --", 75, 9, 0); | |||
| } | |||
| os << std::endl << std::endl; | |||
| } | |||
| // then the rest | |||
| for (ArgListIterator it = argList.begin(); it != argList.end(); it++) | |||
| if ( !xorHandler.contains( (*it) ) ) | |||
| { | |||
| spacePrint( os, (*it)->longID(), 75, 3, 3 ); | |||
| spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); | |||
| os << std::endl; | |||
| } | |||
| os << std::endl; | |||
| spacePrint( os, message, 75, 3, 0 ); | |||
| } | |||
| inline void StdOutput::spacePrint( std::ostream& os, | |||
| const std::string& s, | |||
| int maxWidth, | |||
| int indentSpaces, | |||
| int secondLineOffset ) const | |||
| { | |||
| int len = static_cast<int>(s.length()); | |||
| if ( (len + indentSpaces > maxWidth) && maxWidth > 0 ) | |||
| { | |||
| int allowedLen = maxWidth - indentSpaces; | |||
| int start = 0; | |||
| while ( start < len ) | |||
| { | |||
| // find the substring length | |||
| // int stringLen = std::min<int>( len - start, allowedLen ); | |||
| // doing it this way to support a VisualC++ 2005 bug | |||
| using namespace std; | |||
| int stringLen = min<int>( len - start, allowedLen ); | |||
| // trim the length so it doesn't end in middle of a word | |||
| if ( stringLen == allowedLen ) | |||
| while ( stringLen >= 0 && | |||
| s[stringLen+start] != ' ' && | |||
| s[stringLen+start] != ',' && | |||
| s[stringLen+start] != '|' ) | |||
| stringLen--; | |||
| // ok, the word is longer than the line, so just split | |||
| // wherever the line ends | |||
| if ( stringLen <= 0 ) | |||
| stringLen = allowedLen; | |||
| // check for newlines | |||
| for ( int i = 0; i < stringLen; i++ ) | |||
| if ( s[start+i] == '\n' ) | |||
| stringLen = i+1; | |||
| // print the indent | |||
| for ( int i = 0; i < indentSpaces; i++ ) | |||
| os << " "; | |||
| if ( start == 0 ) | |||
| { | |||
| // handle second line offsets | |||
| indentSpaces += secondLineOffset; | |||
| // adjust allowed len | |||
| allowedLen -= secondLineOffset; | |||
| } | |||
| os << s.substr(start,stringLen) << std::endl; | |||
| // so we don't start a line with a space | |||
| while ( s[stringLen+start] == ' ' && start < len ) | |||
| start++; | |||
| start += stringLen; | |||
| } | |||
| } | |||
| else | |||
| { | |||
| for ( int i = 0; i < indentSpaces; i++ ) | |||
| os << " "; | |||
| os << s << std::endl; | |||
| } | |||
| } | |||
| } //namespace TCLAP | |||
| #endif | |||
| /** | |||
| * This function inserts line breaks and indents long strings | |||
| * according the params input. It will only break lines at spaces, | |||
| * commas and pipes. | |||
| * \param os - The stream to be printed to. | |||
| * \param s - The string to be printed. | |||
| * \param maxWidth - The maxWidth allowed for the output line. | |||
| * \param indentSpaces - The number of spaces to indent the first line. | |||
| * \param secondLineOffset - The number of spaces to indent the second | |||
| * and all subsequent lines in addition to indentSpaces. | |||
| */ | |||
| void spacePrint(std::ostream& os, const std::string& s, int maxWidth, int indentSpaces, int secondLineOffset) const; | |||
| }; | |||
| inline void StdOutput::version(CmdLineInterface& _cmd) | |||
| { | |||
| std::string progName = _cmd.getProgramName(); | |||
| std::string xversion = _cmd.getVersion(); | |||
| std::cout << std::endl | |||
| << progName << " version: " | |||
| << xversion << std::endl | |||
| << std::endl; | |||
| } | |||
| inline void StdOutput::usage(CmdLineInterface& _cmd) | |||
| { | |||
| std::cout << std::endl | |||
| << "USAGE: " << std::endl | |||
| << std::endl; | |||
| _shortUsage(_cmd, std::cout); | |||
| std::cout << std::endl | |||
| << std::endl | |||
| << "Where: " << std::endl | |||
| << std::endl; | |||
| _longUsage(_cmd, std::cout); | |||
| std::cout << std::endl; | |||
| } | |||
| inline void StdOutput::failure(CmdLineInterface& _cmd, ArgException& e) | |||
| { | |||
| std::string progName = _cmd.getProgramName(); | |||
| std::cerr << "PARSE ERROR: " << e.argId() << std::endl | |||
| << " " << e.error() << std::endl | |||
| << std::endl; | |||
| if (_cmd.hasHelpAndVersion()) | |||
| { | |||
| std::cerr << "Brief USAGE: " << std::endl; | |||
| _shortUsage(_cmd, std::cerr); | |||
| std::cerr << std::endl | |||
| << "For complete USAGE and HELP type: " | |||
| << std::endl | |||
| << " " << progName << " " | |||
| << Arg::nameStartString() << "help" | |||
| << std::endl | |||
| << std::endl; | |||
| } | |||
| else | |||
| usage(_cmd); | |||
| throw ExitException(1); | |||
| } | |||
| inline void | |||
| StdOutput::_shortUsage(CmdLineInterface& _cmd, std::ostream& os) const | |||
| { | |||
| std::list<Arg*> argList = _cmd.getArgList(); | |||
| std::string progName = _cmd.getProgramName(); | |||
| XorHandler xorHandler = _cmd.getXorHandler(); | |||
| std::vector<std::vector<Arg*>> xorList = xorHandler.getXorList(); | |||
| std::string s = progName + " "; | |||
| // first the xor | |||
| for (int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++) | |||
| { | |||
| s += " {"; | |||
| for (ArgVectorIterator it = xorList[i].begin(); | |||
| it != xorList[i].end(); | |||
| it++) | |||
| s += (*it)->shortID() + "|"; | |||
| s[s.length() - 1] = '}'; | |||
| } | |||
| // then the rest | |||
| for (ArgListIterator it = argList.begin(); it != argList.end(); it++) | |||
| if (!xorHandler.contains((*it))) | |||
| s += " " + (*it)->shortID(); | |||
| // if the program name is too long, then adjust the second line offset | |||
| int secondLineOffset = static_cast<int>(progName.length()) + 2; | |||
| if (secondLineOffset > 75 / 2) | |||
| secondLineOffset = static_cast<int>(75 / 2); | |||
| spacePrint(os, s, 75, 3, secondLineOffset); | |||
| } | |||
| inline void | |||
| StdOutput::_longUsage(CmdLineInterface& _cmd, std::ostream& os) const | |||
| { | |||
| std::list<Arg*> argList = _cmd.getArgList(); | |||
| std::string message = _cmd.getMessage(); | |||
| XorHandler xorHandler = _cmd.getXorHandler(); | |||
| std::vector<std::vector<Arg*>> xorList = xorHandler.getXorList(); | |||
| // first the xor | |||
| for (int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++) | |||
| { | |||
| for (ArgVectorIterator it = xorList[i].begin(); | |||
| it != xorList[i].end(); | |||
| it++) | |||
| { | |||
| spacePrint(os, (*it)->longID(), 75, 3, 3); | |||
| spacePrint(os, (*it)->getDescription(), 75, 5, 0); | |||
| if (it + 1 != xorList[i].end()) | |||
| spacePrint(os, "-- OR --", 75, 9, 0); | |||
| } | |||
| os << std::endl | |||
| << std::endl; | |||
| } | |||
| // then the rest | |||
| for (ArgListIterator it = argList.begin(); it != argList.end(); it++) | |||
| if (!xorHandler.contains((*it))) | |||
| { | |||
| spacePrint(os, (*it)->longID(), 75, 3, 3); | |||
| spacePrint(os, (*it)->getDescription(), 75, 5, 0); | |||
| os << std::endl; | |||
| } | |||
| os << std::endl; | |||
| spacePrint(os, message, 75, 3, 0); | |||
| } | |||
| inline void StdOutput::spacePrint(std::ostream& os, const std::string& s, int maxWidth, int indentSpaces, int secondLineOffset) const | |||
| { | |||
| int len = static_cast<int>(s.length()); | |||
| if ((len + indentSpaces > maxWidth) && maxWidth > 0) | |||
| { | |||
| int allowedLen = maxWidth - indentSpaces; | |||
| int start = 0; | |||
| while (start < len) | |||
| { | |||
| // find the substring length | |||
| // int stringLen = std::min<int>( len - start, allowedLen ); | |||
| // doing it this way to support a VisualC++ 2005 bug | |||
| using namespace std; | |||
| int stringLen = min<int>(len - start, allowedLen); | |||
| // trim the length so it doesn't end in middle of a word | |||
| if (stringLen == allowedLen) | |||
| while (stringLen >= 0 && | |||
| s[stringLen + start] != ' ' && | |||
| s[stringLen + start] != ',' && | |||
| s[stringLen + start] != '|') | |||
| stringLen--; | |||
| // ok, the word is longer than the line, so just split | |||
| // wherever the line ends | |||
| if (stringLen <= 0) | |||
| stringLen = allowedLen; | |||
| // check for newlines | |||
| for (int i = 0; i < stringLen; i++) | |||
| if (s[start + i] == '\n') | |||
| stringLen = i + 1; | |||
| // print the indent | |||
| for (int i = 0; i < indentSpaces; i++) | |||
| os << " "; | |||
| if (start == 0) | |||
| { | |||
| // handle second line offsets | |||
| indentSpaces += secondLineOffset; | |||
| // adjust allowed len | |||
| allowedLen -= secondLineOffset; | |||
| } | |||
| os << s.substr(start, stringLen) << std::endl; | |||
| // so we don't start a line with a space | |||
| while (s[stringLen + start] == ' ' && start < len) | |||
| start++; | |||
| start += stringLen; | |||
| } | |||
| } | |||
| else | |||
| { | |||
| for (int i = 0; i < indentSpaces; i++) | |||
| os << " "; | |||
| os << s << std::endl; | |||
| } | |||
| } | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -1,28 +1,27 @@ | |||
| // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- | |||
| /****************************************************************************** | |||
| * | |||
| /****************************************************************************** | |||
| * | |||
| * file: SwitchArg.h | |||
| * | |||
| * | |||
| * Copyright (c) 2003, Michael E. Smoot . | |||
| * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. | |||
| * Copyright (c) 2017, Google LLC | |||
| * All rights reserved. | |||
| * | |||
| * | |||
| * See the file COPYING in the top directory of this distribution for | |||
| * more information. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| #ifndef TCLAP_SWITCH_ARG_H | |||
| #define TCLAP_SWITCH_ARG_H | |||
| @@ -31,243 +30,229 @@ | |||
| #include <tclap/Arg.h> | |||
| namespace TCLAP { | |||
| /** | |||
| * A simple switch argument. If the switch is set on the command line, then | |||
| * the getValue method will return the opposite of the default value for the | |||
| * switch. | |||
| */ | |||
| class SwitchArg : public Arg | |||
| { | |||
| protected: | |||
| /** | |||
| * The value of the switch. | |||
| */ | |||
| bool _value; | |||
| /** | |||
| * Used to support the reset() method so that ValueArg can be | |||
| * reset to their constructed value. | |||
| */ | |||
| bool _default; | |||
| public: | |||
| /** | |||
| * SwitchArg constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param def - The default value for this Switch. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| SwitchArg(const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| bool def = false, | |||
| Visitor* v = NULL); | |||
| /** | |||
| * SwitchArg constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param parser - A CmdLine parser object to add this Arg to | |||
| * \param def - The default value for this Switch. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| SwitchArg(const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| CmdLineInterface& parser, | |||
| bool def = false, | |||
| Visitor* v = NULL); | |||
| /** | |||
| * Handles the processing of the argument. | |||
| * This re-implements the Arg version of this method to set the | |||
| * _value of the argument appropriately. | |||
| * \param i - Pointer the the current argument in the list. | |||
| * \param args - Mutable list of strings. Passed | |||
| * in from main(). | |||
| */ | |||
| virtual bool processArg(int* i, std::vector<std::string>& args); | |||
| /** | |||
| * Checks a string to see if any of the chars in the string | |||
| * match the flag for this Switch. | |||
| */ | |||
| bool combinedSwitchesMatch(std::string& combined); | |||
| /** | |||
| * Returns bool, whether or not the switch has been set. | |||
| */ | |||
| bool getValue() const { return _value; } | |||
| /** | |||
| * A SwitchArg can be used as a boolean, indicating | |||
| * whether or not the switch has been set. This is the | |||
| * same as calling getValue() | |||
| */ | |||
| operator bool() const { return _value; } | |||
| virtual void reset(); | |||
| private: | |||
| /** | |||
| * Checks to see if we've found the last match in | |||
| * a combined string. | |||
| */ | |||
| bool lastCombined(std::string& combined); | |||
| /** | |||
| * Does the common processing of processArg. | |||
| */ | |||
| void commonProcessing(); | |||
| }; | |||
| ////////////////////////////////////////////////////////////////////// | |||
| //BEGIN SwitchArg.cpp | |||
| ////////////////////////////////////////////////////////////////////// | |||
| inline SwitchArg::SwitchArg(const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| bool default_val, | |||
| Visitor* v ) | |||
| : Arg(flag, name, desc, false, false, v), | |||
| _value( default_val ), | |||
| _default( default_val ) | |||
| { } | |||
| inline SwitchArg::SwitchArg(const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| CmdLineInterface& parser, | |||
| bool default_val, | |||
| Visitor* v ) | |||
| : Arg(flag, name, desc, false, false, v), | |||
| _value( default_val ), | |||
| _default(default_val) | |||
| { | |||
| parser.add( this ); | |||
| } | |||
| inline bool SwitchArg::lastCombined(std::string& combinedSwitches ) | |||
| namespace TCLAP | |||
| { | |||
| for ( unsigned int i = 1; i < combinedSwitches.length(); i++ ) | |||
| if ( combinedSwitches[i] != Arg::blankChar() ) | |||
| return false; | |||
| return true; | |||
| } | |||
| inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches ) | |||
| { | |||
| // make sure this is actually a combined switch | |||
| if ( combinedSwitches.length() > 0 && | |||
| combinedSwitches[0] != Arg::flagStartString()[0] ) | |||
| return false; | |||
| // make sure it isn't a long name | |||
| if ( combinedSwitches.substr( 0, Arg::nameStartString().length() ) == | |||
| Arg::nameStartString() ) | |||
| return false; | |||
| // make sure the delimiter isn't in the string | |||
| if ( combinedSwitches.find_first_of(Arg::delimiter()) != std::string::npos) | |||
| return false; | |||
| // ok, we're not specifying a ValueArg, so we know that we have | |||
| // a combined switch list. | |||
| for ( unsigned int i = 1; i < combinedSwitches.length(); i++ ) | |||
| if ( _flag.length() > 0 && | |||
| combinedSwitches[i] == _flag[0] && | |||
| _flag[0] != Arg::flagStartString()[0] ) | |||
| { | |||
| // update the combined switches so this one is no longer present | |||
| // this is necessary so that no unlabeled args are matched | |||
| // later in the processing. | |||
| //combinedSwitches.erase(i,1); | |||
| combinedSwitches[i] = Arg::blankChar(); | |||
| return true; | |||
| } | |||
| // none of the switches passed in the list match. | |||
| return false; | |||
| } | |||
| inline void SwitchArg::commonProcessing() | |||
| { | |||
| if ( _xorSet ) | |||
| throw(CmdLineParseException( | |||
| "Mutually exclusive argument already set!", toString())); | |||
| if ( _alreadySet ) | |||
| throw(CmdLineParseException("Argument already set!", toString())); | |||
| /** | |||
| * A simple switch argument. If the switch is set on the command line, then | |||
| * the getValue method will return the opposite of the default value for the | |||
| * switch. | |||
| */ | |||
| class SwitchArg : public Arg | |||
| { | |||
| protected: | |||
| /** | |||
| * The value of the switch. | |||
| */ | |||
| bool _value; | |||
| /** | |||
| * Used to support the reset() method so that ValueArg can be | |||
| * reset to their constructed value. | |||
| */ | |||
| bool _default; | |||
| public: | |||
| /** | |||
| * SwitchArg constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param def - The default value for this Switch. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| SwitchArg(const std::string& flag, const std::string& name, const std::string& desc, bool def = false, Visitor* v = NULL); | |||
| /** | |||
| * SwitchArg constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param parser - A CmdLine parser object to add this Arg to | |||
| * \param def - The default value for this Switch. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| SwitchArg(const std::string& flag, const std::string& name, const std::string& desc, CmdLineInterface& parser, bool def = false, Visitor* v = NULL); | |||
| /** | |||
| * Handles the processing of the argument. | |||
| * This re-implements the Arg version of this method to set the | |||
| * _value of the argument appropriately. | |||
| * \param i - Pointer the the current argument in the list. | |||
| * \param args - Mutable list of strings. Passed | |||
| * in from main(). | |||
| */ | |||
| virtual bool processArg(int* i, std::vector<std::string>& args); | |||
| /** | |||
| * Checks a string to see if any of the chars in the string | |||
| * match the flag for this Switch. | |||
| */ | |||
| bool combinedSwitchesMatch(std::string& combined); | |||
| /** | |||
| * Returns bool, whether or not the switch has been set. | |||
| */ | |||
| bool getValue() const | |||
| { | |||
| return _value; | |||
| } | |||
| /** | |||
| * A SwitchArg can be used as a boolean, indicating | |||
| * whether or not the switch has been set. This is the | |||
| * same as calling getValue() | |||
| */ | |||
| operator bool() const | |||
| { | |||
| return _value; | |||
| } | |||
| virtual void reset(); | |||
| private: | |||
| /** | |||
| * Checks to see if we've found the last match in | |||
| * a combined string. | |||
| */ | |||
| bool lastCombined(std::string& combined); | |||
| /** | |||
| * Does the common processing of processArg. | |||
| */ | |||
| void commonProcessing(); | |||
| }; | |||
| ////////////////////////////////////////////////////////////////////// | |||
| // BEGIN SwitchArg.cpp | |||
| ////////////////////////////////////////////////////////////////////// | |||
| inline SwitchArg::SwitchArg(const std::string& flag, const std::string& name, const std::string& desc, bool default_val, Visitor* v) : | |||
| Arg(flag, name, desc, false, false, v), | |||
| _value(default_val), | |||
| _default(default_val) | |||
| { | |||
| } | |||
| _alreadySet = true; | |||
| inline SwitchArg::SwitchArg(const std::string& flag, const std::string& name, const std::string& desc, CmdLineInterface& parser, bool default_val, Visitor* v) : | |||
| Arg(flag, name, desc, false, false, v), | |||
| _value(default_val), | |||
| _default(default_val) | |||
| { | |||
| parser.add(this); | |||
| } | |||
| if ( _value == true ) | |||
| _value = false; | |||
| else | |||
| _value = true; | |||
| inline bool SwitchArg::lastCombined(std::string& combinedSwitches) | |||
| { | |||
| for (unsigned int i = 1; i < combinedSwitches.length(); i++) | |||
| if (combinedSwitches[i] != Arg::blankChar()) | |||
| return false; | |||
| _checkWithVisitor(); | |||
| } | |||
| return true; | |||
| } | |||
| inline bool SwitchArg::processArg(int *i, std::vector<std::string>& args) | |||
| { | |||
| if ( _ignoreable && Arg::ignoreRest() ) | |||
| return false; | |||
| inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches) | |||
| { | |||
| // make sure this is actually a combined switch | |||
| if (combinedSwitches.length() > 0 && | |||
| combinedSwitches[0] != Arg::flagStartString()[0]) | |||
| return false; | |||
| // make sure it isn't a long name | |||
| if (combinedSwitches.substr(0, Arg::nameStartString().length()) == | |||
| Arg::nameStartString()) | |||
| return false; | |||
| // make sure the delimiter isn't in the string | |||
| if (combinedSwitches.find_first_of(Arg::delimiter()) != std::string::npos) | |||
| return false; | |||
| // ok, we're not specifying a ValueArg, so we know that we have | |||
| // a combined switch list. | |||
| for (unsigned int i = 1; i < combinedSwitches.length(); i++) | |||
| if (_flag.length() > 0 && | |||
| combinedSwitches[i] == _flag[0] && | |||
| _flag[0] != Arg::flagStartString()[0]) | |||
| { | |||
| // update the combined switches so this one is no longer present | |||
| // this is necessary so that no unlabeled args are matched | |||
| // later in the processing. | |||
| // combinedSwitches.erase(i,1); | |||
| combinedSwitches[i] = Arg::blankChar(); | |||
| return true; | |||
| } | |||
| // none of the switches passed in the list match. | |||
| return false; | |||
| } | |||
| // if the whole string matches the flag or name string | |||
| if ( argMatches( args[*i] ) ) | |||
| inline void SwitchArg::commonProcessing() | |||
| { | |||
| commonProcessing(); | |||
| if (_xorSet) | |||
| throw(CmdLineParseException( | |||
| "Mutually exclusive argument already set!", toString() | |||
| )); | |||
| if (_alreadySet) | |||
| throw(CmdLineParseException("Argument already set!", toString())); | |||
| _alreadySet = true; | |||
| if (_value == true) | |||
| _value = false; | |||
| else | |||
| _value = true; | |||
| return true; | |||
| _checkWithVisitor(); | |||
| } | |||
| // if a substring matches the flag as part of a combination | |||
| else if ( combinedSwitchesMatch( args[*i] ) ) | |||
| inline bool SwitchArg::processArg(int* i, std::vector<std::string>& args) | |||
| { | |||
| // check again to ensure we don't misinterpret | |||
| // this as a MultiSwitchArg | |||
| if ( combinedSwitchesMatch( args[*i] ) ) | |||
| throw(CmdLineParseException("Argument already set!", | |||
| toString())); | |||
| commonProcessing(); | |||
| // We only want to return true if we've found the last combined | |||
| // match in the string, otherwise we return true so that other | |||
| // switches in the combination will have a chance to match. | |||
| return lastCombined( args[*i] ); | |||
| if (_ignoreable && Arg::ignoreRest()) | |||
| return false; | |||
| // if the whole string matches the flag or name string | |||
| if (argMatches(args[*i])) | |||
| { | |||
| commonProcessing(); | |||
| return true; | |||
| } | |||
| // if a substring matches the flag as part of a combination | |||
| else if (combinedSwitchesMatch(args[*i])) | |||
| { | |||
| // check again to ensure we don't misinterpret | |||
| // this as a MultiSwitchArg | |||
| if (combinedSwitchesMatch(args[*i])) | |||
| throw(CmdLineParseException("Argument already set!", toString())); | |||
| commonProcessing(); | |||
| // We only want to return true if we've found the last combined | |||
| // match in the string, otherwise we return true so that other | |||
| // switches in the combination will have a chance to match. | |||
| return lastCombined(args[*i]); | |||
| } | |||
| else | |||
| return false; | |||
| } | |||
| else | |||
| return false; | |||
| } | |||
| inline void SwitchArg::reset() | |||
| { | |||
| Arg::reset(); | |||
| _value = _default; | |||
| } | |||
| ////////////////////////////////////////////////////////////////////// | |||
| //End SwitchArg.cpp | |||
| ////////////////////////////////////////////////////////////////////// | |||
| } //namespace TCLAP | |||
| inline void SwitchArg::reset() | |||
| { | |||
| Arg::reset(); | |||
| _value = _default; | |||
| } | |||
| ////////////////////////////////////////////////////////////////////// | |||
| // End SwitchArg.cpp | |||
| ////////////////////////////////////////////////////////////////////// | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -1,27 +1,25 @@ | |||
| // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- | |||
| /****************************************************************************** | |||
| * | |||
| /****************************************************************************** | |||
| * | |||
| * file: UnlabeledMultiArg.h | |||
| * | |||
| * | |||
| * Copyright (c) 2003, Michael E. Smoot. | |||
| * Copyright (c) 2017, Google LLC | |||
| * All rights reserved. | |||
| * | |||
| * | |||
| * See the file COPYING in the top directory of this distribution for | |||
| * more information. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| #ifndef TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H | |||
| #define TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H | |||
| @@ -32,273 +30,224 @@ | |||
| #include <tclap/MultiArg.h> | |||
| #include <tclap/OptionalUnlabeledTracker.h> | |||
| namespace TCLAP { | |||
| /** | |||
| * Just like a MultiArg, except that the arguments are unlabeled. Basically, | |||
| * this Arg will slurp up everything that hasn't been matched to another | |||
| * Arg. | |||
| */ | |||
| template<class T> | |||
| class UnlabeledMultiArg : public MultiArg<T> | |||
| { | |||
| // If compiler has two stage name lookup (as gcc >= 3.4 does) | |||
| // this is required to prevent undef. symbols | |||
| using MultiArg<T>::_ignoreable; | |||
| using MultiArg<T>::_hasBlanks; | |||
| using MultiArg<T>::_extractValue; | |||
| using MultiArg<T>::_typeDesc; | |||
| using MultiArg<T>::_name; | |||
| using MultiArg<T>::_description; | |||
| using MultiArg<T>::_alreadySet; | |||
| using MultiArg<T>::toString; | |||
| public: | |||
| /** | |||
| * Constructor. | |||
| * \param name - The name of the Arg. Note that this is used for | |||
| * identification, not as a long flag. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param typeDesc - A short, human readable description of the | |||
| * type that this object expects. This is used in the generation | |||
| * of the USAGE statement. The goal is to be helpful to the end user | |||
| * of the program. | |||
| * \param ignoreable - Whether or not this argument can be ignored | |||
| * using the "--" flag. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| UnlabeledMultiArg( const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| const std::string& typeDesc, | |||
| bool ignoreable = false, | |||
| Visitor* v = NULL ); | |||
| /** | |||
| * Constructor. | |||
| * \param name - The name of the Arg. Note that this is used for | |||
| * identification, not as a long flag. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param typeDesc - A short, human readable description of the | |||
| * type that this object expects. This is used in the generation | |||
| * of the USAGE statement. The goal is to be helpful to the end user | |||
| * of the program. | |||
| * \param parser - A CmdLine parser object to add this Arg to | |||
| * \param ignoreable - Whether or not this argument can be ignored | |||
| * using the "--" flag. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| UnlabeledMultiArg( const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| const std::string& typeDesc, | |||
| CmdLineInterface& parser, | |||
| bool ignoreable = false, | |||
| Visitor* v = NULL ); | |||
| /** | |||
| * Constructor. | |||
| * \param name - The name of the Arg. Note that this is used for | |||
| * identification, not as a long flag. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param constraint - A pointer to a Constraint object used | |||
| * to constrain this Arg. | |||
| * \param ignoreable - Whether or not this argument can be ignored | |||
| * using the "--" flag. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| UnlabeledMultiArg( const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| Constraint<T>* constraint, | |||
| bool ignoreable = false, | |||
| Visitor* v = NULL ); | |||
| /** | |||
| * Constructor. | |||
| * \param name - The name of the Arg. Note that this is used for | |||
| * identification, not as a long flag. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param constraint - A pointer to a Constraint object used | |||
| * to constrain this Arg. | |||
| * \param parser - A CmdLine parser object to add this Arg to | |||
| * \param ignoreable - Whether or not this argument can be ignored | |||
| * using the "--" flag. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| UnlabeledMultiArg( const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| Constraint<T>* constraint, | |||
| CmdLineInterface& parser, | |||
| bool ignoreable = false, | |||
| Visitor* v = NULL ); | |||
| /** | |||
| * Handles the processing of the argument. | |||
| * This re-implements the Arg version of this method to set the | |||
| * _value of the argument appropriately. It knows the difference | |||
| * between labeled and unlabeled. | |||
| * \param i - Pointer the the current argument in the list. | |||
| * \param args - Mutable list of strings. Passed from main(). | |||
| */ | |||
| virtual bool processArg(int* i, std::vector<std::string>& args); | |||
| /** | |||
| * Returns the a short id string. Used in the usage. | |||
| * \param val - value to be used. | |||
| */ | |||
| virtual std::string shortID(const std::string& val="val") const; | |||
| /** | |||
| * Returns the a long id string. Used in the usage. | |||
| * \param val - value to be used. | |||
| */ | |||
| virtual std::string longID(const std::string& val="val") const; | |||
| /** | |||
| * Operator ==. | |||
| * \param a - The Arg to be compared to this. | |||
| */ | |||
| virtual bool operator==(const Arg& a) const; | |||
| /** | |||
| * Pushes this to back of list rather than front. | |||
| * \param argList - The list this should be added to. | |||
| */ | |||
| virtual void addToList( std::list<Arg*>& argList ) const; | |||
| }; | |||
| template<class T> | |||
| UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| const std::string& typeDesc, | |||
| bool ignoreable, | |||
| Visitor* v) | |||
| : MultiArg<T>("", name, desc, req, typeDesc, v) | |||
| { | |||
| _ignoreable = ignoreable; | |||
| OptionalUnlabeledTracker::check(true, toString()); | |||
| } | |||
| template<class T> | |||
| UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| const std::string& typeDesc, | |||
| CmdLineInterface& parser, | |||
| bool ignoreable, | |||
| Visitor* v) | |||
| : MultiArg<T>("", name, desc, req, typeDesc, v) | |||
| { | |||
| _ignoreable = ignoreable; | |||
| OptionalUnlabeledTracker::check(true, toString()); | |||
| parser.add( this ); | |||
| } | |||
| template<class T> | |||
| UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| Constraint<T>* constraint, | |||
| bool ignoreable, | |||
| Visitor* v) | |||
| : MultiArg<T>("", name, desc, req, constraint, v) | |||
| { | |||
| _ignoreable = ignoreable; | |||
| OptionalUnlabeledTracker::check(true, toString()); | |||
| } | |||
| template<class T> | |||
| UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| Constraint<T>* constraint, | |||
| CmdLineInterface& parser, | |||
| bool ignoreable, | |||
| Visitor* v) | |||
| : MultiArg<T>("", name, desc, req, constraint, v) | |||
| { | |||
| _ignoreable = ignoreable; | |||
| OptionalUnlabeledTracker::check(true, toString()); | |||
| parser.add( this ); | |||
| } | |||
| template<class T> | |||
| bool UnlabeledMultiArg<T>::processArg(int *i, std::vector<std::string>& args) | |||
| { | |||
| if ( _hasBlanks( args[*i] ) ) | |||
| return false; | |||
| // never ignore an unlabeled multi arg | |||
| // always take the first value, regardless of the start string | |||
| _extractValue( args[(*i)] ); | |||
| /* | |||
| // continue taking args until we hit the end or a start string | |||
| while ( (unsigned int)(*i)+1 < args.size() && | |||
| args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 && | |||
| args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 ) | |||
| _extractValue( args[++(*i)] ); | |||
| */ | |||
| _alreadySet = true; | |||
| return true; | |||
| } | |||
| template<class T> | |||
| std::string UnlabeledMultiArg<T>::shortID(const std::string& val) const | |||
| { | |||
| static_cast<void>(val); // Ignore input, don't warn | |||
| return std::string("<") + _typeDesc + "> ..."; | |||
| } | |||
| template<class T> | |||
| std::string UnlabeledMultiArg<T>::longID(const std::string& val) const | |||
| { | |||
| static_cast<void>(val); // Ignore input, don't warn | |||
| return std::string("<") + _typeDesc + "> (accepted multiple times)"; | |||
| } | |||
| template<class T> | |||
| bool UnlabeledMultiArg<T>::operator==(const Arg& a) const | |||
| { | |||
| if ( _name == a.getName() || _description == a.getDescription() ) | |||
| return true; | |||
| else | |||
| return false; | |||
| } | |||
| template<class T> | |||
| void UnlabeledMultiArg<T>::addToList( std::list<Arg*>& argList ) const | |||
| namespace TCLAP | |||
| { | |||
| argList.push_back( const_cast<Arg*>(static_cast<const Arg* const>(this)) ); | |||
| } | |||
| } | |||
| /** | |||
| * Just like a MultiArg, except that the arguments are unlabeled. Basically, | |||
| * this Arg will slurp up everything that hasn't been matched to another | |||
| * Arg. | |||
| */ | |||
| template<class T> | |||
| class UnlabeledMultiArg : public MultiArg<T> | |||
| { | |||
| // If compiler has two stage name lookup (as gcc >= 3.4 does) | |||
| // this is required to prevent undef. symbols | |||
| using MultiArg<T>::_ignoreable; | |||
| using MultiArg<T>::_hasBlanks; | |||
| using MultiArg<T>::_extractValue; | |||
| using MultiArg<T>::_typeDesc; | |||
| using MultiArg<T>::_name; | |||
| using MultiArg<T>::_description; | |||
| using MultiArg<T>::_alreadySet; | |||
| using MultiArg<T>::toString; | |||
| public: | |||
| /** | |||
| * Constructor. | |||
| * \param name - The name of the Arg. Note that this is used for | |||
| * identification, not as a long flag. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param typeDesc - A short, human readable description of the | |||
| * type that this object expects. This is used in the generation | |||
| * of the USAGE statement. The goal is to be helpful to the end user | |||
| * of the program. | |||
| * \param ignoreable - Whether or not this argument can be ignored | |||
| * using the "--" flag. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| UnlabeledMultiArg(const std::string& name, const std::string& desc, bool req, const std::string& typeDesc, bool ignoreable = false, Visitor* v = NULL); | |||
| /** | |||
| * Constructor. | |||
| * \param name - The name of the Arg. Note that this is used for | |||
| * identification, not as a long flag. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param typeDesc - A short, human readable description of the | |||
| * type that this object expects. This is used in the generation | |||
| * of the USAGE statement. The goal is to be helpful to the end user | |||
| * of the program. | |||
| * \param parser - A CmdLine parser object to add this Arg to | |||
| * \param ignoreable - Whether or not this argument can be ignored | |||
| * using the "--" flag. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| UnlabeledMultiArg(const std::string& name, const std::string& desc, bool req, const std::string& typeDesc, CmdLineInterface& parser, bool ignoreable = false, Visitor* v = NULL); | |||
| /** | |||
| * Constructor. | |||
| * \param name - The name of the Arg. Note that this is used for | |||
| * identification, not as a long flag. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param constraint - A pointer to a Constraint object used | |||
| * to constrain this Arg. | |||
| * \param ignoreable - Whether or not this argument can be ignored | |||
| * using the "--" flag. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| UnlabeledMultiArg(const std::string& name, const std::string& desc, bool req, Constraint<T>* constraint, bool ignoreable = false, Visitor* v = NULL); | |||
| /** | |||
| * Constructor. | |||
| * \param name - The name of the Arg. Note that this is used for | |||
| * identification, not as a long flag. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param constraint - A pointer to a Constraint object used | |||
| * to constrain this Arg. | |||
| * \param parser - A CmdLine parser object to add this Arg to | |||
| * \param ignoreable - Whether or not this argument can be ignored | |||
| * using the "--" flag. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| UnlabeledMultiArg(const std::string& name, const std::string& desc, bool req, Constraint<T>* constraint, CmdLineInterface& parser, bool ignoreable = false, Visitor* v = NULL); | |||
| /** | |||
| * Handles the processing of the argument. | |||
| * This re-implements the Arg version of this method to set the | |||
| * _value of the argument appropriately. It knows the difference | |||
| * between labeled and unlabeled. | |||
| * \param i - Pointer the the current argument in the list. | |||
| * \param args - Mutable list of strings. Passed from main(). | |||
| */ | |||
| virtual bool processArg(int* i, std::vector<std::string>& args); | |||
| /** | |||
| * Returns the a short id string. Used in the usage. | |||
| * \param val - value to be used. | |||
| */ | |||
| virtual std::string shortID(const std::string& val = "val") const; | |||
| /** | |||
| * Returns the a long id string. Used in the usage. | |||
| * \param val - value to be used. | |||
| */ | |||
| virtual std::string longID(const std::string& val = "val") const; | |||
| /** | |||
| * Operator ==. | |||
| * \param a - The Arg to be compared to this. | |||
| */ | |||
| virtual bool operator==(const Arg& a) const; | |||
| /** | |||
| * Pushes this to back of list rather than front. | |||
| * \param argList - The list this should be added to. | |||
| */ | |||
| virtual void addToList(std::list<Arg*>& argList) const; | |||
| }; | |||
| template<class T> | |||
| UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name, const std::string& desc, bool req, const std::string& typeDesc, bool ignoreable, Visitor* v) : | |||
| MultiArg<T>("", name, desc, req, typeDesc, v) | |||
| { | |||
| _ignoreable = ignoreable; | |||
| OptionalUnlabeledTracker::check(true, toString()); | |||
| } | |||
| template<class T> | |||
| UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name, const std::string& desc, bool req, const std::string& typeDesc, CmdLineInterface& parser, bool ignoreable, Visitor* v) : | |||
| MultiArg<T>("", name, desc, req, typeDesc, v) | |||
| { | |||
| _ignoreable = ignoreable; | |||
| OptionalUnlabeledTracker::check(true, toString()); | |||
| parser.add(this); | |||
| } | |||
| template<class T> | |||
| UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name, const std::string& desc, bool req, Constraint<T>* constraint, bool ignoreable, Visitor* v) : | |||
| MultiArg<T>("", name, desc, req, constraint, v) | |||
| { | |||
| _ignoreable = ignoreable; | |||
| OptionalUnlabeledTracker::check(true, toString()); | |||
| } | |||
| template<class T> | |||
| UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name, const std::string& desc, bool req, Constraint<T>* constraint, CmdLineInterface& parser, bool ignoreable, Visitor* v) : | |||
| MultiArg<T>("", name, desc, req, constraint, v) | |||
| { | |||
| _ignoreable = ignoreable; | |||
| OptionalUnlabeledTracker::check(true, toString()); | |||
| parser.add(this); | |||
| } | |||
| template<class T> | |||
| bool UnlabeledMultiArg<T>::processArg(int* i, std::vector<std::string>& args) | |||
| { | |||
| if (_hasBlanks(args[*i])) | |||
| return false; | |||
| // never ignore an unlabeled multi arg | |||
| // always take the first value, regardless of the start string | |||
| _extractValue(args[(*i)]); | |||
| /* | |||
| // continue taking args until we hit the end or a start string | |||
| while ( (unsigned int)(*i)+1 < args.size() && | |||
| args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 && | |||
| args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 ) | |||
| _extractValue( args[++(*i)] ); | |||
| */ | |||
| _alreadySet = true; | |||
| return true; | |||
| } | |||
| template<class T> | |||
| std::string UnlabeledMultiArg<T>::shortID(const std::string& val) const | |||
| { | |||
| static_cast<void>(val); // Ignore input, don't warn | |||
| return std::string("<") + _typeDesc + "> ..."; | |||
| } | |||
| template<class T> | |||
| std::string UnlabeledMultiArg<T>::longID(const std::string& val) const | |||
| { | |||
| static_cast<void>(val); // Ignore input, don't warn | |||
| return std::string("<") + _typeDesc + "> (accepted multiple times)"; | |||
| } | |||
| template<class T> | |||
| bool UnlabeledMultiArg<T>::operator==(const Arg& a) const | |||
| { | |||
| if (_name == a.getName() || _description == a.getDescription()) | |||
| return true; | |||
| else | |||
| return false; | |||
| } | |||
| template<class T> | |||
| void UnlabeledMultiArg<T>::addToList(std::list<Arg*>& argList) const | |||
| { | |||
| argList.push_back(const_cast<Arg*>(static_cast<const Arg* const>(this))); | |||
| } | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -1,28 +1,26 @@ | |||
| // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- | |||
| /****************************************************************************** | |||
| * | |||
| /****************************************************************************** | |||
| * | |||
| * file: UnlabeledValueArg.h | |||
| * | |||
| * | |||
| * Copyright (c) 2003, Michael E. Smoot . | |||
| * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. | |||
| * Copyright (c) 2017, Google LLC | |||
| * All rights reserved. | |||
| * | |||
| * | |||
| * See the file COPYING in the top directory of this distribution for | |||
| * more information. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| #ifndef TCLAP_UNLABELED_VALUE_ARGUMENT_H | |||
| #define TCLAP_UNLABELED_VALUE_ARGUMENT_H | |||
| @@ -33,311 +31,253 @@ | |||
| #include <tclap/ValueArg.h> | |||
| #include <tclap/OptionalUnlabeledTracker.h> | |||
| namespace TCLAP { | |||
| /** | |||
| * The basic unlabeled argument that parses a value. | |||
| * This is a template class, which means the type T defines the type | |||
| * that a given object will attempt to parse when an UnlabeledValueArg | |||
| * is reached in the list of args that the CmdLine iterates over. | |||
| */ | |||
| template<class T> | |||
| class UnlabeledValueArg : public ValueArg<T> | |||
| { | |||
| // If compiler has two stage name lookup (as gcc >= 3.4 does) | |||
| // this is required to prevent undef. symbols | |||
| using ValueArg<T>::_ignoreable; | |||
| using ValueArg<T>::_hasBlanks; | |||
| using ValueArg<T>::_extractValue; | |||
| using ValueArg<T>::_typeDesc; | |||
| using ValueArg<T>::_name; | |||
| using ValueArg<T>::_description; | |||
| using ValueArg<T>::_alreadySet; | |||
| using ValueArg<T>::toString; | |||
| public: | |||
| /** | |||
| * UnlabeledValueArg constructor. | |||
| * \param name - A one word name for the argument. Note that this is used for | |||
| * identification, not as a long flag. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param value - The default value assigned to this argument if it | |||
| * is not present on the command line. | |||
| * \param typeDesc - A short, human readable description of the | |||
| * type that this object expects. This is used in the generation | |||
| * of the USAGE statement. The goal is to be helpful to the end user | |||
| * of the program. | |||
| * \param ignoreable - Allows you to specify that this argument can be | |||
| * ignored if the '--' flag is set. This defaults to false (cannot | |||
| * be ignored) and should generally stay that way unless you have | |||
| * some special need for certain arguments to be ignored. | |||
| * \param v - Optional Visitor. You should leave this blank unless | |||
| * you have a very good reason. | |||
| */ | |||
| UnlabeledValueArg( const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| T value, | |||
| const std::string& typeDesc, | |||
| bool ignoreable = false, | |||
| Visitor* v = NULL); | |||
| /** | |||
| * UnlabeledValueArg constructor. | |||
| * \param name - A one word name for the argument. Note that this is used for | |||
| * identification, not as a long flag. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param value - The default value assigned to this argument if it | |||
| * is not present on the command line. | |||
| * \param typeDesc - A short, human readable description of the | |||
| * type that this object expects. This is used in the generation | |||
| * of the USAGE statement. The goal is to be helpful to the end user | |||
| * of the program. | |||
| * \param parser - A CmdLine parser object to add this Arg to | |||
| * \param ignoreable - Allows you to specify that this argument can be | |||
| * ignored if the '--' flag is set. This defaults to false (cannot | |||
| * be ignored) and should generally stay that way unless you have | |||
| * some special need for certain arguments to be ignored. | |||
| * \param v - Optional Visitor. You should leave this blank unless | |||
| * you have a very good reason. | |||
| */ | |||
| UnlabeledValueArg( const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| T value, | |||
| const std::string& typeDesc, | |||
| CmdLineInterface& parser, | |||
| bool ignoreable = false, | |||
| Visitor* v = NULL ); | |||
| /** | |||
| * UnlabeledValueArg constructor. | |||
| * \param name - A one word name for the argument. Note that this is used for | |||
| * identification, not as a long flag. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param value - The default value assigned to this argument if it | |||
| * is not present on the command line. | |||
| * \param constraint - A pointer to a Constraint object used | |||
| * to constrain this Arg. | |||
| * \param ignoreable - Allows you to specify that this argument can be | |||
| * ignored if the '--' flag is set. This defaults to false (cannot | |||
| * be ignored) and should generally stay that way unless you have | |||
| * some special need for certain arguments to be ignored. | |||
| * \param v - Optional Visitor. You should leave this blank unless | |||
| * you have a very good reason. | |||
| */ | |||
| UnlabeledValueArg( const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| T value, | |||
| Constraint<T>* constraint, | |||
| bool ignoreable = false, | |||
| Visitor* v = NULL ); | |||
| /** | |||
| * UnlabeledValueArg constructor. | |||
| * \param name - A one word name for the argument. Note that this is used for | |||
| * identification, not as a long flag. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param value - The default value assigned to this argument if it | |||
| * is not present on the command line. | |||
| * \param constraint - A pointer to a Constraint object used | |||
| * to constrain this Arg. | |||
| * \param parser - A CmdLine parser object to add this Arg to | |||
| * \param ignoreable - Allows you to specify that this argument can be | |||
| * ignored if the '--' flag is set. This defaults to false (cannot | |||
| * be ignored) and should generally stay that way unless you have | |||
| * some special need for certain arguments to be ignored. | |||
| * \param v - Optional Visitor. You should leave this blank unless | |||
| * you have a very good reason. | |||
| */ | |||
| UnlabeledValueArg( const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| T value, | |||
| Constraint<T>* constraint, | |||
| CmdLineInterface& parser, | |||
| bool ignoreable = false, | |||
| Visitor* v = NULL); | |||
| /** | |||
| * Handles the processing of the argument. | |||
| * This re-implements the Arg version of this method to set the | |||
| * _value of the argument appropriately. Handling specific to | |||
| * unlabeled arguments. | |||
| * \param i - Pointer the the current argument in the list. | |||
| * \param args - Mutable list of strings. | |||
| */ | |||
| virtual bool processArg(int* i, std::vector<std::string>& args); | |||
| /** | |||
| * Overrides shortID for specific behavior. | |||
| */ | |||
| virtual std::string shortID(const std::string& val="val") const; | |||
| /** | |||
| * Overrides longID for specific behavior. | |||
| */ | |||
| virtual std::string longID(const std::string& val="val") const; | |||
| /** | |||
| * Overrides operator== for specific behavior. | |||
| */ | |||
| virtual bool operator==(const Arg& a ) const; | |||
| /** | |||
| * Instead of pushing to the front of list, push to the back. | |||
| * \param argList - The list to add this to. | |||
| */ | |||
| virtual void addToList( std::list<Arg*>& argList ) const; | |||
| }; | |||
| /** | |||
| * Constructor implementation. | |||
| */ | |||
| template<class T> | |||
| UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| T val, | |||
| const std::string& typeDesc, | |||
| bool ignoreable, | |||
| Visitor* v) | |||
| : ValueArg<T>("", name, desc, req, val, typeDesc, v) | |||
| { | |||
| _ignoreable = ignoreable; | |||
| OptionalUnlabeledTracker::check(req, toString()); | |||
| } | |||
| template<class T> | |||
| UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| T val, | |||
| const std::string& typeDesc, | |||
| CmdLineInterface& parser, | |||
| bool ignoreable, | |||
| Visitor* v) | |||
| : ValueArg<T>("", name, desc, req, val, typeDesc, v) | |||
| { | |||
| _ignoreable = ignoreable; | |||
| OptionalUnlabeledTracker::check(req, toString()); | |||
| parser.add( this ); | |||
| } | |||
| /** | |||
| * Constructor implementation. | |||
| */ | |||
| template<class T> | |||
| UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| T val, | |||
| Constraint<T>* constraint, | |||
| bool ignoreable, | |||
| Visitor* v) | |||
| : ValueArg<T>("", name, desc, req, val, constraint, v) | |||
| { | |||
| _ignoreable = ignoreable; | |||
| OptionalUnlabeledTracker::check(req, toString()); | |||
| } | |||
| template<class T> | |||
| UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| T val, | |||
| Constraint<T>* constraint, | |||
| CmdLineInterface& parser, | |||
| bool ignoreable, | |||
| Visitor* v) | |||
| : ValueArg<T>("", name, desc, req, val, constraint, v) | |||
| { | |||
| _ignoreable = ignoreable; | |||
| OptionalUnlabeledTracker::check(req, toString()); | |||
| parser.add( this ); | |||
| } | |||
| /** | |||
| * Implementation of processArg(). | |||
| */ | |||
| template<class T> | |||
| bool UnlabeledValueArg<T>::processArg(int *i, std::vector<std::string>& args) | |||
| { | |||
| if ( _alreadySet ) | |||
| return false; | |||
| if ( _hasBlanks( args[*i] ) ) | |||
| return false; | |||
| // never ignore an unlabeled arg | |||
| _extractValue( args[*i] ); | |||
| _alreadySet = true; | |||
| return true; | |||
| } | |||
| /** | |||
| * Overriding shortID for specific output. | |||
| */ | |||
| template<class T> | |||
| std::string UnlabeledValueArg<T>::shortID(const std::string& val) const | |||
| { | |||
| static_cast<void>(val); // Ignore input, don't warn | |||
| return std::string("<") + _typeDesc + ">"; | |||
| } | |||
| /** | |||
| * Overriding longID for specific output. | |||
| */ | |||
| template<class T> | |||
| std::string UnlabeledValueArg<T>::longID(const std::string& val) const | |||
| { | |||
| static_cast<void>(val); // Ignore input, don't warn | |||
| // Ideally we would like to be able to use RTTI to return the name | |||
| // of the type required for this argument. However, g++ at least, | |||
| // doesn't appear to return terribly useful "names" of the types. | |||
| return std::string("<") + _typeDesc + ">"; | |||
| } | |||
| /** | |||
| * Overriding operator== for specific behavior. | |||
| */ | |||
| template<class T> | |||
| bool UnlabeledValueArg<T>::operator==(const Arg& a ) const | |||
| { | |||
| if ( _name == a.getName() || _description == a.getDescription() ) | |||
| return true; | |||
| else | |||
| return false; | |||
| } | |||
| template<class T> | |||
| void UnlabeledValueArg<T>::addToList( std::list<Arg*>& argList ) const | |||
| namespace TCLAP | |||
| { | |||
| argList.push_back( const_cast<Arg*>(static_cast<const Arg* const>(this)) ); | |||
| } | |||
| } | |||
| /** | |||
| * The basic unlabeled argument that parses a value. | |||
| * This is a template class, which means the type T defines the type | |||
| * that a given object will attempt to parse when an UnlabeledValueArg | |||
| * is reached in the list of args that the CmdLine iterates over. | |||
| */ | |||
| template<class T> | |||
| class UnlabeledValueArg : public ValueArg<T> | |||
| { | |||
| // If compiler has two stage name lookup (as gcc >= 3.4 does) | |||
| // this is required to prevent undef. symbols | |||
| using ValueArg<T>::_ignoreable; | |||
| using ValueArg<T>::_hasBlanks; | |||
| using ValueArg<T>::_extractValue; | |||
| using ValueArg<T>::_typeDesc; | |||
| using ValueArg<T>::_name; | |||
| using ValueArg<T>::_description; | |||
| using ValueArg<T>::_alreadySet; | |||
| using ValueArg<T>::toString; | |||
| public: | |||
| /** | |||
| * UnlabeledValueArg constructor. | |||
| * \param name - A one word name for the argument. Note that this is used for | |||
| * identification, not as a long flag. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param value - The default value assigned to this argument if it | |||
| * is not present on the command line. | |||
| * \param typeDesc - A short, human readable description of the | |||
| * type that this object expects. This is used in the generation | |||
| * of the USAGE statement. The goal is to be helpful to the end user | |||
| * of the program. | |||
| * \param ignoreable - Allows you to specify that this argument can be | |||
| * ignored if the '--' flag is set. This defaults to false (cannot | |||
| * be ignored) and should generally stay that way unless you have | |||
| * some special need for certain arguments to be ignored. | |||
| * \param v - Optional Visitor. You should leave this blank unless | |||
| * you have a very good reason. | |||
| */ | |||
| UnlabeledValueArg(const std::string& name, const std::string& desc, bool req, T value, const std::string& typeDesc, bool ignoreable = false, Visitor* v = NULL); | |||
| /** | |||
| * UnlabeledValueArg constructor. | |||
| * \param name - A one word name for the argument. Note that this is used for | |||
| * identification, not as a long flag. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param value - The default value assigned to this argument if it | |||
| * is not present on the command line. | |||
| * \param typeDesc - A short, human readable description of the | |||
| * type that this object expects. This is used in the generation | |||
| * of the USAGE statement. The goal is to be helpful to the end user | |||
| * of the program. | |||
| * \param parser - A CmdLine parser object to add this Arg to | |||
| * \param ignoreable - Allows you to specify that this argument can be | |||
| * ignored if the '--' flag is set. This defaults to false (cannot | |||
| * be ignored) and should generally stay that way unless you have | |||
| * some special need for certain arguments to be ignored. | |||
| * \param v - Optional Visitor. You should leave this blank unless | |||
| * you have a very good reason. | |||
| */ | |||
| UnlabeledValueArg(const std::string& name, const std::string& desc, bool req, T value, const std::string& typeDesc, CmdLineInterface& parser, bool ignoreable = false, Visitor* v = NULL); | |||
| /** | |||
| * UnlabeledValueArg constructor. | |||
| * \param name - A one word name for the argument. Note that this is used for | |||
| * identification, not as a long flag. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param value - The default value assigned to this argument if it | |||
| * is not present on the command line. | |||
| * \param constraint - A pointer to a Constraint object used | |||
| * to constrain this Arg. | |||
| * \param ignoreable - Allows you to specify that this argument can be | |||
| * ignored if the '--' flag is set. This defaults to false (cannot | |||
| * be ignored) and should generally stay that way unless you have | |||
| * some special need for certain arguments to be ignored. | |||
| * \param v - Optional Visitor. You should leave this blank unless | |||
| * you have a very good reason. | |||
| */ | |||
| UnlabeledValueArg(const std::string& name, const std::string& desc, bool req, T value, Constraint<T>* constraint, bool ignoreable = false, Visitor* v = NULL); | |||
| /** | |||
| * UnlabeledValueArg constructor. | |||
| * \param name - A one word name for the argument. Note that this is used for | |||
| * identification, not as a long flag. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param value - The default value assigned to this argument if it | |||
| * is not present on the command line. | |||
| * \param constraint - A pointer to a Constraint object used | |||
| * to constrain this Arg. | |||
| * \param parser - A CmdLine parser object to add this Arg to | |||
| * \param ignoreable - Allows you to specify that this argument can be | |||
| * ignored if the '--' flag is set. This defaults to false (cannot | |||
| * be ignored) and should generally stay that way unless you have | |||
| * some special need for certain arguments to be ignored. | |||
| * \param v - Optional Visitor. You should leave this blank unless | |||
| * you have a very good reason. | |||
| */ | |||
| UnlabeledValueArg(const std::string& name, const std::string& desc, bool req, T value, Constraint<T>* constraint, CmdLineInterface& parser, bool ignoreable = false, Visitor* v = NULL); | |||
| /** | |||
| * Handles the processing of the argument. | |||
| * This re-implements the Arg version of this method to set the | |||
| * _value of the argument appropriately. Handling specific to | |||
| * unlabeled arguments. | |||
| * \param i - Pointer the the current argument in the list. | |||
| * \param args - Mutable list of strings. | |||
| */ | |||
| virtual bool processArg(int* i, std::vector<std::string>& args); | |||
| /** | |||
| * Overrides shortID for specific behavior. | |||
| */ | |||
| virtual std::string shortID(const std::string& val = "val") const; | |||
| /** | |||
| * Overrides longID for specific behavior. | |||
| */ | |||
| virtual std::string longID(const std::string& val = "val") const; | |||
| /** | |||
| * Overrides operator== for specific behavior. | |||
| */ | |||
| virtual bool operator==(const Arg& a) const; | |||
| /** | |||
| * Instead of pushing to the front of list, push to the back. | |||
| * \param argList - The list to add this to. | |||
| */ | |||
| virtual void addToList(std::list<Arg*>& argList) const; | |||
| }; | |||
| /** | |||
| * Constructor implementation. | |||
| */ | |||
| template<class T> | |||
| UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name, const std::string& desc, bool req, T val, const std::string& typeDesc, bool ignoreable, Visitor* v) : | |||
| ValueArg<T>("", name, desc, req, val, typeDesc, v) | |||
| { | |||
| _ignoreable = ignoreable; | |||
| OptionalUnlabeledTracker::check(req, toString()); | |||
| } | |||
| template<class T> | |||
| UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name, const std::string& desc, bool req, T val, const std::string& typeDesc, CmdLineInterface& parser, bool ignoreable, Visitor* v) : | |||
| ValueArg<T>("", name, desc, req, val, typeDesc, v) | |||
| { | |||
| _ignoreable = ignoreable; | |||
| OptionalUnlabeledTracker::check(req, toString()); | |||
| parser.add(this); | |||
| } | |||
| /** | |||
| * Constructor implementation. | |||
| */ | |||
| template<class T> | |||
| UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name, const std::string& desc, bool req, T val, Constraint<T>* constraint, bool ignoreable, Visitor* v) : | |||
| ValueArg<T>("", name, desc, req, val, constraint, v) | |||
| { | |||
| _ignoreable = ignoreable; | |||
| OptionalUnlabeledTracker::check(req, toString()); | |||
| } | |||
| template<class T> | |||
| UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name, const std::string& desc, bool req, T val, Constraint<T>* constraint, CmdLineInterface& parser, bool ignoreable, Visitor* v) : | |||
| ValueArg<T>("", name, desc, req, val, constraint, v) | |||
| { | |||
| _ignoreable = ignoreable; | |||
| OptionalUnlabeledTracker::check(req, toString()); | |||
| parser.add(this); | |||
| } | |||
| /** | |||
| * Implementation of processArg(). | |||
| */ | |||
| template<class T> | |||
| bool UnlabeledValueArg<T>::processArg(int* i, std::vector<std::string>& args) | |||
| { | |||
| if (_alreadySet) | |||
| return false; | |||
| if (_hasBlanks(args[*i])) | |||
| return false; | |||
| // never ignore an unlabeled arg | |||
| _extractValue(args[*i]); | |||
| _alreadySet = true; | |||
| return true; | |||
| } | |||
| /** | |||
| * Overriding shortID for specific output. | |||
| */ | |||
| template<class T> | |||
| std::string UnlabeledValueArg<T>::shortID(const std::string& val) const | |||
| { | |||
| static_cast<void>(val); // Ignore input, don't warn | |||
| return std::string("<") + _typeDesc + ">"; | |||
| } | |||
| /** | |||
| * Overriding longID for specific output. | |||
| */ | |||
| template<class T> | |||
| std::string UnlabeledValueArg<T>::longID(const std::string& val) const | |||
| { | |||
| static_cast<void>(val); // Ignore input, don't warn | |||
| // Ideally we would like to be able to use RTTI to return the name | |||
| // of the type required for this argument. However, g++ at least, | |||
| // doesn't appear to return terribly useful "names" of the types. | |||
| return std::string("<") + _typeDesc + ">"; | |||
| } | |||
| /** | |||
| * Overriding operator== for specific behavior. | |||
| */ | |||
| template<class T> | |||
| bool UnlabeledValueArg<T>::operator==(const Arg& a) const | |||
| { | |||
| if (_name == a.getName() || _description == a.getDescription()) | |||
| return true; | |||
| else | |||
| return false; | |||
| } | |||
| template<class T> | |||
| void UnlabeledValueArg<T>::addToList(std::list<Arg*>& argList) const | |||
| { | |||
| argList.push_back(const_cast<Arg*>(static_cast<const Arg* const>(this))); | |||
| } | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -1,28 +1,27 @@ | |||
| // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- | |||
| /****************************************************************************** | |||
| * | |||
| /****************************************************************************** | |||
| * | |||
| * file: ValueArg.h | |||
| * | |||
| * | |||
| * Copyright (c) 2003, Michael E. Smoot . | |||
| * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. | |||
| * Copyright (c) 2017, Google LLC | |||
| * All rights reserved. | |||
| * | |||
| * | |||
| * See the file COPYING in the top directory of this distribution for | |||
| * more information. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| #ifndef TCLAP_VALUE_ARGUMENT_H | |||
| #define TCLAP_VALUE_ARGUMENT_H | |||
| @@ -32,399 +31,353 @@ | |||
| #include <tclap/Arg.h> | |||
| #include <tclap/Constraint.h> | |||
| namespace TCLAP { | |||
| /** | |||
| * The basic labeled argument that parses a value. | |||
| * This is a template class, which means the type T defines the type | |||
| * that a given object will attempt to parse when the flag/name is matched | |||
| * on the command line. While there is nothing stopping you from creating | |||
| * an unflagged ValueArg, it is unwise and would cause significant problems. | |||
| * Instead use an UnlabeledValueArg. | |||
| */ | |||
| template<class T> | |||
| class ValueArg : public Arg | |||
| { | |||
| protected: | |||
| /** | |||
| * The value parsed from the command line. | |||
| * Can be of any type, as long as the >> operator for the type | |||
| * is defined. | |||
| */ | |||
| T _value; | |||
| /** | |||
| * Used to support the reset() method so that ValueArg can be | |||
| * reset to their constructed value. | |||
| */ | |||
| T _default; | |||
| /** | |||
| * A human readable description of the type to be parsed. | |||
| * This is a hack, plain and simple. Ideally we would use RTTI to | |||
| * return the name of type T, but until there is some sort of | |||
| * consistent support for human readable names, we are left to our | |||
| * own devices. | |||
| */ | |||
| std::string _typeDesc; | |||
| /** | |||
| * A Constraint this Arg must conform to. | |||
| */ | |||
| Constraint<T>* _constraint; | |||
| /** | |||
| * Extracts the value from the string. | |||
| * Attempts to parse string as type T, if this fails an exception | |||
| * is thrown. | |||
| * \param val - value to be parsed. | |||
| */ | |||
| void _extractValue( const std::string& val ); | |||
| public: | |||
| /** | |||
| * Labeled ValueArg constructor. | |||
| * You could conceivably call this constructor with a blank flag, | |||
| * but that would make you a bad person. It would also cause | |||
| * an exception to be thrown. If you want an unlabeled argument, | |||
| * use the other constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param value - The default value assigned to this argument if it | |||
| * is not present on the command line. | |||
| * \param typeDesc - A short, human readable description of the | |||
| * type that this object expects. This is used in the generation | |||
| * of the USAGE statement. The goal is to be helpful to the end user | |||
| * of the program. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| ValueArg( const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| T value, | |||
| const std::string& typeDesc, | |||
| Visitor* v = NULL); | |||
| /** | |||
| * Labeled ValueArg constructor. | |||
| * You could conceivably call this constructor with a blank flag, | |||
| * but that would make you a bad person. It would also cause | |||
| * an exception to be thrown. If you want an unlabeled argument, | |||
| * use the other constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param value - The default value assigned to this argument if it | |||
| * is not present on the command line. | |||
| * \param typeDesc - A short, human readable description of the | |||
| * type that this object expects. This is used in the generation | |||
| * of the USAGE statement. The goal is to be helpful to the end user | |||
| * of the program. | |||
| * \param parser - A CmdLine parser object to add this Arg to | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| ValueArg( const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| T value, | |||
| const std::string& typeDesc, | |||
| CmdLineInterface& parser, | |||
| Visitor* v = NULL ); | |||
| /** | |||
| * Labeled ValueArg constructor. | |||
| * You could conceivably call this constructor with a blank flag, | |||
| * but that would make you a bad person. It would also cause | |||
| * an exception to be thrown. If you want an unlabeled argument, | |||
| * use the other constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param value - The default value assigned to this argument if it | |||
| * is not present on the command line. | |||
| * \param constraint - A pointer to a Constraint object used | |||
| * to constrain this Arg. | |||
| * \param parser - A CmdLine parser object to add this Arg to. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| ValueArg( const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| T value, | |||
| Constraint<T>* constraint, | |||
| CmdLineInterface& parser, | |||
| Visitor* v = NULL ); | |||
| /** | |||
| * Labeled ValueArg constructor. | |||
| * You could conceivably call this constructor with a blank flag, | |||
| * but that would make you a bad person. It would also cause | |||
| * an exception to be thrown. If you want an unlabeled argument, | |||
| * use the other constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param value - The default value assigned to this argument if it | |||
| * is not present on the command line. | |||
| * \param constraint - A pointer to a Constraint object used | |||
| * to constrain this Arg. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| ValueArg( const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| T value, | |||
| Constraint<T>* constraint, | |||
| Visitor* v = NULL ); | |||
| /** | |||
| * Handles the processing of the argument. | |||
| * This re-implements the Arg version of this method to set the | |||
| * _value of the argument appropriately. It knows the difference | |||
| * between labeled and unlabeled. | |||
| * \param i - Pointer the the current argument in the list. | |||
| * \param args - Mutable list of strings. Passed | |||
| * in from main(). | |||
| */ | |||
| virtual bool processArg(int* i, std::vector<std::string>& args); | |||
| /** | |||
| * Returns the value of the argument. | |||
| */ | |||
| const T& getValue() const { return _value; } | |||
| // TODO(macbishop): Non-const variant is deprecated, don't | |||
| // use. Remove in next major. | |||
| T& getValue() { return _value; } | |||
| /** | |||
| * A ValueArg can be used as as its value type (T) This is the | |||
| * same as calling getValue() | |||
| */ | |||
| operator const T&() const { return getValue(); } | |||
| /** | |||
| * Specialization of shortID. | |||
| * \param val - value to be used. | |||
| */ | |||
| virtual std::string shortID(const std::string& val = "val") const; | |||
| /** | |||
| * Specialization of longID. | |||
| * \param val - value to be used. | |||
| */ | |||
| virtual std::string longID(const std::string& val = "val") const; | |||
| virtual void reset() ; | |||
| private: | |||
| /** | |||
| * Prevent accidental copying | |||
| */ | |||
| ValueArg<T>(const ValueArg<T>& rhs); | |||
| ValueArg<T>& operator=(const ValueArg<T>& rhs); | |||
| }; | |||
| /** | |||
| * Constructor implementation. | |||
| */ | |||
| template<class T> | |||
| ValueArg<T>::ValueArg(const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| T val, | |||
| const std::string& typeDesc, | |||
| Visitor* v) | |||
| : Arg(flag, name, desc, req, true, v), | |||
| _value( val ), | |||
| _default( val ), | |||
| _typeDesc( typeDesc ), | |||
| _constraint( NULL ) | |||
| { } | |||
| template<class T> | |||
| ValueArg<T>::ValueArg(const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| T val, | |||
| const std::string& typeDesc, | |||
| CmdLineInterface& parser, | |||
| Visitor* v) | |||
| : Arg(flag, name, desc, req, true, v), | |||
| _value( val ), | |||
| _default( val ), | |||
| _typeDesc( typeDesc ), | |||
| _constraint( NULL ) | |||
| { | |||
| parser.add( this ); | |||
| } | |||
| template<class T> | |||
| ValueArg<T>::ValueArg(const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| T val, | |||
| Constraint<T>* constraint, | |||
| Visitor* v) | |||
| : Arg(flag, name, desc, req, true, v), | |||
| _value( val ), | |||
| _default( val ), | |||
| _typeDesc( Constraint<T>::shortID(constraint) ), | |||
| _constraint( constraint ) | |||
| { } | |||
| template<class T> | |||
| ValueArg<T>::ValueArg(const std::string& flag, | |||
| const std::string& name, | |||
| const std::string& desc, | |||
| bool req, | |||
| T val, | |||
| Constraint<T>* constraint, | |||
| CmdLineInterface& parser, | |||
| Visitor* v) | |||
| : Arg(flag, name, desc, req, true, v), | |||
| _value( val ), | |||
| _default( val ), | |||
| _typeDesc( Constraint<T>::shortID(constraint) ), // TODO(macbishop): Will crash | |||
| // if constraint is NULL | |||
| _constraint( constraint ) | |||
| { | |||
| parser.add( this ); | |||
| } | |||
| /** | |||
| * Implementation of processArg(). | |||
| */ | |||
| template<class T> | |||
| bool ValueArg<T>::processArg(int *i, std::vector<std::string>& args) | |||
| namespace TCLAP | |||
| { | |||
| if ( _ignoreable && Arg::ignoreRest() ) | |||
| return false; | |||
| if ( _hasBlanks( args[*i] ) ) | |||
| return false; | |||
| /** | |||
| * The basic labeled argument that parses a value. | |||
| * This is a template class, which means the type T defines the type | |||
| * that a given object will attempt to parse when the flag/name is matched | |||
| * on the command line. While there is nothing stopping you from creating | |||
| * an unflagged ValueArg, it is unwise and would cause significant problems. | |||
| * Instead use an UnlabeledValueArg. | |||
| */ | |||
| template<class T> | |||
| class ValueArg : public Arg | |||
| { | |||
| protected: | |||
| /** | |||
| * The value parsed from the command line. | |||
| * Can be of any type, as long as the >> operator for the type | |||
| * is defined. | |||
| */ | |||
| T _value; | |||
| /** | |||
| * Used to support the reset() method so that ValueArg can be | |||
| * reset to their constructed value. | |||
| */ | |||
| T _default; | |||
| /** | |||
| * A human readable description of the type to be parsed. | |||
| * This is a hack, plain and simple. Ideally we would use RTTI to | |||
| * return the name of type T, but until there is some sort of | |||
| * consistent support for human readable names, we are left to our | |||
| * own devices. | |||
| */ | |||
| std::string _typeDesc; | |||
| /** | |||
| * A Constraint this Arg must conform to. | |||
| */ | |||
| Constraint<T>* _constraint; | |||
| /** | |||
| * Extracts the value from the string. | |||
| * Attempts to parse string as type T, if this fails an exception | |||
| * is thrown. | |||
| * \param val - value to be parsed. | |||
| */ | |||
| void _extractValue(const std::string& val); | |||
| public: | |||
| /** | |||
| * Labeled ValueArg constructor. | |||
| * You could conceivably call this constructor with a blank flag, | |||
| * but that would make you a bad person. It would also cause | |||
| * an exception to be thrown. If you want an unlabeled argument, | |||
| * use the other constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param value - The default value assigned to this argument if it | |||
| * is not present on the command line. | |||
| * \param typeDesc - A short, human readable description of the | |||
| * type that this object expects. This is used in the generation | |||
| * of the USAGE statement. The goal is to be helpful to the end user | |||
| * of the program. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| ValueArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, T value, const std::string& typeDesc, Visitor* v = NULL); | |||
| /** | |||
| * Labeled ValueArg constructor. | |||
| * You could conceivably call this constructor with a blank flag, | |||
| * but that would make you a bad person. It would also cause | |||
| * an exception to be thrown. If you want an unlabeled argument, | |||
| * use the other constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param value - The default value assigned to this argument if it | |||
| * is not present on the command line. | |||
| * \param typeDesc - A short, human readable description of the | |||
| * type that this object expects. This is used in the generation | |||
| * of the USAGE statement. The goal is to be helpful to the end user | |||
| * of the program. | |||
| * \param parser - A CmdLine parser object to add this Arg to | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| ValueArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, T value, const std::string& typeDesc, CmdLineInterface& parser, Visitor* v = NULL); | |||
| /** | |||
| * Labeled ValueArg constructor. | |||
| * You could conceivably call this constructor with a blank flag, | |||
| * but that would make you a bad person. It would also cause | |||
| * an exception to be thrown. If you want an unlabeled argument, | |||
| * use the other constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param value - The default value assigned to this argument if it | |||
| * is not present on the command line. | |||
| * \param constraint - A pointer to a Constraint object used | |||
| * to constrain this Arg. | |||
| * \param parser - A CmdLine parser object to add this Arg to. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| ValueArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, T value, Constraint<T>* constraint, CmdLineInterface& parser, Visitor* v = NULL); | |||
| /** | |||
| * Labeled ValueArg constructor. | |||
| * You could conceivably call this constructor with a blank flag, | |||
| * but that would make you a bad person. It would also cause | |||
| * an exception to be thrown. If you want an unlabeled argument, | |||
| * use the other constructor. | |||
| * \param flag - The one character flag that identifies this | |||
| * argument on the command line. | |||
| * \param name - A one word name for the argument. Can be | |||
| * used as a long flag on the command line. | |||
| * \param desc - A description of what the argument is for or | |||
| * does. | |||
| * \param req - Whether the argument is required on the command | |||
| * line. | |||
| * \param value - The default value assigned to this argument if it | |||
| * is not present on the command line. | |||
| * \param constraint - A pointer to a Constraint object used | |||
| * to constrain this Arg. | |||
| * \param v - An optional visitor. You probably should not | |||
| * use this unless you have a very good reason. | |||
| */ | |||
| ValueArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, T value, Constraint<T>* constraint, Visitor* v = NULL); | |||
| /** | |||
| * Handles the processing of the argument. | |||
| * This re-implements the Arg version of this method to set the | |||
| * _value of the argument appropriately. It knows the difference | |||
| * between labeled and unlabeled. | |||
| * \param i - Pointer the the current argument in the list. | |||
| * \param args - Mutable list of strings. Passed | |||
| * in from main(). | |||
| */ | |||
| virtual bool processArg(int* i, std::vector<std::string>& args); | |||
| /** | |||
| * Returns the value of the argument. | |||
| */ | |||
| const T& getValue() const | |||
| { | |||
| return _value; | |||
| } | |||
| std::string flag = args[*i]; | |||
| // TODO(macbishop): Non-const variant is deprecated, don't | |||
| // use. Remove in next major. | |||
| T& getValue() | |||
| { | |||
| return _value; | |||
| } | |||
| std::string value = ""; | |||
| trimFlag( flag, value ); | |||
| /** | |||
| * A ValueArg can be used as as its value type (T) This is the | |||
| * same as calling getValue() | |||
| */ | |||
| operator const T&() const | |||
| { | |||
| return getValue(); | |||
| } | |||
| if ( argMatches( flag ) ) | |||
| /** | |||
| * Specialization of shortID. | |||
| * \param val - value to be used. | |||
| */ | |||
| virtual std::string shortID(const std::string& val = "val") const; | |||
| /** | |||
| * Specialization of longID. | |||
| * \param val - value to be used. | |||
| */ | |||
| virtual std::string longID(const std::string& val = "val") const; | |||
| virtual void reset(); | |||
| private: | |||
| /** | |||
| * Prevent accidental copying | |||
| */ | |||
| ValueArg<T>(const ValueArg<T>& rhs); | |||
| ValueArg<T>& operator=(const ValueArg<T>& rhs); | |||
| }; | |||
| /** | |||
| * Constructor implementation. | |||
| */ | |||
| template<class T> | |||
| ValueArg<T>::ValueArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, T val, const std::string& typeDesc, Visitor* v) : | |||
| Arg(flag, name, desc, req, true, v), | |||
| _value(val), | |||
| _default(val), | |||
| _typeDesc(typeDesc), | |||
| _constraint(NULL) | |||
| { | |||
| } | |||
| template<class T> | |||
| ValueArg<T>::ValueArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, T val, const std::string& typeDesc, CmdLineInterface& parser, Visitor* v) : | |||
| Arg(flag, name, desc, req, true, v), | |||
| _value(val), | |||
| _default(val), | |||
| _typeDesc(typeDesc), | |||
| _constraint(NULL) | |||
| { | |||
| parser.add(this); | |||
| } | |||
| template<class T> | |||
| ValueArg<T>::ValueArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, T val, Constraint<T>* constraint, Visitor* v) : | |||
| Arg(flag, name, desc, req, true, v), | |||
| _value(val), | |||
| _default(val), | |||
| _typeDesc(Constraint<T>::shortID(constraint)), | |||
| _constraint(constraint) | |||
| { | |||
| } | |||
| template<class T> | |||
| ValueArg<T>::ValueArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, T val, Constraint<T>* constraint, CmdLineInterface& parser, Visitor* v) : | |||
| Arg(flag, name, desc, req, true, v), | |||
| _value(val), | |||
| _default(val), | |||
| _typeDesc(Constraint<T>::shortID(constraint)), // TODO(macbishop): Will crash | |||
| // if constraint is NULL | |||
| _constraint(constraint) | |||
| { | |||
| if ( _alreadySet ) | |||
| parser.add(this); | |||
| } | |||
| /** | |||
| * Implementation of processArg(). | |||
| */ | |||
| template<class T> | |||
| bool ValueArg<T>::processArg(int* i, std::vector<std::string>& args) | |||
| { | |||
| if (_ignoreable && Arg::ignoreRest()) | |||
| return false; | |||
| if (_hasBlanks(args[*i])) | |||
| return false; | |||
| std::string flag = args[*i]; | |||
| std::string value = ""; | |||
| trimFlag(flag, value); | |||
| if (argMatches(flag)) | |||
| { | |||
| if ( _xorSet ) | |||
| throw( CmdLineParseException("Mutually exclusive argument" | |||
| " already set!", toString())); | |||
| else | |||
| throw( CmdLineParseException("Argument already set!", | |||
| toString()) ); | |||
| if (_alreadySet) | |||
| { | |||
| if (_xorSet) | |||
| throw(CmdLineParseException("Mutually exclusive argument" | |||
| " already set!", | |||
| toString())); | |||
| else | |||
| throw(CmdLineParseException("Argument already set!", toString())); | |||
| } | |||
| if (Arg::delimiter() != ' ' && value == "") | |||
| throw(ArgParseException("Couldn't find delimiter for this argument!", toString())); | |||
| if (value == "") | |||
| { | |||
| (*i)++; | |||
| if (static_cast<unsigned int>(*i) < args.size()) | |||
| _extractValue(args[*i]); | |||
| else | |||
| throw(ArgParseException("Missing a value for this argument!", toString())); | |||
| } | |||
| else | |||
| _extractValue(value); | |||
| _alreadySet = true; | |||
| _checkWithVisitor(); | |||
| return true; | |||
| } | |||
| else | |||
| return false; | |||
| } | |||
| /** | |||
| * Implementation of shortID. | |||
| */ | |||
| template<class T> | |||
| std::string ValueArg<T>::shortID(const std::string& val) const | |||
| { | |||
| static_cast<void>(val); // Ignore input, don't warn | |||
| return Arg::shortID(_typeDesc); | |||
| } | |||
| /** | |||
| * Implementation of longID. | |||
| */ | |||
| template<class T> | |||
| std::string ValueArg<T>::longID(const std::string& val) const | |||
| { | |||
| static_cast<void>(val); // Ignore input, don't warn | |||
| return Arg::longID(_typeDesc); | |||
| } | |||
| if ( Arg::delimiter() != ' ' && value == "" ) | |||
| throw( ArgParseException("Couldn't find delimiter for this argument!", | |||
| toString() ) ); | |||
| if ( value == "" ) | |||
| template<class T> | |||
| void ValueArg<T>::_extractValue(const std::string& val) | |||
| { | |||
| try | |||
| { | |||
| (*i)++; | |||
| if ( static_cast<unsigned int>(*i) < args.size() ) | |||
| _extractValue( args[*i] ); | |||
| else | |||
| throw( ArgParseException("Missing a value for this argument!", | |||
| toString() ) ); | |||
| ExtractValue(_value, val, typename ArgTraits<T>::ValueCategory()); | |||
| } | |||
| catch (ArgParseException& e) | |||
| { | |||
| throw ArgParseException(e.error(), toString()); | |||
| } | |||
| else | |||
| _extractValue( value ); | |||
| _alreadySet = true; | |||
| _checkWithVisitor(); | |||
| return true; | |||
| } | |||
| else | |||
| return false; | |||
| } | |||
| /** | |||
| * Implementation of shortID. | |||
| */ | |||
| template<class T> | |||
| std::string ValueArg<T>::shortID(const std::string& val) const | |||
| { | |||
| static_cast<void>(val); // Ignore input, don't warn | |||
| return Arg::shortID( _typeDesc ); | |||
| } | |||
| /** | |||
| * Implementation of longID. | |||
| */ | |||
| template<class T> | |||
| std::string ValueArg<T>::longID(const std::string& val) const | |||
| { | |||
| static_cast<void>(val); // Ignore input, don't warn | |||
| return Arg::longID( _typeDesc ); | |||
| } | |||
| template<class T> | |||
| void ValueArg<T>::_extractValue( const std::string& val ) | |||
| { | |||
| try { | |||
| ExtractValue(_value, val, typename ArgTraits<T>::ValueCategory()); | |||
| } catch( ArgParseException &e) { | |||
| throw ArgParseException(e.error(), toString()); | |||
| } | |||
| if ( _constraint != NULL ) | |||
| if ( ! _constraint->check( _value ) ) | |||
| throw( CmdLineParseException( "Value '" + val + | |||
| + "' does not meet constraint: " | |||
| + _constraint->description(), | |||
| toString() ) ); | |||
| } | |||
| template<class T> | |||
| void ValueArg<T>::reset() | |||
| { | |||
| Arg::reset(); | |||
| _value = _default; | |||
| } | |||
| if (_constraint != NULL) | |||
| if (!_constraint->check(_value)) | |||
| throw(CmdLineParseException("Value '" + val + +"' does not meet constraint: " + _constraint->description(), toString())); | |||
| } | |||
| template<class T> | |||
| void ValueArg<T>::reset() | |||
| { | |||
| Arg::reset(); | |||
| _value = _default; | |||
| } | |||
| } // namespace TCLAP | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -1,27 +1,25 @@ | |||
| // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- | |||
| /****************************************************************************** | |||
| * | |||
| /****************************************************************************** | |||
| * | |||
| * file: ValuesConstraint.h | |||
| * | |||
| * | |||
| * Copyright (c) 2005, Michael E. Smoot | |||
| * Copyright (c) 2017, Google LLC | |||
| * All rights reserved. | |||
| * | |||
| * | |||
| * See the file COPYING in the top directory of this distribution for | |||
| * more information. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| #ifndef TCLAP_VALUESCONSTRAINT_H | |||
| #define TCLAP_VALUESCONSTRAINT_H | |||
| @@ -35,100 +33,97 @@ | |||
| #include <tclap/Constraint.h> | |||
| #include <tclap/sstream.h> | |||
| namespace TCLAP { | |||
| /** | |||
| * A Constraint that constrains the Arg to only those values specified | |||
| * in the constraint. | |||
| */ | |||
| template<class T> | |||
| class ValuesConstraint : public Constraint<T> | |||
| namespace TCLAP | |||
| { | |||
| public: | |||
| /** | |||
| * Constructor. | |||
| * \param allowed - vector of allowed values. | |||
| */ | |||
| ValuesConstraint(std::vector<T>const& allowed); | |||
| /** | |||
| * Virtual destructor. | |||
| */ | |||
| virtual ~ValuesConstraint() {} | |||
| /** | |||
| * Returns a description of the Constraint. | |||
| */ | |||
| virtual std::string description() const; | |||
| /** | |||
| * Returns the short ID for the Constraint. | |||
| */ | |||
| virtual std::string shortID() const; | |||
| /** | |||
| * The method used to verify that the value parsed from the command | |||
| * line meets the constraint. | |||
| * \param value - The value that will be checked. | |||
| */ | |||
| virtual bool check(const T& value) const; | |||
| protected: | |||
| /** | |||
| * The list of valid values. | |||
| */ | |||
| std::vector<T> _allowed; | |||
| /** | |||
| * The string used to describe the allowed values of this constraint. | |||
| */ | |||
| std::string _typeDesc; | |||
| }; | |||
| template<class T> | |||
| ValuesConstraint<T>::ValuesConstraint(std::vector<T> const& allowed) | |||
| : _allowed(allowed), | |||
| _typeDesc("") | |||
| { | |||
| for ( unsigned int i = 0; i < _allowed.size(); i++ ) | |||
| /** | |||
| * A Constraint that constrains the Arg to only those values specified | |||
| * in the constraint. | |||
| */ | |||
| template<class T> | |||
| class ValuesConstraint : public Constraint<T> | |||
| { | |||
| public: | |||
| /** | |||
| * Constructor. | |||
| * \param allowed - vector of allowed values. | |||
| */ | |||
| ValuesConstraint(std::vector<T> const& allowed); | |||
| /** | |||
| * Virtual destructor. | |||
| */ | |||
| virtual ~ValuesConstraint() | |||
| { | |||
| } | |||
| /** | |||
| * Returns a description of the Constraint. | |||
| */ | |||
| virtual std::string description() const; | |||
| /** | |||
| * Returns the short ID for the Constraint. | |||
| */ | |||
| virtual std::string shortID() const; | |||
| /** | |||
| * The method used to verify that the value parsed from the command | |||
| * line meets the constraint. | |||
| * \param value - The value that will be checked. | |||
| */ | |||
| virtual bool check(const T& value) const; | |||
| protected: | |||
| /** | |||
| * The list of valid values. | |||
| */ | |||
| std::vector<T> _allowed; | |||
| /** | |||
| * The string used to describe the allowed values of this constraint. | |||
| */ | |||
| std::string _typeDesc; | |||
| }; | |||
| template<class T> | |||
| ValuesConstraint<T>::ValuesConstraint(std::vector<T> const& allowed) : | |||
| _allowed(allowed), | |||
| _typeDesc("") | |||
| { | |||
| std::ostringstream os; | |||
| os << _allowed[i]; | |||
| for (unsigned int i = 0; i < _allowed.size(); i++) | |||
| { | |||
| std::ostringstream os; | |||
| os << _allowed[i]; | |||
| std::string temp( os.str() ); | |||
| std::string temp(os.str()); | |||
| if ( i > 0 ) | |||
| _typeDesc += "|"; | |||
| _typeDesc += temp; | |||
| if (i > 0) | |||
| _typeDesc += "|"; | |||
| _typeDesc += temp; | |||
| } | |||
| } | |||
| } | |||
| template<class T> | |||
| bool ValuesConstraint<T>::check( const T& val ) const | |||
| { | |||
| if ( std::find(_allowed.begin(),_allowed.end(),val) == _allowed.end() ) | |||
| return false; | |||
| else | |||
| return true; | |||
| } | |||
| template<class T> | |||
| std::string ValuesConstraint<T>::shortID() const | |||
| { | |||
| return _typeDesc; | |||
| } | |||
| template<class T> | |||
| std::string ValuesConstraint<T>::description() const | |||
| { | |||
| return _typeDesc; | |||
| } | |||
| template<class T> | |||
| bool ValuesConstraint<T>::check(const T& val) const | |||
| { | |||
| if (std::find(_allowed.begin(), _allowed.end(), val) == _allowed.end()) | |||
| return false; | |||
| else | |||
| return true; | |||
| } | |||
| template<class T> | |||
| std::string ValuesConstraint<T>::shortID() const | |||
| { | |||
| return _typeDesc; | |||
| } | |||
| } //namespace TCLAP | |||
| #endif | |||
| template<class T> | |||
| std::string ValuesConstraint<T>::description() const | |||
| { | |||
| return _typeDesc; | |||
| } | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -1,25 +1,24 @@ | |||
| // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- | |||
| /****************************************************************************** | |||
| * | |||
| /****************************************************************************** | |||
| * | |||
| * file: VersionVisitor.h | |||
| * | |||
| * | |||
| * Copyright (c) 2003, Michael E. Smoot . | |||
| * All rights reserved. | |||
| * | |||
| * | |||
| * See the file COPYING in the top directory of this distribution for | |||
| * more information. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| #ifndef TCLAP_VERSION_VISITOR_H | |||
| #define TCLAP_VERSION_VISITOR_H | |||
| @@ -28,54 +27,57 @@ | |||
| #include <tclap/CmdLineOutput.h> | |||
| #include <tclap/Visitor.h> | |||
| namespace TCLAP { | |||
| /** | |||
| * A Visitor that will call the version method of the given CmdLineOutput | |||
| * for the specified CmdLine object and then exit. | |||
| */ | |||
| class VersionVisitor: public Visitor | |||
| namespace TCLAP | |||
| { | |||
| private: | |||
| /** | |||
| * Prevent accidental copying | |||
| */ | |||
| VersionVisitor(const VersionVisitor& rhs); | |||
| VersionVisitor& operator=(const VersionVisitor& rhs); | |||
| protected: | |||
| /** | |||
| * The CmdLine of interest. | |||
| */ | |||
| CmdLineInterface* _cmd; | |||
| /** | |||
| * The output object. | |||
| */ | |||
| CmdLineOutput** _out; | |||
| /** | |||
| * A Visitor that will call the version method of the given CmdLineOutput | |||
| * for the specified CmdLine object and then exit. | |||
| */ | |||
| class VersionVisitor : public Visitor | |||
| { | |||
| private: | |||
| /** | |||
| * Prevent accidental copying | |||
| */ | |||
| VersionVisitor(const VersionVisitor& rhs); | |||
| VersionVisitor& operator=(const VersionVisitor& rhs); | |||
| public: | |||
| protected: | |||
| /** | |||
| * The CmdLine of interest. | |||
| */ | |||
| CmdLineInterface* _cmd; | |||
| /** | |||
| * Constructor. | |||
| * \param cmd - The CmdLine the output is generated for. | |||
| * \param out - The type of output. | |||
| */ | |||
| VersionVisitor( CmdLineInterface* cmd, CmdLineOutput** out ) | |||
| : Visitor(), _cmd( cmd ), _out( out ) { } | |||
| /** | |||
| * The output object. | |||
| */ | |||
| CmdLineOutput** _out; | |||
| /** | |||
| * Calls the version method of the output object using the | |||
| * specified CmdLine. | |||
| */ | |||
| void visit() { | |||
| (*_out)->version(*_cmd); | |||
| throw ExitException(0); | |||
| } | |||
| public: | |||
| /** | |||
| * Constructor. | |||
| * \param cmd - The CmdLine the output is generated for. | |||
| * \param out - The type of output. | |||
| */ | |||
| VersionVisitor(CmdLineInterface* cmd, CmdLineOutput** out) : | |||
| Visitor(), | |||
| _cmd(cmd), | |||
| _out(out) | |||
| { | |||
| } | |||
| }; | |||
| /** | |||
| * Calls the version method of the output object using the | |||
| * specified CmdLine. | |||
| */ | |||
| void visit() | |||
| { | |||
| (*_out)->version(*_cmd); | |||
| throw ExitException(0); | |||
| } | |||
| }; | |||
| } | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -1,57 +1,59 @@ | |||
| // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- | |||
| /****************************************************************************** | |||
| * | |||
| /****************************************************************************** | |||
| * | |||
| * file: Visitor.h | |||
| * | |||
| * | |||
| * Copyright (c) 2003, Michael E. Smoot . | |||
| * Copyright (c) 2017, Google LLC | |||
| * All rights reserved. | |||
| * | |||
| * | |||
| * See the file COPYING in the top directory of this distribution for | |||
| * more information. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| #ifndef TCLAP_VISITOR_H | |||
| #define TCLAP_VISITOR_H | |||
| namespace TCLAP { | |||
| /** | |||
| * A base class that defines the interface for visitors. | |||
| */ | |||
| class Visitor | |||
| namespace TCLAP | |||
| { | |||
| public: | |||
| /** | |||
| * Constructor. Does nothing. | |||
| */ | |||
| Visitor() { } | |||
| /** | |||
| * Destructor. Does nothing. | |||
| */ | |||
| virtual ~Visitor() { } | |||
| /** | |||
| * This method (to implemented by children) will be | |||
| * called when the visitor is visited. | |||
| */ | |||
| virtual void visit() = 0; | |||
| }; | |||
| } | |||
| /** | |||
| * A base class that defines the interface for visitors. | |||
| */ | |||
| class Visitor | |||
| { | |||
| public: | |||
| /** | |||
| * Constructor. Does nothing. | |||
| */ | |||
| Visitor() | |||
| { | |||
| } | |||
| /** | |||
| * Destructor. Does nothing. | |||
| */ | |||
| virtual ~Visitor() | |||
| { | |||
| } | |||
| /** | |||
| * This method (to implemented by children) will be | |||
| * called when the visitor is visited. | |||
| */ | |||
| virtual void visit() = 0; | |||
| }; | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -1,26 +1,25 @@ | |||
| // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- | |||
| /****************************************************************************** | |||
| * | |||
| /****************************************************************************** | |||
| * | |||
| * file: XorHandler.h | |||
| * | |||
| * | |||
| * Copyright (c) 2003, Michael E. Smoot . | |||
| * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. | |||
| * All rights reserved. | |||
| * | |||
| * | |||
| * See the file COPYING in the top directory of this distribution for | |||
| * more information. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| #ifndef TCLAP_XORHANDLER_H | |||
| #define TCLAP_XORHANDLER_H | |||
| @@ -31,138 +30,136 @@ | |||
| #include <algorithm> | |||
| #include <iostream> | |||
| namespace TCLAP { | |||
| /** | |||
| * This class handles lists of Arg's that are to be XOR'd on the command | |||
| * line. This is used by CmdLine and you shouldn't ever use it. | |||
| */ | |||
| class XorHandler | |||
| namespace TCLAP | |||
| { | |||
| protected: | |||
| /** | |||
| * The list of of lists of Arg's to be or'd together. | |||
| */ | |||
| std::vector< std::vector<Arg*> > _orList; | |||
| public: | |||
| /** | |||
| * Constructor. Does nothing. | |||
| */ | |||
| XorHandler( ) : _orList(std::vector< std::vector<Arg*> >()) {} | |||
| /** | |||
| * Add a list of Arg*'s that will be xor'd together. | |||
| * \param ors - list of Arg* that will be xor'd. | |||
| */ | |||
| void add( const std::vector<Arg*>& ors ); | |||
| /** | |||
| * Checks whether the specified Arg is in one of the xor lists and | |||
| * if it does match one, returns the size of the xor list that the | |||
| * Arg matched. If the Arg matches, then it also sets the rest of | |||
| * the Arg's in the list. You shouldn't use this. | |||
| * \param a - The Arg to be checked. | |||
| */ | |||
| int check( const Arg* a ); | |||
| /** | |||
| * Returns the XOR specific short usage. | |||
| */ | |||
| std::string shortUsage(); | |||
| /** | |||
| * Prints the XOR specific long usage. | |||
| * \param os - Stream to print to. | |||
| */ | |||
| void printLongUsage(std::ostream& os); | |||
| /** | |||
| * Simply checks whether the Arg is contained in one of the arg | |||
| * lists. | |||
| * \param a - The Arg to be checked. | |||
| */ | |||
| bool contains( const Arg* a ); | |||
| const std::vector< std::vector<Arg*> >& getXorList() const; | |||
| }; | |||
| ////////////////////////////////////////////////////////////////////// | |||
| //BEGIN XOR.cpp | |||
| ////////////////////////////////////////////////////////////////////// | |||
| inline void XorHandler::add( const std::vector<Arg*>& ors ) | |||
| { | |||
| _orList.push_back( ors ); | |||
| } | |||
| inline int XorHandler::check( const Arg* a ) | |||
| { | |||
| // iterate over each XOR list | |||
| for ( int i = 0; static_cast<unsigned int>(i) < _orList.size(); i++ ) | |||
| { | |||
| // if the XOR list contains the arg.. | |||
| ArgVectorIterator ait = std::find( _orList[i].begin(), | |||
| _orList[i].end(), a ); | |||
| if ( ait != _orList[i].end() ) | |||
| { | |||
| // first check to see if a mutually exclusive switch | |||
| // has not already been set | |||
| for ( ArgVectorIterator it = _orList[i].begin(); | |||
| it != _orList[i].end(); | |||
| it++ ) | |||
| if ( a != (*it) && (*it)->isSet() ) | |||
| throw(CmdLineParseException( | |||
| "Mutually exclusive argument already set!", | |||
| (*it)->toString())); | |||
| // go through and set each arg that is not a | |||
| for ( ArgVectorIterator it = _orList[i].begin(); | |||
| it != _orList[i].end(); | |||
| it++ ) | |||
| if ( a != (*it) ) | |||
| (*it)->xorSet(); | |||
| // return the number of required args that have now been set | |||
| if ( (*ait)->allowMore() ) | |||
| return 0; | |||
| else | |||
| return static_cast<int>(_orList[i].size()); | |||
| } | |||
| } | |||
| if ( a->isRequired() ) | |||
| return 1; | |||
| else | |||
| return 0; | |||
| } | |||
| inline bool XorHandler::contains( const Arg* a ) | |||
| { | |||
| for ( int i = 0; static_cast<unsigned int>(i) < _orList.size(); i++ ) | |||
| for ( ArgVectorIterator it = _orList[i].begin(); | |||
| it != _orList[i].end(); | |||
| it++ ) | |||
| if ( a == (*it) ) | |||
| return true; | |||
| return false; | |||
| } | |||
| inline const std::vector< std::vector<Arg*> >& XorHandler::getXorList() const | |||
| { | |||
| return _orList; | |||
| } | |||
| ////////////////////////////////////////////////////////////////////// | |||
| //END XOR.cpp | |||
| ////////////////////////////////////////////////////////////////////// | |||
| } //namespace TCLAP | |||
| #endif | |||
| /** | |||
| * This class handles lists of Arg's that are to be XOR'd on the command | |||
| * line. This is used by CmdLine and you shouldn't ever use it. | |||
| */ | |||
| class XorHandler | |||
| { | |||
| protected: | |||
| /** | |||
| * The list of of lists of Arg's to be or'd together. | |||
| */ | |||
| std::vector<std::vector<Arg*>> _orList; | |||
| public: | |||
| /** | |||
| * Constructor. Does nothing. | |||
| */ | |||
| XorHandler() : | |||
| _orList(std::vector<std::vector<Arg*>>()) | |||
| { | |||
| } | |||
| /** | |||
| * Add a list of Arg*'s that will be xor'd together. | |||
| * \param ors - list of Arg* that will be xor'd. | |||
| */ | |||
| void add(const std::vector<Arg*>& ors); | |||
| /** | |||
| * Checks whether the specified Arg is in one of the xor lists and | |||
| * if it does match one, returns the size of the xor list that the | |||
| * Arg matched. If the Arg matches, then it also sets the rest of | |||
| * the Arg's in the list. You shouldn't use this. | |||
| * \param a - The Arg to be checked. | |||
| */ | |||
| int check(const Arg* a); | |||
| /** | |||
| * Returns the XOR specific short usage. | |||
| */ | |||
| std::string shortUsage(); | |||
| /** | |||
| * Prints the XOR specific long usage. | |||
| * \param os - Stream to print to. | |||
| */ | |||
| void printLongUsage(std::ostream& os); | |||
| /** | |||
| * Simply checks whether the Arg is contained in one of the arg | |||
| * lists. | |||
| * \param a - The Arg to be checked. | |||
| */ | |||
| bool contains(const Arg* a); | |||
| const std::vector<std::vector<Arg*>>& getXorList() const; | |||
| }; | |||
| ////////////////////////////////////////////////////////////////////// | |||
| // BEGIN XOR.cpp | |||
| ////////////////////////////////////////////////////////////////////// | |||
| inline void XorHandler::add(const std::vector<Arg*>& ors) | |||
| { | |||
| _orList.push_back(ors); | |||
| } | |||
| inline int XorHandler::check(const Arg* a) | |||
| { | |||
| // iterate over each XOR list | |||
| for (int i = 0; static_cast<unsigned int>(i) < _orList.size(); i++) | |||
| { | |||
| // if the XOR list contains the arg.. | |||
| ArgVectorIterator ait = std::find(_orList[i].begin(), _orList[i].end(), a); | |||
| if (ait != _orList[i].end()) | |||
| { | |||
| // first check to see if a mutually exclusive switch | |||
| // has not already been set | |||
| for (ArgVectorIterator it = _orList[i].begin(); | |||
| it != _orList[i].end(); | |||
| it++) | |||
| if (a != (*it) && (*it)->isSet()) | |||
| throw(CmdLineParseException( | |||
| "Mutually exclusive argument already set!", | |||
| (*it)->toString() | |||
| )); | |||
| // go through and set each arg that is not a | |||
| for (ArgVectorIterator it = _orList[i].begin(); | |||
| it != _orList[i].end(); | |||
| it++) | |||
| if (a != (*it)) | |||
| (*it)->xorSet(); | |||
| // return the number of required args that have now been set | |||
| if ((*ait)->allowMore()) | |||
| return 0; | |||
| else | |||
| return static_cast<int>(_orList[i].size()); | |||
| } | |||
| } | |||
| if (a->isRequired()) | |||
| return 1; | |||
| else | |||
| return 0; | |||
| } | |||
| inline bool XorHandler::contains(const Arg* a) | |||
| { | |||
| for (int i = 0; static_cast<unsigned int>(i) < _orList.size(); i++) | |||
| for (ArgVectorIterator it = _orList[i].begin(); | |||
| it != _orList[i].end(); | |||
| it++) | |||
| if (a == (*it)) | |||
| return true; | |||
| return false; | |||
| } | |||
| inline const std::vector<std::vector<Arg*>>& XorHandler::getXorList() const | |||
| { | |||
| return _orList; | |||
| } | |||
| ////////////////////////////////////////////////////////////////////// | |||
| // END XOR.cpp | |||
| ////////////////////////////////////////////////////////////////////// | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -1,25 +1,25 @@ | |||
| // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- | |||
| /****************************************************************************** | |||
| * | |||
| /****************************************************************************** | |||
| * | |||
| * file: ZshCompletionOutput.h | |||
| * | |||
| * | |||
| * Copyright (c) 2006, Oliver Kiddle | |||
| * Copyright (c) 2017 Google Inc. | |||
| * All rights reserved. | |||
| * | |||
| * | |||
| * See the file COPYING in the top directory of this distribution for | |||
| * more information. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * | |||
| * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| * DEALINGS IN THE SOFTWARE. | |||
| * | |||
| *****************************************************************************/ | |||
| * | |||
| *****************************************************************************/ | |||
| #ifndef TCLAP_ZSHCOMPLETIONOUTPUT_H | |||
| #define TCLAP_ZSHCOMPLETIONOUTPUT_H | |||
| @@ -40,297 +40,297 @@ | |||
| #include <tclap/Arg.h> | |||
| #include <tclap/sstream.h> | |||
| namespace TCLAP { | |||
| /** | |||
| * A class that generates a Zsh completion function as output from the usage() | |||
| * method for the given CmdLine and its Args. | |||
| */ | |||
| class ZshCompletionOutput : public CmdLineOutput | |||
| namespace TCLAP | |||
| { | |||
| public: | |||
| ZshCompletionOutput(); | |||
| /** | |||
| * Prints the usage to stdout. Can be overridden to | |||
| * produce alternative behavior. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| */ | |||
| virtual void usage(CmdLineInterface& c); | |||
| /** | |||
| * Prints the version to stdout. Can be overridden | |||
| * to produce alternative behavior. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| */ | |||
| virtual void version(CmdLineInterface& c); | |||
| /** | |||
| * Prints (to stderr) an error message, short usage | |||
| * Can be overridden to produce alternative behavior. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| * \param e - The ArgException that caused the failure. | |||
| */ | |||
| virtual void failure(CmdLineInterface& c, | |||
| ArgException& e ); | |||
| protected: | |||
| void basename( std::string& s ); | |||
| void quoteSpecialChars( std::string& s ); | |||
| std::string getMutexList( CmdLineInterface& _cmd, Arg* a ); | |||
| void printOption( Arg* it, std::string mutex ); | |||
| void printArg( Arg* it ); | |||
| std::map<std::string, std::string> common; | |||
| char theDelimiter; | |||
| }; | |||
| ZshCompletionOutput::ZshCompletionOutput() | |||
| : common(std::map<std::string, std::string>()), | |||
| theDelimiter('=') | |||
| { | |||
| common["host"] = "_hosts"; | |||
| common["hostname"] = "_hosts"; | |||
| common["file"] = "_files"; | |||
| common["filename"] = "_files"; | |||
| common["user"] = "_users"; | |||
| common["username"] = "_users"; | |||
| common["directory"] = "_directories"; | |||
| common["path"] = "_directories"; | |||
| common["url"] = "_urls"; | |||
| } | |||
| inline void ZshCompletionOutput::version(CmdLineInterface& _cmd) | |||
| { | |||
| std::cout << _cmd.getVersion() << std::endl; | |||
| } | |||
| /** | |||
| * A class that generates a Zsh completion function as output from the usage() | |||
| * method for the given CmdLine and its Args. | |||
| */ | |||
| class ZshCompletionOutput : public CmdLineOutput | |||
| { | |||
| public: | |||
| ZshCompletionOutput(); | |||
| /** | |||
| * Prints the usage to stdout. Can be overridden to | |||
| * produce alternative behavior. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| */ | |||
| virtual void usage(CmdLineInterface& c); | |||
| /** | |||
| * Prints the version to stdout. Can be overridden | |||
| * to produce alternative behavior. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| */ | |||
| virtual void version(CmdLineInterface& c); | |||
| /** | |||
| * Prints (to stderr) an error message, short usage | |||
| * Can be overridden to produce alternative behavior. | |||
| * \param c - The CmdLine object the output is generated for. | |||
| * \param e - The ArgException that caused the failure. | |||
| */ | |||
| virtual void failure(CmdLineInterface& c, ArgException& e); | |||
| protected: | |||
| void basename(std::string& s); | |||
| void quoteSpecialChars(std::string& s); | |||
| std::string getMutexList(CmdLineInterface& _cmd, Arg* a); | |||
| void printOption(Arg* it, std::string mutex); | |||
| void printArg(Arg* it); | |||
| std::map<std::string, std::string> common; | |||
| char theDelimiter; | |||
| }; | |||
| ZshCompletionOutput::ZshCompletionOutput() : | |||
| common(std::map<std::string, std::string>()), | |||
| theDelimiter('=') | |||
| { | |||
| common["host"] = "_hosts"; | |||
| common["hostname"] = "_hosts"; | |||
| common["file"] = "_files"; | |||
| common["filename"] = "_files"; | |||
| common["user"] = "_users"; | |||
| common["username"] = "_users"; | |||
| common["directory"] = "_directories"; | |||
| common["path"] = "_directories"; | |||
| common["url"] = "_urls"; | |||
| } | |||
| inline void ZshCompletionOutput::version(CmdLineInterface& _cmd) | |||
| { | |||
| std::cout << _cmd.getVersion() << std::endl; | |||
| } | |||
| inline void ZshCompletionOutput::usage(CmdLineInterface& _cmd) | |||
| { | |||
| std::list<Arg*> argList = _cmd.getArgList(); | |||
| std::string progName = _cmd.getProgramName(); | |||
| std::string xversion = _cmd.getVersion(); | |||
| theDelimiter = _cmd.getDelimiter(); | |||
| basename(progName); | |||
| std::cout << "#compdef " << progName << std::endl | |||
| << std::endl | |||
| << "# " << progName << " version " << _cmd.getVersion() << std::endl | |||
| << std::endl | |||
| << "_arguments -s -S"; | |||
| for (ArgListIterator it = argList.begin(); it != argList.end(); it++) | |||
| { | |||
| if ((*it)->shortID().at(0) == '<') | |||
| printArg((*it)); | |||
| else if ((*it)->getFlag() != "-") | |||
| printOption((*it), getMutexList(_cmd, *it)); | |||
| } | |||
| inline void ZshCompletionOutput::usage(CmdLineInterface& _cmd ) | |||
| { | |||
| std::list<Arg*> argList = _cmd.getArgList(); | |||
| std::string progName = _cmd.getProgramName(); | |||
| std::string xversion = _cmd.getVersion(); | |||
| theDelimiter = _cmd.getDelimiter(); | |||
| basename(progName); | |||
| std::cout << "#compdef " << progName << std::endl << std::endl << | |||
| "# " << progName << " version " << _cmd.getVersion() << std::endl << std::endl << | |||
| "_arguments -s -S"; | |||
| for (ArgListIterator it = argList.begin(); it != argList.end(); it++) | |||
| { | |||
| if ( (*it)->shortID().at(0) == '<' ) | |||
| printArg((*it)); | |||
| else if ( (*it)->getFlag() != "-" ) | |||
| printOption((*it), getMutexList(_cmd, *it)); | |||
| } | |||
| std::cout << std::endl; | |||
| } | |||
| inline void ZshCompletionOutput::failure( CmdLineInterface& _cmd, | |||
| ArgException& e ) | |||
| { | |||
| static_cast<void>(_cmd); // unused | |||
| std::cout << e.what() << std::endl; | |||
| } | |||
| std::cout << std::endl; | |||
| } | |||
| inline void ZshCompletionOutput::failure(CmdLineInterface& _cmd, ArgException& e) | |||
| { | |||
| static_cast<void>(_cmd); // unused | |||
| std::cout << e.what() << std::endl; | |||
| } | |||
| inline void ZshCompletionOutput::quoteSpecialChars(std::string& s) | |||
| { | |||
| size_t idx = s.find_last_of(':'); | |||
| while (idx != std::string::npos) | |||
| { | |||
| s.insert(idx, 1, '\\'); | |||
| idx = s.find_last_of(':', idx); | |||
| } | |||
| idx = s.find_last_of('\''); | |||
| while (idx != std::string::npos) | |||
| { | |||
| s.insert(idx, "'\\'"); | |||
| if (idx == 0) | |||
| idx = std::string::npos; | |||
| else | |||
| idx = s.find_last_of('\'', --idx); | |||
| } | |||
| } | |||
| inline void ZshCompletionOutput::basename(std::string& s) | |||
| { | |||
| size_t p = s.find_last_of('/'); | |||
| if (p != std::string::npos) | |||
| { | |||
| s.erase(0, p + 1); | |||
| } | |||
| } | |||
| inline void ZshCompletionOutput::printArg(Arg* a) | |||
| { | |||
| static int count = 1; | |||
| std::cout << " \\" << std::endl | |||
| << " '"; | |||
| if (a->acceptsMultipleValues()) | |||
| std::cout << '*'; | |||
| else | |||
| std::cout << count++; | |||
| std::cout << ':'; | |||
| if (!a->isRequired()) | |||
| std::cout << ':'; | |||
| std::cout << a->getName() << ':'; | |||
| std::map<std::string, std::string>::iterator compArg = common.find(a->getName()); | |||
| if (compArg != common.end()) | |||
| { | |||
| std::cout << compArg->second; | |||
| } | |||
| else | |||
| { | |||
| std::cout << "_guard \"^-*\" " << a->getName(); | |||
| } | |||
| std::cout << '\''; | |||
| } | |||
| inline void ZshCompletionOutput::printOption(Arg* a, std::string mutex) | |||
| { | |||
| std::string flag = a->flagStartChar() + a->getFlag(); | |||
| std::string name = a->nameStartString() + a->getName(); | |||
| std::string desc = a->getDescription(); | |||
| // remove full stop and capitalization from description as | |||
| // this is the convention for zsh function | |||
| if (!desc.compare(0, 12, "(required) ")) | |||
| { | |||
| desc.erase(0, 12); | |||
| } | |||
| if (!desc.compare(0, 15, "(OR required) ")) | |||
| { | |||
| desc.erase(0, 15); | |||
| } | |||
| size_t len = desc.length(); | |||
| if (len && desc.at(--len) == '.') | |||
| { | |||
| desc.erase(len); | |||
| } | |||
| if (len) | |||
| { | |||
| desc.replace(0, 1, 1, tolower(desc.at(0))); | |||
| } | |||
| inline void ZshCompletionOutput::quoteSpecialChars( std::string& s ) | |||
| { | |||
| size_t idx = s.find_last_of(':'); | |||
| while ( idx != std::string::npos ) | |||
| { | |||
| s.insert(idx, 1, '\\'); | |||
| idx = s.find_last_of(':', idx); | |||
| } | |||
| idx = s.find_last_of('\''); | |||
| while ( idx != std::string::npos ) | |||
| { | |||
| s.insert(idx, "'\\'"); | |||
| if (idx == 0) | |||
| idx = std::string::npos; | |||
| else | |||
| idx = s.find_last_of('\'', --idx); | |||
| } | |||
| } | |||
| inline void ZshCompletionOutput::basename( std::string& s ) | |||
| { | |||
| size_t p = s.find_last_of('/'); | |||
| if ( p != std::string::npos ) | |||
| { | |||
| s.erase(0, p + 1); | |||
| } | |||
| } | |||
| inline void ZshCompletionOutput::printArg(Arg* a) | |||
| { | |||
| static int count = 1; | |||
| std::cout << " \\" << std::endl << " '"; | |||
| if ( a->acceptsMultipleValues() ) | |||
| std::cout << '*'; | |||
| else | |||
| std::cout << count++; | |||
| std::cout << ':'; | |||
| if ( !a->isRequired() ) | |||
| std::cout << ':'; | |||
| std::cout << a->getName() << ':'; | |||
| std::map<std::string, std::string>::iterator compArg = common.find(a->getName()); | |||
| if ( compArg != common.end() ) | |||
| { | |||
| std::cout << compArg->second; | |||
| } | |||
| else | |||
| { | |||
| std::cout << "_guard \"^-*\" " << a->getName(); | |||
| } | |||
| std::cout << '\''; | |||
| } | |||
| inline void ZshCompletionOutput::printOption(Arg* a, std::string mutex) | |||
| { | |||
| std::string flag = a->flagStartChar() + a->getFlag(); | |||
| std::string name = a->nameStartString() + a->getName(); | |||
| std::string desc = a->getDescription(); | |||
| // remove full stop and capitalization from description as | |||
| // this is the convention for zsh function | |||
| if (!desc.compare(0, 12, "(required) ")) | |||
| { | |||
| desc.erase(0, 12); | |||
| } | |||
| if (!desc.compare(0, 15, "(OR required) ")) | |||
| { | |||
| desc.erase(0, 15); | |||
| } | |||
| size_t len = desc.length(); | |||
| if (len && desc.at(--len) == '.') | |||
| { | |||
| desc.erase(len); | |||
| } | |||
| if (len) | |||
| { | |||
| desc.replace(0, 1, 1, tolower(desc.at(0))); | |||
| } | |||
| std::cout << " \\" << std::endl << " '" << mutex; | |||
| if ( a->getFlag().empty() ) | |||
| { | |||
| std::cout << name; | |||
| } | |||
| else | |||
| { | |||
| std::cout << "'{" << flag << ',' << name << "}'"; | |||
| } | |||
| if ( theDelimiter == '=' && a->isValueRequired() ) | |||
| std::cout << "=-"; | |||
| quoteSpecialChars(desc); | |||
| std::cout << '[' << desc << ']'; | |||
| if ( a->isValueRequired() ) | |||
| { | |||
| std::string arg = a->shortID(); | |||
| // Example arg: "[-A <integer>] ..." | |||
| size_t pos = arg.rfind(" ..."); | |||
| if (pos != std::string::npos) { | |||
| arg.erase(pos); | |||
| std::cout << " \\" << std::endl | |||
| << " '" << mutex; | |||
| if (a->getFlag().empty()) | |||
| { | |||
| std::cout << name; | |||
| } | |||
| else | |||
| { | |||
| std::cout << "'{" << flag << ',' << name << "}'"; | |||
| } | |||
| if (theDelimiter == '=' && a->isValueRequired()) | |||
| std::cout << "=-"; | |||
| quoteSpecialChars(desc); | |||
| std::cout << '[' << desc << ']'; | |||
| if (a->isValueRequired()) | |||
| { | |||
| std::string arg = a->shortID(); | |||
| // Example arg: "[-A <integer>] ..." | |||
| size_t pos = arg.rfind(" ..."); | |||
| if (pos != std::string::npos) | |||
| { | |||
| arg.erase(pos); | |||
| } | |||
| arg.erase(0, arg.find_last_of(theDelimiter) + 1); | |||
| if (arg.at(arg.length() - 1) == ']') | |||
| arg.erase(arg.length() - 1); | |||
| if (arg.at(arg.length() - 1) == ']') | |||
| { | |||
| arg.erase(arg.length() - 1); | |||
| } | |||
| if (arg.at(0) == '<') | |||
| { | |||
| arg.erase(arg.length() - 1); | |||
| arg.erase(0, 1); | |||
| } | |||
| size_t p = arg.find('|'); | |||
| if (p != std::string::npos) | |||
| { | |||
| do | |||
| { | |||
| arg.replace(p, 1, 1, ' '); | |||
| } while ((p = arg.find_first_of('|', p)) != std::string::npos); | |||
| quoteSpecialChars(arg); | |||
| std::cout << ": :(" << arg << ')'; | |||
| } | |||
| else | |||
| { | |||
| std::cout << ':' << arg; | |||
| std::map<std::string, std::string>::iterator compArg = common.find(arg); | |||
| if (compArg != common.end()) | |||
| { | |||
| std::cout << ':' << compArg->second; | |||
| } | |||
| } | |||
| } | |||
| arg.erase(0, arg.find_last_of(theDelimiter) + 1); | |||
| if ( arg.at(arg.length()-1) == ']' ) | |||
| arg.erase(arg.length()-1); | |||
| if ( arg.at(arg.length()-1) == ']' ) | |||
| { | |||
| arg.erase(arg.length()-1); | |||
| } | |||
| if ( arg.at(0) == '<' ) | |||
| { | |||
| arg.erase(arg.length()-1); | |||
| arg.erase(0, 1); | |||
| } | |||
| size_t p = arg.find('|'); | |||
| if ( p != std::string::npos ) | |||
| { | |||
| do | |||
| { | |||
| arg.replace(p, 1, 1, ' '); | |||
| } | |||
| while ( (p = arg.find_first_of('|', p)) != std::string::npos ); | |||
| quoteSpecialChars(arg); | |||
| std::cout << ": :(" << arg << ')'; | |||
| } | |||
| else | |||
| { | |||
| std::cout << ':' << arg; | |||
| std::map<std::string, std::string>::iterator compArg = common.find(arg); | |||
| if ( compArg != common.end() ) | |||
| { | |||
| std::cout << ':' << compArg->second; | |||
| } | |||
| } | |||
| } | |||
| std::cout << '\''; | |||
| } | |||
| inline std::string ZshCompletionOutput::getMutexList( CmdLineInterface& _cmd, Arg* a) | |||
| { | |||
| XorHandler xorHandler = _cmd.getXorHandler(); | |||
| std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList(); | |||
| if (a->getName() == "help" || a->getName() == "version") | |||
| { | |||
| return "(-)"; | |||
| } | |||
| ostringstream list; | |||
| if ( a->acceptsMultipleValues() ) | |||
| { | |||
| list << '*'; | |||
| } | |||
| for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ ) | |||
| { | |||
| for ( ArgVectorIterator it = xorList[i].begin(); | |||
| it != xorList[i].end(); | |||
| it++) | |||
| if ( a == (*it) ) | |||
| { | |||
| list << '('; | |||
| for ( ArgVectorIterator iu = xorList[i].begin(); | |||
| iu != xorList[i].end(); | |||
| iu++ ) | |||
| { | |||
| bool notCur = (*iu) != a; | |||
| bool hasFlag = !(*iu)->getFlag().empty(); | |||
| if ( iu != xorList[i].begin() && (notCur || hasFlag) ) | |||
| list << ' '; | |||
| if (hasFlag) | |||
| list << (*iu)->flagStartChar() << (*iu)->getFlag() << ' '; | |||
| if ( notCur || hasFlag ) | |||
| list << (*iu)->nameStartString() << (*iu)->getName(); | |||
| } | |||
| list << ')'; | |||
| return list.str(); | |||
| } | |||
| } | |||
| // wasn't found in xor list | |||
| if (!a->getFlag().empty()) { | |||
| list << "(" << a->flagStartChar() << a->getFlag() << ' ' << | |||
| a->nameStartString() << a->getName() << ')'; | |||
| } | |||
| return list.str(); | |||
| } | |||
| } //namespace TCLAP | |||
| std::cout << '\''; | |||
| } | |||
| inline std::string ZshCompletionOutput::getMutexList(CmdLineInterface& _cmd, Arg* a) | |||
| { | |||
| XorHandler xorHandler = _cmd.getXorHandler(); | |||
| std::vector<std::vector<Arg*>> xorList = xorHandler.getXorList(); | |||
| if (a->getName() == "help" || a->getName() == "version") | |||
| { | |||
| return "(-)"; | |||
| } | |||
| ostringstream list; | |||
| if (a->acceptsMultipleValues()) | |||
| { | |||
| list << '*'; | |||
| } | |||
| for (int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++) | |||
| { | |||
| for (ArgVectorIterator it = xorList[i].begin(); | |||
| it != xorList[i].end(); | |||
| it++) | |||
| if (a == (*it)) | |||
| { | |||
| list << '('; | |||
| for (ArgVectorIterator iu = xorList[i].begin(); | |||
| iu != xorList[i].end(); | |||
| iu++) | |||
| { | |||
| bool notCur = (*iu) != a; | |||
| bool hasFlag = !(*iu)->getFlag().empty(); | |||
| if (iu != xorList[i].begin() && (notCur || hasFlag)) | |||
| list << ' '; | |||
| if (hasFlag) | |||
| list << (*iu)->flagStartChar() << (*iu)->getFlag() << ' '; | |||
| if (notCur || hasFlag) | |||
| list << (*iu)->nameStartString() << (*iu)->getName(); | |||
| } | |||
| list << ')'; | |||
| return list.str(); | |||
| } | |||
| } | |||
| // wasn't found in xor list | |||
| if (!a->getFlag().empty()) | |||
| { | |||
| list << "(" << a->flagStartChar() << a->getFlag() << ' ' << a->nameStartString() << a->getName() << ')'; | |||
| } | |||
| return list.str(); | |||
| } | |||
| } // namespace TCLAP | |||
| #endif | |||
| @@ -33,16 +33,18 @@ | |||
| #if defined(HAVE_SSTREAM) | |||
| #include <sstream> | |||
| namespace TCLAP { | |||
| namespace TCLAP | |||
| { | |||
| typedef std::istringstream istringstream; | |||
| typedef std::ostringstream ostringstream; | |||
| } | |||
| } // namespace TCLAP | |||
| #elif defined(HAVE_STRSTREAM) | |||
| #include <strstream> | |||
| namespace TCLAP { | |||
| namespace TCLAP | |||
| { | |||
| typedef std::istrstream istringstream; | |||
| typedef std::ostrstream ostringstream; | |||
| } | |||
| } // namespace TCLAP | |||
| #else | |||
| #error "Need a stringstream (sstream or strstream) to compile!" | |||
| #endif | |||