diff options
author | 2009-12-17 21:12:45 +0000 | |
---|---|---|
committer | 2009-12-17 21:12:45 +0000 | |
commit | 7045e87a387b78a97ec4352729527ce0174d4c60 (patch) | |
tree | c84672df83e150fdf8073a274fd8193b2ede1224 /paludis | |
parent | 5b0b77894361ac4ca7cc68a5d1915cac4f5a15e1 (diff) | |
download | paludis-7045e87a387b78a97ec4352729527ce0174d4c60.tar.gz paludis-7045e87a387b78a97ec4352729527ce0174d4c60.tar.xz |
Make [.k=v] deps work on spec trees
Diffstat (limited to 'paludis')
-rw-r--r-- | paludis/user_dep_spec.cc | 154 | ||||
-rw-r--r-- | paludis/util/accept_visitor.hh | 43 |
2 files changed, 190 insertions, 7 deletions
diff --git a/paludis/user_dep_spec.cc b/paludis/user_dep_spec.cc index 6e2a48e51..7c95b70d1 100644 --- a/paludis/user_dep_spec.cc +++ b/paludis/user_dep_spec.cc @@ -28,6 +28,7 @@ #include <paludis/filter.hh> #include <paludis/package_id.hh> #include <paludis/metadata_key.hh> +#include <paludis/dep_label.hh> #include <paludis/util/make_shared_ptr.hh> #include <paludis/util/options.hh> #include <paludis/util/log.hh> @@ -401,6 +402,89 @@ namespace } }; + struct SpecTreeSearcher + { + const std::string pattern; + + SpecTreeSearcher(const std::string & p) : + 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<ConditionalDepSpec>::Type & n) const + { + if (n.spec()->condition_met()) + 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 std::string pattern; @@ -495,38 +579,94 @@ namespace return pattern == stringify(*k.value()); } - bool visit(const MetadataSpecTreeKey<DependencySpecTree> &) const + bool visit(const MetadataSpecTreeKey<DependencySpecTree> & s) const { + switch (op) + { + case '=': + return false; + case '<': + return s.value()->root()->accept_returning<bool>(SpecTreeSearcher(pattern)); + } + return false; } - bool visit(const MetadataSpecTreeKey<SetSpecTree> &) const + bool visit(const MetadataSpecTreeKey<SetSpecTree> & s) const { + switch (op) + { + case '=': + return false; + case '<': + return s.value()->root()->accept_returning<bool>(SpecTreeSearcher(pattern)); + } + return false; } - bool visit(const MetadataSpecTreeKey<PlainTextSpecTree> &) const + bool visit(const MetadataSpecTreeKey<PlainTextSpecTree> & s) const { + switch (op) + { + case '=': + return false; + case '<': + return s.value()->root()->accept_returning<bool>(SpecTreeSearcher(pattern)); + } + return false; } - bool visit(const MetadataSpecTreeKey<ProvideSpecTree> &) const + bool visit(const MetadataSpecTreeKey<ProvideSpecTree> & s) const { + switch (op) + { + case '=': + return false; + case '<': + return s.value()->root()->accept_returning<bool>(SpecTreeSearcher(pattern)); + } + return false; } - bool visit(const MetadataSpecTreeKey<SimpleURISpecTree> &) const + bool visit(const MetadataSpecTreeKey<SimpleURISpecTree> & s) const { + switch (op) + { + case '=': + return false; + case '<': + return s.value()->root()->accept_returning<bool>(SpecTreeSearcher(pattern)); + } + return false; } - bool visit(const MetadataSpecTreeKey<FetchableURISpecTree> &) const + bool visit(const MetadataSpecTreeKey<FetchableURISpecTree> & s) const { + switch (op) + { + case '=': + return false; + case '<': + return s.value()->root()->accept_returning<bool>(SpecTreeSearcher(pattern)); + } + return false; } - bool visit(const MetadataSpecTreeKey<LicenseSpecTree> &) const + bool visit(const MetadataSpecTreeKey<LicenseSpecTree> & s) const { + switch (op) + { + case '=': + return false; + case '<': + return s.value()->root()->accept_returning<bool>(SpecTreeSearcher(pattern)); + } + return false; } diff --git a/paludis/util/accept_visitor.hh b/paludis/util/accept_visitor.hh index bccb0fe37..d68ead189 100644 --- a/paludis/util/accept_visitor.hh +++ b/paludis/util/accept_visitor.hh @@ -57,6 +57,38 @@ namespace paludis }; /** + * Used by accept_visitor. + * + * \nosubgrouping + * \ingroup g_visitors + */ + template <typename Visitor_, typename Returning_> + class PALUDIS_VISIBLE AcceptVisitorReturning + { + private: + Visitor_ & _v; + + public: + typedef Returning_ result_type; + + ///\name Visitor operations + ///\{ + + AcceptVisitorReturning(Visitor_ & v) : + _v(v) + { + } + + template <typename T_> + Returning_ operator() (T_ & t) const + { + return t.template accept_returning<Returning_>(_v); + } + + ///\} + }; + + /** * Convenience function for using a visitor with a standard algorithm. * * \ingroup g_visitors @@ -66,6 +98,17 @@ namespace paludis { return AcceptVisitor<Visitor_>(v); } + + /** + * Convenience function for using a visitor with a standard algorithm. + * + * \ingroup g_visitors + */ + template <typename Returning_, typename Visitor_> + AcceptVisitorReturning<Visitor_, Returning_> PALUDIS_VISIBLE accept_visitor_returning(Visitor_ & v) + { + return AcceptVisitorReturning<Visitor_, Returning_>(v); + } } #endif |