added a new parse method that accepts a vector

This commit is contained in:
mes5k 2007-03-04 19:08:17 +00:00
parent a5161226b8
commit df1f8e9938
2 changed files with 29 additions and 8 deletions

View File

@ -229,6 +229,13 @@ private:
*/
void parse(int argc, char** argv);
/**
* Parses the command line.
* \param args - A vector of strings representing the args.
* args[0] is still the program name.
*/
void parse(std::vector<std::string>& args);
/**
*
*/
@ -383,19 +390,26 @@ inline void CmdLine::add( Arg* a )
_numRequired++;
}
inline void CmdLine::parse(int argc, char** argv)
{
// this step is necessary so that we have easy access to
// mutable strings.
std::vector<std::string> args;
for (int i = 0; i < argc; i++)
args.push_back(argv[i]);
parse(args);
}
inline void CmdLine::parse(std::vector<std::string>& args)
{
bool shouldExit = false;
int estat = 0;
try {
_progName = argv[0];
// this step is necessary so that we have easy access to
// mutable strings.
std::vector<std::string> args;
for (int i = 1; i < argc; i++)
args.push_back(argv[i]);
_progName = args.front();
args.erase(args.begin());
int requiredCount = 0;
@ -431,7 +445,7 @@ inline void CmdLine::parse(int argc, char** argv)
} catch ( ArgException& e ) {
try {
_output->failure(*this,e);
} catch (ExitException &ee) {
} catch ( ExitException &ee ) {
estat = ee.getExitStatus();
shouldExit = true;
}

View File

@ -84,6 +84,13 @@ class CmdLineInterface
*/
virtual void parse(int argc, char** argv)=0;
/**
* Parses the command line.
* \param args - A vector of strings representing the args.
* args[0] is still the program name.
*/
void parse(std::vector<std::string>& args);
/**
* Returns the CmdLineOutput object.
*/