aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Paul Mulders <info@mld.demon.nl> 2010-03-06 13:04:31 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-03-06 12:23:28 +0000
commit4f64c70b09cd995fbd9cd2b36f59f1164a0013c0 (patch)
treed3c0a62fbc2331ee99e9675d355eabf617d22a31
parent7a58de7637da67d8420cab0b69c79bbb376a5688 (diff)
downloadpaludis-4f64c70b09cd995fbd9cd2b36f59f1164a0013c0.tar.gz
paludis-4f64c70b09cd995fbd9cd2b36f59f1164a0013c0.tar.xz
Implement filter::Matches.
-rw-r--r--paludis/filter-fwd.hh1
-rw-r--r--paludis/filter.cc43
-rw-r--r--paludis/filter.hh16
-rw-r--r--paludis/filter_TEST.cc75
4 files changed, 135 insertions, 0 deletions
diff --git a/paludis/filter-fwd.hh b/paludis/filter-fwd.hh
index 69c92e8..84bed5b 100644
--- a/paludis/filter-fwd.hh
+++ b/paludis/filter-fwd.hh
@@ -41,6 +41,7 @@ namespace paludis
class InstalledAtRoot;
class And;
class Slot;
+ class Matches;
}
/**
diff --git a/paludis/filter.cc b/paludis/filter.cc
index 1083841..4429d11 100644
--- a/paludis/filter.cc
+++ b/paludis/filter.cc
@@ -25,6 +25,7 @@
#include <paludis/package_id.hh>
#include <paludis/package_database.hh>
#include <paludis/metadata_key.hh>
+#include <paludis/match_package.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/set.hh>
#include <paludis/util/sequence.hh>
@@ -371,6 +372,43 @@ namespace
return "has no slot";
}
};
+
+ struct MatchesHandler :
+ AllFilterHandlerBase
+ {
+ const PackageDepSpec spec;
+ const MatchPackageOptions options;
+
+ MatchesHandler(const PackageDepSpec & s, const MatchPackageOptions & o) :
+ spec(s),
+ options(o)
+ {
+ }
+
+ virtual std::tr1::shared_ptr<const PackageIDSet> ids(
+ const Environment * const env,
+ const std::tr1::shared_ptr<const PackageIDSet> & id) const
+ {
+ std::tr1::shared_ptr<PackageIDSet> result(new PackageIDSet);
+
+ for (PackageIDSet::ConstIterator i(id->begin()), i_end(id->end()) ;
+ i != i_end ; ++i)
+ {
+ if (match_package(*env, spec, **i, options))
+ result->insert(*i);
+ }
+
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ std::string suffix;
+ if (options[mpo_ignore_additional_requirements])
+ suffix = " (ignoring additional requirements)";
+ return "packages matching " + stringify(spec) + suffix;
+ }
+ };
}
filter::All::All() :
@@ -414,6 +452,11 @@ filter::NoSlot::NoSlot() :
{
}
+filter::Matches::Matches(const PackageDepSpec & spec, const MatchPackageOptions & o) :
+ Filter(make_shared_ptr(new MatchesHandler(spec, o)))
+{
+}
+
std::ostream &
paludis::operator<< (std::ostream & s, const Filter & f)
{
diff --git a/paludis/filter.hh b/paludis/filter.hh
index fe025af..9f882e8 100644
--- a/paludis/filter.hh
+++ b/paludis/filter.hh
@@ -30,6 +30,8 @@
#include <paludis/environment-fwd.hh>
#include <paludis/package_id-fwd.hh>
#include <paludis/action-fwd.hh>
+#include <paludis/dep_spec-fwd.hh>
+#include <paludis/match_package-fwd.hh>
#include <tr1/memory>
/** \file
@@ -221,6 +223,20 @@ namespace paludis
public:
NoSlot();
};
+
+ /**
+ * A Filter which accepts only PackageID instances that match a
+ * particular PackageDepSpec.
+ *
+ * \ingroup g_selections
+ */
+
+ class PALUDIS_VISIBLE Matches :
+ public Filter
+ {
+ public:
+ Matches(const PackageDepSpec &, const MatchPackageOptions &);
+ };
}
#ifdef PALUDIS_HAVE_EXTERN_TEMPLATE
diff --git a/paludis/filter_TEST.cc b/paludis/filter_TEST.cc
index a96669a..13495b5 100644
--- a/paludis/filter_TEST.cc
+++ b/paludis/filter_TEST.cc
@@ -217,5 +217,80 @@ namespace test_cases
"cat/c-3:0::repo2";
}
} not_masked_and_installable_filter_test;
+
+ struct MatchesFilterTestCase : FilterTestCaseBase
+ {
+ MatchesFilterTestCase() :
+ FilterTestCaseBase("matches", filter::Matches(parse_user_package_dep_spec("cat/a",
+ &env, UserPackageDepSpecOptions()), MatchPackageOptions()))
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return
+ "cat/a-1:0::inst_repo1, "
+ "cat/a-1:0::repo1, "
+ "cat/a-1:0::repo2, "
+ "cat/a-2:0::repo2";
+ }
+ } matches_filter_test;
+
+ struct MatchesCatWildcardFilterTestCase : FilterTestCaseBase
+ {
+ MatchesCatWildcardFilterTestCase() :
+ FilterTestCaseBase("matches cat wildcard", filter::Matches(parse_user_package_dep_spec("*/a",
+ &env, UserPackageDepSpecOptions() + updso_allow_wildcards), MatchPackageOptions()))
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return
+ "cat/a-1:0::inst_repo1, "
+ "cat/a-1:0::repo1, "
+ "cat/a-1:0::repo2, "
+ "cat/a-2:0::repo2";
+ }
+ } matches_cat_wildcard_filter_test;
+
+ struct MatchesPkgWildcardFilterTestCase : FilterTestCaseBase
+ {
+ MatchesPkgWildcardFilterTestCase() :
+ FilterTestCaseBase("matches pkg wildcard", filter::Matches(parse_user_package_dep_spec("cat/*",
+ &env, UserPackageDepSpecOptions() + updso_allow_wildcards), MatchPackageOptions()))
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return
+ "cat/a-1:0::inst_repo1, "
+ "cat/a-1:0::repo1, "
+ "cat/a-1:0::repo2, "
+ "cat/a-2:0::repo2, "
+ "cat/b-2:0::repo1, "
+ "cat/c-3:0::repo2";
+ }
+ } matches_pkg_wildcard_filter_test;
+
+ struct MatchesAllWildcardFilterTestCase : FilterTestCaseBase
+ {
+ MatchesAllWildcardFilterTestCase() :
+ FilterTestCaseBase("matches all wildcard", filter::Matches(
+ parse_user_package_dep_spec(">=*/*-2",
+ &env, UserPackageDepSpecOptions() + updso_allow_wildcards), MatchPackageOptions()))
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return
+ "cat/a-2:0::repo2, "
+ "cat/b-2:0::repo1, "
+ "cat/c-3:0::repo2";
+ }
+ } matches_all_wildcard_filter_test;
+
}