diff options
author | 2014-01-05 18:23:34 +0000 | |
---|---|---|
committer | 2014-01-05 18:35:56 +0000 | |
commit | e7bcd85c494e5bdc6d2446bb94dd49df0c39dbb2 (patch) | |
tree | c235f8b6d99a3e2539f12fa78a18206e9cef6331 | |
parent | 2dc3c09d27897760ee2d6dbb1c9044e42278d255 (diff) | |
download | paludis-e7bcd85c494e5bdc6d2446bb94dd49df0c39dbb2.tar.gz paludis-e7bcd85c494e5bdc6d2446bb94dd49df0c39dbb2.tar.xz |
filter::ByFunction
-rw-r--r-- | paludis/filter-fwd.hh | 3 | ||||
-rw-r--r-- | paludis/filter.cc | 43 | ||||
-rw-r--r-- | paludis/filter.hh | 18 |
3 files changed, 60 insertions, 4 deletions
diff --git a/paludis/filter-fwd.hh b/paludis/filter-fwd.hh index d68dffe64..2cbc5dfb5 100644 --- a/paludis/filter-fwd.hh +++ b/paludis/filter-fwd.hh @@ -1,7 +1,7 @@ /* vim: set sw=4 sts=4 et foldmethod=syntax : */ /* - * Copyright (c) 2008, 2010 Ciaran McCreesh + * Copyright (c) 2008, 2010, 2014 Ciaran McCreesh * * This file is part of the Paludis package manager. Paludis is free software; * you can redistribute it and/or modify it under the terms of the GNU General @@ -41,6 +41,7 @@ namespace paludis class And; class Slot; class Matches; + class ByFunction; class InstalledAtRoot; class InstalledAtSlash; diff --git a/paludis/filter.cc b/paludis/filter.cc index 53d8f8a4d..46ef1ac04 100644 --- a/paludis/filter.cc +++ b/paludis/filter.cc @@ -1,7 +1,7 @@ /* vim: set sw=4 sts=4 et foldmethod=syntax : */ /* - * Copyright (c) 2008, 2009, 2010, 2011 Ciaran McCreesh + * Copyright (c) 2008, 2009, 2010, 2011, 2014 Ciaran McCreesh * * This file is part of the Paludis package manager. Paludis is free software; * you can redistribute it and/or modify it under the terms of the GNU General @@ -473,6 +473,40 @@ namespace return "packages matching " + stringify(spec) + suffix; } }; + + struct ByFunctionHandler : + AllFilterHandlerBase + { + const std::function<bool (const std::shared_ptr<const PackageID> &)> func; + const std::string desc; + + ByFunctionHandler(const std::function<bool (const std::shared_ptr<const PackageID> &)> & f, const std::string & s) : + func(f), + desc(s) + { + } + + virtual std::shared_ptr<const PackageIDSet> ids( + const Environment * const, + const std::shared_ptr<const PackageIDSet> & id) const + { + std::shared_ptr<PackageIDSet> result(std::make_shared<PackageIDSet>()); + + for (PackageIDSet::ConstIterator i(id->begin()), i_end(id->end()) ; + i != i_end ; ++i) + { + if (! func(*i)) + result->insert(*i); + } + + return result; + } + + virtual std::string as_string() const + { + return desc; + } + }; } filter::All::All() : @@ -536,6 +570,13 @@ filter::Matches::Matches(const PackageDepSpec & spec, const std::shared_ptr<cons { } +filter::ByFunction::ByFunction( + const std::function<bool (const std::shared_ptr<const PackageID> &)> & f, + const std::string & s) : + Filter(std::make_shared<ByFunctionHandler>(f, s)) +{ +} + std::ostream & paludis::operator<< (std::ostream & s, const Filter & f) { diff --git a/paludis/filter.hh b/paludis/filter.hh index c79a111ae..7ed4b68fe 100644 --- a/paludis/filter.hh +++ b/paludis/filter.hh @@ -1,7 +1,7 @@ /* vim: set sw=4 sts=4 et foldmethod=syntax : */ /* - * Copyright (c) 2008, 2009, 2010, 2011 Ciaran McCreesh + * Copyright (c) 2008, 2009, 2010, 2011, 2014 Ciaran McCreesh * * This file is part of the Paludis package manager. Paludis is free software; * you can redistribute it and/or modify it under the terms of the GNU General @@ -282,7 +282,6 @@ namespace paludis * * \ingroup g_selections */ - class PALUDIS_VISIBLE Matches : public Filter { @@ -298,6 +297,21 @@ namespace paludis const std::shared_ptr<const PackageID> & from_id, const MatchPackageOptions &); }; + + /** + * A Filter which rejects PackageIDs using a function. + * + * \ingroup g_selections + * \since 2.0 + */ + class PALUDIS_VISIBLE ByFunction : + public Filter + { + public: + ByFunction( + const std::function<bool (const std::shared_ptr<const PackageID> &)> &, + const std::string &); + }; } extern template class Pimp<Filter>; |