aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-06-13 16:04:52 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-06-14 13:22:07 +0100
commitc8eae70be8510bdd42283c1ecac745af2f9a8a80 (patch)
treeacf6352e5f3b4dbad79f3f8ce29c6ec84dbd8591
parent4385b8c9283bb33f412281dd40da09569476cfc4 (diff)
downloadpaludis-c8eae70be8510bdd42283c1ecac745af2f9a8a80.tar.gz
paludis-c8eae70be8510bdd42283c1ecac745af2f9a8a80.tar.xz
Linearise, but in no particular order
-rw-r--r--paludis/resolver/decisions.cc36
-rw-r--r--paludis/resolver/decisions.hh10
-rw-r--r--paludis/resolver/lineariser.cc62
3 files changed, 99 insertions, 9 deletions
diff --git a/paludis/resolver/decisions.cc b/paludis/resolver/decisions.cc
index 624ad12..1203e44 100644
--- a/paludis/resolver/decisions.cc
+++ b/paludis/resolver/decisions.cc
@@ -18,7 +18,12 @@
*/
#include <paludis/resolver/decisions.hh>
+#include <paludis/resolver/decision.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
+#include <paludis/util/simple_visitor_cast.hh>
+#include <paludis/util/exception.hh>
+#include <paludis/util/stringify.hh>
+#include <list>
using namespace paludis;
using namespace paludis::resolver;
@@ -28,23 +33,40 @@ namespace paludis
#ifdef PALUDIS_NO_DOUBLE_TEMPLATE
template <>
#endif
- template <typename D_>
- struct Implementation<Decisions<D_> >
+ template <typename Decision_>
+ struct Implementation<Decisions<Decision_> >
{
+ std::list<std::tr1::shared_ptr<const Decision_> > values;
};
}
-template <typename D_>
-Decisions<D_>::Decisions() :
- PrivateImplementationPattern<Decisions<D_> >(new Implementation<Decisions<D_> >)
+template <typename Decision_>
+Decisions<Decision_>::Decisions() :
+ PrivateImplementationPattern<Decisions<Decision_> >(new Implementation<Decisions<Decision_> >)
{
}
-template <typename D_>
-Decisions<D_>::~Decisions()
+template <typename Decision_>
+Decisions<Decision_>::~Decisions()
{
}
+template <typename Decision_>
+void
+Decisions<Decision_>::push_back(const std::tr1::shared_ptr<const Decision_> & d)
+{
+ _imp->values.push_back(d);
+}
+
+template <typename Decision_>
+void
+Decisions<Decision_>::cast_push_back(const std::tr1::shared_ptr<const Decision> & d)
+{
+ if (! simple_visitor_cast<const Decision_>(*d))
+ throw InternalError(PALUDIS_HERE, "Wrong Decision type");
+ push_back(std::tr1::static_pointer_cast<const Decision_>(d));
+}
+
template class Decisions<UnableToMakeDecision>;
template class Decisions<ChangesToMakeDecision>;
template class Decisions<ChangeOrRemoveDecision>;
diff --git a/paludis/resolver/decisions.hh b/paludis/resolver/decisions.hh
index cb63713..fc1e89a 100644
--- a/paludis/resolver/decisions.hh
+++ b/paludis/resolver/decisions.hh
@@ -23,18 +23,24 @@
#include <paludis/resolver/decisions-fwd.hh>
#include <paludis/resolver/decision-fwd.hh>
#include <paludis/util/private_implementation_pattern.hh>
+#include <tr1/memory>
namespace paludis
{
namespace resolver
{
- template <typename D_>
+ template <typename Decision_>
class PALUDIS_VISIBLE Decisions :
- private PrivateImplementationPattern<Decisions<D_> >
+ private PrivateImplementationPattern<Decisions<Decision_> >
{
+ using PrivateImplementationPattern<Decisions<Decision_> >::_imp;
+
public:
Decisions();
~Decisions();
+
+ void push_back(const std::tr1::shared_ptr<const Decision_> &);
+ void cast_push_back(const std::tr1::shared_ptr<const Decision> &);
};
extern template class Decisions<UnableToMakeDecision>;
diff --git a/paludis/resolver/lineariser.cc b/paludis/resolver/lineariser.cc
index ee49a60..8f73505 100644
--- a/paludis/resolver/lineariser.cc
+++ b/paludis/resolver/lineariser.cc
@@ -18,7 +18,13 @@
*/
#include <paludis/resolver/lineariser.hh>
+#include <paludis/resolver/decision.hh>
+#include <paludis/resolver/decisions.hh>
+#include <paludis/resolver/resolutions.hh>
+#include <paludis/resolver/resolution.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
+#include <paludis/util/exception.hh>
+#include <paludis/util/stringify.hh>
using namespace paludis;
using namespace paludis::resolver;
@@ -46,8 +52,64 @@ Lineariser::~Lineariser()
{
}
+namespace
+{
+ struct DecisionDispatcher
+ {
+ const std::tr1::shared_ptr<Resolved> resolved;
+ const std::tr1::shared_ptr<const Decision> decision;
+
+ DecisionDispatcher(
+ const std::tr1::shared_ptr<Resolved> & r,
+ const std::tr1::shared_ptr<const Decision> & d) :
+ resolved(r),
+ decision(d)
+ {
+ }
+
+ void visit(const UnableToMakeDecision &)
+ {
+ if (decision->taken())
+ resolved->taken_unable_to_make_decisions()->cast_push_back(decision);
+ else
+ resolved->untaken_unable_to_make_decisions()->cast_push_back(decision);
+ }
+
+ void visit(const NothingNoChangeDecision &)
+ {
+ }
+
+ void visit(const ExistingNoChangeDecision &)
+ {
+ }
+
+ void visit(const ChangesToMakeDecision &)
+ {
+ if (decision->taken())
+ resolved->display_change_or_remove_decisions()->cast_push_back(decision);
+ else
+ resolved->untaken_change_or_remove_decisions()->cast_push_back(decision);
+ }
+
+ void visit(const RemoveDecision &)
+ {
+ if (decision->taken())
+ resolved->display_change_or_remove_decisions()->cast_push_back(decision);
+ else
+ throw InternalError(PALUDIS_HERE, "untaken RemoveDecision");
+ }
+ };
+}
+
void
Lineariser::resolve()
{
+ for (Resolutions::ConstIterator r(_imp->resolved->resolutions()->begin()),
+ r_end(_imp->resolved->resolutions()->end()) ;
+ r != r_end ; ++r)
+ {
+ DecisionDispatcher decision_dispatcher(_imp->resolved, (*r)->decision());
+ (*r)->decision()->accept(decision_dispatcher);
+ }
}