aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-04-08 16:15:34 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-04-08 16:15:34 +0100
commit815e11334707b7322f904cf2e93a50b9f9aefa13 (patch)
tree28efb3354052f33747f50182baab859f0eeafc3d
parent8718a44f82a3aaf6dd1b445545ce6568e24bd5df (diff)
downloadpaludis-815e11334707b7322f904cf2e93a50b9f9aefa13.tar.gz
paludis-815e11334707b7322f904cf2e93a50b9f9aefa13.tar.xz
Move more logic into PackageDepSpec
-rw-r--r--paludis/dep_spec.cc360
-rw-r--r--paludis/dep_spec_data.cc402
-rw-r--r--paludis/dep_spec_data.hh112
3 files changed, 344 insertions, 530 deletions
diff --git a/paludis/dep_spec.cc b/paludis/dep_spec.cc
index 1943e58..e0de73a 100644
--- a/paludis/dep_spec.cc
+++ b/paludis/dep_spec.cc
@@ -21,6 +21,9 @@
#include <paludis/environment.hh>
#include <paludis/version_operator.hh>
#include <paludis/version_spec.hh>
+#include <paludis/dep_spec_data.hh>
+#include <paludis/package_dep_spec_requirement.hh>
+
#include <paludis/util/clone-impl.hh>
#include <paludis/util/log.hh>
#include <paludis/util/join.hh>
@@ -33,7 +36,8 @@
#include <paludis/util/iterator_funcs.hh>
#include <paludis/util/indirect_iterator-impl.hh>
#include <paludis/util/options.hh>
-#include <paludis/dep_spec_data.hh>
+#include <paludis/util/accept_visitor.hh>
+#include <paludis/util/make_null_shared_ptr.hh>
#include <functional>
#include <algorithm>
@@ -531,16 +535,74 @@ LabelsDepSpec<T_>::add_label(const std::shared_ptr<const T_> & item)
_imp->items.push_back(item);
}
+namespace
+{
+ template <typename T_>
+ struct Detect
+ {
+ bool visit(const T_ &) const
+ {
+ return true;
+ }
+
+ bool visit(const PackageDepSpecRequirement &) const
+ {
+ return false;
+ }
+ };
+
+ template <typename I_, typename P_>
+ I_ find_unique_if(I_ cur, I_ end, P_ pred)
+ {
+ I_ result(end);
+ for ( ; cur != end ; ++cur)
+ if (pred(*cur))
+ {
+ if (result != end)
+ return end;
+ else
+ result = cur;
+ }
+
+ return result;
+ }
+}
+
namespace paludis
{
template <>
struct Imp<PackageDepSpec>
{
const std::shared_ptr<const PackageDepSpecData> data;
+ std::shared_ptr<VersionRequirementSequence> all_versions;
+ std::shared_ptr<KeyRequirementSequence> all_keys;
+ std::shared_ptr<ChoiceRequirementSequence> all_choices;
Imp(const std::shared_ptr<const PackageDepSpecData> & d) :
data(d)
{
+ for (auto u(data->requirements()->begin()), u_end(data->requirements()->end()) ;
+ u != u_end ; ++u)
+ {
+ if ((*u)->accept_returning<bool>(Detect<VersionRequirement>()))
+ {
+ if (! all_versions)
+ all_versions = std::make_shared<VersionRequirementSequence>();
+ all_versions->push_back(std::static_pointer_cast<const VersionRequirement>(*u));
+ }
+ else if ((*u)->accept_returning<bool>(Detect<KeyRequirement>()))
+ {
+ if (! all_keys)
+ all_keys = std::make_shared<KeyRequirementSequence>();
+ all_keys->push_back(std::static_pointer_cast<const KeyRequirement>(*u));
+ }
+ else if ((*u)->accept_returning<bool>(Detect<ChoiceRequirement>()))
+ {
+ if (! all_choices)
+ all_choices = std::make_shared<ChoiceRequirementSequence>();
+ all_choices->push_back(std::static_pointer_cast<const ChoiceRequirement>(*u));
+ }
+ }
}
};
}
@@ -566,91 +628,341 @@ PackageDepSpec::PackageDepSpec(const PackageDepSpec & d) :
const std::string
PackageDepSpec::text() const
{
- return _imp->data->as_string();
+ std::ostringstream s;
+
+ if (all_version_requirements())
+ {
+ if (all_version_requirements()->begin() == all_version_requirements()->end())
+ {
+ }
+ else if (next(all_version_requirements()->begin()) == all_version_requirements()->end() &&
+ ! _imp->data->options()[pdsdo_always_use_ranged_deps])
+ {
+ if ((*all_version_requirements()->begin())->version_operator() == vo_stupid_equal_star ||
+ (*all_version_requirements()->begin())->version_operator() == vo_nice_equal_star)
+ s << "=";
+ else
+ s << (*all_version_requirements()->begin())->version_operator();
+ }
+ }
+
+ if (package_name_requirement())
+ s << package_name_requirement()->name();
+ else
+ {
+ if (category_name_part_requirement())
+ s << category_name_part_requirement()->name_part();
+ else
+ s << "*";
+
+ s << "/";
+
+ if (package_name_part_requirement())
+ s << package_name_part_requirement()->name_part();
+ else
+ s << "*";
+ }
+
+ if (all_version_requirements())
+ {
+ if (all_version_requirements()->begin() == all_version_requirements()->end())
+ {
+ }
+ else if (next(all_version_requirements()->begin()) == all_version_requirements()->end() &&
+ ! _imp->data->options()[pdsdo_always_use_ranged_deps])
+ {
+ s << "-" << (*all_version_requirements()->begin())->version_spec();
+ if ((*all_version_requirements()->begin())->version_operator() == vo_stupid_equal_star ||
+ (*all_version_requirements()->begin())->version_operator() == vo_nice_equal_star)
+ s << "*";
+ }
+ }
+
+ if (exact_slot_requirement())
+ {
+ if (exact_slot_requirement()->locked())
+ s << ":=";
+ else
+ s << ":";
+
+ s << stringify(exact_slot_requirement()->name());
+ }
+
+ if (any_slot_requirement())
+ {
+ if (any_slot_requirement()->locking())
+ s << ":=";
+ else
+ s << ":*";
+ }
+
+ std::string left, right;
+ bool need_arrow(false);
+
+ if (from_repository_requirement())
+ left = stringify(from_repository_requirement()->name());
+
+ if (in_repository_requirement())
+ right = stringify(in_repository_requirement()->name());
+
+ if (installed_at_path_requirement())
+ {
+ if (! right.empty())
+ {
+ need_arrow = true;
+ right.append("->");
+ }
+ right.append(stringify(installed_at_path_requirement()->path()));
+ }
+
+ if (installable_to_repository_requirement())
+ {
+ if (! right.empty())
+ {
+ need_arrow = true;
+ right.append("->");
+ }
+ if (installable_to_repository_requirement()->include_masked())
+ right.append(stringify(installable_to_repository_requirement()->name()) + "??");
+ else
+ right.append(stringify(installable_to_repository_requirement()->name()) + "?");
+ }
+
+ if (installable_to_path_requirement())
+ {
+ if (! right.empty())
+ {
+ need_arrow = true;
+ right.append("->");
+ }
+ if (installable_to_path_requirement()->include_masked())
+ right.append(stringify(installable_to_path_requirement()->path()) + "??");
+ else
+ right.append(stringify(installable_to_path_requirement()->path()) + "?");
+ }
+
+ if (need_arrow || ((! left.empty()) && (! right.empty())))
+ s << "::" << left << "->" << right;
+ else if (! right.empty())
+ s << "::" << right;
+ else if (! left.empty())
+ s << "::" << left << "->";
+
+ if (all_version_requirements())
+ {
+ if (all_version_requirements()->begin() == all_version_requirements()->end())
+ {
+ }
+ else if (next(all_version_requirements()->begin()) == all_version_requirements()->end() &&
+ ! _imp->data->options()[pdsdo_always_use_ranged_deps])
+ {
+ }
+ else
+ {
+ bool need_op(false);
+ s << "[";
+ for (auto r(all_version_requirements()->begin()), r_end(all_version_requirements()->end()) ; r != r_end ; ++r)
+ {
+ if (need_op)
+ {
+ do
+ {
+ switch ((*r)->combiner())
+ {
+ case vrc_and:
+ s << "&";
+ continue;
+
+ case vrc_or:
+ s << "|";
+ continue;
+
+ case last_vrc:
+ ;
+ }
+ throw InternalError(PALUDIS_HERE, "Bad version_requirements_mode");
+ } while (false);
+ }
+
+ if ((*r)->version_operator() == vo_stupid_equal_star || (*r)->version_operator() == vo_nice_equal_star)
+ s << "=";
+ else
+ s << (*r)->version_operator();
+
+ s << (*r)->version_spec();
+
+ if ((*r)->version_operator() == vo_stupid_equal_star || (*r)->version_operator() == vo_nice_equal_star)
+ s << "*";
+
+ need_op = true;
+ }
+ s << "]";
+ }
+ }
+
+ if (all_choice_requirements())
+ for (auto u(all_choice_requirements()->begin()), u_end(all_choice_requirements()->end()) ; u != u_end ; ++u)
+ s << (*u)->as_raw_string();
+
+ if (all_key_requirements())
+ for (auto u(all_key_requirements()->begin()), u_end(all_key_requirements()->end()) ; u != u_end ; ++u)
+ s << (*u)->as_raw_string();
+
+ return s.str();
}
const std::shared_ptr<const NameRequirement>
PackageDepSpec::package_name_requirement() const
{
- return _imp->data->package_name_requirement();
+ Detect<NameRequirement> v;
+ auto r(find_unique_if(indirect_iterator(_imp->data->requirements()->begin()),
+ indirect_iterator(_imp->data->requirements()->end()), accept_visitor_returning<bool>(v)));
+
+ if (r != indirect_iterator(_imp->data->requirements()->end()))
+ return std::static_pointer_cast<const NameRequirement>(*r.underlying_iterator());
+ else
+ return make_null_shared_ptr();
}
const std::shared_ptr<const PackageNamePartRequirement>
PackageDepSpec::package_name_part_requirement() const
{
- return _imp->data->package_name_part_requirement();
+ Detect<PackageNamePartRequirement> v;
+ auto r(find_unique_if(indirect_iterator(_imp->data->requirements()->begin()),
+ indirect_iterator(_imp->data->requirements()->end()), accept_visitor_returning<bool>(v)));
+
+ if (r != indirect_iterator(_imp->data->requirements()->end()))
+ return std::static_pointer_cast<const PackageNamePartRequirement>(*r.underlying_iterator());
+ else
+ return make_null_shared_ptr();
}
const std::shared_ptr<const CategoryNamePartRequirement>
PackageDepSpec::category_name_part_requirement() const
{
- return _imp->data->category_name_part_requirement();
+ Detect<CategoryNamePartRequirement> v;
+ auto r(find_unique_if(indirect_iterator(_imp->data->requirements()->begin()),
+ indirect_iterator(_imp->data->requirements()->end()), accept_visitor_returning<bool>(v)));
+
+ if (r != indirect_iterator(_imp->data->requirements()->end()))
+ return std::static_pointer_cast<const CategoryNamePartRequirement>(*r.underlying_iterator());
+ else
+ return make_null_shared_ptr();
}
const std::shared_ptr<const VersionRequirementSequence>
PackageDepSpec::all_version_requirements() const
{
- return _imp->data->all_version_requirements();
+ return _imp->all_versions;
}
-const std::shared_ptr<const AnySlotRequirement>
-PackageDepSpec::any_slot_requirement() const
+const std::shared_ptr<const ExactSlotRequirement>
+PackageDepSpec::exact_slot_requirement() const
{
- return _imp->data->any_slot_requirement();
+ Detect<ExactSlotRequirement> v;
+ auto r(find_unique_if(indirect_iterator(_imp->data->requirements()->begin()),
+ indirect_iterator(_imp->data->requirements()->end()), accept_visitor_returning<bool>(v)));
+
+ if (r != indirect_iterator(_imp->data->requirements()->end()))
+ return std::static_pointer_cast<const ExactSlotRequirement>(*r.underlying_iterator());
+ else
+ return make_null_shared_ptr();
}
-const std::shared_ptr<const ExactSlotRequirement>
-PackageDepSpec::exact_slot_requirement() const
+const std::shared_ptr<const AnySlotRequirement>
+PackageDepSpec::any_slot_requirement() const
{
- return _imp->data->exact_slot_requirement();
+ Detect<AnySlotRequirement> v;
+ auto r(find_unique_if(indirect_iterator(_imp->data->requirements()->begin()),
+ indirect_iterator(_imp->data->requirements()->end()), accept_visitor_returning<bool>(v)));
+
+ if (r != indirect_iterator(_imp->data->requirements()->end()))
+ return std::static_pointer_cast<const AnySlotRequirement>(*r.underlying_iterator());
+ else
+ return make_null_shared_ptr();
}
const std::shared_ptr<const InRepositoryRequirement>
PackageDepSpec::in_repository_requirement() const
{
- return _imp->data->in_repository_requirement();
+ Detect<InRepositoryRequirement> v;
+ auto r(find_unique_if(indirect_iterator(_imp->data->requirements()->begin()),
+ indirect_iterator(_imp->data->requirements()->end()), accept_visitor_returning<bool>(v)));
+
+ if (r != indirect_iterator(_imp->data->requirements()->end()))
+ return std::static_pointer_cast<const InRepositoryRequirement>(*r.underlying_iterator());
+ else
+ return make_null_shared_ptr();
}
const std::shared_ptr<const InstallableToRepositoryRequirement>
PackageDepSpec::installable_to_repository_requirement() const
{
- return _imp->data->installable_to_repository_requirement();
+ Detect<InstallableToRepositoryRequirement> v;
+ auto r(find_unique_if(indirect_iterator(_imp->data->requirements()->begin()),
+ indirect_iterator(_imp->data->requirements()->end()), accept_visitor_returning<bool>(v)));
+
+ if (r != indirect_iterator(_imp->data->requirements()->end()))
+ return std::static_pointer_cast<const InstallableToRepositoryRequirement>(*r.underlying_iterator());
+ else
+ return make_null_shared_ptr();
}
const std::shared_ptr<const FromRepositoryRequirement>
PackageDepSpec::from_repository_requirement() const
{
- return _imp->data->from_repository_requirement();
+ Detect<FromRepositoryRequirement> v;
+ auto r(find_unique_if(indirect_iterator(_imp->data->requirements()->begin()),
+ indirect_iterator(_imp->data->requirements()->end()), accept_visitor_returning<bool>(v)));
+
+ if (r != indirect_iterator(_imp->data->requirements()->end()))
+ return std::static_pointer_cast<const FromRepositoryRequirement>(*r.underlying_iterator());
+ else
+ return make_null_shared_ptr();
}
const std::shared_ptr<const InstalledAtPathRequirement>
PackageDepSpec::installed_at_path_requirement() const
{
- return _imp->data->installed_at_path_requirement();
+ Detect<InstalledAtPathRequirement> v;
+ auto r(find_unique_if(indirect_iterator(_imp->data->requirements()->begin()),
+ indirect_iterator(_imp->data->requirements()->end()), accept_visitor_returning<bool>(v)));
+
+ if (r != indirect_iterator(_imp->data->requirements()->end()))
+ return std::static_pointer_cast<const InstalledAtPathRequirement>(*r.underlying_iterator());
+ else
+ return make_null_shared_ptr();
}
const std::shared_ptr<const InstallableToPathRequirement>
PackageDepSpec::installable_to_path_requirement() const
{
- return _imp->data->installable_to_path_requirement();
-}
+ Detect<InstallableToPathRequirement> v;
+ auto r(find_unique_if(indirect_iterator(_imp->data->requirements()->begin()),
+ indirect_iterator(_imp->data->requirements()->end()), accept_visitor_returning<bool>(v)));
-const std::shared_ptr<const ChoiceRequirementSequence>
-PackageDepSpec::all_choice_requirements() const
-{
- return _imp->data->all_choice_requirements();
+ if (r != indirect_iterator(_imp->data->requirements()->end()))
+ return std::static_pointer_cast<const InstallableToPathRequirement>(*r.underlying_iterator());
+ else
+ return make_null_shared_ptr();
}
const std::shared_ptr<const KeyRequirementSequence>
PackageDepSpec::all_key_requirements() const
{
- return _imp->data->all_key_requirements();
+ return _imp->all_keys;
+}
+
+const std::shared_ptr<const ChoiceRequirementSequence>
+PackageDepSpec::all_choice_requirements() const
+{
+ return _imp->all_choices;
}
std::string
PackageDepSpec::_as_string() const
{
- return _imp->data->as_string();
+ return text();
}
const std::shared_ptr<const PackageDepSpecData>
diff --git a/paludis/dep_spec_data.cc b/paludis/dep_spec_data.cc
index dcd4e9c..511c8aa 100644
--- a/paludis/dep_spec_data.cc
+++ b/paludis/dep_spec_data.cc
@@ -49,9 +49,6 @@ namespace paludis
struct Imp<PackageDepSpecData>
{
std::shared_ptr<PackageDepSpecRequirementSequence> requirements;
- std::shared_ptr<VersionRequirementSequence> all_versions;
- std::shared_ptr<KeyRequirementSequence> all_keys;
- std::shared_ptr<ChoiceRequirementSequence> all_choices;
PackageDepSpecDataOptions options;
Imp(const PackageDepSpecDataOptions & o) :
@@ -62,24 +59,9 @@ namespace paludis
Imp(const PackageDepSpecData & other) :
requirements(std::make_shared<PackageDepSpecRequirementSequence>()),
- all_versions(other.all_version_requirements() ? new VersionRequirementSequence : 0),
- all_keys(other.all_key_requirements() ? new KeyRequirementSequence : 0),
- all_choices(other.all_choice_requirements() ? new ChoiceRequirementSequence : 0),
options(other.options())
{
std::copy(other.requirements()->begin(), other.requirements()->end(), requirements->back_inserter());
-
- if (all_versions)
- std::copy(other.all_version_requirements()->begin(), other.all_version_requirements()->end(),
- all_versions->back_inserter());
-
- if (all_keys)
- std::copy(other.all_key_requirements()->begin(), other.all_key_requirements()->end(),
- all_keys->back_inserter());
-
- if (all_choices)
- std::copy(other.all_choice_requirements()->begin(), other.all_choice_requirements()->end(),
- all_choices->back_inserter());
}
};
}
@@ -96,187 +78,6 @@ PackageDepSpecData::PackageDepSpecData(const PackageDepSpecData & o) :
PackageDepSpecData::~PackageDepSpecData() = default;
-namespace
-{
- template <typename T_>
- struct Detect
- {
- bool visit(const T_ &) const
- {
- return true;
- }
-
- bool visit(const PackageDepSpecRequirement &) const
- {
- return false;
- }
- };
-
- template <typename I_, typename P_>
- I_ find_unique_if(I_ cur, I_ end, P_ pred)
- {
- I_ result(end);
- for ( ; cur != end ; ++cur)
- if (pred(*cur))
- {
- if (result != end)
- return end;
- else
- result = cur;
- }
-
- return result;
- }
-}
-
-const std::shared_ptr<const NameRequirement>
-PackageDepSpecData::package_name_requirement() const
-{
- Detect<NameRequirement> v;
- auto r(find_unique_if(indirect_iterator(_imp->requirements->begin()),
- indirect_iterator(_imp->requirements->end()), accept_visitor_returning<bool>(v)));
-
- if (r != indirect_iterator(_imp->requirements->end()))
- return std::static_pointer_cast<const NameRequirement>(*r.underlying_iterator());
- else
- return make_null_shared_ptr();
-}
-
-const std::shared_ptr<const PackageNamePartRequirement>
-PackageDepSpecData::package_name_part_requirement() const
-{
- Detect<PackageNamePartRequirement> v;
- auto r(find_unique_if(indirect_iterator(_imp->requirements->begin()),
- indirect_iterator(_imp->requirements->end()), accept_visitor_returning<bool>(v)));
-
- if (r != indirect_iterator(_imp->requirements->end()))
- return std::static_pointer_cast<const PackageNamePartRequirement>(*r.underlying_iterator());
- else
- return make_null_shared_ptr();
-}
-
-const std::shared_ptr<const CategoryNamePartRequirement>
-PackageDepSpecData::category_name_part_requirement() const
-{
- Detect<CategoryNamePartRequirement> v;
- auto r(find_unique_if(indirect_iterator(_imp->requirements->begin()),
- indirect_iterator(_imp->requirements->end()), accept_visitor_returning<bool>(v)));
-
- if (r != indirect_iterator(_imp->requirements->end()))
- return std::static_pointer_cast<const CategoryNamePartRequirement>(*r.underlying_iterator());
- else
- return make_null_shared_ptr();
-}
-
-const std::shared_ptr<const VersionRequirementSequence>
-PackageDepSpecData::all_version_requirements() const
-{
- return _imp->all_versions;
-}
-
-const std::shared_ptr<const ExactSlotRequirement>
-PackageDepSpecData::exact_slot_requirement() const
-{
- Detect<ExactSlotRequirement> v;
- auto r(find_unique_if(indirect_iterator(_imp->requirements->begin()),
- indirect_iterator(_imp->requirements->end()), accept_visitor_returning<bool>(v)));
-
- if (r != indirect_iterator(_imp->requirements->end()))
- return std::static_pointer_cast<const ExactSlotRequirement>(*r.underlying_iterator());
- else
- return make_null_shared_ptr();
-}
-
-const std::shared_ptr<const AnySlotRequirement>
-PackageDepSpecData::any_slot_requirement() const
-{
- Detect<AnySlotRequirement> v;
- auto r(find_unique_if(indirect_iterator(_imp->requirements->begin()),
- indirect_iterator(_imp->requirements->end()), accept_visitor_returning<bool>(v)));
-
- if (r != indirect_iterator(_imp->requirements->end()))
- return std::static_pointer_cast<const AnySlotRequirement>(*r.underlying_iterator());
- else
- return make_null_shared_ptr();
-}
-
-const std::shared_ptr<const InRepositoryRequirement>
-PackageDepSpecData::in_repository_requirement() const
-{
- Detect<InRepositoryRequirement> v;
- auto r(find_unique_if(indirect_iterator(_imp->requirements->begin()),
- indirect_iterator(_imp->requirements->end()), accept_visitor_returning<bool>(v)));
-
- if (r != indirect_iterator(_imp->requirements->end()))
- return std::static_pointer_cast<const InRepositoryRequirement>(*r.underlying_iterator());
- else
- return make_null_shared_ptr();
-}
-
-const std::shared_ptr<const InstallableToRepositoryRequirement>
-PackageDepSpecData::installable_to_repository_requirement() const
-{
- Detect<InstallableToRepositoryRequirement> v;
- auto r(find_unique_if(indirect_iterator(_imp->requirements->begin()),
- indirect_iterator(_imp->requirements->end()), accept_visitor_returning<bool>(v)));
-
- if (r != indirect_iterator(_imp->requirements->end()))
- return std::static_pointer_cast<const InstallableToRepositoryRequirement>(*r.underlying_iterator());
- else
- return make_null_shared_ptr();
-}
-
-const std::shared_ptr<const FromRepositoryRequirement>
-PackageDepSpecData::from_repository_requirement() const
-{
- Detect<FromRepositoryRequirement> v;
- auto r(find_unique_if(indirect_iterator(_imp->requirements->begin()),
- indirect_iterator(_imp->requirements->end()), accept_visitor_returning<bool>(v)));
-
- if (r != indirect_iterator(_imp->requirements->end()))
- return std::static_pointer_cast<const FromRepositoryRequirement>(*r.underlying_iterator());
- else
- return make_null_shared_ptr();
-}
-
-const std::shared_ptr<const InstalledAtPathRequirement>
-PackageDepSpecData::installed_at_path_requirement() const
-{
- Detect<InstalledAtPathRequirement> v;
- auto r(find_unique_if(indirect_iterator(_imp->requirements->begin()),
- indirect_iterator(_imp->requirements->end()), accept_visitor_returning<bool>(v)));
-
- if (r != indirect_iterator(_imp->requirements->end()))
- return std::static_pointer_cast<const InstalledAtPathRequirement>(*r.underlying_iterator());
- else
- return make_null_shared_ptr();
-}
-
-const std::shared_ptr<const InstallableToPathRequirement>
-PackageDepSpecData::installable_to_path_requirement() const
-{
- Detect<InstallableToPathRequirement> v;
- auto r(find_unique_if(indirect_iterator(_imp->requirements->begin()),
- indirect_iterator(_imp->requirements->end()), accept_visitor_returning<bool>(v)));
-
- if (r != indirect_iterator(_imp->requirements->end()))
- return std::static_pointer_cast<const InstallableToPathRequirement>(*r.underlying_iterator());
- else
- return make_null_shared_ptr();
-}
-
-const std::shared_ptr<const KeyRequirementSequence>
-PackageDepSpecData::all_key_requirements() const
-{
- return _imp->all_keys;
-}
-
-const std::shared_ptr<const ChoiceRequirementSequence>
-PackageDepSpecData::all_choice_requirements() const
-{
- return _imp->all_choices;
-}
-
const std::shared_ptr<const PackageDepSpecRequirementSequence>
PackageDepSpecData::requirements() const
{
@@ -289,190 +90,21 @@ PackageDepSpecData::options() const
return _imp->options;
}
-std::string
-PackageDepSpecData::as_string() const
+namespace
{
- std::ostringstream s;
-
- if (all_version_requirements())
- {
- if (all_version_requirements()->begin() == all_version_requirements()->end())
- {
- }
- else if (next(all_version_requirements()->begin()) == all_version_requirements()->end() &&
- ! options()[pdsdo_always_use_ranged_deps])
- {
- if ((*all_version_requirements()->begin())->version_operator() == vo_stupid_equal_star ||
- (*all_version_requirements()->begin())->version_operator() == vo_nice_equal_star)
- s << "=";
- else
- s << (*all_version_requirements()->begin())->version_operator();
- }
- }
-
- if (package_name_requirement())
- s << package_name_requirement()->name();
- else
- {
- if (category_name_part_requirement())
- s << category_name_part_requirement()->name_part();
- else
- s << "*";
-
- s << "/";
-
- if (package_name_part_requirement())
- s << package_name_part_requirement()->name_part();
- else
- s << "*";
- }
-
- if (all_version_requirements())
- {
- if (all_version_requirements()->begin() == all_version_requirements()->end())
- {
- }
- else if (next(all_version_requirements()->begin()) == all_version_requirements()->end() &&
- ! options()[pdsdo_always_use_ranged_deps])
- {
- s << "-" << (*all_version_requirements()->begin())->version_spec();
- if ((*all_version_requirements()->begin())->version_operator() == vo_stupid_equal_star ||
- (*all_version_requirements()->begin())->version_operator() == vo_nice_equal_star)
- s << "*";
- }
- }
-
- if (exact_slot_requirement())
- {
- if (exact_slot_requirement()->locked())
- s << ":=";
- else
- s << ":";
-
- s << stringify(exact_slot_requirement()->name());
- }
-
- if (any_slot_requirement())
- {
- if (any_slot_requirement()->locking())
- s << ":=";
- else
- s << ":*";
- }
-
- std::string left, right;
- bool need_arrow(false);
-
- if (from_repository_requirement())
- left = stringify(from_repository_requirement()->name());
-
- if (in_repository_requirement())
- right = stringify(in_repository_requirement()->name());
-
- if (installed_at_path_requirement())
- {
- if (! right.empty())
- {
- need_arrow = true;
- right.append("->");
- }
- right.append(stringify(installed_at_path_requirement()->path()));
- }
-
- if (installable_to_repository_requirement())
+ template <typename T_>
+ struct Detect
{
- if (! right.empty())
+ bool visit(const T_ &) const
{
- need_arrow = true;
- right.append("->");
+ return true;
}
- if (installable_to_repository_requirement()->include_masked())
- right.append(stringify(installable_to_repository_requirement()->name()) + "??");
- else
- right.append(stringify(installable_to_repository_requirement()->name()) + "?");
- }
- if (installable_to_path_requirement())
- {
- if (! right.empty())
- {
- need_arrow = true;
- right.append("->");
- }
- if (installable_to_path_requirement()->include_masked())
- right.append(stringify(installable_to_path_requirement()->path()) + "??");
- else
- right.append(stringify(installable_to_path_requirement()->path()) + "?");
- }
-
- if (need_arrow || ((! left.empty()) && (! right.empty())))
- s << "::" << left << "->" << right;
- else if (! right.empty())
- s << "::" << right;
- else if (! left.empty())
- s << "::" << left << "->";
-
- if (all_version_requirements())
- {
- if (all_version_requirements()->begin() == all_version_requirements()->end())
- {
- }
- else if (next(all_version_requirements()->begin()) == all_version_requirements()->end() &&
- ! options()[pdsdo_always_use_ranged_deps])
- {
- }
- else
+ bool visit(const PackageDepSpecRequirement &) const
{
- bool need_op(false);
- s << "[";
- for (auto r(all_version_requirements()->begin()), r_end(all_version_requirements()->end()) ; r != r_end ; ++r)
- {
- if (need_op)
- {
- do
- {
- switch ((*r)->combiner())
- {
- case vrc_and:
- s << "&";
- continue;
-
- case vrc_or:
- s << "|";
- continue;
-
- case last_vrc:
- ;
- }
- throw InternalError(PALUDIS_HERE, "Bad version_requirements_mode");
- } while (false);
- }
-
- if ((*r)->version_operator() == vo_stupid_equal_star || (*r)->version_operator() == vo_nice_equal_star)
- s << "=";
- else
- s << (*r)->version_operator();
-
- s << (*r)->version_spec();
-
- if ((*r)->version_operator() == vo_stupid_equal_star || (*r)->version_operator() == vo_nice_equal_star)
- s << "*";
-
- need_op = true;
- }
- s << "]";
+ return false;
}
- }
-
- if (all_choice_requirements())
- for (auto u(all_choice_requirements()->begin()), u_end(all_choice_requirements()->end()) ; u != u_end ; ++u)
- s << (*u)->as_raw_string();
-
- if (all_key_requirements())
- for (auto u(all_key_requirements()->begin()), u_end(all_key_requirements()->end()) ; u != u_end ; ++u)
- s << (*u)->as_raw_string();
-
- return s.str();
+ };
}
MutablePackageDepSpecData::MutablePackageDepSpecData(const PackageDepSpecDataOptions & o) :
@@ -558,18 +190,12 @@ MutablePackageDepSpecData::require_version(const VersionRequirementCombiner vc,
auto r(std::make_shared<VersionRequirement>(vs, vo, vc));
_imp->requirements->push_back(r);
- if (! _imp->all_versions)
- _imp->all_versions = std::make_shared<VersionRequirementSequence>();
- _imp->all_versions->push_back(r);
-
return *this;
}
MutablePackageDepSpecData &
MutablePackageDepSpecData::unrequire_versions()
{
- _imp->all_versions.reset();
-
auto r(std::make_shared<PackageDepSpecRequirementSequence>());
for (auto u(_imp->requirements->begin()), u_end(_imp->requirements->end()) ;
u != u_end ; ++u)
@@ -725,18 +351,12 @@ MutablePackageDepSpecData::require_choice(const std::shared_ptr<const ChoiceRequ
{
_imp->requirements->push_back(c);
- if (! _imp->all_choices)
- _imp->all_choices = std::make_shared<ChoiceRequirementSequence>();
- _imp->all_choices->push_back(c);
-
return *this;
}
MutablePackageDepSpecData &
MutablePackageDepSpecData::unrequire_choices()
{
- _imp->all_choices.reset();
-
auto r(std::make_shared<PackageDepSpecRequirementSequence>());
for (auto u(_imp->requirements->begin()), u_end(_imp->requirements->end()) ;
u != u_end ; ++u)
@@ -754,18 +374,12 @@ MutablePackageDepSpecData::require_key(const KeyRequirementKeyType t, const std:
_imp->requirements->push_back(r);
- if (! _imp->all_keys)
- _imp->all_keys = std::make_shared<KeyRequirementSequence>();
- _imp->all_keys->push_back(r);
-
return *this;
}
MutablePackageDepSpecData &
MutablePackageDepSpecData::unrequire_keys()
{
- _imp->all_keys.reset();
-
auto r(std::make_shared<PackageDepSpecRequirementSequence>());
for (auto u(_imp->requirements->begin()), u_end(_imp->requirements->end()) ;
u != u_end ; ++u)
diff --git a/paludis/dep_spec_data.hh b/paludis/dep_spec_data.hh
index 04c9e56..33fb892 100644
--- a/paludis/dep_spec_data.hh
+++ b/paludis/dep_spec_data.hh
@@ -114,118 +114,6 @@ namespace paludis
///\}
/**
- * Fetch ourself as a string.
- */
- std::string as_string() const;
-
- /**
- * Fetch the single NameRequirement, if we have one, or
- * a null pointer otherwise.
- *
- * \since 0.61
- */
- const std::shared_ptr<const NameRequirement> package_name_requirement() const
- PALUDIS_ATTRIBUTE((warn_unused_result));
-
- /**
- * Fetch the single PackageNamePartRequirement, if we have one, or
- * a null pointer otherwise.
- *
- * \since 0.61
- */
- const std::shared_ptr<const PackageNamePartRequirement> package_name_part_requirement() const
- PALUDIS_ATTRIBUTE((warn_unused_result));
-
- /**
- * Fetch the single CategoryNamePartRequirement, if we have one, or
- * a null pointer otherwise.
- *
- * \since 0.61
- */
- const std::shared_ptr<const CategoryNamePartRequirement> category_name_part_requirement() const
- PALUDIS_ATTRIBUTE((warn_unused_result));
-
- /**
- * Fetch all our VersionRequirements, if we have any, or
- * a null pointer otherwise.
- *
- * \since 0.61
- */
- const std::shared_ptr<const VersionRequirementSequence> all_version_requirements() const;
-
- /**
- * Fetch the single ExactSlotRequirement, if we have one, or
- * a null pointer otherwise.
- *
- * \since 0.61
- */
- const std::shared_ptr<const ExactSlotRequirement> exact_slot_requirement() const;
-
- /**
- * Fetch the single AnySlotRequirement, if we have one, or
- * a null pointer otherwise.
- *
- * \since 0.61
- */
- const std::shared_ptr<const AnySlotRequirement> any_slot_requirement() const;
-
- /**
- * Fetch the single InRepositoryRequirement, if we have one, or
- * a null pointer otherwise.
- *
- * \since 0.61
- */
- const std::shared_ptr<const InRepositoryRequirement> in_repository_requirement() const
- PALUDIS_ATTRIBUTE((warn_unused_result));
-
- /**
- * Fetch the single InstallableToRepositoryRequirement, if we have one, or
- *
- * \since 0.61
- */
- const std::shared_ptr<const InstallableToRepositoryRequirement> installable_to_repository_requirement() const;
-
- /**
- * Fetch the single FromRepositoryRequirement, if we have one, or
- * a null pointer otherwise.
- *
- * \since 0.61
- */
- const std::shared_ptr<const FromRepositoryRequirement> from_repository_requirement() const;
-
- /**
- * Fetch the single InstalledAtPathRequirement, if we have one, or
- * a null pointer otherwise.
- *
- * \since 0.61
- */
- const std::shared_ptr<const InstalledAtPathRequirement> installed_at_path_requirement() const;
-
- /**
- * Fetch the single InstallableToPathRequirement, if we have one, or
- * a null pointer otherwise.
- *
- * \since 0.61
- */
- const std::shared_ptr<const InstallableToPathRequirement> installable_to_path_requirement() const;
-
- /**
- * Fetch all our KeyRequirements, if we have any, or
- * a null pointer otherwise.
- *
- * \since 0.61
- */
- const std::shared_ptr<const KeyRequirementSequence> all_key_requirements() const;
-
- /**
- * Fetch all our ChoiceRequirements, if we have any, or
- * a null pointer otherwise.
- *
- * \since 0.61
- */
- const std::shared_ptr<const ChoiceRequirementSequence> all_choice_requirements() const;
-
- /**
* All our requirements.
*
* \since 0.61