aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-09-16 21:13:31 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-09-16 21:13:31 +0100
commit988e54546d7a22c3862ed4c4d8bb2deace1825aa (patch)
treee0f5867db62ed8675fce63f0aeef39d562e51810
parent914b2665a1360c8daead4e0c5419da6984c23b7f (diff)
downloadpaludis-988e54546d7a22c3862ed4c4d8bb2deace1825aa.tar.gz
paludis-988e54546d7a22c3862ed4c4d8bb2deace1825aa.tar.xz
Add union generator
-rw-r--r--paludis/generator-fwd.hh6
-rw-r--r--paludis/generator.cc88
-rw-r--r--paludis/generator.hh9
3 files changed, 101 insertions, 2 deletions
diff --git a/paludis/generator-fwd.hh b/paludis/generator-fwd.hh
index 821c0dd..48bc9cb 100644
--- a/paludis/generator-fwd.hh
+++ b/paludis/generator-fwd.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008 Ciaran McCreesh
+ * Copyright (c) 2008, 2009 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
@@ -36,12 +36,16 @@ namespace paludis
class InRepository;
class Category;
class Intersection;
+ class Union;
template <typename> class SomeIDsMightSupportAction;
}
Generator operator& (const Generator &, const Generator &)
PALUDIS_ATTRIBUTE((warn_unused_result)) PALUDIS_VISIBLE;
+ Generator operator+ (const Generator &, const Generator &)
+ PALUDIS_ATTRIBUTE((warn_unused_result)) PALUDIS_VISIBLE;
+
std::ostream & operator<< (std::ostream &, const Generator &)
PALUDIS_VISIBLE;
}
diff --git a/paludis/generator.cc b/paludis/generator.cc
index f272d40..1abe6f8 100644
--- a/paludis/generator.cc
+++ b/paludis/generator.cc
@@ -565,6 +565,83 @@ namespace
}
};
+ struct UnionGeneratorHandler :
+ GeneratorHandler
+ {
+ const Generator g1;
+ const Generator g2;
+
+ UnionGeneratorHandler(const Generator & h1, const Generator & h2) :
+ g1(h1),
+ g2(h2)
+ {
+ }
+
+ virtual std::tr1::shared_ptr<const RepositoryNameSet> repositories(
+ const Environment * const env) const
+ {
+ std::tr1::shared_ptr<const RepositoryNameSet> r1(g1.repositories(env));
+ std::tr1::shared_ptr<const RepositoryNameSet> r2(g2.repositories(env));
+ std::tr1::shared_ptr<RepositoryNameSet> result(new RepositoryNameSet);
+ std::set_union(
+ r1->begin(), r1->end(),
+ r2->begin(), r2->end(),
+ result->inserter(),
+ RepositoryNameComparator());
+ return result;
+ }
+
+ virtual std::tr1::shared_ptr<const CategoryNamePartSet> categories(
+ const Environment * const env,
+ const std::tr1::shared_ptr<const RepositoryNameSet> & repos) const
+ {
+ std::tr1::shared_ptr<const CategoryNamePartSet> c1(g1.categories(env, repos));
+ std::tr1::shared_ptr<const CategoryNamePartSet> c2(g2.categories(env, repos));
+ std::tr1::shared_ptr<CategoryNamePartSet> result(new CategoryNamePartSet);
+ std::set_union(
+ c1->begin(), c1->end(),
+ c2->begin(), c2->end(),
+ result->inserter());
+ return result;
+ }
+
+ virtual std::tr1::shared_ptr<const QualifiedPackageNameSet> packages(
+ const Environment * const env,
+ const std::tr1::shared_ptr<const RepositoryNameSet> & repos,
+ const std::tr1::shared_ptr<const CategoryNamePartSet> & cats) const
+ {
+ std::tr1::shared_ptr<const QualifiedPackageNameSet> q1(g1.packages(env, repos, cats));
+ std::tr1::shared_ptr<const QualifiedPackageNameSet> q2(g2.packages(env, repos, cats));
+ std::tr1::shared_ptr<QualifiedPackageNameSet> result(new QualifiedPackageNameSet);
+ std::set_union(
+ q1->begin(), q1->end(),
+ q2->begin(), q2->end(),
+ result->inserter());
+ return result;
+ }
+
+ virtual std::tr1::shared_ptr<const PackageIDSet> ids(
+ const Environment * const env,
+ const std::tr1::shared_ptr<const RepositoryNameSet> & repos,
+ const std::tr1::shared_ptr<const QualifiedPackageNameSet> & qpns) const
+ {
+ std::tr1::shared_ptr<const PackageIDSet> i1(g1.ids(env, repos, qpns));
+ std::tr1::shared_ptr<const PackageIDSet> i2(g2.ids(env, repos, qpns));
+ std::tr1::shared_ptr<PackageIDSet> result(new PackageIDSet);
+ std::set_union(
+ i1->begin(), i1->end(),
+ i2->begin(), i2->end(),
+ result->inserter(),
+ PackageIDSetComparator());
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return stringify(g1) + " unioned with " + stringify(g2);
+ }
+ };
+
struct AllGeneratorHandler :
AllGeneratorHandlerBase
{
@@ -632,6 +709,11 @@ generator::Intersection::Intersection(const Generator & g1, const Generator & g2
{
}
+generator::Union::Union(const Generator & g1, const Generator & g2) :
+ Generator(make_shared_ptr(new UnionGeneratorHandler(g1, g2)))
+{
+}
+
template <typename A_>
generator::SomeIDsMightSupportAction<A_>::SomeIDsMightSupportAction() :
Generator(make_shared_ptr(new SomeIDsMightSupportActionGeneratorHandler<A_>))
@@ -644,6 +726,12 @@ paludis::operator& (const Generator & g1, const Generator & g2)
return generator::Intersection(g1, g2);
}
+Generator
+paludis::operator+ (const Generator & g1, const Generator & g2)
+{
+ return generator::Union(g1, g2);
+}
+
std::ostream &
paludis::operator<< (std::ostream & s, const Generator & g)
{
diff --git a/paludis/generator.hh b/paludis/generator.hh
index e8ceb68..f826d20 100644
--- a/paludis/generator.hh
+++ b/paludis/generator.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008 Ciaran McCreesh
+ * Copyright (c) 2008, 2009 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
@@ -122,6 +122,13 @@ namespace paludis
Intersection(const Generator &, const Generator &);
};
+ class PALUDIS_VISIBLE Union :
+ public Generator
+ {
+ public:
+ Union(const Generator &, const Generator &);
+ };
+
template <typename>
class PALUDIS_VISIBLE SomeIDsMightSupportAction :
public Generator