aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-04-21 06:59:02 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-04-21 06:59:02 +0100
commit759b51c3476a3d01c14e20e708a509b784dcaaf1 (patch)
treea301f4611a437ccbcd12aca4f4d17f44a96f271a
parentbb06c0f5ac5e7fe01e5ab0a957bc310179eb5bab (diff)
downloadpaludis-759b51c3476a3d01c14e20e708a509b784dcaaf1.tar.gz
paludis-759b51c3476a3d01c14e20e708a509b784dcaaf1.tar.xz
Tweak a bit more
-rw-r--r--paludis/dep_spec.cc18
-rw-r--r--paludis/dep_spec.hh12
-rw-r--r--paludis/dep_spec_data.cc60
-rw-r--r--paludis/dep_spec_data.hh18
-rw-r--r--paludis/package_dep_spec_properties.cc22
5 files changed, 82 insertions, 48 deletions
diff --git a/paludis/dep_spec.cc b/paludis/dep_spec.cc
index 0d2260d..bc95d0c 100644
--- a/paludis/dep_spec.cc
+++ b/paludis/dep_spec.cc
@@ -806,14 +806,7 @@ PackageDepSpec::text() const
const std::shared_ptr<const NameRequirement>
PackageDepSpec::package_name_requirement() const
{
- DetectPackageDepSpecRequirement<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();
+ return _imp->data->package_name_requirement();
}
const std::shared_ptr<const PackageNamePartRequirement>
@@ -845,14 +838,7 @@ PackageDepSpec::category_name_part_requirement() const
const std::shared_ptr<const ExactSlotRequirement>
PackageDepSpec::exact_slot_requirement() const
{
- DetectPackageDepSpecRequirement<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();
+ return _imp->data->exact_slot_requirement();
}
const std::shared_ptr<const AnySlotRequirement>
diff --git a/paludis/dep_spec.hh b/paludis/dep_spec.hh
index c23115f..d2307cb 100644
--- a/paludis/dep_spec.hh
+++ b/paludis/dep_spec.hh
@@ -296,8 +296,10 @@ namespace paludis
virtual const std::string text() const;
/**
- * Fetch the single NameRequirement, if we have one, or
- * a null pointer otherwise.
+ * Fetch our NameRequirement, if we have one, or a null pointer otherwise.
+ *
+ * If we have multiple NameRequirement requirements, returns one such
+ * requirement.
*
* \since 0.61
*/
@@ -320,8 +322,10 @@ namespace paludis
const std::shared_ptr<const CategoryNamePartRequirement> category_name_part_requirement() const;
/**
- * Fetch the single ExactSlotRequirement, if we have one, or
- * a null pointer otherwise.
+ * Fetch our ExactSlotRequirement, if we have one, or a null pointer otherwise.
+ *
+ * If we have multiple ExactSlotRequirement requirements, returns one such
+ * requirement.
*
* \since 0.61
*/
diff --git a/paludis/dep_spec_data.cc b/paludis/dep_spec_data.cc
index 6176742..4df8f6a 100644
--- a/paludis/dep_spec_data.cc
+++ b/paludis/dep_spec_data.cc
@@ -49,6 +49,8 @@ namespace paludis
template <>
struct Imp<PackageDepSpecData>
{
+ std::shared_ptr<const NameRequirement> package_name_requirement;
+ std::shared_ptr<const ExactSlotRequirement> exact_slot_requirement;
std::shared_ptr<PackageDepSpecRequirementSequence> requirements;
PackageDepSpecDataOptions options;
@@ -59,6 +61,8 @@ namespace paludis
}
Imp(const PackageDepSpecData & other) :
+ package_name_requirement(other.package_name_requirement()),
+ exact_slot_requirement(other.exact_slot_requirement()),
requirements(std::make_shared<PackageDepSpecRequirementSequence>()),
options(other.options())
{
@@ -91,6 +95,18 @@ PackageDepSpecData::options() const
return _imp->options;
}
+const std::shared_ptr<const NameRequirement>
+PackageDepSpecData::package_name_requirement() const
+{
+ return _imp->package_name_requirement;
+}
+
+const std::shared_ptr<const ExactSlotRequirement>
+PackageDepSpecData::exact_slot_requirement() const
+{
+ return _imp->exact_slot_requirement;
+}
+
MutablePackageDepSpecData::MutablePackageDepSpecData(const PackageDepSpecDataOptions & o) :
PackageDepSpecData(o)
{
@@ -111,20 +127,28 @@ MutablePackageDepSpecData::~MutablePackageDepSpecData() = default;
MutablePackageDepSpecData &
MutablePackageDepSpecData::require_package(const QualifiedPackageName & name)
{
- _imp->requirements->push_front(NameRequirementPool::get_instance()->create(name));
+ auto r(NameRequirementPool::get_instance()->create(name));
+ _imp->package_name_requirement = r;
+ _imp->requirements->push_front(r);
return *this;
}
MutablePackageDepSpecData &
MutablePackageDepSpecData::unrequire_package()
{
- auto r(std::make_shared<PackageDepSpecRequirementSequence>());
- for (auto u(_imp->requirements->begin()), u_end(_imp->requirements->end()) ;
- u != u_end ; ++u)
- if (! (*u)->accept_returning<bool>(DetectPackageDepSpecRequirement<NameRequirement>()))
- r->push_back(*u);
+ if (_imp->package_name_requirement)
+ {
+ _imp->package_name_requirement.reset();
+
+ auto r(std::make_shared<PackageDepSpecRequirementSequence>());
+ for (auto u(_imp->requirements->begin()), u_end(_imp->requirements->end()) ;
+ u != u_end ; ++u)
+ if (! (*u)->accept_returning<bool>(DetectPackageDepSpecRequirement<NameRequirement>()))
+ r->push_back(*u);
+
+ _imp->requirements = r;
+ }
- _imp->requirements = r;
return *this;
}
@@ -193,20 +217,28 @@ MutablePackageDepSpecData::unrequire_versions()
MutablePackageDepSpecData &
MutablePackageDepSpecData::require_exact_slot(const SlotName & n, const bool s)
{
- _imp->requirements->push_back(ExactSlotRequirementPool::get_instance()->create(n, s));
+ auto r(ExactSlotRequirementPool::get_instance()->create(n, s));
+ _imp->exact_slot_requirement = r;
+ _imp->requirements->push_back(r);
return *this;
}
MutablePackageDepSpecData &
MutablePackageDepSpecData::unrequire_exact_slot()
{
- auto r(std::make_shared<PackageDepSpecRequirementSequence>());
- for (auto u(_imp->requirements->begin()), u_end(_imp->requirements->end()) ;
- u != u_end ; ++u)
- if (! (*u)->accept_returning<bool>(DetectPackageDepSpecRequirement<ExactSlotRequirement>()))
- r->push_back(*u);
+ if (_imp->exact_slot_requirement)
+ {
+ _imp->exact_slot_requirement.reset();
+
+ auto r(std::make_shared<PackageDepSpecRequirementSequence>());
+ for (auto u(_imp->requirements->begin()), u_end(_imp->requirements->end()) ;
+ u != u_end ; ++u)
+ if (! (*u)->accept_returning<bool>(DetectPackageDepSpecRequirement<ExactSlotRequirement>()))
+ r->push_back(*u);
+
+ _imp->requirements = r;
+ }
- _imp->requirements = r;
return *this;
}
diff --git a/paludis/dep_spec_data.hh b/paludis/dep_spec_data.hh
index 33fb892..6a7b67a 100644
--- a/paludis/dep_spec_data.hh
+++ b/paludis/dep_spec_data.hh
@@ -126,6 +126,24 @@ namespace paludis
* \since 0.61
*/
const PackageDepSpecDataOptions options() const;
+
+ /**
+ * Fetch one of our NameRequirement requirements, if we have any, or
+ * a null pointer otherwise.
+ *
+ * \since 0.61
+ */
+ const std::shared_ptr<const NameRequirement> package_name_requirement() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ /**
+ * Fetch our ExactSlotRequirement, if we have one, or a null pointer otherwise.
+ *
+ * If we have multiple ExactSlotRequirement requirements, returns one such
+ * requirement.
+ *
+ * \since 0.61
+ */
+ const std::shared_ptr<const ExactSlotRequirement> exact_slot_requirement() const;
};
/**
diff --git a/paludis/package_dep_spec_properties.cc b/paludis/package_dep_spec_properties.cc
index c7a62a9..8fb4670 100644
--- a/paludis/package_dep_spec_properties.cc
+++ b/paludis/package_dep_spec_properties.cc
@@ -32,14 +32,12 @@ namespace
bool has_any_slot_requirement;
bool has_category_name_part;
bool has_choice_requirements;
- bool has_exact_slot_requirement;
bool has_from_repository;
bool has_in_repository;
bool has_installable_to_path;
bool has_installable_to_repository;
bool has_installed_at_path;
bool has_key_requirements;
- bool has_package;
bool has_package_name_part;
bool has_tag;
bool has_version_requirements;
@@ -48,14 +46,12 @@ namespace
has_any_slot_requirement(false),
has_category_name_part(false),
has_choice_requirements(false),
- has_exact_slot_requirement(false),
has_from_repository(false),
has_in_repository(false),
has_installable_to_path(false),
has_installable_to_repository(false),
has_installed_at_path(false),
has_key_requirements(false),
- has_package(false),
has_package_name_part(false),
has_tag(false),
has_version_requirements(false)
@@ -64,7 +60,6 @@ namespace
void visit(const NameRequirement &)
{
- has_package = true;
}
void visit(const PackageNamePartRequirement &)
@@ -109,7 +104,6 @@ namespace
void visit(const ExactSlotRequirement &)
{
- has_exact_slot_requirement = true;
}
void visit(const AnySlotRequirement &)
@@ -132,6 +126,14 @@ namespace
bool
paludis::package_dep_spec_has_properties(const PackageDepSpec & spec, const PackageDepSpecProperties & properties)
{
+ if (! properties.has_package().is_indeterminate())
+ if (properties.has_package().is_true() != bool(spec.package_name_requirement()))
+ return false;
+
+ if (! properties.has_exact_slot_requirement().is_indeterminate())
+ if (properties.has_exact_slot_requirement().is_true() != bool(spec.exact_slot_requirement()))
+ return false;
+
Finder f;
for (auto r(spec.requirements()->begin()), r_end(spec.requirements()->end()) ;
r != r_end ; ++r)
@@ -149,10 +151,6 @@ paludis::package_dep_spec_has_properties(const PackageDepSpec & spec, const Pack
if (properties.has_choice_requirements().is_true() != f.has_choice_requirements)
return false;
- if (! properties.has_exact_slot_requirement().is_indeterminate())
- if (properties.has_exact_slot_requirement().is_true() != f.has_exact_slot_requirement)
- return false;
-
if (! properties.has_from_repository().is_indeterminate())
if (properties.has_from_repository().is_true() != f.has_from_repository)
return false;
@@ -177,10 +175,6 @@ paludis::package_dep_spec_has_properties(const PackageDepSpec & spec, const Pack
if (properties.has_key_requirements().is_true() != f.has_key_requirements)
return false;
- if (! properties.has_package().is_indeterminate())
- if (properties.has_package().is_true() != f.has_package)
- return false;
-
if (! properties.has_package_name_part().is_indeterminate())
if (properties.has_package_name_part().is_true() != f.has_package_name_part)
return false;