X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fgetopt.h;h=7e5e25f5a1a9ee9994995cc9c77ca4355db8e8b7;hb=cfc8e0b7b15ea505bd6a6a9599cbc5ce1e316963;hp=2824a0b7c7f3b79378477853fa8874300a98eb75;hpb=521cf1db00f8ce2d9f9494dca503d6c17d89ac2f;p=libs%2Fcore.git diff --git a/source/core/getopt.h b/source/core/getopt.h index 2824a0b..7e5e25f 100644 --- a/source/core/getopt.h +++ b/source/core/getopt.h @@ -7,10 +7,10 @@ Distributed under the LGPL #ifndef MSP_CORE_GETOPT_H_ #define MSP_CORE_GETOPT_H_ -#include #include #include -#include "error.h" +#include +#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::list &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,8 +108,30 @@ private: T &data; }; - std::list opts; - std::list args; + 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 &);