Skip to content
Snippets Groups Projects
Commit 42065158 authored by David Flitney's avatar David Flitney
Browse files

*** empty log message ***

parent f551f2b1
No related branches found
No related tags found
No related merge requests found
...@@ -40,38 +40,65 @@ ostream& operator<<(ostream &os, const BaseOption& o) { ...@@ -40,38 +40,65 @@ ostream& operator<<(ostream &os, const BaseOption& o) {
void OptionParser::usage() void OptionParser::usage()
{ {
cerr << "Usage: " << endl << "\t" << progname_ << " " << example_ << endl; cerr << endl << progname_ << endl << endl;
cerr << "Usage: " << endl << example_ << endl;
cerr << endl << "Compulsory arguments:" << endl;
for(Options::iterator option = options_.begin(); option != options_.end(); for(Options::iterator option = options_.begin(); option != options_.end();
option++) option++)
{ {
if((*option)->compulsory()) if((*option)->compulsory()) {
static bool banner = true;
if(banner) {
cerr << endl << "Compulsory arguments (You MUST set one or more of):" << endl;
banner = false;
}
cerr << **option << endl; cerr << **option << endl;
}
} }
cerr << endl << "Optional arguments:" << endl;
for(Options::iterator option = options_.begin(); option != options_.end(); for(Options::iterator option = options_.begin(); option != options_.end();
option++) option++)
{ {
if(!(*option)->compulsory()) if(!(*option)->compulsory()) {
static bool banner = true;
if(banner) {
cerr << endl << "Optional arguments (You may optionally specify one or more of):" << endl;
banner = false;
}
cerr << **option << endl; cerr << **option << endl;
}
} }
cerr << endl; cerr << endl;
cerr << endl; cerr << endl;
} }
// BaseOption * OptionParser::operator[](const string& key) bool OptionParser::check_compulsory_arguments(bool verbose)
// { {
// OptionMap::iterator option = options_.find(key); bool okay = true;
// if(option != options_.end())
// return option->second; for(Options::iterator option = options_.begin();
// else // An unknown option! option != options_.end();
// return NULL; option++) {
// }
if((*option)->compulsory() && (*option)->unset()) {
if(okay) {
if(verbose) {
cerr << "***************************************************" << endl;
cerr << "The following COMPULSORY options have not been set:" << endl;
}
okay = false;
}
if(verbose)
cerr << **option << endl;
}
}
if(!okay && verbose)
cerr << "***************************************************" << endl;
return okay;
}
unsigned int OptionParser::parse_command_line(unsigned int argc, unsigned int OptionParser::parse_command_line(unsigned int argc,
char **argv) char **argv)
...@@ -123,28 +150,6 @@ unsigned int OptionParser::parse_command_line(unsigned int argc, ...@@ -123,28 +150,6 @@ unsigned int OptionParser::parse_command_line(unsigned int argc,
} }
argcount += increments; argcount += increments;
} }
// Now check that any compulsory options
// have been set
for(Options::iterator option = options_.begin();
option != options_.end();
option++) {
static bool banner = true;
if((*option)->compulsory() && (*option)->unset()) {
if(banner) {
cerr << "***************************************************" << endl;
cerr << "The following COMPULSORY options have not been set!" << endl;
banner = false;
usage_needed = true;
}
cerr << **option << endl;
}
}
if(usage_needed) {
cerr << "***************************************************" << endl;
usage();
exit(-1);
}
return argcount; // User should process any remaining args return argcount; // User should process any remaining args
} }
...@@ -177,11 +182,11 @@ int main(unsigned int argc, char **argv) { ...@@ -177,11 +182,11 @@ int main(unsigned int argc, char **argv) {
OptionParser options("options", OptionParser options("options",
"-d <number> --mask <filename> --res <filename>"); "-d <number> --mask <filename> --res <filename>");
options.add(&verbose); options.add(verbose);
options.add(&help); options.add(help);
options.add(&dof); options.add(dof);
options.add(&mask); options.add(mask);
options.add(&resid); options.add(resid);
for(unsigned int a = options.parse_command_line(argc, argv); a < argc; a++) for(unsigned int a = options.parse_command_line(argc, argv); a < argc; a++)
cout << argv[a] << endl; cout << argv[a] << endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment