Added support for automatic addition to a CmdLine parser

This commit is contained in:
macbishop 2004-09-09 19:56:12 +00:00
parent 35a072e0b6
commit 46fdfd07c3
2 changed files with 69 additions and 18 deletions

View File

@ -21,6 +21,7 @@
#include <tclap/Arg.h>
#include <tclap/CommandLine.h>
using namespace std;
@ -35,24 +36,8 @@ const string Arg::flagStartString = "-";
const string Arg::nameStartString = "--";
const string Arg::ignoreNameString = "ignore_rest";
Arg::Arg( const string& flag,
const string& name,
const string& desc,
bool req,
bool valreq,
Visitor* v)
:
_flag(flag),
_name(name),
_description(desc),
_required(req),
_requireLabel("required"),
_valueRequired(valreq),
_alreadySet(false),
_visitor( v ),
_ignoreable(true),
_xorSet(false)
{
void Arg::init()
{
if ( _flag.length() > 1 )
throw(ArgException("Argument flag can only be one character long",
toString() ) );
@ -73,9 +58,62 @@ Arg::Arg( const string& flag,
Arg::flagStartString + "' or '" +
Arg::nameStartString + "' or space.",
toString() ) );
}
Arg::Arg( const string& flag,
const string& name,
const string& desc,
bool req,
bool valreq,
Visitor* v)
:
_flag(flag),
_name(name),
_description(desc),
_required(req),
_requireLabel("required"),
_valueRequired(valreq),
_alreadySet(false),
_visitor( v ),
_ignoreable(true),
_xorSet(false)
{
try {
init(); //< initialize the object
} catch (ArgException ae) {
throw(ae); //< and forward any exceptions
}
};
Arg::Arg(const std::string& flag,
const std::string& name,
const std::string& desc,
bool req,
bool valreq,
CmdLine &parser,
Visitor* v) :
_flag(flag),
_name(name),
_description(desc),
_required(req),
_requireLabel("required"),
_valueRequired(valreq),
_alreadySet(false),
_visitor( v ),
_ignoreable(true),
_xorSet(false)
{
try {
init(); //< initialize the object
} catch (ArgException ae) {
throw(ae); //< and forward any exceptions
}
//Add to the parser, what about exceptions
parser.add(*this);
}
Arg::Arg()
:
_flag(""),

View File

@ -21,6 +21,7 @@
#include <tclap/SwitchArg.h>
#include <tclap/CommandLine.h>
using namespace std;
@ -35,6 +36,18 @@ SwitchArg::SwitchArg(const string& flag,
_value( _default )
{ };
SwitchArg::SwitchArg(const string& flag,
const string& name,
const string& desc,
bool _default,
CmdLine &parser,
Visitor* v )
: Arg(flag, name, desc, false, false, v),
_value( _default )
{
parser.add(*this);
}
SwitchArg::~SwitchArg() { };
bool SwitchArg::getValue() { return _value; };