diff options
author | 2011-04-04 07:47:28 +0100 | |
---|---|---|
committer | 2011-04-04 08:33:00 +0100 | |
commit | 508e7564e1d8d1de765d4d517bc899b7ef137716 (patch) | |
tree | b37e064c3697c72ff90ac70972ed4e779a9bbb0e | |
parent | de5f08b35621fd4a790885b2707468203b2df379 (diff) | |
download | paludis-508e7564e1d8d1de765d4d517bc899b7ef137716.tar.gz paludis-508e7564e1d8d1de765d4d517bc899b7ef137716.tar.xz |
Move match logic to constraint class
-rw-r--r-- | paludis/match_package.cc | 575 | ||||
-rw-r--r-- | paludis/package_dep_spec_constraint.cc | 582 | ||||
-rw-r--r-- | paludis/package_dep_spec_constraint.hh | 6 |
3 files changed, 589 insertions, 574 deletions
diff --git a/paludis/match_package.cc b/paludis/match_package.cc index 44a46535a..5b40768a4 100644 --- a/paludis/match_package.cc +++ b/paludis/match_package.cc @@ -50,577 +50,6 @@ using namespace paludis; #include <paludis/match_package-se.cc> -namespace -{ - std::string stringify_contents_entry(const ContentsEntry & e) - { - return stringify(e.location_key()->value()); - } - - struct StringifyEqual - { - const std::string pattern; - - StringifyEqual(const std::string & p) : - pattern(p) - { - } - - template <typename T_> - bool operator() (const T_ & t) const - { - return stringify(t) == pattern; - } - - bool operator() (const ContentsEntry & e) const - { - return stringify_contents_entry(e) == pattern; - } - }; - - struct SpecTreeSearcher - { - const Environment * const env; - const std::shared_ptr<const PackageID> id; - const std::string pattern; - - SpecTreeSearcher(const Environment * const e, const std::shared_ptr<const PackageID> & i, const std::string & p) : - env(e), - id(i), - pattern(p) - { - } - - bool visit(const GenericSpecTree::NodeType<AllDepSpec>::Type & n) const - { - return indirect_iterator(n.end()) != std::find_if(indirect_iterator(n.begin()), indirect_iterator(n.end()), - accept_visitor_returning<bool>(*this)); - } - - bool visit(const GenericSpecTree::NodeType<AnyDepSpec>::Type & n) const - { - return indirect_iterator(n.end()) != std::find_if(indirect_iterator(n.begin()), indirect_iterator(n.end()), - accept_visitor_returning<bool>(*this)); - } - - bool visit(const GenericSpecTree::NodeType<ExactlyOneDepSpec>::Type & n) const - { - return indirect_iterator(n.end()) != std::find_if(indirect_iterator(n.begin()), indirect_iterator(n.end()), - accept_visitor_returning<bool>(*this)); - } - - bool visit(const GenericSpecTree::NodeType<ConditionalDepSpec>::Type & n) const - { - if (n.spec()->condition_met(env, id)) - return indirect_iterator(n.end()) != std::find_if(indirect_iterator(n.begin()), indirect_iterator(n.end()), - accept_visitor_returning<bool>(*this)); - else - return false; - } - - bool visit(const GenericSpecTree::NodeType<NamedSetDepSpec>::Type & n) const - { - return stringify(*n.spec()) == pattern; - } - - bool visit(const GenericSpecTree::NodeType<PlainTextDepSpec>::Type & n) const - { - return stringify(*n.spec()) == pattern; - } - - bool visit(const GenericSpecTree::NodeType<PackageDepSpec>::Type & n) const - { - return stringify(*n.spec()) == pattern; - } - - bool visit(const GenericSpecTree::NodeType<BlockDepSpec>::Type & n) const - { - return stringify(*n.spec()) == pattern; - } - - bool visit(const GenericSpecTree::NodeType<LicenseDepSpec>::Type & n) const - { - return stringify(*n.spec()) == pattern; - } - - bool visit(const GenericSpecTree::NodeType<SimpleURIDepSpec>::Type & n) const - { - return stringify(*n.spec()) == pattern; - } - - bool visit(const GenericSpecTree::NodeType<FetchableURIDepSpec>::Type & n) const - { - return stringify(*n.spec()) == pattern; - } - - bool visit(const GenericSpecTree::NodeType<DependenciesLabelsDepSpec>::Type & n) const - { - return indirect_iterator(n.spec()->end()) != std::find_if(indirect_iterator(n.spec()->begin()), - indirect_iterator(n.spec()->end()), StringifyEqual(pattern)); - } - - bool visit(const GenericSpecTree::NodeType<URILabelsDepSpec>::Type & n) const - { - return indirect_iterator(n.spec()->end()) != std::find_if(indirect_iterator(n.spec()->begin()), - indirect_iterator(n.spec()->end()), StringifyEqual(pattern)); - } - - bool visit(const GenericSpecTree::NodeType<PlainTextLabelDepSpec>::Type & n) const - { - return stringify(*n.spec()) == pattern; - } - }; - - struct KeyComparator - { - const Environment * const env; - const std::shared_ptr<const PackageID> id; - const std::string pattern; - const KeyConstraintOperation op; - - KeyComparator(const Environment * const e, const std::shared_ptr<const PackageID> & i, - const std::string & p, const KeyConstraintOperation o) : - env(e), - id(i), - pattern(p), - op(o) - { - } - - bool visit(const MetadataSectionKey &) const - { - return false; - } - - bool visit(const MetadataTimeKey & k) const - { - switch (op) - { - case kco_equals: - return pattern == stringify(k.value().seconds()); - case kco_less_than: - return k.value().seconds() < destringify<time_t>(pattern); - case kco_greater_than: - return k.value().seconds() > destringify<time_t>(pattern); - case kco_question: - case last_kco: - break; - } - - return false; - } - - bool visit(const MetadataValueKey<std::string> & k) const - { - return pattern == stringify(k.value()); - } - - bool visit(const MetadataValueKey<SlotName> & k) const - { - return pattern == stringify(k.value()); - } - - bool visit(const MetadataValueKey<FSPath> & k) const - { - return pattern == stringify(k.value()); - } - - bool visit(const MetadataValueKey<bool> & k) const - { - return pattern == stringify(k.value()); - } - - bool visit(const MetadataValueKey<long> & k) const - { - switch (op) - { - case kco_equals: - return pattern == stringify(k.value()); - case kco_less_than: - return k.value() < destringify<long>(pattern); - case kco_greater_than: - return k.value() > destringify<long>(pattern); - case kco_question: - case last_kco: - break; - } - - return false; - } - - bool visit(const MetadataValueKey<std::shared_ptr<const Choices> > &) const - { - return false; - } - - bool visit(const MetadataValueKey<std::shared_ptr<const Contents> > & s) const - { - switch (op) - { - case kco_equals: - return pattern == join(indirect_iterator(s.value()->begin()), indirect_iterator(s.value()->end()), " ", - stringify_contents_entry); - case kco_less_than: - return indirect_iterator(s.value()->end()) != std::find_if( - indirect_iterator(s.value()->begin()), - indirect_iterator(s.value()->end()), - StringifyEqual(pattern)); - - case kco_greater_than: - case kco_question: - case last_kco: - break; - } - - return false; - } - - bool visit(const MetadataValueKey<std::shared_ptr<const PackageID> > & k) const - { - return pattern == stringify(*k.value()); - } - - bool visit(const MetadataSpecTreeKey<DependencySpecTree> & s) const - { - switch (op) - { - case kco_equals: - return false; - case kco_less_than: - return s.value()->top()->accept_returning<bool>(SpecTreeSearcher(env, id, pattern)); - - case kco_greater_than: - case kco_question: - case last_kco: - break; - } - - return false; - } - - bool visit(const MetadataSpecTreeKey<SetSpecTree> & s) const - { - switch (op) - { - case kco_equals: - return false; - case kco_less_than: - return s.value()->top()->accept_returning<bool>(SpecTreeSearcher(env, id, pattern)); - - case kco_greater_than: - case kco_question: - case last_kco: - break; - } - - return false; - } - - bool visit(const MetadataSpecTreeKey<PlainTextSpecTree> & s) const - { - switch (op) - { - case kco_equals: - return false; - case kco_less_than: - return s.value()->top()->accept_returning<bool>(SpecTreeSearcher(env, id, pattern)); - - case kco_greater_than: - case kco_question: - case last_kco: - break; - } - - return false; - } - - bool visit(const MetadataSpecTreeKey<RequiredUseSpecTree> & s) const - { - switch (op) - { - case kco_equals: - return false; - case kco_less_than: - return s.value()->top()->accept_returning<bool>(SpecTreeSearcher(env, id, pattern)); - - case kco_greater_than: - case kco_question: - case last_kco: - break; - } - - return false; - } - - bool visit(const MetadataSpecTreeKey<ProvideSpecTree> & s) const - { - switch (op) - { - case kco_equals: - return false; - case kco_less_than: - return s.value()->top()->accept_returning<bool>(SpecTreeSearcher(env, id, pattern)); - - case kco_greater_than: - case kco_question: - case last_kco: - break; - } - - return false; - } - - bool visit(const MetadataSpecTreeKey<SimpleURISpecTree> & s) const - { - switch (op) - { - case kco_equals: - return false; - case kco_less_than: - return s.value()->top()->accept_returning<bool>(SpecTreeSearcher(env, id, pattern)); - - case kco_greater_than: - case kco_question: - case last_kco: - break; - } - - return false; - } - - bool visit(const MetadataSpecTreeKey<FetchableURISpecTree> & s) const - { - switch (op) - { - case kco_equals: - return false; - case kco_less_than: - return s.value()->top()->accept_returning<bool>(SpecTreeSearcher(env, id, pattern)); - - case kco_greater_than: - case kco_question: - case last_kco: - break; - } - - return false; - } - - bool visit(const MetadataSpecTreeKey<LicenseSpecTree> & s) const - { - switch (op) - { - case kco_equals: - return false; - case kco_less_than: - return s.value()->top()->accept_returning<bool>(SpecTreeSearcher(env, id, pattern)); - - case kco_greater_than: - case kco_question: - case last_kco: - break; - } - - return false; - } - - bool visit(const MetadataCollectionKey<FSPathSequence> & s) const - { - switch (op) - { - case kco_equals: - return pattern == join(s.value()->begin(), s.value()->end(), " "); - case kco_less_than: - return s.value()->end() != std::find_if(s.value()->begin(), s.value()->end(), - StringifyEqual(pattern)); - - case kco_greater_than: - case kco_question: - case last_kco: - break; - } - - return false; - } - - bool visit(const MetadataCollectionKey<PackageIDSequence> & s) const - { - switch (op) - { - case kco_equals: - return pattern == join(indirect_iterator(s.value()->begin()), indirect_iterator(s.value()->end()), " "); - case kco_less_than: - return indirect_iterator(s.value()->end()) != std::find_if( - indirect_iterator(s.value()->begin()), - indirect_iterator(s.value()->end()), - StringifyEqual(pattern)); - - case kco_greater_than: - case kco_question: - case last_kco: - break; - } - - return false; - } - - bool visit(const MetadataCollectionKey<Sequence<std::string> > & s) const - { - switch (op) - { - case kco_equals: - return pattern == join(s.value()->begin(), s.value()->end(), " "); - case kco_less_than: - return s.value()->end() != std::find_if(s.value()->begin(), s.value()->end(), - StringifyEqual(pattern)); - - case kco_greater_than: - case kco_question: - case last_kco: - break; - } - - return false; - } - - bool visit(const MetadataCollectionKey<Set<std::string> > & s) const - { - switch (op) - { - case kco_equals: - return pattern == join(s.value()->begin(), s.value()->end(), " "); - case kco_less_than: - return s.value()->end() != std::find_if(s.value()->begin(), s.value()->end(), - StringifyEqual(pattern)); - - case kco_greater_than: - case kco_question: - case last_kco: - break; - } - - return false; - } - - bool visit(const MetadataCollectionKey<Map<std::string, std::string> > &) const - { - return false; - } - - bool visit(const MetadataCollectionKey<KeywordNameSet> & s) const - { - switch (op) - { - case kco_equals: - return pattern == join(s.value()->begin(), s.value()->end(), " "); - case kco_less_than: - return s.value()->end() != std::find_if(s.value()->begin(), s.value()->end(), - StringifyEqual(pattern)); - - case kco_greater_than: - case kco_question: - case last_kco: - break; - } - - return false; - } - }; - - bool - match_key_constraint( - const Environment * const env, - const std::shared_ptr<const PackageID> & id, - const std::shared_ptr<const PackageID> &, - const std::shared_ptr<const KeyConstraint> & constraint) - { - const MetadataKey * key(0); - - auto repo(env->fetch_repository(id->repository_name())); - if (0 == constraint->key().compare(0, 3, "::$")) - { - if (constraint->key() == "::$format") - key = repo->format_key().get(); - else if (constraint->key() == "::$location") - key = repo->location_key().get(); - else if (constraint->key() == "::$installed_root") - key = repo->installed_root_key().get(); - else if (constraint->key() == "::$accept_keywords") - key = repo->accept_keywords_key().get(); - else if (constraint->key() == "::$sync_host") - key = repo->sync_host_key().get(); - } - else if (0 == constraint->key().compare(0, 1, "$")) - { - if (constraint->key() == "$behaviours") - key = id->behaviours_key().get(); - else if (constraint->key() == "$build_dependencies") - key = id->build_dependencies_key().get(); - else if (constraint->key() == "$choices") - key = id->choices_key().get(); - else if (constraint->key() == "$contained_in") - key = id->contained_in_key().get(); - else if (constraint->key() == "$contains") - key = id->contains_key().get(); - else if (constraint->key() == "$contents") - key = id->contents_key().get(); - else if (constraint->key() == "$dependencies") - key = id->dependencies_key().get(); - else if (constraint->key() == "$fetches") - key = id->fetches_key().get(); - else if (constraint->key() == "$from_repositories") - key = id->from_repositories_key().get(); - else if (constraint->key() == "$fs_location") - key = id->fs_location_key().get(); - else if (constraint->key() == "$homepage") - key = id->homepage_key().get(); - else if (constraint->key() == "$installed_time") - key = id->installed_time_key().get(); - else if (constraint->key() == "$keywords") - key = id->keywords_key().get(); - else if (constraint->key() == "$long_description") - key = id->long_description_key().get(); - else if (constraint->key() == "$post_dependencies") - key = id->post_dependencies_key().get(); - else if (constraint->key() == "$provide") - key = id->provide_key().get(); - else if (constraint->key() == "$run_dependencies") - key = id->run_dependencies_key().get(); - else if (constraint->key() == "$short_description") - key = id->short_description_key().get(); - else if (constraint->key() == "$slot") - key = id->slot_key().get(); - else if (constraint->key() == "$suggested_dependencies") - key = id->suggested_dependencies_key().get(); - else if (constraint->key() == "$virtual_for") - key = id->virtual_for_key().get(); - } - else if (0 == constraint->key().compare(0, 2, "::")) - { - Repository::MetadataConstIterator m(repo->find_metadata(constraint->key().substr(2))); - if (m != repo->end_metadata()) - key = m->get(); - } - else - { - PackageID::MetadataConstIterator m(id->find_metadata(constraint->key())); - if (m != id->end_metadata()) - key = m->get(); - } - - if (! key) - return false; - - if (constraint->operation() == kco_question) - return true; - else - { - KeyComparator c(env, id, constraint->pattern(), constraint->operation()); - return key->accept_returning<bool>(c); - } - } -} - bool paludis::match_package_with_maybe_changes( const Environment & env, @@ -755,10 +184,8 @@ paludis::match_package_with_maybe_changes( { for (auto c(spec.all_key_constraints()->begin()), c_end(spec.all_key_constraints()->end()) ; c != c_end ; ++c) - { - if (! match_key_constraint(&env, id, from_id, *c)) + if (! (*c)->matches(&env, id)) return false; - } } return true; diff --git a/paludis/package_dep_spec_constraint.cc b/paludis/package_dep_spec_constraint.cc index 0c5482339..226da49ac 100644 --- a/paludis/package_dep_spec_constraint.cc +++ b/paludis/package_dep_spec_constraint.cc @@ -20,6 +20,12 @@ #include <paludis/package_dep_spec_constraint.hh> #include <paludis/version_spec.hh> #include <paludis/version_operator.hh> +#include <paludis/contents.hh> +#include <paludis/metadata_key.hh> +#include <paludis/package_id.hh> +#include <paludis/dep_spec.hh> +#include <paludis/environment.hh> +#include <paludis/repository.hh> #include <paludis/util/pool-impl.hh> #include <paludis/util/pimp-impl.hh> @@ -27,11 +33,18 @@ #include <paludis/util/stringify.hh> #include <paludis/util/exception.hh> #include <paludis/util/sequence-impl.hh> +#include <paludis/util/set-impl.hh> #include <paludis/util/wrapped_forward_iterator-impl.hh> #include <paludis/util/pimp-impl.hh> +#include <paludis/util/indirect_iterator-impl.hh> +#include <paludis/util/accept_visitor.hh> +#include <paludis/util/timestamp.hh> +#include <paludis/util/destringify.hh> +#include <paludis/util/join.hh> #include <istream> #include <ostream> +#include <algorithm> using namespace paludis; @@ -312,6 +325,575 @@ KeyConstraint::pattern() const return _pattern; } +namespace +{ + std::string stringify_contents_entry(const ContentsEntry & e) + { + return stringify(e.location_key()->value()); + } + + struct StringifyEqual + { + const std::string pattern; + + StringifyEqual(const std::string & p) : + pattern(p) + { + } + + template <typename T_> + bool operator() (const T_ & t) const + { + return stringify(t) == pattern; + } + + bool operator() (const ContentsEntry & e) const + { + return stringify_contents_entry(e) == pattern; + } + }; + + struct SpecTreeSearcher + { + const Environment * const env; + const std::shared_ptr<const PackageID> id; + const std::string pattern; + + SpecTreeSearcher(const Environment * const e, const std::shared_ptr<const PackageID> & i, const std::string & p) : + env(e), + id(i), + pattern(p) + { + } + + bool visit(const GenericSpecTree::NodeType<AllDepSpec>::Type & n) const + { + return indirect_iterator(n.end()) != std::find_if(indirect_iterator(n.begin()), indirect_iterator(n.end()), + accept_visitor_returning<bool>(*this)); + } + + bool visit(const GenericSpecTree::NodeType<AnyDepSpec>::Type & n) const + { + return indirect_iterator(n.end()) != std::find_if(indirect_iterator(n.begin()), indirect_iterator(n.end()), + accept_visitor_returning<bool>(*this)); + } + + bool visit(const GenericSpecTree::NodeType<ExactlyOneDepSpec>::Type & n) const + { + return indirect_iterator(n.end()) != std::find_if(indirect_iterator(n.begin()), indirect_iterator(n.end()), + accept_visitor_returning<bool>(*this)); + } + + bool visit(const GenericSpecTree::NodeType<ConditionalDepSpec>::Type & n) const + { + if (n.spec()->condition_met(env, id)) + return indirect_iterator(n.end()) != std::find_if(indirect_iterator(n.begin()), indirect_iterator(n.end()), + accept_visitor_returning<bool>(*this)); + else + return false; + } + + bool visit(const GenericSpecTree::NodeType<NamedSetDepSpec>::Type & n) const + { + return stringify(*n.spec()) == pattern; + } + + bool visit(const GenericSpecTree::NodeType<PlainTextDepSpec>::Type & n) const + { + return stringify(*n.spec()) == pattern; + } + + bool visit(const GenericSpecTree::NodeType<PackageDepSpec>::Type & n) const + { + return stringify(*n.spec()) == pattern; + } + + bool visit(const GenericSpecTree::NodeType<BlockDepSpec>::Type & n) const + { + return stringify(*n.spec()) == pattern; + } + + bool visit(const GenericSpecTree::NodeType<LicenseDepSpec>::Type & n) const + { + return stringify(*n.spec()) == pattern; + } + + bool visit(const GenericSpecTree::NodeType<SimpleURIDepSpec>::Type & n) const + { + return stringify(*n.spec()) == pattern; + } + + bool visit(const GenericSpecTree::NodeType<FetchableURIDepSpec>::Type & n) const + { + return stringify(*n.spec()) == pattern; + } + + bool visit(const GenericSpecTree::NodeType<DependenciesLabelsDepSpec>::Type & n) const + { + return indirect_iterator(n.spec()->end()) != std::find_if(indirect_iterator(n.spec()->begin()), + indirect_iterator(n.spec()->end()), StringifyEqual(pattern)); + } + + bool visit(const GenericSpecTree::NodeType<URILabelsDepSpec>::Type & n) const + { + return indirect_iterator(n.spec()->end()) != std::find_if(indirect_iterator(n.spec()->begin()), + indirect_iterator(n.spec()->end()), StringifyEqual(pattern)); + } + + bool visit(const GenericSpecTree::NodeType<PlainTextLabelDepSpec>::Type & n) const + { + return stringify(*n.spec()) == pattern; + } + }; + + struct KeyComparator + { + const Environment * const env; + const std::shared_ptr<const PackageID> id; + const std::string pattern; + const KeyConstraintOperation op; + + KeyComparator(const Environment * const e, const std::shared_ptr<const PackageID> & i, + const std::string & p, const KeyConstraintOperation o) : + env(e), + id(i), + pattern(p), + op(o) + { + } + + bool visit(const MetadataSectionKey &) const + { + return false; + } + + bool visit(const MetadataTimeKey & k) const + { + switch (op) + { + case kco_equals: + return pattern == stringify(k.value().seconds()); + case kco_less_than: + return k.value().seconds() < destringify<time_t>(pattern); + case kco_greater_than: + return k.value().seconds() > destringify<time_t>(pattern); + case kco_question: + case last_kco: + break; + } + + return false; + } + + bool visit(const MetadataValueKey<std::string> & k) const + { + return pattern == stringify(k.value()); + } + + bool visit(const MetadataValueKey<SlotName> & k) const + { + return pattern == stringify(k.value()); + } + + bool visit(const MetadataValueKey<FSPath> & k) const + { + return pattern == stringify(k.value()); + } + + bool visit(const MetadataValueKey<bool> & k) const + { + return pattern == stringify(k.value()); + } + + bool visit(const MetadataValueKey<long> & k) const + { + switch (op) + { + case kco_equals: + return pattern == stringify(k.value()); + case kco_less_than: + return k.value() < destringify<long>(pattern); + case kco_greater_than: + return k.value() > destringify<long>(pattern); + case kco_question: + case last_kco: + break; + } + + return false; + } + + bool visit(const MetadataValueKey<std::shared_ptr<const Choices> > &) const + { + return false; + } + + bool visit(const MetadataValueKey<std::shared_ptr<const Contents> > & s) const + { + switch (op) + { + case kco_equals: + return pattern == join(indirect_iterator(s.value()->begin()), indirect_iterator(s.value()->end()), " ", + stringify_contents_entry); + case kco_less_than: + return indirect_iterator(s.value()->end()) != std::find_if( + indirect_iterator(s.value()->begin()), + indirect_iterator(s.value()->end()), + StringifyEqual(pattern)); + + case kco_greater_than: + case kco_question: + case last_kco: + break; + } + + return false; + } + + bool visit(const MetadataValueKey<std::shared_ptr<const PackageID> > & k) const + { + return pattern == stringify(*k.value()); + } + + bool visit(const MetadataSpecTreeKey<DependencySpecTree> & s) const + { + switch (op) + { + case kco_equals: + return false; + case kco_less_than: + return s.value()->top()->accept_returning<bool>(SpecTreeSearcher(env, id, pattern)); + + case kco_greater_than: + case kco_question: + case last_kco: + break; + } + + return false; + } + + bool visit(const MetadataSpecTreeKey<SetSpecTree> & s) const + { + switch (op) + { + case kco_equals: + return false; + case kco_less_than: + return s.value()->top()->accept_returning<bool>(SpecTreeSearcher(env, id, pattern)); + + case kco_greater_than: + case kco_question: + case last_kco: + break; + } + + return false; + } + + bool visit(const MetadataSpecTreeKey<PlainTextSpecTree> & s) const + { + switch (op) + { + case kco_equals: + return false; + case kco_less_than: + return s.value()->top()->accept_returning<bool>(SpecTreeSearcher(env, id, pattern)); + + case kco_greater_than: + case kco_question: + case last_kco: + break; + } + + return false; + } + + bool visit(const MetadataSpecTreeKey<RequiredUseSpecTree> & s) const + { + switch (op) + { + case kco_equals: + return false; + case kco_less_than: + return s.value()->top()->accept_returning<bool>(SpecTreeSearcher(env, id, pattern)); + + case kco_greater_than: + case kco_question: + case last_kco: + break; + } + + return false; + } + + bool visit(const MetadataSpecTreeKey<ProvideSpecTree> & s) const + { + switch (op) + { + case kco_equals: + return false; + case kco_less_than: + return s.value()->top()->accept_returning<bool>(SpecTreeSearcher(env, id, pattern)); + + case kco_greater_than: + case kco_question: + case last_kco: + break; + } + + return false; + } + + bool visit(const MetadataSpecTreeKey<SimpleURISpecTree> & s) const + { + switch (op) + { + case kco_equals: + return false; + case kco_less_than: + return s.value()->top()->accept_returning<bool>(SpecTreeSearcher(env, id, pattern)); + + case kco_greater_than: + case kco_question: + case last_kco: + break; + } + + return false; + } + + bool visit(const MetadataSpecTreeKey<FetchableURISpecTree> & s) const + { + switch (op) + { + case kco_equals: + return false; + case kco_less_than: + return s.value()->top()->accept_returning<bool>(SpecTreeSearcher(env, id, pattern)); + + case kco_greater_than: + case kco_question: + case last_kco: + break; + } + + return false; + } + + bool visit(const MetadataSpecTreeKey<LicenseSpecTree> & s) const + { + switch (op) + { + case kco_equals: + return false; + case kco_less_than: + return s.value()->top()->accept_returning<bool>(SpecTreeSearcher(env, id, pattern)); + + case kco_greater_than: + case kco_question: + case last_kco: + break; + } + + return false; + } + + bool visit(const MetadataCollectionKey<FSPathSequence> & s) const + { + switch (op) + { + case kco_equals: + return pattern == join(s.value()->begin(), s.value()->end(), " "); + case kco_less_than: + return s.value()->end() != std::find_if(s.value()->begin(), s.value()->end(), + StringifyEqual(pattern)); + + case kco_greater_than: + case kco_question: + case last_kco: + break; + } + + return false; + } + + bool visit(const MetadataCollectionKey<PackageIDSequence> & s) const + { + switch (op) + { + case kco_equals: + return pattern == join(indirect_iterator(s.value()->begin()), indirect_iterator(s.value()->end()), " "); + case kco_less_than: + return indirect_iterator(s.value()->end()) != std::find_if( + indirect_iterator(s.value()->begin()), + indirect_iterator(s.value()->end()), + StringifyEqual(pattern)); + + case kco_greater_than: + case kco_question: + case last_kco: + break; + } + + return false; + } + + bool visit(const MetadataCollectionKey<Sequence<std::string> > & s) const + { + switch (op) + { + case kco_equals: + return pattern == join(s.value()->begin(), s.value()->end(), " "); + case kco_less_than: + return s.value()->end() != std::find_if(s.value()->begin(), s.value()->end(), + StringifyEqual(pattern)); + + case kco_greater_than: + case kco_question: + case last_kco: + break; + } + + return false; + } + + bool visit(const MetadataCollectionKey<Set<std::string> > & s) const + { + switch (op) + { + case kco_equals: + return pattern == join(s.value()->begin(), s.value()->end(), " "); + case kco_less_than: + return s.value()->end() != std::find_if(s.value()->begin(), s.value()->end(), + StringifyEqual(pattern)); + + case kco_greater_than: + case kco_question: + case last_kco: + break; + } + + return false; + } + + bool visit(const MetadataCollectionKey<Map<std::string, std::string> > &) const + { + return false; + } + + bool visit(const MetadataCollectionKey<KeywordNameSet> & s) const + { + switch (op) + { + case kco_equals: + return pattern == join(s.value()->begin(), s.value()->end(), " "); + case kco_less_than: + return s.value()->end() != std::find_if(s.value()->begin(), s.value()->end(), + StringifyEqual(pattern)); + + case kco_greater_than: + case kco_question: + case last_kco: + break; + } + + return false; + } + }; +} + +bool +KeyConstraint::matches( + const Environment * const env, + const std::shared_ptr<const PackageID> & id) const +{ + const MetadataKey * k(0); + + auto repo(env->fetch_repository(id->repository_name())); + if (0 == key().compare(0, 3, "::$")) + { + if (key() == "::$format") + k = repo->format_key().get(); + else if (key() == "::$location") + k = repo->location_key().get(); + else if (key() == "::$installed_root") + k = repo->installed_root_key().get(); + else if (key() == "::$accept_keywords") + k = repo->accept_keywords_key().get(); + else if (key() == "::$sync_host") + k = repo->sync_host_key().get(); + } + else if (0 == key().compare(0, 1, "$")) + { + if (key() == "$behaviours") + k = id->behaviours_key().get(); + else if (key() == "$build_dependencies") + k = id->build_dependencies_key().get(); + else if (key() == "$choices") + k = id->choices_key().get(); + else if (key() == "$contained_in") + k = id->contained_in_key().get(); + else if (key() == "$contains") + k = id->contains_key().get(); + else if (key() == "$contents") + k = id->contents_key().get(); + else if (key() == "$dependencies") + k = id->dependencies_key().get(); + else if (key() == "$fetches") + k = id->fetches_key().get(); + else if (key() == "$from_repositories") + k = id->from_repositories_key().get(); + else if (key() == "$fs_location") + k = id->fs_location_key().get(); + else if (key() == "$homepage") + k = id->homepage_key().get(); + else if (key() == "$installed_time") + k = id->installed_time_key().get(); + else if (key() == "$keywords") + k = id->keywords_key().get(); + else if (key() == "$long_description") + k = id->long_description_key().get(); + else if (key() == "$post_dependencies") + k = id->post_dependencies_key().get(); + else if (key() == "$provide") + k = id->provide_key().get(); + else if (key() == "$run_dependencies") + k = id->run_dependencies_key().get(); + else if (key() == "$short_description") + k = id->short_description_key().get(); + else if (key() == "$slot") + k = id->slot_key().get(); + else if (key() == "$suggested_dependencies") + k = id->suggested_dependencies_key().get(); + else if (key() == "$virtual_for") + k = id->virtual_for_key().get(); + } + else if (0 == key().compare(0, 2, "::")) + { + Repository::MetadataConstIterator m(repo->find_metadata(key().substr(2))); + if (m != repo->end_metadata()) + k = m->get(); + } + else + { + PackageID::MetadataConstIterator m(id->find_metadata(key())); + if (m != id->end_metadata()) + k = m->get(); + } + + if (! k) + return false; + + if (operation() == kco_question) + return true; + else + { + KeyComparator c(env, id, pattern(), operation()); + return k->accept_returning<bool>(c); + } +} + template class Pool<KeyConstraint>; template class Singleton<Pool<KeyConstraint> >; template const std::shared_ptr<const KeyConstraint> Pool<KeyConstraint>::create(const std::string &, const KeyConstraintOperation &, const std::string &) const; diff --git a/paludis/package_dep_spec_constraint.hh b/paludis/package_dep_spec_constraint.hh index 87643bbda..10bf96b86 100644 --- a/paludis/package_dep_spec_constraint.hh +++ b/paludis/package_dep_spec_constraint.hh @@ -24,6 +24,8 @@ #include <paludis/name.hh> #include <paludis/version_operator-fwd.hh> #include <paludis/version_spec-fwd.hh> +#include <paludis/environment-fwd.hh> +#include <paludis/package_id-fwd.hh> #include <paludis/util/attributes.hh> #include <paludis/util/pool.hh> @@ -291,6 +293,10 @@ namespace paludis const std::string key() const PALUDIS_ATTRIBUTE((warn_unused_result)); KeyConstraintOperation operation() const PALUDIS_ATTRIBUTE((warn_unused_result)); const std::string pattern() const PALUDIS_ATTRIBUTE((warn_unused_result)); + + bool matches( + const Environment * const env, + const std::shared_ptr<const PackageID> & id) const PALUDIS_ATTRIBUTE((warn_unused_result)); }; extern template class Pool<NameConstraint>; |