REQUIRED_ARG
};
- class OptBase
+ class Option
+ {
+ protected:
+ Option() { }
+ public:
+ virtual ~Option() { }
+
+ virtual Option &set_help(const std::string &) = 0;
+ virtual Option &set_help(const std::string &, const std::string &) = 0;
+ virtual unsigned get_seen_count() const = 0;
+ };
+
+private:
+ class OptBase: public Option
{
protected:
char shrt;
public:
virtual ~OptBase() { }
- OptBase &set_help(const std::string &);
- OptBase &set_help(const std::string &, const std::string &);
+ virtual OptBase &set_help(const std::string &);
+ virtual OptBase &set_help(const std::string &, const std::string &);
char get_short() const { return shrt; }
const std::string &get_long() const { return lng; }
ArgType get_arg_type() const { return arg_type; }
const std::string &get_help() const { return help; }
const std::string &get_metavar() const { return metavar; }
- unsigned get_seen_count() const { return seen_count; }
+ virtual unsigned get_seen_count() const { return seen_count; }
void process();
void process(const std::string &);
protected:
virtual void store(const std::string &) = 0;
};
-private:
template<typename T>
- class Option: public OptBase
+ class SimpleOption: public OptBase
{
private:
T &data;
public:
- Option(char s, const std::string &l, T &d, ArgType a): OptBase(s, l, a), data(d) { }
+ SimpleOption(char s, const std::string &l, T &d, ArgType a): OptBase(s, l, a), data(d) { }
virtual void store() { }
const std::vector<std::string> &get_args() const { return args; }
template<typename T>
- OptBase &add_option(char s, const std::string &l, T &d, ArgType a = NO_ARG)
- { return add_option(new Option<T>(s, l, d, a)); }
+ Option &add_option(char s, const std::string &l, T &d, ArgType a = NO_ARG)
+ { return add_option(new SimpleOption<T>(s, l, d, a)); }
template<typename T>
- OptBase &add_option(char s, const std::string &l, std::list<T> &d, ArgType a = REQUIRED_ARG)
+ Option &add_option(char s, const std::string &l, std::list<T> &d, ArgType a = REQUIRED_ARG)
{ return add_option(new ListOption<std::list<T> >(s, l, d, a)); }
template<typename T>
- OptBase &add_option(const std::string &l, T &d, ArgType a)
+ Option &add_option(const std::string &l, T &d, ArgType a)
{ return add_option(0, l, d, a); }
private:
std::string generate_help() const;
};
-template<> inline void GetOpt::Option<bool>::store()
+template<> inline void GetOpt::SimpleOption<bool>::store()
{ data = true; }
-template<> inline void GetOpt::Option<unsigned>::store()
+template<> inline void GetOpt::SimpleOption<unsigned>::store()
{ ++data; }
-template<> inline void GetOpt::Option<std::string>::store(const std::string &a)
+template<> inline void GetOpt::SimpleOption<std::string>::store(const std::string &a)
{ data = a; }
template<> inline void GetOpt::ListOption<std::list<std::string> >::store(const std::string &a)