X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcore%2Fgetopt.h;h=d45e888692ea9f96d2947180f19de75f6652eabb;hp=8e0f49a3fb9d12c83d986289e6cf69d5fc10cee9;hb=c2eeec205dbf17f6ca38fda2671c6aaf2d1c505f;hpb=b56eb5ec1da675da0c66abc53c1e4f6c4e4cccbd diff --git a/source/core/getopt.h b/source/core/getopt.h index 8e0f49a..d45e888 100644 --- a/source/core/getopt.h +++ b/source/core/getopt.h @@ -8,13 +8,27 @@ Distributed under the LGPL #ifndef MSP_CORE_GETOPT_H_ #define MSP_CORE_GETOPT_H_ +#include #include +#include #include #include -#include "except.h" namespace Msp { +class usage_error: public std::runtime_error +{ +private: + std::string help_; + +public: + usage_error(const std::string &w, const std::string &h = std::string()): std::runtime_error(w), help_(h) { } + ~usage_error() throw() { } + + const char *help() const throw() { return help_.c_str(); } +}; + + class GetOpt { public: @@ -69,7 +83,7 @@ private: std::istringstream ss(a); ss>>tmp; if(ss.fail()) - throw UsageError("Invalid argument for --"+lng); + throw usage_error("Invalid argument for --"+lng); data = tmp; } @@ -82,7 +96,7 @@ private: { public: ListOption(char s, const std::string &l, T &d, ArgType a): OptBase(s, l, a), data(d) - { if(arg_type!=REQUIRED_ARG) throw Exception("ListOption with arg_type!=REQUIRED makes no sense"); } + { if(arg_type!=REQUIRED_ARG) throw std::invalid_argument("ListOption arg_type!=REQUIRED"); } virtual void store() { } @@ -92,7 +106,7 @@ private: std::istringstream ss(a); ss>>tmp; if(ss.fail()) - throw UsageError("Invalid argument for --"+lng); + throw usage_error("Invalid argument for --"+lng); data.push_back(tmp); } @@ -100,10 +114,12 @@ private: T &data; }; + bool help; std::list opts; std::vector args; public: + GetOpt(); ~GetOpt(); const std::vector &get_args() const { return args; }