aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-03 19:32:59 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-03 19:32:59 +0100
commitab43c09cb67218faf3868a253aefa0f52dff241d (patch)
tree2549af2d3ebb88750897d1c64b041191408b590e
parente30daaa82a43e387ec22e0175f6c3faaf7da17e5 (diff)
downloadpaludis-ab43c09cb67218faf3868a253aefa0f52dff241d.tar.gz
paludis-ab43c09cb67218faf3868a253aefa0f52dff241d.tar.xz
move initial constraints to a function
-rw-r--r--paludis/resolver/constraint.cc6
-rw-r--r--paludis/resolver/constraint.hh2
-rw-r--r--paludis/resolver/resolver.cc36
-rw-r--r--paludis/resolver/resolver.hh3
-rw-r--r--paludis/resolver/resolver_functions.hh5
-rw-r--r--src/clients/cave/cmd_resolve.cc24
6 files changed, 35 insertions, 41 deletions
diff --git a/paludis/resolver/constraint.cc b/paludis/resolver/constraint.cc
index 910be49..6cb740c 100644
--- a/paludis/resolver/constraint.cc
+++ b/paludis/resolver/constraint.cc
@@ -85,6 +85,12 @@ Constraints::add(const std::tr1::shared_ptr<const Constraint> & c)
_imp->strictest_use_installed = std::min(_imp->strictest_use_installed, c->use_installed());
}
+bool
+Constraints::empty() const
+{
+ return _imp->constraints.empty();
+}
+
template class PrivateImplementationPattern<Constraints>;
template class WrappedForwardIterator<Constraints::ConstIteratorTag, const std::tr1::shared_ptr<const Constraint> >;
diff --git a/paludis/resolver/constraint.hh b/paludis/resolver/constraint.hh
index 5bafe7e..6b3d33c 100644
--- a/paludis/resolver/constraint.hh
+++ b/paludis/resolver/constraint.hh
@@ -65,6 +65,8 @@ namespace paludis
typedef WrappedForwardIterator<ConstIteratorTag, const std::tr1::shared_ptr<const Constraint> > ConstIterator;
ConstIterator begin() const PALUDIS_ATTRIBUTE((warn_unused_result));
ConstIterator end() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ bool empty() const PALUDIS_ATTRIBUTE((warn_unused_result));
};
}
diff --git a/paludis/resolver/resolver.cc b/paludis/resolver/resolver.cc
index 8d22e26..324aa2e 100644
--- a/paludis/resolver/resolver.cc
+++ b/paludis/resolver/resolver.cc
@@ -72,7 +72,6 @@ namespace paludis
const ResolverFunctions fns;
ResolutionsByQPN_SMap resolutions_by_qpn_s;
- InitialConstraints initial_constraints;
OrderedResolutionsList ordered_resolutions;
Implementation(const Environment * const e, const ResolverFunctions & f) :
@@ -910,11 +909,7 @@ Resolver::_unable_to_order_more() const
const std::tr1::shared_ptr<Constraints>
Resolver::_initial_constraints_for(const QPN_S & qpn_s) const
{
- InitialConstraints::const_iterator i(_imp->initial_constraints.find(qpn_s));
- if (i == _imp->initial_constraints.end())
- return make_shared_ptr(new Constraints);
- else
- return i->second;
+ return _imp->fns.get_initial_constraints_for_fn()(qpn_s);
}
void
@@ -930,8 +925,7 @@ Resolver::_made_wrong_decision(const QPN_S & qpn_s,
if (decision)
{
/* can we preload and restart? */
- InitialConstraints::const_iterator x(_imp->initial_constraints.find(qpn_s));
- if (x == _imp->initial_constraints.end())
+ if (_initial_constraints_for(qpn_s)->empty())
{
/* we've not already locked this to something. yes! */
_suggest_restart_with(qpn_s, resolution, constraint, decision);
@@ -972,24 +966,6 @@ Resolver::_make_constraint_for_preloading(
)));
}
-void
-Resolver::copy_initial_constraints_from(const Resolver & other)
-{
- for (InitialConstraints::const_iterator i(other._imp->initial_constraints.begin()),
- i_end(other._imp->initial_constraints.end()) ;
- i != i_end ; ++i)
- _imp->initial_constraints.insert(*i);
-}
-
-void
-Resolver::add_initial_constraint(const QPN_S & q, const std::tr1::shared_ptr<const Constraint> & c)
-{
- InitialConstraints::iterator i(_imp->initial_constraints.find(q));
- if (i == _imp->initial_constraints.end())
- i = _imp->initial_constraints.insert(std::make_pair(q, make_shared_ptr(new Constraints))).first;
- i->second->add(c);
-}
-
namespace
{
struct DesireStrengthFinder
@@ -1051,14 +1027,6 @@ Resolver::end() const
void
Resolver::dump(std::ostream & s, const bool show_deps) const
{
- s << "Initial Constraints:" << std::endl;
- for (InitialConstraints::const_iterator i(_imp->initial_constraints.begin()),
- i_end(_imp->initial_constraints.end()) ;
- i != i_end ; ++i)
- s << " [*] " << std::left << std::setw(30) << i->first << " " <<
- join(indirect_iterator(i->second->begin()), indirect_iterator(i->second->end()), ", ") << std::endl;
- s << std::endl;
-
s << "Resolutions by QPN:S:" << std::endl;
for (ResolutionsByQPN_SMap::const_iterator i(_imp->resolutions_by_qpn_s.begin()),
i_end(_imp->resolutions_by_qpn_s.end()) ;
diff --git a/paludis/resolver/resolver.hh b/paludis/resolver/resolver.hh
index 851891b..566fe6c 100644
--- a/paludis/resolver/resolver.hh
+++ b/paludis/resolver/resolver.hh
@@ -162,9 +162,6 @@ namespace paludis
void add_target(const PackageDepSpec &);
void add_target(const SetName &);
- void copy_initial_constraints_from(const Resolver &);
- void add_initial_constraint(const QPN_S &, const std::tr1::shared_ptr<const Constraint> &);
-
void resolve();
void dump(std::ostream &, const bool deps) const;
diff --git a/paludis/resolver/resolver_functions.hh b/paludis/resolver/resolver_functions.hh
index ad665dc..ac3b604 100644
--- a/paludis/resolver/resolver_functions.hh
+++ b/paludis/resolver/resolver_functions.hh
@@ -32,11 +32,15 @@ namespace paludis
{
namespace n
{
+ struct get_initial_constraints_for_fn;
struct get_use_installed_fn;
}
namespace resolver
{
+ typedef std::tr1::function<std::tr1::shared_ptr<Constraints> (
+ const QPN_S &)> GetInitialConstraintsFunction;
+
typedef std::tr1::function<UseInstalled (
const QPN_S &,
const PackageDepSpec &,
@@ -44,6 +48,7 @@ namespace paludis
struct ResolverFunctions
{
+ NamedValue<n::get_initial_constraints_for_fn, GetInitialConstraintsFunction> get_initial_constraints_for_fn;
NamedValue<n::get_use_installed_fn, GetUseInstalledFunction> get_use_installed_fn;
};
}
diff --git a/src/clients/cave/cmd_resolve.cc b/src/clients/cave/cmd_resolve.cc
index d9a216d..8f7da6f 100644
--- a/src/clients/cave/cmd_resolve.cc
+++ b/src/clients/cave/cmd_resolve.cc
@@ -34,11 +34,13 @@
#include <paludis/resolver/reason.hh>
#include <paludis/resolver/suggest_restart.hh>
#include <paludis/resolver/qpn_s.hh>
+#include <paludis/resolver/constraint.hh>
#include <paludis/user_dep_spec.hh>
#include <paludis/notifier_callback.hh>
#include <iostream>
#include <cstdlib>
+#include <map>
using namespace paludis;
using namespace paludis::resolver;
@@ -536,8 +538,20 @@ namespace
UseInstalledVisitor v(cmdline, false);
return reason->accept_returning<UseInstalled>(v);
}
+
+ typedef std::map<QPN_S, std::tr1::shared_ptr<Constraints> > InitialConstraints;
+
+ const std::tr1::shared_ptr<Constraints> initial_constraints_for_fn(const InitialConstraints & initial_constraints, const QPN_S & qpn_s)
+ {
+ InitialConstraints::const_iterator i(initial_constraints.find(qpn_s));
+ if (i == initial_constraints.end())
+ return make_shared_ptr(new Constraints);
+ else
+ return i->second;
+ }
}
+
bool
ResolveCommand::important() const
{
@@ -561,7 +575,11 @@ ResolveCommand::run(
int retcode(0);
+ InitialConstraints initial_constraints;
+
ResolverFunctions resolver_functions(make_named_values<ResolverFunctions>(
+ value_for<n::get_initial_constraints_for_fn>(std::tr1::bind(&initial_constraints_for_fn,
+ std::tr1::cref(initial_constraints), std::tr1::placeholders::_1)),
value_for<n::get_use_installed_fn>(std::tr1::bind(&use_installed_fn,
std::tr1::cref(cmdline), std::tr1::placeholders::_1, std::tr1::placeholders::_2, std::tr1::placeholders::_3))
));
@@ -584,10 +602,8 @@ ResolveCommand::run(
std::cout << "Restarting: for '" << e.qpn_s() << "' we had chosen '" << *e.previous_decision()
<< "' but new constraint '" << *e.problematic_constraint() << "' means we now want '"
<< *e.new_decision() << "' instead" << std::endl;
- std::tr1::shared_ptr<Resolver> new_resolver(new Resolver(env.get(), resolver_functions));
- new_resolver->copy_initial_constraints_from(*resolver);
- new_resolver->add_initial_constraint(e.qpn_s(), e.suggested_preset());
- resolver = new_resolver;
+ initial_constraints.insert(std::make_pair(e.qpn_s(), make_shared_ptr(new Constraints))).first->second->add(e.suggested_preset());
+ resolver = make_shared_ptr(new Resolver(env.get(), resolver_functions));
}
}