aboutsummaryrefslogtreecommitdiff
path: root/paludis/resolver/make_origin_filtered_generator_helper.cc
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-07 16:39:47 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-08 10:53:07 +0100
commit490687fe881a3d2f9ba194a5675d522adff20e96 (patch)
tree0ad8a0ae1fa4d974c36965388da8286d73cf3f50 /paludis/resolver/make_origin_filtered_generator_helper.cc
parent2071e4f42961487f4a7e1c565790bc2647f344bf (diff)
downloadpaludis-490687fe881a3d2f9ba194a5675d522adff20e96.tar.gz
paludis-490687fe881a3d2f9ba194a5675d522adff20e96.tar.xz
MakeOriginFilteredGeneratorHelper
Diffstat (limited to 'paludis/resolver/make_origin_filtered_generator_helper.cc')
-rw-r--r--paludis/resolver/make_origin_filtered_generator_helper.cc110
1 files changed, 110 insertions, 0 deletions
diff --git a/paludis/resolver/make_origin_filtered_generator_helper.cc b/paludis/resolver/make_origin_filtered_generator_helper.cc
new file mode 100644
index 000000000..1e18ed6d9
--- /dev/null
+++ b/paludis/resolver/make_origin_filtered_generator_helper.cc
@@ -0,0 +1,110 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2010 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
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <paludis/resolver/make_origin_filtered_generator_helper.hh>
+#include <paludis/resolver/destination_utils.hh>
+#include <paludis/util/pimp-impl.hh>
+#include <paludis/util/set.hh>
+#include <paludis/filter.hh>
+#include <paludis/filter_handler.hh>
+#include <paludis/generator.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/package_id.hh>
+#include <paludis/metadata_key.hh>
+
+using namespace paludis;
+using namespace paludis::resolver;
+
+namespace paludis
+{
+ template <>
+ struct Imp<MakeOriginFilteredGeneratorHelper>
+ {
+ const Environment * const env;
+ bool making_binaries;
+
+ Imp(const Environment * const e) :
+ env(e),
+ making_binaries(false)
+ {
+ }
+ };
+}
+
+MakeOriginFilteredGeneratorHelper::MakeOriginFilteredGeneratorHelper(const Environment * const e) :
+ Pimp<MakeOriginFilteredGeneratorHelper>(e)
+{
+}
+
+MakeOriginFilteredGeneratorHelper::~MakeOriginFilteredGeneratorHelper() = default;
+
+void
+MakeOriginFilteredGeneratorHelper::set_making_binaries(const bool v)
+{
+ _imp->making_binaries = v;
+}
+
+namespace
+{
+ struct BinaryableFilterHandler :
+ AllFilterHandlerBase
+ {
+ 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 (can_make_binary_for(*i))
+ result->insert(*i);
+
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return "binaryable";
+ }
+ };
+
+ struct BinaryableFilter :
+ Filter
+ {
+ BinaryableFilter() :
+ Filter(std::make_shared<BinaryableFilterHandler>())
+ {
+ }
+ };
+}
+
+FilteredGenerator
+MakeOriginFilteredGeneratorHelper::operator() (
+ const Generator & g,
+ const std::shared_ptr<const Resolution> &) const
+{
+ if (_imp->making_binaries)
+ return g | BinaryableFilter();
+ else
+ return g;
+}
+
+template class Pimp<MakeOriginFilteredGeneratorHelper>;
+