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,
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