aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-09-19 20:34:56 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-09-19 20:34:56 +0100
commit99f4d0b5d3262844f1f4c9f1461d966a88e7b391 (patch)
tree1085f6dad07c0225300c53ac54e55d677dd81cc9
parent673b696a13c3cf7049df4b8810397aedaa1c3d14 (diff)
downloadpaludis-99f4d0b5d3262844f1f4c9f1461d966a88e7b391.tar.gz
paludis-99f4d0b5d3262844f1f4c9f1461d966a88e7b391.tar.xz
Move destination types back into a container
-rw-r--r--paludis/resolver/destinations.cc55
-rw-r--r--paludis/resolver/destinations.hh26
-rw-r--r--paludis/resolver/resolver.cc19
-rw-r--r--src/clients/cave/cmd_display_resolution.cc30
-rw-r--r--src/clients/cave/cmd_execute_resolution.cc8
-rw-r--r--src/clients/cave/cmd_resolve_dump.cc16
6 files changed, 113 insertions, 41 deletions
diff --git a/paludis/resolver/destinations.cc b/paludis/resolver/destinations.cc
index 62b4423..a9f1cca 100644
--- a/paludis/resolver/destinations.cc
+++ b/paludis/resolver/destinations.cc
@@ -24,19 +24,57 @@
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/join.hh>
#include <paludis/util/make_named_values.hh>
+#include <paludis/util/enum_iterator.hh>
+#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/package_id.hh>
#include <ostream>
#include <sstream>
+#include <vector>
using namespace paludis;
using namespace paludis::resolver;
+namespace paludis
+{
+ template <>
+ struct Implementation<Destinations>
+ {
+ std::vector<std::tr1::shared_ptr<const Destination> > destinations;
+
+ Implementation() :
+ destinations(static_cast<int>(last_dt), make_null_shared_ptr())
+ {
+ }
+ };
+}
+
+Destinations::Destinations() :
+ PrivateImplementationPattern<Destinations>(new Implementation<Destinations>)
+{
+}
+
+Destinations::~Destinations()
+{
+}
+
+const std::tr1::shared_ptr<const Destination>
+Destinations::by_type(const DestinationType t) const
+{
+ return _imp->destinations.at(static_cast<int>(t));
+}
+
+void
+Destinations::set_destination_type(const DestinationType t, const std::tr1::shared_ptr<const Destination> & d)
+{
+ _imp->destinations.at(t) = d;
+}
+
void
Destinations::serialise(Serialiser & s) const
{
- s.object("Destinations")
- .member(SerialiserFlags<serialise::might_be_null>(), "slash", slash())
- ;
+ SerialiserObjectWriter w(s.object("Destinations"));
+ for (EnumIterator<DestinationType> t, t_end(last_dt) ; t != t_end ; ++t)
+ w.member(SerialiserFlags<serialise::might_be_null>(), stringify(*t), by_type(*t));
}
void
@@ -51,10 +89,13 @@ Destination::serialise(Serialiser & s) const
const std::tr1::shared_ptr<Destinations>
Destinations::deserialise(Deserialisation & d)
{
+ const std::tr1::shared_ptr<Destinations> result(new Destinations);
Deserialisator v(d, "Destinations");
- return make_shared_ptr(new Destinations(make_named_values<Destinations>(
- value_for<n::slash>(v.member<std::tr1::shared_ptr<Destination> >("slash"))
- )));
+
+ for (EnumIterator<DestinationType> t, t_end(last_dt) ; t != t_end ; ++t)
+ result->set_destination_type(*t, v.member<std::tr1::shared_ptr<Destination> >(stringify(*t)));
+
+ return result;
}
const std::tr1::shared_ptr<Destination>
@@ -73,3 +114,5 @@ Destination::deserialise(Deserialisation & d)
)));
}
+template class PrivateImplementationPattern<Destinations>;
+
diff --git a/paludis/resolver/destinations.hh b/paludis/resolver/destinations.hh
index 8c327dc..8c1c10f 100644
--- a/paludis/resolver/destinations.hh
+++ b/paludis/resolver/destinations.hh
@@ -22,7 +22,9 @@
#include <paludis/resolver/destinations-fwd.hh>
#include <paludis/resolver/serialise-fwd.hh>
+#include <paludis/resolver/destination_types-fwd.hh>
#include <paludis/util/named_value.hh>
+#include <paludis/util/private_implementation_pattern.hh>
#include <paludis/name.hh>
#include <paludis/package_id-fwd.hh>
#include <tr1/memory>
@@ -33,7 +35,6 @@ namespace paludis
{
struct replacing;
struct repository;
- struct slash;
}
namespace resolver
@@ -49,16 +50,29 @@ namespace paludis
Deserialisation & d) PALUDIS_ATTRIBUTE((warn_unused_result));
};
- struct Destinations
+ class PALUDIS_VISIBLE Destinations :
+ private PrivateImplementationPattern<Destinations>
{
- NamedValue<n::slash, std::tr1::shared_ptr<Destination> > slash;
+ public:
+ Destinations();
+ ~Destinations();
- void serialise(Serialiser &) const;
+ const std::tr1::shared_ptr<const Destination> by_type(const DestinationType)
+ const PALUDIS_ATTRIBUTE((warn_unused_result));
- static const std::tr1::shared_ptr<Destinations> deserialise(
- Deserialisation & d) PALUDIS_ATTRIBUTE((warn_unused_result));
+ void set_destination_type(const DestinationType, const std::tr1::shared_ptr<const Destination> &);
+
+ void serialise(Serialiser &) const;
+
+ static const std::tr1::shared_ptr<Destinations> deserialise(
+ Deserialisation & d) PALUDIS_ATTRIBUTE((warn_unused_result));
};
}
+
+#ifdef PALUDIS_HAVE_EXTERN_TEMPLATE
+ extern template class PrivateImplementationPattern<resolver::Destinations>;
+#endif
+
}
#endif
diff --git a/paludis/resolver/resolver.cc b/paludis/resolver/resolver.cc
index ba36e71..981c759 100644
--- a/paludis/resolver/resolver.cc
+++ b/paludis/resolver/resolver.cc
@@ -192,24 +192,27 @@ Resolver::_make_destinations_for(
const QPN_S & qpn_s,
const std::tr1::shared_ptr<const Resolution> & resolution) const
{
+ std::tr1::shared_ptr<Destinations> result(new Destinations);
+
switch (resolution->decision()->kind())
{
case dk_existing_no_change:
case dk_nothing_no_change:
case dk_unable_to_decide:
- return make_shared_ptr(new Destinations(make_named_values<Destinations>(
- value_for<n::slash>(make_null_shared_ptr())
- )));
+ case last_dk:
+ break;
case dk_changes_to_make:
- case last_dk:
+ {
+ bool requires_slash(true); // (resolution->constraints()->for_destination_type(dt_slash)->required());
+ if (requires_slash)
+ result->set_destination_type(dt_slash, _make_slash_destination_for(qpn_s, resolution));
+ }
break;
}
- bool requires_slash(true); // (resolution->constraints()->for_destination_type(dt_slash)->required());
- return make_shared_ptr(new Destinations(make_named_values<Destinations>(
- value_for<n::slash>(requires_slash ? _make_slash_destination_for(qpn_s, resolution) : make_null_shared_ptr())
- )));
+
+ return result;
}
diff --git a/src/clients/cave/cmd_display_resolution.cc b/src/clients/cave/cmd_display_resolution.cc
index 54216b2..df84d1c 100644
--- a/src/clients/cave/cmd_display_resolution.cc
+++ b/src/clients/cave/cmd_display_resolution.cc
@@ -255,20 +255,20 @@ namespace
other_slots(false);
std::tr1::shared_ptr<const PackageID> old_id;
- if ((*c)->destinations()->slash())
+ if ((*c)->destinations()->by_type(dt_slash))
{
- if ((*c)->destinations()->slash()->replacing()->empty())
+ if ((*c)->destinations()->by_type(dt_slash)->replacing()->empty())
{
is_new = true;
const std::tr1::shared_ptr<const PackageIDSequence> others((*env)[selection::SomeArbitraryVersion(
generator::Package(id->name()) &
- generator::InRepository((*c)->destinations()->slash()->repository())
+ generator::InRepository((*c)->destinations()->by_type(dt_slash)->repository())
)]);
other_slots = ! others->empty();
}
else
- for (PackageIDSequence::ConstIterator x((*c)->destinations()->slash()->replacing()->begin()),
- x_end((*c)->destinations()->slash()->replacing()->end()) ;
+ for (PackageIDSequence::ConstIterator x((*c)->destinations()->by_type(dt_slash)->replacing()->begin()),
+ x_end((*c)->destinations()->by_type(dt_slash)->replacing()->end()) ;
x != x_end ; ++x)
{
old_id = *x;
@@ -307,15 +307,15 @@ namespace
cout << c::normal() << " " << id->canonical_form(idcf_version);
- if ((*c)->destinations()->slash())
+ if ((*c)->destinations()->by_type(dt_slash))
{
- cout << " to ::" << (*c)->destinations()->slash()->repository();
- if (! (*c)->destinations()->slash()->replacing()->empty())
+ cout << " to ::" << (*c)->destinations()->by_type(dt_slash)->repository();
+ if (! (*c)->destinations()->by_type(dt_slash)->replacing()->empty())
{
cout << " replacing";
bool first(true);
- for (PackageIDSequence::ConstIterator x((*c)->destinations()->slash()->replacing()->begin()),
- x_end((*c)->destinations()->slash()->replacing()->end()) ;
+ for (PackageIDSequence::ConstIterator x((*c)->destinations()->by_type(dt_slash)->replacing()->begin()),
+ x_end((*c)->destinations()->by_type(dt_slash)->replacing()->end()) ;
x != x_end ; ++x)
{
bool different(false);
@@ -623,12 +623,12 @@ namespace
{
std::cout << " The decision made was:" << std::endl;
std::cout << " Use " << *(*r)->decision()->if_package_id() << std::endl;
- if ((*r)->destinations()->slash())
+ if ((*r)->destinations()->by_type(dt_slash))
{
- std::cout << " Install to / using repository " << (*r)->destinations()->slash()->repository() << std::endl;
- if (! (*r)->destinations()->slash()->replacing()->empty())
- for (PackageIDSequence::ConstIterator x((*r)->destinations()->slash()->replacing()->begin()),
- x_end((*r)->destinations()->slash()->replacing()->end()) ;
+ std::cout << " Install to / using repository " << (*r)->destinations()->by_type(dt_slash)->repository() << std::endl;
+ if (! (*r)->destinations()->by_type(dt_slash)->replacing()->empty())
+ for (PackageIDSequence::ConstIterator x((*r)->destinations()->by_type(dt_slash)->replacing()->begin()),
+ x_end((*r)->destinations()->by_type(dt_slash)->replacing()->end()) ;
x != x_end ; ++x)
std::cout << " Replacing " << **x << std::endl;
}
diff --git a/src/clients/cave/cmd_execute_resolution.cc b/src/clients/cave/cmd_execute_resolution.cc
index d82ba19..742661e 100644
--- a/src/clients/cave/cmd_execute_resolution.cc
+++ b/src/clients/cave/cmd_execute_resolution.cc
@@ -196,9 +196,9 @@ namespace
command.append(" install --hooks ");
command.append(stringify(id->uniquely_identifying_spec()));
- command.append(" --destination " + stringify(r->destinations()->slash()->repository()));
- for (PackageIDSequence::ConstIterator i(r->destinations()->slash()->replacing()->begin()),
- i_end(r->destinations()->slash()->replacing()->end()) ;
+ command.append(" --destination " + stringify(r->destinations()->by_type(dt_slash)->repository()));
+ for (PackageIDSequence::ConstIterator i(r->destinations()->by_type(dt_slash)->replacing()->begin()),
+ i_end(r->destinations()->by_type(dt_slash)->replacing()->end()) ;
i != i_end ; ++i)
command.append(" --replacing " + stringify((*i)->uniquely_identifying_spec()));
@@ -291,7 +291,7 @@ namespace
if (0 != retcode)
return retcode;
- if ((*c)->destinations()->slash())
+ if ((*c)->destinations()->by_type(dt_slash))
{
retcode = do_install_slash(env, cmdline, *c, x, y);
if (0 != retcode)
diff --git a/src/clients/cave/cmd_resolve_dump.cc b/src/clients/cave/cmd_resolve_dump.cc
index ed0e785..22a7e67 100644
--- a/src/clients/cave/cmd_resolve_dump.cc
+++ b/src/clients/cave/cmd_resolve_dump.cc
@@ -27,6 +27,7 @@
#include <paludis/resolver/destinations.hh>
#include <paludis/resolver/reason.hh>
#include <paludis/resolver/arrow.hh>
+#include <paludis/util/enum_iterator.hh>
#include <paludis/util/indirect_iterator-impl.hh>
#include <paludis/util/join.hh>
#include <paludis/util/stringify.hh>
@@ -86,8 +87,19 @@ namespace
{
std::stringstream ss;
ss << "Destinations(";
- if (d.slash())
- ss << "slash: " << *d.slash();
+ for (EnumIterator<DestinationType> t, t_end(last_dt) ; t != t_end ; ++t)
+ if (d.by_type(*t))
+ {
+ switch (*t)
+ {
+ case dt_slash:
+ ss << "slash: " << *d.by_type(*t);
+ break;
+
+ case last_dt:
+ break;
+ }
+ }
ss << ")";
s << ss.str();