summaryrefslogtreecommitdiffstats
path: root/dwarflint/option.hh
diff options
context:
space:
mode:
authorPetr Machata <[email protected]>2010-09-23 18:00:36 +0200
committerPetr Machata <[email protected]>2010-09-23 18:00:36 +0200
commit75c18f5e549e400cafca2b9137c83f7c6460cf02 (patch)
tree0b36c7f0b49484a061de7d4b614bfae70c2fc9fb /dwarflint/option.hh
parent56df0cc20114ed6042de2838e22f21bcbd5c1c33 (diff)
dwarflint: Don't assume all options are global
- currently this breaks dwarflint, because per-check options are not yet processed. Options that belonged to global group before still work and are correctly registered as globals, but e.g. -i or the suite of options at locstats aren't recognized.
Diffstat (limited to 'dwarflint/option.hh')
-rw-r--r--dwarflint/option.hh70
1 files changed, 56 insertions, 14 deletions
diff --git a/dwarflint/option.hh b/dwarflint/option.hh
index aa256d62..4c79b58b 100644
--- a/dwarflint/option.hh
+++ b/dwarflint/option.hh
@@ -31,33 +31,49 @@
#include <map>
#include <vector>
#include <cassert>
-
#include <iostream>
-class option_common;
+#include "option.ii"
class options
- : private std::map<int, option_common *>
+ : private std::map<int, option_i *>
{
friend class option_common;
std::vector<argp_option> _m_opts;
- option_common *opt (int key) const;
+ option_i *find_opt (int key) const;
static error_t parse_opt (int key, char *arg, argp_state *state);
public:
- static options &registered ();
- option_common const *getopt (int key) const;
+ option_i const *getopt (int key) const;
argp build_argp ();
+ void add (option_i *opt);
};
-class option_common
+class option_i // we cannot call it simply "option", this conflicts
+ // with another global declaration
{
- argp_option _m_opt;
-
+ // last allocated option unique identifier
static int _m_last_opt;
+
+protected:
+ // Answer either opt_short argument if it's non-0. Otherwise create
+ // new unique identifier.
static int get_short_option (char opt_short);
+public:
+ virtual bool seen () const = 0;
+ virtual argp_option const &build_option () const = 0;
+ virtual error_t parse_opt (char *arg, argp_state *state) = 0;
+ virtual int key () const = 0;
+ virtual ~option_i () {}
+};
+
+class option_common
+ : public option_i
+{
+ argp_option _m_opt;
+
protected:
bool _m_seen;
@@ -66,12 +82,24 @@ protected:
char const *opt_long, char opt_short,
int flags = 0);
-public: // consumer interface
- bool seen () const { return _m_seen; }
+public:
+ bool
+ seen () const
+ {
+ return _m_seen;
+ }
-public: // option handler interface
- argp_option const &build_option () const { return _m_opt; }
- virtual error_t parse_opt (char *arg, argp_state *state) = 0;
+ argp_option const &
+ build_option () const
+ {
+ return _m_opt;
+ }
+
+ int
+ key () const
+ {
+ return _m_opt.key;
+ }
};
template<class arg_type>
@@ -144,4 +172,18 @@ struct value_converter<std::string>
typedef xoption<void> void_option;
typedef xoption<std::string> string_option;
+extern options global_opts;
+
+template<class OPT>
+struct global_opt
+ : public OPT
+{
+ template<typename... Args>
+ global_opt (Args const&... args)
+ : OPT (args...)
+ {
+ global_opts.add (this);
+ }
+};
+
#endif//DWARFLINT_OPTION_HH