X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcore%2Fgetopt.cpp;fp=source%2Fcore%2Fgetopt.cpp;h=9b8b84cdee323bc1c83f2ebb35dd69915b2f9a00;hp=74f14761c8636c19c7612cd27972ae5ac683832d;hb=c2eeec205dbf17f6ca38fda2671c6aaf2d1c505f;hpb=b56eb5ec1da675da0c66abc53c1e4f6c4e4cccbd diff --git a/source/core/getopt.cpp b/source/core/getopt.cpp index 74f1476..9b8b84c 100644 --- a/source/core/getopt.cpp +++ b/source/core/getopt.cpp @@ -11,6 +11,12 @@ using namespace std; namespace Msp { +GetOpt::GetOpt(): + help(false) +{ + add_option("help", help, NO_ARG).set_help("Displays this help"); +} + GetOpt::~GetOpt() { for(list::iterator i=opts.begin(); i!=opts.end(); ++i) @@ -22,7 +28,7 @@ GetOpt::OptBase &GetOpt::get_option(char s) for(list::iterator i=opts.begin(); i!=opts.end(); ++i) if((*i)->get_short()==s) return **i; - throw UsageError(string("Unknown option -")+s); + throw usage_error(string("Unknown option -")+s); } GetOpt::OptBase &GetOpt::get_option(const string &l) @@ -30,32 +36,42 @@ GetOpt::OptBase &GetOpt::get_option(const string &l) for(list::iterator i=opts.begin(); i!=opts.end(); ++i) if((*i)->get_long()==l) return **i; - throw UsageError(string("Unknown option --")+l); + throw usage_error(string("Unknown option --")+l); } void GetOpt::operator()(unsigned argc, const char *const *argv) { - unsigned i = 1; - for(; i