aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2013-05-31 11:18:59 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2013-06-04 07:40:47 +0100
commit5f03e4a9ccc71b027f09f93f3e48ed399ee38281 (patch)
tree0526be6925efcb153a7681ffcb9ab2ad2977f214
parent69b7b1d8961503771d03217e41669ca12e6852b5 (diff)
downloadpaludis-5f03e4a9ccc71b027f09f93f3e48ed399ee38281.tar.gz
paludis-5f03e4a9ccc71b027f09f93f3e48ed399ee38281.tar.xz
Convert to fancy new visitors
-rw-r--r--src/clients/cave/cmd_contents.cc63
-rw-r--r--src/clients/cave/cmd_display_resolution.cc239
-rw-r--r--src/clients/cave/cmd_execute_resolution.cc131
3 files changed, 139 insertions, 294 deletions
diff --git a/src/clients/cave/cmd_contents.cc b/src/clients/cave/cmd_contents.cc
index e893005..46e35c4 100644
--- a/src/clients/cave/cmd_contents.cc
+++ b/src/clients/cave/cmd_contents.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008, 2009, 2010, 2011 Ciaran McCreesh
+ * Copyright (c) 2008, 2009, 2010, 2011, 2013 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -77,41 +77,34 @@ namespace
}
};
- struct StringifyContentsEntry
+ std::string stringify_contents_entry(const std::shared_ptr<const ContentsEntry> & entry)
{
- std::string visit(const ContentsFileEntry & e) const
- {
- return fuc(fs_file(),
- fv<'p'>(e.part_key()
- ? stringify(e.part_key()->parse_value())
- : ""),
- fv<'s'>(stringify(e.location_key()->parse_value())));
- }
-
- std::string visit(const ContentsDirEntry & e) const
- {
- return fuc(fs_dir(), fv<'s'>(stringify(e.location_key()->parse_value())));
- }
-
- std::string visit(const ContentsSymEntry & e) const
- {
- return fuc(fs_sym(),
- fv<'p'>(e.part_key()
- ? stringify(e.part_key()->parse_value())
- : ""),
- fv<'s'>(stringify(e.location_key()->parse_value())),
- fv<'t'>(stringify(e.target_key()->parse_value())));
- }
-
- std::string visit(const ContentsOtherEntry & e) const
- {
- return fuc(fs_other(), fv<'s'>(stringify(e.location_key()->parse_value())));
- }
- };
-
- std::string stringify_contents_entry(const std::shared_ptr<const ContentsEntry> & e)
- {
- return e->accept_returning<std::string>(StringifyContentsEntry());
+ return entry->make_accept_returning(
+ [&] (const ContentsFileEntry & e) {
+ return fuc(fs_file(),
+ fv<'p'>(e.part_key()
+ ? stringify(e.part_key()->parse_value())
+ : ""),
+ fv<'s'>(stringify(e.location_key()->parse_value())));
+ },
+
+ [&] (const ContentsDirEntry & e) {
+ return fuc(fs_dir(), fv<'s'>(stringify(e.location_key()->parse_value())));
+ },
+
+ [&] (const ContentsSymEntry & e) {
+ return fuc(fs_sym(),
+ fv<'p'>(e.part_key()
+ ? stringify(e.part_key()->parse_value())
+ : ""),
+ fv<'s'>(stringify(e.location_key()->parse_value())),
+ fv<'t'>(stringify(e.target_key()->parse_value())));
+ },
+
+ [&] (const ContentsOtherEntry & e) {
+ return fuc(fs_other(), fv<'s'>(stringify(e.location_key()->parse_value())));
+ }
+ );
}
}
diff --git a/src/clients/cave/cmd_display_resolution.cc b/src/clients/cave/cmd_display_resolution.cc
index ea0549a..20fa2a9 100644
--- a/src/clients/cave/cmd_display_resolution.cc
+++ b/src/clients/cave/cmd_display_resolution.cc
@@ -291,42 +291,16 @@ namespace
}
};
- struct IDForDecisionOrNullVisitor
+ const std::shared_ptr<const PackageID> id_for_decision_or_null(const Decision & decision)
{
- const std::shared_ptr<const PackageID> visit(const ExistingNoChangeDecision & d) const
- {
- return d.existing_id();
- }
-
- const std::shared_ptr<const PackageID> visit(const BreakDecision & d) const
- {
- return d.existing_id();
- }
-
- const std::shared_ptr<const PackageID> visit(const ChangesToMakeDecision & d) const
- {
- return d.origin_id();
- }
-
- const std::shared_ptr<const PackageID> visit(const UnableToMakeDecision &) const
- {
- return nullptr;
- }
-
- const std::shared_ptr<const PackageID> visit(const RemoveDecision &) const
- {
- return nullptr;
- }
-
- const std::shared_ptr<const PackageID> visit(const NothingNoChangeDecision &) const
- {
- return nullptr;
- }
- };
-
- const std::shared_ptr<const PackageID> id_for_decision_or_null(const Decision & d)
- {
- return d.accept_returning<std::shared_ptr<const PackageID> >(IDForDecisionOrNullVisitor());
+ return decision.make_accept_returning(
+ [&] (const ExistingNoChangeDecision & d) { return d.existing_id(); },
+ [&] (const BreakDecision & d) { return d.existing_id(); },
+ [&] (const ChangesToMakeDecision & d) { return d.origin_id(); },
+ [&] (const UnableToMakeDecision &) { return nullptr; },
+ [&] (const RemoveDecision &) { return nullptr; },
+ [&] (const NothingNoChangeDecision &) { return nullptr; }
+ );
}
bool decision_matches_spec(
@@ -426,73 +400,64 @@ namespace
}
}
- struct DisplayExplanationDecisionVisitor
+ void display_explanation_decision(const Decision & decision)
{
- void visit(const ExistingNoChangeDecision & d) const
- {
- cout << fuc(fs_explanation_decision_heading());
- if (d.taken())
- cout << fuc(fs_explanation_decision_existing_taken(), fv<'i'>(stringify(*d.existing_id())));
- else
- cout << fuc(fs_explanation_decision_existing_untaken(), fv<'i'>(stringify(*d.existing_id())));
- }
-
- void visit(const RemoveDecision & d) const
- {
- cout << fuc(fs_explanation_decision_heading());
- if (d.taken())
- cout << fuc(fs_explanation_decision_remove_taken());
- else
- cout << fuc(fs_explanation_decision_remove_untaken());
+ decision.make_accept(
+ [&] (const ExistingNoChangeDecision & d) {
+ cout << fuc(fs_explanation_decision_heading());
+ if (d.taken())
+ cout << fuc(fs_explanation_decision_existing_taken(), fv<'i'>(stringify(*d.existing_id())));
+ else
+ cout << fuc(fs_explanation_decision_existing_untaken(), fv<'i'>(stringify(*d.existing_id())));
+ },
- for (PackageIDSequence::ConstIterator i(d.ids()->begin()), i_end(d.ids()->end()) ;
- i != i_end ; ++i)
- cout << fuc(fs_explanation_decision_remove_id(), fv<'i'>(stringify(**i)));
- }
+ [&] (const RemoveDecision & d) {
+ cout << fuc(fs_explanation_decision_heading());
+ if (d.taken())
+ cout << fuc(fs_explanation_decision_remove_taken());
+ else
+ cout << fuc(fs_explanation_decision_remove_untaken());
- void visit(const NothingNoChangeDecision &) const
- {
- cout << fuc(fs_explanation_decision_heading());
- cout << fuc(fs_explanation_decision_nothing());
- }
+ for (PackageIDSequence::ConstIterator i(d.ids()->begin()), i_end(d.ids()->end()) ;
+ i != i_end ; ++i)
+ cout << fuc(fs_explanation_decision_remove_id(), fv<'i'>(stringify(**i)));
+ },
- void visit(const ChangesToMakeDecision & d) const
- {
- if (d.taken())
- cout << fuc(fs_explanation_decision_heading());
- else
- cout << fuc(fs_explanation_decision_untaken_heading());
+ [&] (const NothingNoChangeDecision &) {
+ cout << fuc(fs_explanation_decision_heading());
+ cout << fuc(fs_explanation_decision_nothing());
+ },
- cout << fuc(fs_explanation_decision_change_origin(), fv<'i'>(stringify(*d.origin_id())));
- if (d.if_via_new_binary_in())
- cout << fuc(fs_explanation_decision_change_via(), fv<'r'>(stringify(*d.if_via_new_binary_in())));
- cout << fuc(fs_explanation_decision_change_destination(), fv<'r'>(stringify(d.destination()->repository())));
+ [&] (const ChangesToMakeDecision & d) {
+ if (d.taken())
+ cout << fuc(fs_explanation_decision_heading());
+ else
+ cout << fuc(fs_explanation_decision_untaken_heading());
- for (PackageIDSequence::ConstIterator i(d.destination()->replacing()->begin()), i_end(d.destination()->replacing()->end()) ;
- i != i_end ; ++i)
- cout << fuc(fs_explanation_decision_change_replacing(), fv<'i'>(stringify(**i)));
- }
+ cout << fuc(fs_explanation_decision_change_origin(), fv<'i'>(stringify(*d.origin_id())));
+ if (d.if_via_new_binary_in())
+ cout << fuc(fs_explanation_decision_change_via(), fv<'r'>(stringify(*d.if_via_new_binary_in())));
+ cout << fuc(fs_explanation_decision_change_destination(), fv<'r'>(stringify(d.destination()->repository())));
- void visit(const UnableToMakeDecision & d) const
- {
- if (d.taken())
- cout << fuc(fs_explanation_decision_unable_taken());
- else
- cout << fuc(fs_explanation_decision_unable_untaken());
- }
+ for (PackageIDSequence::ConstIterator i(d.destination()->replacing()->begin()), i_end(d.destination()->replacing()->end()) ;
+ i != i_end ; ++i)
+ cout << fuc(fs_explanation_decision_change_replacing(), fv<'i'>(stringify(**i)));
+ },
- void visit(const BreakDecision & d) const
- {
- if (d.taken())
- cout << fuc(fs_explanation_decision_break_taken(), fv<'i'>(stringify(*d.existing_id())));
- else
- cout << fuc(fs_explanation_decision_break_untaken(), fv<'i'>(stringify(*d.existing_id())));
- }
- };
+ [&] (const UnableToMakeDecision & d) {
+ if (d.taken())
+ cout << fuc(fs_explanation_decision_unable_taken());
+ else
+ cout << fuc(fs_explanation_decision_unable_untaken());
+ },
- void display_explanation_decision(const Decision & decision)
- {
- decision.accept(DisplayExplanationDecisionVisitor());
+ [&] (const BreakDecision & d) {
+ if (d.taken())
+ cout << fuc(fs_explanation_decision_break_taken(), fv<'i'>(stringify(*d.existing_id())));
+ else
+ cout << fuc(fs_explanation_decision_break_untaken(), fv<'i'>(stringify(*d.existing_id())));
+ }
+ );
}
void display_explanations(
@@ -823,42 +788,16 @@ namespace
cout << fuc(fs_reasons_end());
}
- struct DisplayConfirmationVisitor
- {
- std::string visit(const DowngradeConfirmation &) const
- {
- return "--permit-downgrade";
- }
-
- std::string visit(const NotBestConfirmation &) const
- {
- return "--permit-old-version";
- }
-
- std::string visit(const BreakConfirmation &) const
- {
- return "--uninstalls-may-break or --remove-if-dependent";
- }
-
- std::string visit(const RemoveSystemPackageConfirmation &) const
- {
- return "--uninstalls-may-break system";
- }
-
- std::string visit(const MaskedConfirmation &) const
- {
- return "being unmasked";
- }
-
- std::string visit(const ChangedChoicesConfirmation &) const
- {
- return "user configuration changes";
- }
- };
-
std::string stringify_confirmation(const RequiredConfirmation & c)
{
- return c.accept_returning<std::string>(DisplayConfirmationVisitor());
+ return c.make_accept_returning(
+ [&] (const DowngradeConfirmation &) { return "--permit-downgrade"; },
+ [&] (const NotBestConfirmation &) { return "--permit-old-version"; },
+ [&] (const BreakConfirmation &) { return "--uninstalls-may-break or --remove-if-dependent"; },
+ [&] (const RemoveSystemPackageConfirmation &) { return "--uninstalls-may-break system"; },
+ [&] (const MaskedConfirmation &) { return "being unmasked"; },
+ [&] (const ChangedChoicesConfirmation &) { return "user configuration changes"; }
+ );
}
void display_confirmations(
@@ -901,51 +840,7 @@ namespace
cout << fuc(fs_take(), fv<'g'>(find_suggestion_groups(resolution, decision)));
}
- struct IsPurgeVisitor
- {
- bool visit(const TargetReason &) const
- {
- return false;
- }
-
- bool visit(const SetReason & r) const
- {
- return r.reason_for_set()->accept_returning<bool>(*this);
- }
-
- bool visit(const LikeOtherDestinationTypeReason & r) const
- {
- return r.reason_for_other()->accept_returning<bool>(*this);
- }
-
- bool visit(const PresetReason &) const
- {
- return false;
- }
-
- bool visit(const DependencyReason &) const
- {
- return false;
- }
-
- bool visit(const ViaBinaryReason &) const
- {
- return false;
- }
-
- bool visit(const DependentReason &) const
- {
- return false;
- }
-
- bool visit(const WasUsedByReason &) const
- {
- return true;
- }
- };
-
- void display_untaken_remove(
- const RemoveDecision &)
+ void display_untaken_remove(const RemoveDecision &)
{
cout << fuc(fs_take_purge());
}
diff --git a/src/clients/cave/cmd_execute_resolution.cc b/src/clients/cave/cmd_execute_resolution.cc
index 54ff330..9fc1d94 100644
--- a/src/clients/cave/cmd_execute_resolution.cc
+++ b/src/clients/cave/cmd_execute_resolution.cc
@@ -1028,35 +1028,6 @@ namespace
}
};
- struct ContinueAfterState
- {
- bool visit(const JobPendingState &) const
- {
- /* it's still pending because it's a circular dep that we ended up ignoring */
- return true;
- }
-
- bool visit(const JobActiveState &) const PALUDIS_ATTRIBUTE((noreturn))
- {
- throw InternalError(PALUDIS_HERE, "still active? how did that happen?");
- }
-
- bool visit(const JobSucceededState &) const
- {
- return true;
- }
-
- bool visit(const JobFailedState &) const
- {
- return false;
- }
-
- bool visit(const JobSkippedState &) const
- {
- return false;
- }
- };
-
struct ExistingStateVisitor
{
bool done;
@@ -1163,33 +1134,6 @@ namespace
cout << fuc(fs_already_action(), fv<'x'>(make_x_of_y(v.x, v.y, v.f, v.s)), fv<'s'>(state), fv<'t'>(v.text));
}
- struct MakeJobID
- {
- const std::shared_ptr<Environment> env;
-
- MakeJobID(const std::shared_ptr<Environment> & e) :
- env(e)
- {
- }
-
- std::string visit(const UninstallJob & j) const
- {
- return "uninstalling " + join(j.ids_to_remove_specs()->begin(), j.ids_to_remove_specs()->end(), ", ",
- std::bind(stringify_id_or_spec, env, std::placeholders::_1));
- }
-
- std::string visit(const InstallJob & j) const
- {
- return "installing " + stringify_id_or_spec(env, j.origin_id_spec()) + " to ::" + stringify(j.destination_repository_name())
- + maybe_replacing(env, ensequence(j.origin_id_spec()), j.replacing_specs());
- }
-
- std::string visit(const FetchJob & j) const
- {
- return "fetch " + stringify_id_or_spec(env, j.origin_id_spec());
- }
- };
-
struct GetOutputManager
{
const std::shared_ptr<OutputManager> visit(const JobActiveState & s) const
@@ -1218,34 +1162,6 @@ namespace
}
};
- struct CanStartState
- {
- bool visit(const JobSkippedState &) const
- {
- return true;
- }
-
- bool visit(const JobPendingState &) const
- {
- return false;
- }
-
- bool visit(const JobActiveState &) const
- {
- return false;
- }
-
- bool visit(const JobSucceededState &) const
- {
- return true;
- }
-
- bool visit(const JobFailedState &) const
- {
- return true;
- }
- };
-
struct ExecuteJobExecutive :
Executive
{
@@ -1309,7 +1225,21 @@ namespace
std::string unique_id() const
{
- return job->accept_returning<std::string>(MakeJobID(env));
+ return job->make_accept_returning(
+ [&] (const UninstallJob & j) {
+ return "uninstalling " + join(j.ids_to_remove_specs()->begin(), j.ids_to_remove_specs()->end(), ", ",
+ std::bind(stringify_id_or_spec, env, std::placeholders::_1));
+ },
+
+ [&] (const InstallJob & j) {
+ return "installing " + stringify_id_or_spec(env, j.origin_id_spec()) + " to ::" + stringify(j.destination_repository_name())
+ + maybe_replacing(env, ensequence(j.origin_id_spec()), j.replacing_specs());
+ },
+
+ [&] (const FetchJob & j) {
+ return "fetch " + stringify_id_or_spec(env, j.origin_id_spec());
+ }
+ );
}
bool can_run() const
@@ -1321,7 +1251,13 @@ namespace
continue;
const std::shared_ptr<const ExecuteJob> req(*lists->execute_job_list()->fetch(r->job_number()));
- if (! req->state()->accept_returning<bool>(CanStartState()))
+ if (! req->state()->make_accept_returning(
+ [&] (const JobSkippedState &) { return true; },
+ [&] (const JobPendingState &) { return false; },
+ [&] (const JobActiveState &) { return false; },
+ [&] (const JobSucceededState &) { return true; },
+ [&] (const JobFailedState &) { return true; }
+ ))
return false;
}
@@ -1380,7 +1316,28 @@ namespace
continue;
const std::shared_ptr<const ExecuteJob> req(*lists->execute_job_list()->fetch(r->job_number()));
- want = want && req->state()->accept_returning<bool>(ContinueAfterState());
+ want = want && req->state()->make_accept_returning(
+ [&] (const JobPendingState &) {
+ /* it's still pending because it's a circular dep that we ended up ignoring */
+ return true;
+ },
+
+ [&] (const JobActiveState &) -> bool {
+ throw InternalError(PALUDIS_HERE, "still active? how did that happen?");
+ },
+
+ [&] (const JobSucceededState &) {
+ return true;
+ },
+
+ [&] (const JobFailedState &) {
+ return false;
+ },
+
+ [&] (const JobSkippedState &) {
+ return false;
+ }
+ );
}
}
}