diff options
author | 2013-05-24 00:39:38 +0100 | |
---|---|---|
committer | 2013-05-24 00:39:38 +0100 | |
commit | 5b56eb71629d72bb3b1fa1bf1633d2b7748459f9 (patch) | |
tree | 7b37d98bc3016404553caf0a1eb4c8145c1c6cb9 | |
parent | 53b757d8595fd4821fc7f69eebe7940f0c9f4c35 (diff) | |
download | paludis-5b56eb71629d72bb3b1fa1bf1633d2b7748459f9.tar.gz paludis-5b56eb71629d72bb3b1fa1bf1633d2b7748459f9.tar.xz |
Convert to fancy new visitors
-rw-r--r-- | paludis/repositories/unpackaged/installed_id.cc | 132 | ||||
-rw-r--r-- | paludis/repositories/unpackaged/installed_repository.cc | 52 |
2 files changed, 49 insertions, 135 deletions
diff --git a/paludis/repositories/unpackaged/installed_id.cc b/paludis/repositories/unpackaged/installed_id.cc index 6400f8f9a..2dbca35a2 100644 --- a/paludis/repositories/unpackaged/installed_id.cc +++ b/paludis/repositories/unpackaged/installed_id.cc @@ -618,106 +618,54 @@ InstalledUnpackagedID::behaviours_key() const return _imp->behaviours_key; } -namespace -{ - struct SupportVisitor - { - bool visit(const SupportsActionTest<UninstallAction> &) const - { - return true; - } - - bool visit(const SupportsActionTest<ConfigAction> &) const - { - return false; - } - - bool visit(const SupportsActionTest<InfoAction> &) const - { - return false; - } - - bool visit(const SupportsActionTest<PretendAction> &) const - { - return false; - } - - bool visit(const SupportsActionTest<FetchAction> &) const - { - return false; - } - - bool visit(const SupportsActionTest<InstallAction> &) const - { - return false; - } - - bool visit(const SupportsActionTest<PretendFetchAction> &) const - { - return false; - } - }; - - struct PerformAction - { - const InstalledUnpackagedID * const id; - - PerformAction(const InstalledUnpackagedID * const i) : - id(i) - { - } - - void visit(InstallAction & a) PALUDIS_ATTRIBUTE((noreturn)) - { - throw ActionFailedError("Unsupported action: " + a.simple_name()); - } - - void visit(FetchAction & a) PALUDIS_ATTRIBUTE((noreturn)) - { - throw ActionFailedError("Unsupported action: " + a.simple_name()); - } - - void visit(ConfigAction & a) PALUDIS_ATTRIBUTE((noreturn)) - { - throw ActionFailedError("Unsupported action: " + a.simple_name()); - } - - void visit(PretendAction & a) PALUDIS_ATTRIBUTE((noreturn)) - { - throw ActionFailedError("Unsupported action: " + a.simple_name()); - } - - void visit(PretendFetchAction & a) PALUDIS_ATTRIBUTE((noreturn)) - { - throw ActionFailedError("Unsupported action: " + a.simple_name()); - } - - void visit(InfoAction & a) PALUDIS_ATTRIBUTE((noreturn)) - { - throw ActionFailedError("Unsupported action: " + a.simple_name()); - } - - void visit(UninstallAction & a) - { - std::shared_ptr<OutputManager> output_manager(a.options.make_output_manager()(a)); - id->uninstall(false, a.options.if_for_install_id(), output_manager); - output_manager->succeeded(); - } - }; -} - bool InstalledUnpackagedID::supports_action(const SupportsActionTestBase & test) const { - SupportVisitor v; - return test.accept_returning<bool>(v); + return test.make_accept_returning( + [&] (const SupportsActionTest<UninstallAction> &) { return true; }, + [&] (const SupportsActionTest<ConfigAction> &) { return false; }, + [&] (const SupportsActionTest<InfoAction> &) { return false; }, + [&] (const SupportsActionTest<PretendAction> &) { return false; }, + [&] (const SupportsActionTest<FetchAction> &) { return false; }, + [&] (const SupportsActionTest<InstallAction> &) { return false; }, + [&] (const SupportsActionTest<PretendFetchAction> &) { return false; } + ); } void InstalledUnpackagedID::perform_action(Action & action) const { - PerformAction v(this); - action.accept(v); + action.make_accept( + [&] (const InstallAction & a) { + throw ActionFailedError("Unsupported action: " + a.simple_name()); + }, + + [&] (const FetchAction & a) { + throw ActionFailedError("Unsupported action: " + a.simple_name()); + }, + + [&] (const ConfigAction & a) { + throw ActionFailedError("Unsupported action: " + a.simple_name()); + }, + + [&] (const PretendAction & a) { + throw ActionFailedError("Unsupported action: " + a.simple_name()); + }, + + [&] (const PretendFetchAction & a) { + throw ActionFailedError("Unsupported action: " + a.simple_name()); + }, + + [&] (const InfoAction & a) { + throw ActionFailedError("Unsupported action: " + a.simple_name()); + }, + + [&] (const UninstallAction & a) { + std::shared_ptr<OutputManager> output_manager(a.options.make_output_manager()(a)); + uninstall(false, a.options.if_for_install_id(), output_manager); + output_manager->succeeded(); + } + ); } std::shared_ptr<const Set<std::string> > diff --git a/paludis/repositories/unpackaged/installed_repository.cc b/paludis/repositories/unpackaged/installed_repository.cc index 4e5c2564c..2159e93fb 100644 --- a/paludis/repositories/unpackaged/installed_repository.cc +++ b/paludis/repositories/unpackaged/installed_repository.cc @@ -167,52 +167,18 @@ InstalledUnpackagedRepository::has_category_named(const CategoryNamePart & c, co return _imp->ndbam.has_category_named(c); } -namespace -{ - struct SomeIDsMightSupportVisitor - { - bool visit(const SupportsActionTest<UninstallAction> &) const - { - return true; - } - - bool visit(const SupportsActionTest<ConfigAction> &) const - { - return false; - } - - bool visit(const SupportsActionTest<InfoAction> &) const - { - return false; - } - - bool visit(const SupportsActionTest<PretendAction> &) const - { - return false; - } - - bool visit(const SupportsActionTest<FetchAction> &) const - { - return false; - } - - bool visit(const SupportsActionTest<PretendFetchAction> &) const - { - return false; - } - - bool visit(const SupportsActionTest<InstallAction> &) const - { - return false; - } - }; -} - bool InstalledUnpackagedRepository::some_ids_might_support_action(const SupportsActionTestBase & test) const { - SomeIDsMightSupportVisitor v; - return test.accept_returning<bool>(v); + return test.make_accept_returning( + [&] (const SupportsActionTest<UninstallAction> &) { return true; }, + [&] (const SupportsActionTest<ConfigAction> &) { return false; }, + [&] (const SupportsActionTest<InfoAction> &) { return false; }, + [&] (const SupportsActionTest<PretendAction> &) { return false; }, + [&] (const SupportsActionTest<FetchAction> &) { return false; }, + [&] (const SupportsActionTest<PretendFetchAction> &) { return false; }, + [&] (const SupportsActionTest<InstallAction> &) { return false; } + ); } bool |