28 #include <cmdLine/cmdLineInterface.h>
31 #include <cmdLine/cmdUnlabeledValueArg.h>
32 #include <cmdLine/cmdUnlabeledMultiArg.h>
34 #include <cmdLine/cmdXorHandler.h>
35 #include <cmdLine/cmdHelpVisitor.h>
36 #include <cmdLine/cmdVersionVisitor.h>
37 #include <cmdLine/cmdIgnoreRestVisitor.h>
39 #include <cmdLine/cmdLineOutput.h>
40 #include <cmdLine/cmdStdOutput.h>
49 #include <vlutil/vlProcessControl.h>
50 #include <vlutil/vlKeyboard.h>
51 #include <vlutil/vlPrint.h>
59 class CmdLine :
public DtCmdLine::CmdLineInterface
171 CmdLine(
const std::string& name,
172 const std::string& message,
173 const std::string& version =
"none",
175 bool pressAnyKey =
true);
177 bool pressAnyKey =
false);
191 CmdLine(
const std::string& message,
192 const char delimiter =
' ',
193 const std::string& version =
"none",
195 bool pressAnyKey =
true);
197 bool pressAnyKey =
false);
209 void add( DtCmdLine::Arg& a );
215 void add( DtCmdLine::Arg* a );
223 void xorAdd( DtCmdLine::Arg& a, DtCmdLine::Arg& b );
230 void xorAdd( std::vector<DtCmdLine::Arg*>& xors );
238 void parse(
int argc,
char** argv,
bool printOnError =
true);
248 void setOutput(DtCmdLine::CmdLineOutput* co);
287 const std::string& m,
288 const std::string& v,
295 myPressAnyKey(pressAnyKey),
296 _userSetOutput(false)
303 const std::string& v,
305 : _progName(
"not_set_yet"),
310 myPressAnyKey(pressAnyKey),
311 _userSetOutput(false)
318 DtCmdLine::ArgListIterator argIter;
319 DtCmdLine::VisitorListIterator visIter;
337 _output =
new DtCmdLine::StdOutput;
339 DtCmdLine::Visitor *v;
345 "Displays usage information and exits.",
353 "Displays version information and exits.",
359 v =
new DtCmdLine::IgnoreRestVisitor();
361 DtCmdLine::Arg::ignoreNameString(),
362 "Ignores the rest of the labeled arguments following this flag.",
373 for (DtCmdLine::ArgVectorIterator it = ors.begin(); it != ors.end(); ++it)
375 (*it)->forceRequired();
376 (*it)->setRequireLabel(
"OR required" );
384 std::vector<DtCmdLine::Arg*> ors;
397 for( DtCmdLine::ArgListIterator it =
_argList.begin(); it !=
_argList.end(); ++it )
399 throw( DtCmdLine::SpecificationException(
"Argument with same flag/name already exists!",
404 if ( a->isRequired() )
415 std::vector<std::string> args;
417 for (i = 1; i < argc; i++)
418 args.push_back(argv[i]);
420 int requiredCount = 0;
422 for (i = 0; (
unsigned int)i < args.size(); i++)
424 bool matched =
false;
425 for (DtCmdLine::ArgListIterator it =
_argList.begin(); it !=
_argList.end(); ++it)
429 if(!(*it)->isIgnoreable() || !DtCmdLine::Arg::ignoreRest())
431 if ( (*it)->processArg( &i, args ) )
446 if ( !matched && !DtCmdLine::Arg::ignoreRest() )
447 throw(DtCmdLine::CmdLineParseException(
"Couldn't find match for argument",
452 throw(DtCmdLine::CmdLineParseException(
"One or more required arguments missing!"));
455 throw(DtCmdLine::CmdLineParseException(
"Too many arguments!"));
457 }
catch ( DtCmdLine::ArgException& e ) {
460 int oldNotifyLevel = DtNotifyLevel;
465 DtInfo <<
"Press any key to continue" << std::endl;
467 while (DtPollBlockingInputChar() ==
'\0')
473 DtNotifyLevel = oldNotifyLevel;
481 if ( s[0] != DtCmdLine::Arg::flagStartChar() )
484 for (
int i = 1; (
unsigned int)i < s.length(); i++ )
485 if ( s[i] != DtCmdLine::Arg::blankChar() )
std::string & getMessage()
Definition: DtVrvCommandLineParser.h:537
std::string & getVersion()
Definition: DtVrvCommandLineParser.h:512
std::string & getProgramName()
Definition: DtVrvCommandLineParser.h:517
std::list< DtCmdLine::Arg * > & getArgList()
Definition: DtVrvCommandLineParser.h:522
void _constructor()
Encapsulates the code common to the constructors (which is all of it).
Definition: DtVrvCommandLineParser.h:335
CmdLine(const std::string &name, const std::string &message, const std::string &version="none", bool pressAnyKey=false)
Command line constructor.
Definition: DtVrvCommandLineParser.h:286
DtCmdLine::XorHandler & getXorHandler()
Definition: DtVrvCommandLineParser.h:527
std::string _version
The version to be displayed with the –version switch.
Definition: DtVrvCommandLineParser.h:85
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
DtCmdLine::XorHandler _xorHandler
The handler that manages xoring lists of args.
Definition: DtVrvCommandLineParser.h:103
DtCmdLine::CmdLineOutput * _output
Object that handles all output for the CmdLine.
Definition: DtVrvCommandLineParser.h:122
virtual ~CmdLine()
Deletes any resources allocated by a CmdLine object.
Definition: DtVrvCommandLineParser.h:316
std::string _progName
The name of the program.
Definition: DtVrvCommandLineParser.h:75
bool _userSetOutput
Is set to true when a user sets the output object.
Definition: DtVrvCommandLineParser.h:156
void deleteOnExit(DtCmdLine::Arg *ptr)
Perform a delete ptr; operation on ptr when this object is deleted.
Definition: DtVrvCommandLineParser.h:491
char _delimiter
The character that is used to separate the argument flag/name from the value.
Definition: DtVrvCommandLineParser.h:98
void setOutput(DtCmdLine::CmdLineOutput *co)
Definition: DtVrvCommandLineParser.h:506
This file declares the class SwitchArg.
void parse(int argc, char **argv, bool printOnError=true)
Parses the command line.
Definition: DtVrvCommandLineParser.h:408
bool myPressAnyKey
Definition: DtVrvCommandLineParser.h:132
std::list< DtCmdLine::Arg * > _argList
The list of arguments that will be tested against the command line.
Definition: DtVrvCommandLineParser.h:70
A simple switch argument.
Definition: DtVrvCmdSwitchArg.h:42
std::string _message
A message used to describe the program.
Definition: DtVrvCommandLineParser.h:80
char getDelimiter()
Definition: DtVrvCommandLineParser.h:532
int _numRequired
The number of arguments that are required to be present on the command line.
Definition: DtVrvCommandLineParser.h:92
std::list< DtCmdLine::Arg * > _argDeleteOnExitList
A list of Args to be explicitly deleted when the destructor is called.
Definition: DtVrvCommandLineParser.h:110
void add(DtCmdLine::Arg &a)
Adds an argument to the list of arguments to be parsed.
Definition: DtVrvCommandLineParser.h:390
std::list< DtCmdLine::Visitor * > _visitorDeleteOnExitList
A list of Visitors to be explicitly deleted when the destructor is called.
Definition: DtVrvCommandLineParser.h:117
bool _emptyCombined(const std::string &s)
Checks whether a name/flag string matches entirely matches the Arg::blankChar.
Definition: DtVrvCommandLineParser.h:479
DtCmdLine::CmdLineOutput * getOutput()
Definition: DtVrvCommandLineParser.h:501
void xorAdd(DtCmdLine::Arg &a, DtCmdLine::Arg &b)
Add two Args that will be xor'd.
Definition: DtVrvCommandLineParser.h:382