diff options
author | 2011-04-14 23:31:04 +0100 | |
---|---|---|
committer | 2011-04-14 23:31:04 +0100 | |
commit | c01c7bc64cda93624500c5e3c7c7b701dbcae089 (patch) | |
tree | ff439679479562339baf1cc963d1163fef805a22 | |
parent | 0d18bf226d035dacaacf65b396ed2e126157d600 (diff) | |
download | paludis-c01c7bc64cda93624500c5e3c7c7b701dbcae089.tar.gz paludis-c01c7bc64cda93624500c5e3c7c7b701dbcae089.tar.xz |
Use requirements() for properties checks
-rw-r--r-- | paludis/package_dep_spec_properties.cc | 188 |
1 files changed, 163 insertions, 25 deletions
diff --git a/paludis/package_dep_spec_properties.cc b/paludis/package_dep_spec_properties.cc index 0ac1b3969..c7a62a97a 100644 --- a/paludis/package_dep_spec_properties.cc +++ b/paludis/package_dep_spec_properties.cc @@ -19,42 +19,180 @@ #include <paludis/package_dep_spec_properties.hh> #include <paludis/dep_spec.hh> +#include <paludis/package_dep_spec_requirement.hh> + #include <paludis/util/sequence.hh> using namespace paludis; namespace { - inline bool check(const bool c, const Tribool w) + struct Finder { - if (w.is_true()) - return c; - else if (w.is_false()) - return ! c; - else - return true; - } + 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; + + Finder() : + 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) + { + } + + void visit(const NameRequirement &) + { + has_package = true; + } + + void visit(const PackageNamePartRequirement &) + { + has_package_name_part = true; + } + + void visit(const CategoryNamePartRequirement &) + { + has_category_name_part = true; + } + + void visit(const VersionRequirement &) + { + has_version_requirements = true; + } + + void visit(const InRepositoryRequirement &) + { + has_in_repository = true; + } + + void visit(const FromRepositoryRequirement &) + { + has_from_repository = true; + } + + void visit(const InstalledAtPathRequirement &) + { + has_installed_at_path = true; + } + + void visit(const InstallableToRepositoryRequirement &) + { + has_installable_to_repository = true; + } + + void visit(const InstallableToPathRequirement &) + { + has_installable_to_path = true; + } + + void visit(const ExactSlotRequirement &) + { + has_exact_slot_requirement = true; + } + + void visit(const AnySlotRequirement &) + { + has_any_slot_requirement = true; + } + + void visit(const ChoiceRequirement &) + { + has_choice_requirements = true; + } + + void visit(const KeyRequirement &) + { + has_key_requirements = true; + } + }; } bool paludis::package_dep_spec_has_properties(const PackageDepSpec & spec, const PackageDepSpecProperties & properties) { - bool result(true); - - result = result && check(bool(spec.all_choice_requirements()) && ! spec.all_choice_requirements()->empty(), properties.has_choice_requirements()); - result = result && check(bool(spec.category_name_part_requirement()), properties.has_category_name_part()); - result = result && check(bool(spec.from_repository_requirement()), properties.has_from_repository()); - result = result && check(bool(spec.all_key_requirements()) && ! spec.all_key_requirements()->empty(), properties.has_key_requirements()); - result = result && check(bool(spec.in_repository_requirement()), properties.has_in_repository()); - result = result && check(bool(spec.installable_to_path_requirement()), properties.has_installable_to_path()); - result = result && check(bool(spec.installable_to_repository_requirement()), properties.has_installable_to_repository()); - result = result && check(bool(spec.installed_at_path_requirement()), properties.has_installed_at_path()); - result = result && check(bool(spec.package_name_requirement()), properties.has_package()); - result = result && check(bool(spec.package_name_part_requirement()), properties.has_package_name_part()); - result = result && check(bool(spec.exact_slot_requirement()), properties.has_exact_slot_requirement()); - result = result && check(bool(spec.any_slot_requirement()), properties.has_any_slot_requirement()); - result = result && check(bool(spec.all_version_requirements()) && ! spec.all_version_requirements()->empty(), properties.has_version_requirements()); - - return result; + Finder f; + for (auto r(spec.requirements()->begin()), r_end(spec.requirements()->end()) ; + r != r_end ; ++r) + (*r)->accept(f); + + if (! properties.has_any_slot_requirement().is_indeterminate()) + if (properties.has_any_slot_requirement().is_true() != f.has_any_slot_requirement) + return false; + + if (! properties.has_category_name_part().is_indeterminate()) + if (properties.has_category_name_part().is_true() != f.has_category_name_part) + return false; + + if (! properties.has_choice_requirements().is_indeterminate()) + 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; + + if (! properties.has_in_repository().is_indeterminate()) + if (properties.has_in_repository().is_true() != f.has_in_repository) + return false; + + if (! properties.has_installable_to_path().is_indeterminate()) + if (properties.has_installable_to_path().is_true() != f.has_installable_to_path) + return false; + + if (! properties.has_installable_to_repository().is_indeterminate()) + if (properties.has_installable_to_repository().is_true() != f.has_installable_to_repository) + return false; + + if (! properties.has_installed_at_path().is_indeterminate()) + if (properties.has_installed_at_path().is_true() != f.has_installed_at_path) + return false; + + if (! properties.has_key_requirements().is_indeterminate()) + 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; + + if (! properties.has_tag().is_indeterminate()) + if (properties.has_tag().is_true() != f.has_tag) + return false; + + if (! properties.has_version_requirements().is_indeterminate()) + if (properties.has_version_requirements().is_true() != f.has_version_requirements) + return false; + + return true; } |