22 #ifndef DtCmdLine_CMDLINE_H
23 #define DtCmdLine_CMDLINE_H
52 #ifdef DtUSE_UTILITIES_NAMESPACE
53 namespace DtUSE_UTILITIES_NAMESPACE
63 class CmdLine :
public CmdLineInterface
132 bool _emptyCombined(
const std::string& s);
147 void deleteOnExit(
Arg* ptr);
152 void deleteOnExit(
Visitor* ptr);
172 CmdLine(
const std::string& name,
173 const std::string& message,
174 const std::string& version =
"none",
176 bool pressAnyKey =
true);
178 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);
223 void xorAdd(
Arg& a,
Arg& b );
230 void xorAdd( std::vector<Arg*>& xors );
239 void parse(
int argc,
char** argv,
bool printOnError =
true)
251 char** checkHelpOption(
int & argc,
char** argv,
bool & result,
bool removeFromArgs = true );
266 std::
string& getVersion();
271 std::
string& getProgramName();
276 std::list<
Arg*>& getArgList();
291 std::
string& getMessage();
300 const std::
string& m,
301 const std::
string& v,
308 myPressAnyKey(pressAnyKey),
309 _userSetOutput(false)
314 inline CmdLine::CmdLine(
const std::string& m,
316 const std::string& v,
323 myPressAnyKey(pressAnyKey),
324 _userSetOutput(false)
358 "Displays usage information and exits.",
366 "Displays version information and exits.",
375 "Ignores the rest of the labeled arguments following this flag.",
388 (*it)->forceRequired();
389 (*it)->setRequireLabel(
"OR required" );
397 std::vector<Arg*> ors;
432 std::vector<std::string> args;
433 for (
int i = 1; i < argc; i++)
434 args.push_back(argv[i]);
436 std::vector<std::string>::iterator prev;
437 std::vector<std::string>::iterator cur;
438 std::vector<std::string>::iterator end = args.end();
444 bool finished =
false;
446 while( ( cur != end && finished ==
false ) )
448 if( (*cur) ==
"--help" )
470 else if ((*cur) ==
"-h")
501 if( ( removeFromArgs ==
true ) && ( finished ==
true ) )
506 char ** new_argv =
new char * [ args.size() ];
507 for(
unsigned int i = 0; i < args.size(); ++i )
509 new_argv[i] =
new char[ args[i].length() + 1 ];
510 memcpy( new_argv[i], args[i].c_str(), args[i].length() );
529 std::vector<std::string> args;
531 for (i = 1; i < argc; i++)
532 args.push_back(argv[i]);
534 int requiredCount = 0;
536 for (i = 0; (
unsigned int)i < args.size(); i++)
538 bool matched =
false;
539 for (
ArgListIterator it = _argList.begin(); it != _argList.end(); it++)
541 if ( (*it)->processArg( &i, args ) )
543 requiredCount += _xorHandler.check( *it );
551 if ( !matched && _emptyCombined( args[i] ) )
559 if ( requiredCount < _numRequired )
562 if ( requiredCount > _numRequired )
567 if( printOnError ==
false )
572 _output->failure(*
this,e);
579 DtInfo <<
"Press any key to continue" << std::endl;
598 for (
int i = 1; (
unsigned int)i < s.length(); i++ )
664 #ifdef DtUSE_UTILITIES_NAMESPACE
void add(std::vector< Arg * > &ors)
Add a list of Arg*'s that will be orred together.
Definition: cmdXorHandler.h:105
XorHandler & getXorHandler()
Returns the XorHandler.
Definition: cmdLine.h:641
A base class that defines the interface for visitors.
Definition: cmdVisitor.h:41
void add(Arg &a)
Adds an argument to the list of arguments to be parsed.
Definition: cmdLine.h:403
static void setDelimiter(char c)
Sets the delimiter for all arguments.
Definition: cmdArg.h:219
static const char blankChar()
The char used as a place holder when SwitchArgs are combined.
Definition: cmdArg.h:191
A simple switch argument.
Definition: cmdSwitchArg.h:49
std::list< Arg * > _argList
The list of arguments that will be tested against the command line.
Definition: cmdLine.h:72
This file declares the class DtCmdLine::CmdLineOutput.
This file declares the class DtCmdLine::StdOutput.
A Vistor that tells the CmdLine to begin ignoring arguments after this one is parsed.
Definition: cmdIgnoreRestVisitor.h:45
Thrown from Arg and CmdLine when an Arg is improperly specified, e.g.
Definition: cmdArgException.h:177
This file declares the class DtCmdLine::VersionVisitor.
std::string & getMessage()
Returns the message string.
Definition: cmdLine.h:651
char DtPollBlockingInputChar(void)
Polls standard input for a single character.
virtual bool isRequired() const
Indicates whether the argument is required.
Definition: cmdArg.h:475
virtual std::string longID(const std::string &valueId="val") const
Returns a long ID for the usage.
Definition: cmdArg.h:422
bool _emptyCombined(const std::string &s)
Checks whether a name/flag string matches entirely matches the Arg::blankChar.
Definition: cmdLine.h:593
Functions in vlPrint.h provide an error and print facility for vrlink.
static const std::string flagStartString()
The sting that indicates the beginning of a flag.
Definition: cmdArg.h:202
char ** checkHelpOption(int &argc, char **argv, bool &result, bool removeFromArgs=true)
Checks the command line to see if "--help" if entered.
Definition: cmdLine.h:423
static const char flagStartChar()
The char that indicates the beginning of a flag.
Definition: cmdArg.h:196
Thrown from CmdLine when the arguments on the command line are not properly specified, e.g.
Definition: cmdArgException.h:153
This file declares the class DtCmdLine::IgnoreRestVisitor.
A class that isolates any output from the CmdLine object so that it may be easily modified...
Definition: cmdStdOutput.h:54
This class handles lists of Arg's that are to be XOR'd on the command line.
Definition: cmdXorHandler.h:48
void _constructor()
Encapsulates the code common to the constructors (which is all of it).
Definition: cmdLine.h:348
A Vistor that will call the version method of the given CmdLineOutput for the specified CmdLine objec...
Definition: cmdVersionVisitor.h:50
void deleteOnExit(Arg *ptr)
Perform a delete ptr; operation on ptr when this object is deleted.
Definition: cmdLine.h:605
std::string _message
A message used to describe the program.
Definition: cmdLine.h:82
virtual void addToList(std::list< Arg * > &argList) const
Adds this to the specified list of Args.
Definition: cmdArg.h:568
std::list< Visitor * >::iterator VisitorListIterator
Typedef of a Visitor list iterator.
Definition: cmdArg.h:352
The base class that manages the command line definition and passes along the parsing to the appropria...
Definition: cmdLine.h:64
std::list< Arg * > & getArgList()
Returns the argList.
Definition: cmdLine.h:636
A simple class that defines and argument exception.
Definition: cmdArgException.h:43
std::string _progName
The name of the program.
Definition: cmdLine.h:77
void DtSleep(DtTime sleep_period)
Puts the process to sleep for the specified number of seconds.
static bool ignoreRest()
Whether to ignore the rest.
Definition: cmdArg.h:178
This file declares the class DtCmdLine::HelpVisitor.
std::string & getVersion()
Returns the version string.
Definition: cmdLine.h:626
void xorAdd(Arg &a, Arg &b)
Add two Args that will be xor'd.
Definition: cmdLine.h:395
int DtNotifyLevel
DtNotifyLevel is used to control the level of diagnostics output by VR-Link.
char _delimiter
The character that is used to separate the argument flag/name from the value.
Definition: cmdLine.h:100
bool _userSetOutput
Is set to true when a user sets the output object.
Definition: cmdLine.h:158
This file declares the class DtCmdLine::XorHandler.
char getDelimiter()
Returns the delimiter string.
Definition: cmdLine.h:646
This file declares the class DtCmdLine::SwitchArg.
A virtual base class that defines the essential data for all arguments.
Definition: cmdArg.h:48
static const std::string ignoreNameString()
The name used to identify the ignore rest argument.
Definition: cmdArg.h:213
This file declares the class DtCmdLine::UnlabeledValueArg.
std::string error() const
Returns the error text.
Definition: cmdArgException.h:70
XorHandler _xorHandler
The handler that manages xoring lists of args.
Definition: cmdLine.h:105
std::string _version
The version to be displayed with the –version switch.
Definition: cmdLine.h:87
int _numRequired
The number of arguments that are required to be present on the command line.
Definition: cmdLine.h:94
CmdLineOutput * getOutput()
Returns the CmdLineOutput object.
Definition: cmdLine.h:615
void setOutput(CmdLineOutput *co)
Definition: cmdLine.h:620
A Visitor object that calls the usage method of the given CmdLineOutput object for the specified CmdL...
Definition: cmdHelpVisitor.h:49
DtOutputStream DtInfo
DtInfo is an global instance of a DtOutputStream.
std::list< Arg * >::iterator ArgListIterator
Typedef of an Arg list iterator.
Definition: cmdArg.h:342
This file contains declarations of classes and functions which aid in keyboard input.
CmdLineOutput * _output
Object that handles all output for the CmdLine.
Definition: cmdLine.h:124
std::string & getProgramName()
Returns the program name string.
Definition: cmdLine.h:631
std::list< Arg * > _argDeleteOnExitList
A list of Args to be explicitly deleted when the destructor is called.
Definition: cmdLine.h:112
std::vector< Arg * >::iterator ArgVectorIterator
Typedef of an Arg vector iterator.
Definition: cmdArg.h:347
void parse(int argc, char **argv, bool printOnError=true)
Parses the command line.
Definition: cmdLine.h:521
ProcControl.h provides operating system independent methods to control processes. ...
std::list< Visitor * > _visitorDeleteOnExitList
A list of Visitors to be explicitly deleted when the destructor is called.
Definition: cmdLine.h:119
The interface that any output object must implement.
Definition: cmdLineOutput.h:51
virtual ~CmdLine()
Deletes any resources allocated by a CmdLine object.
Definition: cmdLine.h:329
This file declares the class DtCmdLine::UnlabeledMultiArg.
bool myPressAnyKey
Definition: cmdLine.h:134