diff options
Diffstat (limited to 'project2/common/options.cpp')
-rw-r--r-- | project2/common/options.cpp | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/project2/common/options.cpp b/project2/common/options.cpp index a99c78e..8ff7f55 100644 --- a/project2/common/options.cpp +++ b/project2/common/options.cpp @@ -6,42 +6,66 @@ class NamedOption : public Options::Option { public: NamedOption(Glib::ustring const & n, Options::TargetPtr t, Glib::ustring const & d) : - name(n), + id(n), target(t), desc(d) { } void consume(const Glib::ustring & n, const Glib::ustring & p, const Glib::ustring & v) const { - if (n == name) { + if (n == id) { target->consume(p, v); } } void reset() const { target->reset(); } + bool accepts(const Glib::ustring & n) const { + return (n == id); + } + bool paramRequired() const { + return target->paramRequired(); + } + Glib::ustring name() const { + return id; + } + Glib::ustring description() const { + return desc; + } - const Glib::ustring name; + const Glib::ustring id; const Options::TargetPtr target; const Glib::ustring desc; }; class OptionAlias : public Options::Option { public: - OptionAlias(const Glib::ustring & a, Options::TargetPtr t) : + OptionAlias(const Glib::ustring & a, const NamedOption * t) : alias(a), target(t) { } void consume(const Glib::ustring & a, const Glib::ustring & p, const Glib::ustring & v) const { if (a == alias) { - target->consume(p, v); + target->target->consume(p, v); } } void reset() const { - target->reset(); + target->target->reset(); + } + bool accepts(const Glib::ustring & n) const { + return (n == alias); + } + bool paramRequired() const { + return target->target->paramRequired(); + } + Glib::ustring name() const { + return alias; + } + Glib::ustring description() const { + return "Alias for " + target->name(); } const Glib::ustring alias; - const Options::TargetPtr target; + const NamedOption * target; }; Options::Options(Glib::ustring const&) @@ -60,7 +84,7 @@ Options::operator()(const Glib::ustring & a) { for (OptionList::const_reverse_iterator i = options.rbegin(); i != options.rend(); i++) { if (const NamedOption * no = dynamic_cast<const NamedOption *>(i->get())) { - options.push_back(new OptionAlias(a, no->target)); + options.push_back(new OptionAlias(a, no)); break; } } @@ -89,6 +113,15 @@ Options::consume(const Glib::ustring & n, const Glib::ustring & p, const Glib::u o->consume(n, p, v); } } +const Options::Option * +Options::find(const Glib::ustring & n) const { + BOOST_FOREACH(const OptionPtr & o, options) { + if (o->accepts(n)) { + return o.get(); + } + } + return NULL; +} Options::InstanceTarget::InstanceTarget() : ts(Default) |