X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fgetopt.cpp;h=b472c58b835a94e27fa94046c488e9777096b60f;hb=c7afef88380ebebc8c2b04e48664d73281ec8848;hp=74f14761c8636c19c7612cd27972ae5ac683832d;hpb=d5dd704b2576f878809e87dbb8ff8591b9bdbce4;p=libs%2Fcore.git diff --git a/source/core/getopt.cpp b/source/core/getopt.cpp index 74f1476..b472c58 100644 --- a/source/core/getopt.cpp +++ b/source/core/getopt.cpp @@ -1,16 +1,15 @@ -/* $Id$ - -This file is part of libmspcore -Copyright © 2006-2009, 2011 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include "getopt.h" 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 +21,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 +29,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