mirror of
https://github.com/cuberite/TCLAP.git
synced 2025-09-08 11:49:39 -04:00
Added support for automatic addition to a CmdLine parser
This commit is contained in:
parent
35a072e0b6
commit
46fdfd07c3
74
src/Arg.cpp
74
src/Arg.cpp
@ -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(""),
|
||||
|
@ -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; };
|
||||
|
Loading…
x
Reference in New Issue
Block a user