aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-06-17 22:55:54 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-06-17 22:55:54 +0100
commit92f80490a9f0c31e17455621a1b86111c0007224 (patch)
tree17f75d49d57645508bbed5bfdf0d5d28a719572b
parent06edded18b26bc8d604a0a3f18e71b303a31748a (diff)
downloadpaludis-92f80490a9f0c31e17455621a1b86111c0007224.tar.gz
paludis-92f80490a9f0c31e17455621a1b86111c0007224.tar.xz
remove some icky casts
-rw-r--r--paludis/resolver/decider.cc79
-rw-r--r--paludis/resolver/decisions.cc11
-rw-r--r--paludis/resolver/decisions.hh4
-rw-r--r--paludis/resolver/orderer.cc12
-rw-r--r--paludis/resolver/sanitised_dependencies.cc1
5 files changed, 64 insertions, 43 deletions
diff --git a/paludis/resolver/decider.cc b/paludis/resolver/decider.cc
index e6649cd..0371c5c 100644
--- a/paludis/resolver/decider.cc
+++ b/paludis/resolver/decider.cc
@@ -40,7 +40,6 @@
#include <paludis/util/enum_iterator.hh>
#include <paludis/util/indirect_iterator-impl.hh>
#include <paludis/util/tribool.hh>
-#include <paludis/util/simple_visitor_cast.hh>
#include <paludis/environment.hh>
#include <paludis/notifier_callback.hh>
#include <paludis/repository.hh>
@@ -1784,35 +1783,69 @@ Decider::_already_met(const SanitisedDependency & dep) const
return dep.spec().if_package();
}
-void
-Decider::_confirm(
- const std::tr1::shared_ptr<const Resolution> & resolution)
+namespace
{
- ChangesToMakeDecision * const changes_to_make_decision(simple_visitor_cast<ChangesToMakeDecision>(*resolution->decision()));
- BreakDecision * const break_decision(simple_visitor_cast<BreakDecision>(*resolution->decision()));
-
- if (changes_to_make_decision)
+ struct ConfirmVisitor
{
- if (! changes_to_make_decision->best())
+ const ResolverFunctions & fns;
+ const std::tr1::shared_ptr<const Resolution> resolution;
+
+ ConfirmVisitor(
+ const ResolverFunctions & f,
+ const std::tr1::shared_ptr<const Resolution> & r) :
+ fns(f),
+ resolution(r)
{
- const std::tr1::shared_ptr<RequiredConfirmation> c(new NotBestConfirmation);
- if (! _imp->fns.confirm_fn()(resolution, c))
- changes_to_make_decision->add_required_confirmation(c);
}
- if (ct_downgrade == changes_to_make_decision->change_type())
+ void visit(ChangesToMakeDecision & changes_to_make_decision) const
{
- const std::tr1::shared_ptr<DowngradeConfirmation> c(new DowngradeConfirmation);
- if (! _imp->fns.confirm_fn()(resolution, c))
- changes_to_make_decision->add_required_confirmation(c);
+ if (! changes_to_make_decision.best())
+ {
+ const std::tr1::shared_ptr<RequiredConfirmation> c(new NotBestConfirmation);
+ if (! fns.confirm_fn()(resolution, c))
+ changes_to_make_decision.add_required_confirmation(c);
+ }
+
+ if (ct_downgrade == changes_to_make_decision.change_type())
+ {
+ const std::tr1::shared_ptr<DowngradeConfirmation> c(new DowngradeConfirmation);
+ if (! fns.confirm_fn()(resolution, c))
+ changes_to_make_decision.add_required_confirmation(c);
+ }
}
- }
- else if (break_decision)
- {
- const std::tr1::shared_ptr<BreakConfirmation> c(new BreakConfirmation);
- if (! _imp->fns.confirm_fn()(resolution, c))
- break_decision->add_required_confirmation(c);
- }
+
+ void visit(BreakDecision & break_decision) const
+ {
+ const std::tr1::shared_ptr<BreakConfirmation> c(new BreakConfirmation);
+ if (! fns.confirm_fn()(resolution, c))
+ break_decision.add_required_confirmation(c);
+ }
+
+ void visit(UnableToMakeDecision &) const
+ {
+ }
+
+ void visit(ExistingNoChangeDecision &) const
+ {
+ }
+
+ void visit(NothingNoChangeDecision &) const
+ {
+ }
+
+ void visit(RemoveDecision &) const
+ {
+ /* remove confirms are done elsewhere */
+ }
+ };
+}
+
+void
+Decider::_confirm(
+ const std::tr1::shared_ptr<const Resolution> & resolution)
+{
+ resolution->decision()->accept(ConfirmVisitor(_imp->fns, resolution));
}
diff --git a/paludis/resolver/decisions.cc b/paludis/resolver/decisions.cc
index 5942b86..2dda588 100644
--- a/paludis/resolver/decisions.cc
+++ b/paludis/resolver/decisions.cc
@@ -137,17 +137,6 @@ Decisions<Decision_, Notes_>::push_back(
}
template <typename Decision_, typename Notes_>
-void
-Decisions<Decision_, Notes_>::cast_push_back(
- const std::tr1::shared_ptr<const Decision> & d,
- const Notes_ & n)
-{
- if (! simple_visitor_cast<const Decision_>(*d))
- throw InternalError(PALUDIS_HERE, "Wrong Decision type");
- push_back(std::tr1::static_pointer_cast<const Decision_>(d), n);
-}
-
-template <typename Decision_, typename Notes_>
typename Decisions<Decision_, Notes_>::ConstIterator
Decisions<Decision_, Notes_>::begin() const
{
diff --git a/paludis/resolver/decisions.hh b/paludis/resolver/decisions.hh
index 65139b5..939abd7 100644
--- a/paludis/resolver/decisions.hh
+++ b/paludis/resolver/decisions.hh
@@ -62,10 +62,6 @@ namespace paludis
const std::tr1::shared_ptr<const Decision_> &,
const Notes_ & = static_cast<NoType<0u> *>(0));
- void cast_push_back(
- const std::tr1::shared_ptr<const Decision> &,
- const Notes_ & = static_cast<NoType<0u> *>(0));
-
typedef DecisionsConstIteratorTag<Decision_, Notes_> ConstIteratorTag;
typedef WrappedForwardIterator<ConstIteratorTag,
typename DecisionsIteratorValueType<Decision_, Notes_>::Type> ConstIterator;
diff --git a/paludis/resolver/orderer.cc b/paludis/resolver/orderer.cc
index cd6cbc4..76c4507 100644
--- a/paludis/resolver/orderer.cc
+++ b/paludis/resolver/orderer.cc
@@ -113,9 +113,11 @@ namespace
bool visit(const UnableToMakeDecision &)
{
if (decision->taken())
- resolved->taken_unable_to_make_decisions()->cast_push_back(decision);
+ resolved->taken_unable_to_make_decisions()->push_back(
+ std::tr1::static_pointer_cast<const UnableToMakeDecision>(decision));
else
- resolved->untaken_unable_to_make_decisions()->cast_push_back(decision);
+ resolved->untaken_unable_to_make_decisions()->push_back(
+ std::tr1::static_pointer_cast<const UnableToMakeDecision>(decision));
ignore_dependencies_from_resolvents.insert(resolvent);
@@ -145,7 +147,8 @@ namespace
}
else
{
- resolved->untaken_change_or_remove_decisions()->cast_push_back(decision);
+ resolved->untaken_change_or_remove_decisions()->push_back(
+ std::tr1::static_pointer_cast<const ChangesToMakeDecision>(decision));
return false;
}
}
@@ -166,7 +169,8 @@ namespace
bool visit(const BreakDecision & d)
{
if (d.required_confirmations_if_any())
- resolved->taken_unconfirmed_decisions()->cast_push_back(decision);
+ resolved->taken_unconfirmed_decisions()->push_back(
+ std::tr1::static_pointer_cast<const BreakDecision>(decision));
return false;
}
};
diff --git a/paludis/resolver/sanitised_dependencies.cc b/paludis/resolver/sanitised_dependencies.cc
index 8b3cd07..ca32d7b 100644
--- a/paludis/resolver/sanitised_dependencies.cc
+++ b/paludis/resolver/sanitised_dependencies.cc
@@ -32,7 +32,6 @@
#include <paludis/util/indirect_iterator-impl.hh>
#include <paludis/util/wrapped_output_iterator-impl.hh>
#include <paludis/util/sequence-impl.hh>
-#include <paludis/util/simple_visitor_cast.hh>
#include <paludis/util/log.hh>
#include <paludis/util/map.hh>
#include <paludis/spec_tree.hh>