22 #ifndef DtCmdLine_CMDLINE_H
23 #define DtCmdLine_CMDLINE_H
52 #ifdef DtUSE_UTILITIES_NAMESPACE
53 namespace DtUSE_UTILITIES_NAMESPACE
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,
318 : _progName(
"not_set_yet"),
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;
427 std::vector<std::string> args;
428 for (
int i = 1; i < argc; i++)
429 args.push_back(argv[i]);
431 std::vector<std::string>::iterator prev;
432 std::vector<std::string>::iterator cur;
433 std::vector<std::string>::iterator end = args.end();
439 bool finished =
false;
441 while( ( cur != end && finished ==
false ) )
443 if( (*cur) ==
"--help" )
473 if( ( removeFromArgs ==
true ) && ( finished ==
true ) )
478 char ** new_argv =
new char * [ args.size() ];
479 for(
unsigned int i = 0; i < args.size(); ++i )
481 new_argv[i] =
new char[ args[i].length() + 1 ];
482 memcpy( new_argv[i], args[i].c_str(), args[i].length() );
501 std::vector<std::string> args;
503 for (i = 1; i < argc; i++)
504 args.push_back(argv[i]);
506 int requiredCount = 0;
508 for (i = 0; (
unsigned int)i < args.size(); i++)
510 bool matched =
false;
511 for (
ArgListIterator it = _argList.begin(); it != _argList.end(); it++)
513 if ( (*it)->processArg( &i, args ) )
515 requiredCount += _xorHandler.check( *it );
523 if ( !matched && _emptyCombined( args[i] ) )
531 if ( requiredCount < _numRequired )
534 if ( requiredCount > _numRequired )
539 if( printOnError ==
false )
544 _output->failure(*
this,e);
551 DtInfo <<
"Press any key to continue" << std::endl;
570 for (
int i = 1; (
unsigned int)i < s.length(); i++ )
636 #ifdef DtUSE_UTILITIES_NAMESPACE