Cleanup: Unify indentation and line length across files.

Consistenly use 4 space indent (no tabs) and < 80 char lines. The
files were very inconsistent and hard to edit.
This commit is contained in:
Daniel Aarno 2015-05-11 22:08:25 +02:00
parent b162f59fcb
commit b3f85f4965
2 changed files with 445 additions and 448 deletions

View File

@ -1,5 +1,4 @@
/******************************************************************************
/******************************************************************************
* *
* file: SwitchArg.h * file: SwitchArg.h
* *
@ -11,14 +10,14 @@
* more information. * 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, * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 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 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
* *
*****************************************************************************/ *****************************************************************************/
#ifndef TCLAP_SWITCH_ARG_H #ifndef TCLAP_SWITCH_ARG_H
@ -38,231 +37,231 @@ namespace TCLAP {
*/ */
class SwitchArg : public Arg class SwitchArg : public Arg
{ {
protected: protected:
/** /**
* The value of the switch. * The value of the switch.
*/ */
bool _value; bool _value;
/** /**
* Used to support the reset() method so that ValueArg can be * Used to support the reset() method so that ValueArg can be
* reset to their constructed value. * reset to their constructed value.
*/ */
bool _default; bool _default;
public: public:
/** /**
* SwitchArg constructor. * SwitchArg constructor.
* \param flag - The one character flag that identifies this * \param flag - The one character flag that identifies this
* argument on the command line. * argument on the command line.
* \param name - A one word name for the argument. Can be * \param name - A one word name for the argument. Can be
* used as a long flag on the command line. * used as a long flag on the command line.
* \param desc - A description of what the argument is for or * \param desc - A description of what the argument is for or
* does. * does.
* \param def - The default value for this Switch. * \param def - The default value for this Switch.
* \param v - An optional visitor. You probably should not * \param v - An optional visitor. You probably should not
* use this unless you have a very good reason. * use this unless you have a very good reason.
*/ */
SwitchArg(const std::string& flag, SwitchArg(const std::string& flag,
const std::string& name, const std::string& name,
const std::string& desc, const std::string& desc,
bool def = false, bool def = false,
Visitor* v = NULL); Visitor* v = NULL);
/** /**
* SwitchArg constructor. * SwitchArg constructor.
* \param flag - The one character flag that identifies this * \param flag - The one character flag that identifies this
* argument on the command line. * argument on the command line.
* \param name - A one word name for the argument. Can be * \param name - A one word name for the argument. Can be
* used as a long flag on the command line. * used as a long flag on the command line.
* \param desc - A description of what the argument is for or * \param desc - A description of what the argument is for or
* does. * does.
* \param parser - A CmdLine parser object to add this Arg to * \param parser - A CmdLine parser object to add this Arg to
* \param def - The default value for this Switch. * \param def - The default value for this Switch.
* \param v - An optional visitor. You probably should not * \param v - An optional visitor. You probably should not
* use this unless you have a very good reason. * use this unless you have a very good reason.
*/ */
SwitchArg(const std::string& flag, SwitchArg(const std::string& flag,
const std::string& name, const std::string& name,
const std::string& desc, const std::string& desc,
CmdLineInterface& parser, CmdLineInterface& parser,
bool def = false, bool def = false,
Visitor* v = NULL); Visitor* v = NULL);
/** /**
* Handles the processing of the argument. * Handles the processing of the argument.
* This re-implements the Arg version of this method to set the * This re-implements the Arg version of this method to set the
* _value of the argument appropriately. * _value of the argument appropriately.
* \param i - Pointer the the current argument in the list. * \param i - Pointer the the current argument in the list.
* \param args - Mutable list of strings. Passed * \param args - Mutable list of strings. Passed
* in from main(). * in from main().
*/ */
virtual bool processArg(int* i, std::vector<std::string>& args); virtual bool processArg(int* i, std::vector<std::string>& args);
/** /**
* Checks a string to see if any of the chars in the string * Checks a string to see if any of the chars in the string
* match the flag for this Switch. * match the flag for this Switch.
*/ */
bool combinedSwitchesMatch(std::string& combined); bool combinedSwitchesMatch(std::string& combined);
/** /**
* Returns bool, whether or not the switch has been set. * Returns bool, whether or not the switch has been set.
*/ */
bool getValue() /* TODO(macbishop) should be const */; bool getValue() /* TODO(macbishop) should be const */;
/** /**
* A SwitchArg can be used as a boolean, indicating * A SwitchArg can be used as a boolean, indicating
* whether or not the switch has been set. This is the * whether or not the switch has been set. This is the
* same as calling getValue() * same as calling getValue()
*/ */
operator bool() const { return _value; } operator bool() const { return _value; }
virtual void reset(); virtual void reset();
private: private:
/** /**
* Checks to see if we've found the last match in * Checks to see if we've found the last match in
* a combined string. * a combined string.
*/ */
bool lastCombined(std::string& combined); bool lastCombined(std::string& combined);
/** /**
* Does the common processing of processArg. * Does the common processing of processArg.
*/ */
void commonProcessing(); void commonProcessing();
}; };
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
//BEGIN SwitchArg.cpp //BEGIN SwitchArg.cpp
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
inline SwitchArg::SwitchArg(const std::string& flag, inline SwitchArg::SwitchArg(const std::string& flag,
const std::string& name, const std::string& name,
const std::string& desc, const std::string& desc,
bool default_val, bool default_val,
Visitor* v ) Visitor* v )
: Arg(flag, name, desc, false, false, v), : Arg(flag, name, desc, false, false, v),
_value( default_val ), _value( default_val ),
_default( default_val ) _default( default_val )
{ } { }
inline SwitchArg::SwitchArg(const std::string& flag, inline SwitchArg::SwitchArg(const std::string& flag,
const std::string& name, const std::string& name,
const std::string& desc, const std::string& desc,
CmdLineInterface& parser, CmdLineInterface& parser,
bool default_val, bool default_val,
Visitor* v ) Visitor* v )
: Arg(flag, name, desc, false, false, v), : Arg(flag, name, desc, false, false, v),
_value( default_val ), _value( default_val ),
_default(default_val) _default(default_val)
{ {
parser.add( this ); parser.add( this );
} }
inline bool SwitchArg::getValue() { return _value; } inline bool SwitchArg::getValue() { return _value; }
inline bool SwitchArg::lastCombined(std::string& combinedSwitches ) inline bool SwitchArg::lastCombined(std::string& combinedSwitches )
{ {
for ( unsigned int i = 1; i < combinedSwitches.length(); i++ ) for ( unsigned int i = 1; i < combinedSwitches.length(); i++ )
if ( combinedSwitches[i] != Arg::blankChar() ) if ( combinedSwitches[i] != Arg::blankChar() )
return false; return false;
return true; return true;
} }
inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches ) inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches )
{ {
// make sure this is actually a combined switch // make sure this is actually a combined switch
if ( combinedSwitches.length() > 0 && if ( combinedSwitches.length() > 0 &&
combinedSwitches[0] != Arg::flagStartString()[0] ) combinedSwitches[0] != Arg::flagStartString()[0] )
return false; return false;
// make sure it isn't a long name // make sure it isn't a long name
if ( combinedSwitches.substr( 0, Arg::nameStartString().length() ) == if ( combinedSwitches.substr( 0, Arg::nameStartString().length() ) ==
Arg::nameStartString() ) Arg::nameStartString() )
return false; return false;
// make sure the delimiter isn't in the string // make sure the delimiter isn't in the string
if ( combinedSwitches.find_first_of( Arg::delimiter() ) != std::string::npos ) if ( combinedSwitches.find_first_of(Arg::delimiter()) != std::string::npos)
return false; return false;
// ok, we're not specifying a ValueArg, so we know that we have // ok, we're not specifying a ValueArg, so we know that we have
// a combined switch list. // a combined switch list.
for ( unsigned int i = 1; i < combinedSwitches.length(); i++ ) for ( unsigned int i = 1; i < combinedSwitches.length(); i++ )
if ( _flag.length() > 0 && if ( _flag.length() > 0 &&
combinedSwitches[i] == _flag[0] && combinedSwitches[i] == _flag[0] &&
_flag[0] != Arg::flagStartString()[0] ) _flag[0] != Arg::flagStartString()[0] )
{ {
// update the combined switches so this one is no longer present // update the combined switches so this one is no longer present
// this is necessary so that no unlabeled args are matched // this is necessary so that no unlabeled args are matched
// later in the processing. // later in the processing.
//combinedSwitches.erase(i,1); //combinedSwitches.erase(i,1);
combinedSwitches[i] = Arg::blankChar(); combinedSwitches[i] = Arg::blankChar();
return true; return true;
} }
// none of the switches passed in the list match. // none of the switches passed in the list match.
return false; return false;
} }
inline void SwitchArg::commonProcessing() inline void SwitchArg::commonProcessing()
{ {
if ( _xorSet ) if ( _xorSet )
throw(CmdLineParseException( throw(CmdLineParseException(
"Mutually exclusive argument already set!", toString())); "Mutually exclusive argument already set!", toString()));
if ( _alreadySet ) if ( _alreadySet )
throw(CmdLineParseException("Argument already set!", toString())); throw(CmdLineParseException("Argument already set!", toString()));
_alreadySet = true; _alreadySet = true;
if ( _value == true ) if ( _value == true )
_value = false; _value = false;
else else
_value = true; _value = true;
_checkWithVisitor(); _checkWithVisitor();
} }
inline bool SwitchArg::processArg(int *i, std::vector<std::string>& args) inline bool SwitchArg::processArg(int *i, std::vector<std::string>& args)
{ {
if ( _ignoreable && Arg::ignoreRest() ) if ( _ignoreable && Arg::ignoreRest() )
return false; return false;
// if the whole string matches the flag or name string // if the whole string matches the flag or name string
if ( argMatches( args[*i] ) ) if ( argMatches( args[*i] ) )
{ {
commonProcessing(); commonProcessing();
return true; return true;
} }
// if a substring matches the flag as part of a combination // if a substring matches the flag as part of a combination
else if ( combinedSwitchesMatch( args[*i] ) ) else if ( combinedSwitchesMatch( args[*i] ) )
{ {
// check again to ensure we don't misinterpret // check again to ensure we don't misinterpret
// this as a MultiSwitchArg // this as a MultiSwitchArg
if ( combinedSwitchesMatch( args[*i] ) ) if ( combinedSwitchesMatch( args[*i] ) )
throw(CmdLineParseException("Argument already set!", throw(CmdLineParseException("Argument already set!",
toString())); toString()));
commonProcessing(); commonProcessing();
// We only want to return true if we've found the last combined // We only want to return true if we've found the last combined
// match in the string, otherwise we return true so that other // match in the string, otherwise we return true so that other
// switches in the combination will have a chance to match. // switches in the combination will have a chance to match.
return lastCombined( args[*i] ); return lastCombined( args[*i] );
} }
else else
return false; return false;
} }
inline void SwitchArg::reset() inline void SwitchArg::reset()
{ {
Arg::reset(); Arg::reset();
_value = _default; _value = _default;
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
//End SwitchArg.cpp //End SwitchArg.cpp

View File

@ -1,4 +1,4 @@
/****************************************************************************** /******************************************************************************
* *
* file: ValueArg.h * file: ValueArg.h
* *
@ -10,14 +10,14 @@
* more information. * 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, * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * 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 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
* *
*****************************************************************************/ *****************************************************************************/
#ifndef TCLAP_VALUE_ARGUMENT_H #ifndef TCLAP_VALUE_ARGUMENT_H
@ -42,212 +42,212 @@ namespace TCLAP {
template<class T> template<class T>
class ValueArg : public Arg class ValueArg : public Arg
{ {
protected: protected:
/** /**
* The value parsed from the command line. * The value parsed from the command line.
* Can be of any type, as long as the >> operator for the type * Can be of any type, as long as the >> operator for the type
* is defined. * is defined.
*/ */
T _value; T _value;
/** /**
* Used to support the reset() method so that ValueArg can be * Used to support the reset() method so that ValueArg can be
* reset to their constructed value. * reset to their constructed value.
*/ */
T _default; T _default;
/** /**
* A human readable description of the type to be parsed. * A human readable description of the type to be parsed.
* This is a hack, plain and simple. Ideally we would use RTTI to * 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 * return the name of type T, but until there is some sort of
* consistent support for human readable names, we are left to our * consistent support for human readable names, we are left to our
* own devices. * own devices.
*/ */
std::string _typeDesc; std::string _typeDesc;
/** /**
* A Constraint this Arg must conform to. * A Constraint this Arg must conform to.
*/ */
Constraint<T>* _constraint; Constraint<T>* _constraint;
/** /**
* Extracts the value from the string. * Extracts the value from the string.
* Attempts to parse string as type T, if this fails an exception * Attempts to parse string as type T, if this fails an exception
* is thrown. * is thrown.
* \param val - value to be parsed. * \param val - value to be parsed.
*/ */
void _extractValue( const std::string& val ); void _extractValue( const std::string& val );
public: public:
/** /**
* Labeled ValueArg constructor. * Labeled ValueArg constructor.
* You could conceivably call this constructor with a blank flag, * You could conceivably call this constructor with a blank flag,
* but that would make you a bad person. It would also cause * but that would make you a bad person. It would also cause
* an exception to be thrown. If you want an unlabeled argument, * an exception to be thrown. If you want an unlabeled argument,
* use the other constructor. * use the other constructor.
* \param flag - The one character flag that identifies this * \param flag - The one character flag that identifies this
* argument on the command line. * argument on the command line.
* \param name - A one word name for the argument. Can be * \param name - A one word name for the argument. Can be
* used as a long flag on the command line. * used as a long flag on the command line.
* \param desc - A description of what the argument is for or * \param desc - A description of what the argument is for or
* does. * does.
* \param req - Whether the argument is required on the command * \param req - Whether the argument is required on the command
* line. * line.
* \param value - The default value assigned to this argument if it * \param value - The default value assigned to this argument if it
* is not present on the command line. * is not present on the command line.
* \param typeDesc - A short, human readable description of the * \param typeDesc - A short, human readable description of the
* type that this object expects. This is used in the generation * 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 USAGE statement. The goal is to be helpful to the end user
* of the program. * of the program.
* \param v - An optional visitor. You probably should not * \param v - An optional visitor. You probably should not
* use this unless you have a very good reason. * use this unless you have a very good reason.
*/ */
ValueArg( const std::string& flag, ValueArg( const std::string& flag,
const std::string& name, const std::string& name,
const std::string& desc, const std::string& desc,
bool req, bool req,
T value, T value,
const std::string& typeDesc, const std::string& typeDesc,
Visitor* v = NULL); Visitor* v = NULL);
/** /**
* Labeled ValueArg constructor. * Labeled ValueArg constructor.
* You could conceivably call this constructor with a blank flag, * You could conceivably call this constructor with a blank flag,
* but that would make you a bad person. It would also cause * but that would make you a bad person. It would also cause
* an exception to be thrown. If you want an unlabeled argument, * an exception to be thrown. If you want an unlabeled argument,
* use the other constructor. * use the other constructor.
* \param flag - The one character flag that identifies this * \param flag - The one character flag that identifies this
* argument on the command line. * argument on the command line.
* \param name - A one word name for the argument. Can be * \param name - A one word name for the argument. Can be
* used as a long flag on the command line. * used as a long flag on the command line.
* \param desc - A description of what the argument is for or * \param desc - A description of what the argument is for or
* does. * does.
* \param req - Whether the argument is required on the command * \param req - Whether the argument is required on the command
* line. * line.
* \param value - The default value assigned to this argument if it * \param value - The default value assigned to this argument if it
* is not present on the command line. * is not present on the command line.
* \param typeDesc - A short, human readable description of the * \param typeDesc - A short, human readable description of the
* type that this object expects. This is used in the generation * 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 USAGE statement. The goal is to be helpful to the end user
* of the program. * of the program.
* \param parser - A CmdLine parser object to add this Arg to * \param parser - A CmdLine parser object to add this Arg to
* \param v - An optional visitor. You probably should not * \param v - An optional visitor. You probably should not
* use this unless you have a very good reason. * use this unless you have a very good reason.
*/ */
ValueArg( const std::string& flag, ValueArg( const std::string& flag,
const std::string& name, const std::string& name,
const std::string& desc, const std::string& desc,
bool req, bool req,
T value, T value,
const std::string& typeDesc, const std::string& typeDesc,
CmdLineInterface& parser, CmdLineInterface& parser,
Visitor* v = NULL ); Visitor* v = NULL );
/** /**
* Labeled ValueArg constructor. * Labeled ValueArg constructor.
* You could conceivably call this constructor with a blank flag, * You could conceivably call this constructor with a blank flag,
* but that would make you a bad person. It would also cause * but that would make you a bad person. It would also cause
* an exception to be thrown. If you want an unlabeled argument, * an exception to be thrown. If you want an unlabeled argument,
* use the other constructor. * use the other constructor.
* \param flag - The one character flag that identifies this * \param flag - The one character flag that identifies this
* argument on the command line. * argument on the command line.
* \param name - A one word name for the argument. Can be * \param name - A one word name for the argument. Can be
* used as a long flag on the command line. * used as a long flag on the command line.
* \param desc - A description of what the argument is for or * \param desc - A description of what the argument is for or
* does. * does.
* \param req - Whether the argument is required on the command * \param req - Whether the argument is required on the command
* line. * line.
* \param value - The default value assigned to this argument if it * \param value - The default value assigned to this argument if it
* is not present on the command line. * is not present on the command line.
* \param constraint - A pointer to a Constraint object used * \param constraint - A pointer to a Constraint object used
* to constrain this Arg. * to constrain this Arg.
* \param parser - A CmdLine parser object to add this Arg to. * \param parser - A CmdLine parser object to add this Arg to.
* \param v - An optional visitor. You probably should not * \param v - An optional visitor. You probably should not
* use this unless you have a very good reason. * use this unless you have a very good reason.
*/ */
ValueArg( const std::string& flag, ValueArg( const std::string& flag,
const std::string& name, const std::string& name,
const std::string& desc, const std::string& desc,
bool req, bool req,
T value, T value,
Constraint<T>* constraint, Constraint<T>* constraint,
CmdLineInterface& parser, CmdLineInterface& parser,
Visitor* v = NULL ); Visitor* v = NULL );
/** /**
* Labeled ValueArg constructor. * Labeled ValueArg constructor.
* You could conceivably call this constructor with a blank flag, * You could conceivably call this constructor with a blank flag,
* but that would make you a bad person. It would also cause * but that would make you a bad person. It would also cause
* an exception to be thrown. If you want an unlabeled argument, * an exception to be thrown. If you want an unlabeled argument,
* use the other constructor. * use the other constructor.
* \param flag - The one character flag that identifies this * \param flag - The one character flag that identifies this
* argument on the command line. * argument on the command line.
* \param name - A one word name for the argument. Can be * \param name - A one word name for the argument. Can be
* used as a long flag on the command line. * used as a long flag on the command line.
* \param desc - A description of what the argument is for or * \param desc - A description of what the argument is for or
* does. * does.
* \param req - Whether the argument is required on the command * \param req - Whether the argument is required on the command
* line. * line.
* \param value - The default value assigned to this argument if it * \param value - The default value assigned to this argument if it
* is not present on the command line. * is not present on the command line.
* \param constraint - A pointer to a Constraint object used * \param constraint - A pointer to a Constraint object used
* to constrain this Arg. * to constrain this Arg.
* \param v - An optional visitor. You probably should not * \param v - An optional visitor. You probably should not
* use this unless you have a very good reason. * use this unless you have a very good reason.
*/ */
ValueArg( const std::string& flag, ValueArg( const std::string& flag,
const std::string& name, const std::string& name,
const std::string& desc, const std::string& desc,
bool req, bool req,
T value, T value,
Constraint<T>* constraint, Constraint<T>* constraint,
Visitor* v = NULL ); Visitor* v = NULL );
/** /**
* Handles the processing of the argument. * Handles the processing of the argument.
* This re-implements the Arg version of this method to set the * This re-implements the Arg version of this method to set the
* _value of the argument appropriately. It knows the difference * _value of the argument appropriately. It knows the difference
* between labeled and unlabeled. * between labeled and unlabeled.
* \param i - Pointer the the current argument in the list. * \param i - Pointer the the current argument in the list.
* \param args - Mutable list of strings. Passed * \param args - Mutable list of strings. Passed
* in from main(). * in from main().
*/ */
virtual bool processArg(int* i, std::vector<std::string>& args); virtual bool processArg(int* i, std::vector<std::string>& args);
/** /**
* Returns the value of the argument. * Returns the value of the argument.
*/ */
/* const */ T& getValue() /* TODO(macbishop): should be const */; /* const */ T& getValue() /* TODO(macbishop): should be const */;
/** /**
* A ValueArg can be used as as its value type (T) This is the * A ValueArg can be used as as its value type (T) This is the
* same as calling getValue() * same as calling getValue()
*/ */
operator const T&() const { return _value; } operator const T&() const { return _value; }
/** /**
* Specialization of shortID. * Specialization of shortID.
* \param val - value to be used. * \param val - value to be used.
*/ */
virtual std::string shortID(const std::string& val = "val") const; virtual std::string shortID(const std::string& val = "val") const;
/** /**
* Specialization of longID. * Specialization of longID.
* \param val - value to be used. * \param val - value to be used.
*/ */
virtual std::string longID(const std::string& val = "val") const; virtual std::string longID(const std::string& val = "val") const;
virtual void reset() ; virtual void reset() ;
private: private:
/** /**
* Prevent accidental copying * Prevent accidental copying
*/ */
ValueArg<T>(const ValueArg<T>& rhs); ValueArg<T>(const ValueArg<T>& rhs);
ValueArg<T>& operator=(const ValueArg<T>& rhs); ValueArg<T>& operator=(const ValueArg<T>& rhs);
}; };
@ -262,11 +262,11 @@ ValueArg<T>::ValueArg(const std::string& flag,
T val, T val,
const std::string& typeDesc, const std::string& typeDesc,
Visitor* v) Visitor* v)
: Arg(flag, name, desc, req, true, v), : Arg(flag, name, desc, req, true, v),
_value( val ), _value( val ),
_default( val ), _default( val ),
_typeDesc( typeDesc ), _typeDesc( typeDesc ),
_constraint( NULL ) _constraint( NULL )
{ } { }
template<class T> template<class T>
@ -278,13 +278,13 @@ ValueArg<T>::ValueArg(const std::string& flag,
const std::string& typeDesc, const std::string& typeDesc,
CmdLineInterface& parser, CmdLineInterface& parser,
Visitor* v) Visitor* v)
: Arg(flag, name, desc, req, true, v), : Arg(flag, name, desc, req, true, v),
_value( val ), _value( val ),
_default( val ), _default( val ),
_typeDesc( typeDesc ), _typeDesc( typeDesc ),
_constraint( NULL ) _constraint( NULL )
{ {
parser.add( this ); parser.add( this );
} }
template<class T> template<class T>
@ -295,11 +295,11 @@ ValueArg<T>::ValueArg(const std::string& flag,
T val, T val,
Constraint<T>* constraint, Constraint<T>* constraint,
Visitor* v) Visitor* v)
: Arg(flag, name, desc, req, true, v), : Arg(flag, name, desc, req, true, v),
_value( val ), _value( val ),
_default( val ), _default( val ),
_typeDesc( constraint->shortID() ), _typeDesc( constraint->shortID() ),
_constraint( constraint ) _constraint( constraint )
{ } { }
template<class T> template<class T>
@ -311,14 +311,14 @@ ValueArg<T>::ValueArg(const std::string& flag,
Constraint<T>* constraint, Constraint<T>* constraint,
CmdLineInterface& parser, CmdLineInterface& parser,
Visitor* v) Visitor* v)
: Arg(flag, name, desc, req, true, v), : Arg(flag, name, desc, req, true, v),
_value( val ), _value( val ),
_default( val ), _default( val ),
_typeDesc( constraint->shortID() ), // TODO(macbishop): Will crash _typeDesc( constraint->shortID() ), // TODO(macbishop): Will crash
// if constraint is NULL // if constraint is NULL
_constraint( constraint ) _constraint( constraint )
{ {
parser.add( this ); parser.add( this );
} }
@ -334,53 +334,51 @@ T& ValueArg<T>::getValue() { return _value; }
template<class T> template<class T>
bool ValueArg<T>::processArg(int *i, std::vector<std::string>& args) bool ValueArg<T>::processArg(int *i, std::vector<std::string>& args)
{ {
if ( _ignoreable && Arg::ignoreRest() ) if ( _ignoreable && Arg::ignoreRest() )
return false; return false;
if ( _hasBlanks( args[*i] ) ) if ( _hasBlanks( args[*i] ) )
return false; return false;
std::string flag = args[*i]; std::string flag = args[*i];
std::string value = ""; std::string value = "";
trimFlag( flag, value ); trimFlag( flag, value );
if ( argMatches( flag ) ) if ( argMatches( flag ) )
{ {
if ( _alreadySet ) 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 ( _xorSet )
if ( static_cast<unsigned int>(*i) < args.size() ) throw( CmdLineParseException("Mutually exclusive argument"
_extractValue( args[*i] ); " already set!", toString()));
else else
throw( ArgParseException("Missing a value for this argument!", throw( CmdLineParseException("Argument already set!",
toString() ) ); toString()) );
} }
else
_extractValue( value ); if ( Arg::delimiter() != ' ' && value == "" )
throw( ArgParseException("Couldn't find delimiter for this argument!",
_alreadySet = true; toString() ) );
_checkWithVisitor();
return true; if ( value == "" )
} {
else (*i)++;
return false; 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;
} }
/** /**
@ -389,8 +387,8 @@ bool ValueArg<T>::processArg(int *i, std::vector<std::string>& args)
template<class T> template<class T>
std::string ValueArg<T>::shortID(const std::string& val) const std::string ValueArg<T>::shortID(const std::string& val) const
{ {
static_cast<void>(val); // Ignore input, don't warn static_cast<void>(val); // Ignore input, don't warn
return Arg::shortID( _typeDesc ); return Arg::shortID( _typeDesc );
} }
/** /**
@ -399,32 +397,32 @@ std::string ValueArg<T>::shortID(const std::string& val) const
template<class T> template<class T>
std::string ValueArg<T>::longID(const std::string& val) const std::string ValueArg<T>::longID(const std::string& val) const
{ {
static_cast<void>(val); // Ignore input, don't warn static_cast<void>(val); // Ignore input, don't warn
return Arg::longID( _typeDesc ); return Arg::longID( _typeDesc );
} }
template<class T> template<class T>
void ValueArg<T>::_extractValue( const std::string& val ) void ValueArg<T>::_extractValue( const std::string& val )
{ {
try { try {
ExtractValue(_value, val, typename ArgTraits<T>::ValueCategory()); ExtractValue(_value, val, typename ArgTraits<T>::ValueCategory());
} catch( ArgParseException &e) { } catch( ArgParseException &e) {
throw ArgParseException(e.error(), toString()); throw ArgParseException(e.error(), toString());
} }
if ( _constraint != NULL ) if ( _constraint != NULL )
if ( ! _constraint->check( _value ) ) if ( ! _constraint->check( _value ) )
throw( CmdLineParseException( "Value '" + val + throw( CmdLineParseException( "Value '" + val +
+ "' does not meet constraint: " + "' does not meet constraint: "
+ _constraint->description(), + _constraint->description(),
toString() ) ); toString() ) );
} }
template<class T> template<class T>
void ValueArg<T>::reset() void ValueArg<T>::reset()
{ {
Arg::reset(); Arg::reset();
_value = _default; _value = _default;
} }
} // namespace TCLAP } // namespace TCLAP