X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fgetopt.h;h=7e5e25f5a1a9ee9994995cc9c77ca4355db8e8b7;hb=cfc8e0b7b15ea505bd6a6a9599cbc5ce1e316963;hp=3315108f05d34939d6d8d609fae973c915252296;hpb=0fa00d18f607f329d2b2a979e1d4339e233817fa;p=libs%2Fcore.git diff --git a/source/core/getopt.h b/source/core/getopt.h index 3315108..7e5e25f 100644 --- a/source/core/getopt.h +++ b/source/core/getopt.h @@ -10,7 +10,7 @@ Distributed under the LGPL #include #include #include -#include "error.h" +#include "except.h" namespace Msp { @@ -46,25 +46,6 @@ public: OptBase(char s, const std::string &l, ArgType a): shrt(s), lng(l), arg_type(a), seen_count(0) { } }; - const std::vector &get_args() const { return args; } - - template - OptBase &add_option(char s, const std::string &l, T &d, ArgType a=NO_ARG) - { opts.push_back(new Option(s, l, d, a)); return *opts.back(); } - - template - OptBase &add_option(char s, const std::string &l, std::list &d, ArgType a=REQUIRED_ARG) - { opts.push_back(new ListOption >(s, l, d, a)); return *opts.back(); } - - template - OptBase &add_option(const std::string &l, T &d, ArgType a) - { return add_option(0, l, d, a); } - - std::string generate_usage(const std::string &) const; - std::string generate_help() const; - void operator()(unsigned, const char *const *); - - ~GetOpt(); private: template class Option: public OptBase @@ -127,9 +108,31 @@ private: T &data; }; - std::list opts; + std::list opts; std::vector args; +public: + ~GetOpt(); + + const std::vector &get_args() const { return args; } + + template + OptBase &add_option(char s, const std::string &l, T &d, ArgType a=NO_ARG) + { opts.push_back(new Option(s, l, d, a)); return *opts.back(); } + + template + OptBase &add_option(char s, const std::string &l, std::list &d, ArgType a=REQUIRED_ARG) + { opts.push_back(new ListOption >(s, l, d, a)); return *opts.back(); } + + template + OptBase &add_option(const std::string &l, T &d, ArgType a) + { return add_option(0, l, d, a); } + + std::string generate_usage(const std::string &) const; + std::string generate_help() const; + void operator()(unsigned, const char *const *); +private: + OptBase &get_option(char); OptBase &get_option(const std::string &); unsigned process_long(const char *const *);