aboutsummaryrefslogtreecommitdiff
path: root/paludis
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-06-01 13:51:46 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-06-01 13:51:46 +0000
commit87294dc0c47918934ac032e9a080e8cf386f9bf2 (patch)
tree36dc289aa22200601ec28f2d7b497cd078e34ab6 /paludis
parent3b9f4ed10c9eb6901f33c7037989f3b67eb5de07 (diff)
downloadpaludis-87294dc0c47918934ac032e9a080e8cf386f9bf2.tar.gz
paludis-87294dc0c47918934ac032e9a080e8cf386f9bf2.tar.xz
New Selection + Filter + Generator interface using Environment, replacing the old PackageDatabase Query. Fixes: ticket:559
Diffstat (limited to 'paludis')
-rw-r--r--paludis/action.cc1
-rw-r--r--paludis/action_names-fwd.hh (renamed from paludis/query_delegate-fwd.hh)15
-rw-r--r--paludis/action_names.cc32
-rw-r--r--paludis/action_names.hh78
-rw-r--r--paludis/dep_list.cc48
-rw-r--r--paludis/environment.cc2
-rw-r--r--paludis/environment.hh7
-rw-r--r--paludis/environment_implementation.cc7
-rw-r--r--paludis/environment_implementation.hh3
-rw-r--r--paludis/environments/adapted/adapted_environment.cc6
-rw-r--r--paludis/environments/adapted/adapted_environment.hh3
-rw-r--r--paludis/environments/paludis/paludis_environment_TEST.cc33
-rw-r--r--paludis/environments/portage/portage_environment_TEST.cc37
-rw-r--r--paludis/files.m410
-rw-r--r--paludis/filter-fwd.hh43
-rw-r--r--paludis/filter.cc388
-rw-r--r--paludis/filter.hh126
-rw-r--r--paludis/filter_TEST.cc221
-rw-r--r--paludis/filtered_generator-fwd.hh38
-rw-r--r--paludis/filtered_generator.cc100
-rw-r--r--paludis/filtered_generator.hh49
-rw-r--r--paludis/filtered_generator_TEST.cc34
-rw-r--r--paludis/find_unused_packages_task.cc16
-rw-r--r--paludis/fuzzy_finder.cc52
-rw-r--r--paludis/fuzzy_finder.hh4
-rw-r--r--paludis/fuzzy_finder_TEST.cc13
-rw-r--r--paludis/generator-fwd.hh (renamed from paludis/query-fwd.hh)46
-rw-r--r--paludis/generator.cc545
-rw-r--r--paludis/generator.hh131
-rw-r--r--paludis/generator_TEST.cc326
-rw-r--r--paludis/generator_handler-fwd.hh29
-rw-r--r--paludis/generator_handler.cc110
-rw-r--r--paludis/generator_handler.hh85
-rw-r--r--paludis/install_task.cc34
-rw-r--r--paludis/name-fwd.hh9
-rw-r--r--paludis/name.cc4
-rw-r--r--paludis/package_database-fwd.hh8
-rw-r--r--paludis/package_database.cc229
-rw-r--r--paludis/package_database.hh36
-rw-r--r--paludis/package_database.se25
-rw-r--r--paludis/package_database_TEST.cc169
-rw-r--r--paludis/query.cc609
-rw-r--r--paludis/query.hh292
-rw-r--r--paludis/query_delegate.cc58
-rw-r--r--paludis/query_delegate.hh112
-rw-r--r--paludis/query_visitor.cc9
-rw-r--r--paludis/report_task.cc17
-rw-r--r--paludis/repositories/cran/dep_spec_pretty_printer.cc18
-rw-r--r--paludis/repositories/e/dep_spec_pretty_printer.cc22
-rw-r--r--paludis/repositories/e/e_repository.cc15
-rw-r--r--paludis/repositories/e/e_repository_TEST.cc304
-rw-r--r--paludis/repositories/e/e_repository_news.cc14
-rw-r--r--paludis/repositories/e/e_repository_sets.cc26
-rw-r--r--paludis/repositories/e/fetch_visitor_TEST.cc9
-rw-r--r--paludis/repositories/e/fix_locked_dependencies.cc9
-rw-r--r--paludis/repositories/e/pipe_command_handler.cc16
-rw-r--r--paludis/repositories/e/qa/visibility.cc9
-rw-r--r--paludis/repositories/e/qa/visibility_TEST.cc45
-rw-r--r--paludis/repositories/e/vdb_repository_TEST.cc186
-rw-r--r--paludis/repositories/fake/fake_package_id.hh4
-rw-r--r--paludis/repositories/unpackaged/dep_printer.cc18
-rw-r--r--paludis/repositories/unpackaged/installed_repository_TEST.cc110
-rw-r--r--paludis/repositories/unpackaged/unpackaged_repository_TEST.cc17
-rw-r--r--paludis/repositories/virtuals/package_id.cc27
-rw-r--r--paludis/repositories/virtuals/virtuals_repository.cc12
-rw-r--r--paludis/repositories/virtuals/virtuals_repository_TEST.cc11
-rw-r--r--paludis/selection-fwd.hh46
-rw-r--r--paludis/selection.cc516
-rw-r--r--paludis/selection.hh121
-rw-r--r--paludis/selection_TEST.cc184
-rw-r--r--paludis/set_file.cc20
-rw-r--r--paludis/show_suggest_visitor.cc15
-rw-r--r--paludis/uninstall_list.cc12
-rw-r--r--paludis/uninstall_task.cc24
-rw-r--r--paludis/util/indirect_iterator-impl.hh2
75 files changed, 3929 insertions, 2132 deletions
diff --git a/paludis/action.cc b/paludis/action.cc
index 8cede231d..7b36471f8 100644
--- a/paludis/action.cc
+++ b/paludis/action.cc
@@ -44,6 +44,7 @@ template class AcceptInterfaceVisitsThis<SupportsActionTestVisitorTypes, Support
template class AcceptInterfaceVisitsThis<SupportsActionTestVisitorTypes, SupportsActionTest<InstalledAction> >;
template class AcceptInterfaceVisitsThis<SupportsActionTestVisitorTypes, SupportsActionTest<UninstallAction> >;
template class AcceptInterfaceVisitsThis<SupportsActionTestVisitorTypes, SupportsActionTest<FetchAction> >;
+template class AcceptInterfaceVisitsThis<SupportsActionTestVisitorTypes, SupportsActionTest<PretendFetchAction> >;
template class Sequence<FetchActionFailure>;
diff --git a/paludis/query_delegate-fwd.hh b/paludis/action_names-fwd.hh
index 246628951..0fded6ee6 100644
--- a/paludis/query_delegate-fwd.hh
+++ b/paludis/action_names-fwd.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007 Ciaran McCreesh
+ * Copyright (c) 2008 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
@@ -17,18 +17,13 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef PALUDIS_GUARD_PALUDIS_QUERY_DELEGATE_FWD_HH
-#define PALUDIS_GUARD_PALUDIS_QUERY_DELEGATE_FWD_HH 1
-
-/** \file
- * Forward declarations for paludis/query_delegate.hh .
- *
- * \ingroup g_query
- */
+#ifndef PALUDIS_GUARD_PALUDIS_ACTION_NAMES_FWD_HH
+#define PALUDIS_GUARD_PALUDIS_ACTION_NAMES_FWD_HH 1
namespace paludis
{
- class QueryDelegate;
+ template <typename>
+ struct ActionNames;
}
#endif
diff --git a/paludis/action_names.cc b/paludis/action_names.cc
new file mode 100644
index 000000000..f90dec355
--- /dev/null
+++ b/paludis/action_names.cc
@@ -0,0 +1,32 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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/action_names.hh>
+
+using namespace paludis;
+
+const char * const ActionNames<InstallAction>::value = "install";
+const char * const ActionNames<InstalledAction>::value = "installed";
+const char * const ActionNames<UninstallAction>::value = "uninstall";
+const char * const ActionNames<ConfigAction>::value = "config";
+const char * const ActionNames<PretendAction>::value = "pretend";
+const char * const ActionNames<InfoAction>::value = "info";
+const char * const ActionNames<FetchAction>::value = "fetch";
+const char * const ActionNames<PretendFetchAction>::value = "pretend fetch";
+
diff --git a/paludis/action_names.hh b/paludis/action_names.hh
new file mode 100644
index 000000000..0510ddd92
--- /dev/null
+++ b/paludis/action_names.hh
@@ -0,0 +1,78 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_ACTION_NAMES_HH
+#define PALUDIS_GUARD_PALUDIS_ACTION_NAMES_HH 1
+
+#include <paludis/action_names-fwd.hh>
+#include <paludis/action-fwd.hh>
+#include <paludis/util/attributes.hh>
+
+namespace paludis
+{
+ template <>
+ struct PALUDIS_VISIBLE ActionNames<InstallAction>
+ {
+ static const char * const value;
+ };
+
+ template <>
+ struct PALUDIS_VISIBLE ActionNames<InstalledAction>
+ {
+ static const char * const value;
+ };
+
+ template <>
+ struct PALUDIS_VISIBLE ActionNames<UninstallAction>
+ {
+ static const char * const value;
+ };
+
+ template <>
+ struct PALUDIS_VISIBLE ActionNames<ConfigAction>
+ {
+ static const char * const value;
+ };
+
+ template <>
+ struct PALUDIS_VISIBLE ActionNames<PretendAction>
+ {
+ static const char * const value;
+ };
+
+ template <>
+ struct PALUDIS_VISIBLE ActionNames<InfoAction>
+ {
+ static const char * const value;
+ };
+
+ template <>
+ struct PALUDIS_VISIBLE ActionNames<FetchAction>
+ {
+ static const char * const value;
+ };
+
+ template <>
+ struct PALUDIS_VISIBLE ActionNames<PretendFetchAction>
+ {
+ static const char * const value;
+ };
+}
+
+#endif
diff --git a/paludis/dep_list.cc b/paludis/dep_list.cc
index 122261369..515c7f800 100644
--- a/paludis/dep_list.cc
+++ b/paludis/dep_list.cc
@@ -32,9 +32,12 @@
#include <paludis/distribution.hh>
#include <paludis/match_package.hh>
#include <paludis/metadata_key.hh>
-#include <paludis/query.hh>
#include <paludis/package_id.hh>
#include <paludis/version_requirements.hh>
+#include <paludis/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
#include <paludis/util/join.hh>
#include <paludis/util/log.hh>
@@ -277,10 +280,9 @@ namespace
const PackageDepSpec * const u(get_const_item(i)->as_package_dep_spec());
if (0 != u && u->package_ptr())
{
- return ! env.package_database()->query(
- query::SupportsAction<InstalledAction>() &
- query::Matches(make_package_dep_spec().package(*u->package_ptr())),
- qo_whatever)->empty();
+ return ! env[selection::SomeArbitraryVersion(
+ generator::Package(*u->package_ptr()) |
+ filter::SupportsAction<InstalledAction>())]->empty();
}
else
return false;
@@ -383,10 +385,8 @@ DepList::AddVisitor::visit_leaf(const PackageDepSpec & a)
/* find already installed things */
// TODO: check destinations
- std::tr1::shared_ptr<const PackageIDSequence> already_installed(d->_imp->env->package_database()->query(
- query::SupportsAction<InstalledAction>() &
- query::Matches(a),
- qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> already_installed((*d->_imp->env)[selection::AllVersionsSorted(
+ generator::Matches(a) | filter::SupportsAction<InstalledAction>())]);
/* are we already on the merge list? */
std::pair<MergeListIndex::iterator, MergeListIndex::iterator> q;
@@ -442,10 +442,7 @@ DepList::AddVisitor::visit_leaf(const PackageDepSpec & a)
/* find installable candidates, and find the best visible candidate */
std::tr1::shared_ptr<const PackageID> best_visible_candidate;
std::tr1::shared_ptr<const PackageIDSequence> installable_candidates(
- d->_imp->env->package_database()->query(
- query::MaybeSupportsAction<InstallAction>() &
- query::Matches(a),
- qo_order_by_version));
+ (*d->_imp->env)[selection::AllVersionsSorted(generator::Matches(a) | filter::SupportsAction<InstallAction>())]);
for (PackageIDSequence::ReverseConstIterator p(installable_candidates->rbegin()),
p_end(installable_candidates->rend()) ; p != p_end ; ++p)
@@ -543,8 +540,8 @@ DepList::AddVisitor::visit_leaf(const PackageDepSpec & a)
if (! a.additional_requirements_ptr())
throw AllMaskedError(a);
- std::tr1::shared_ptr<const PackageIDSequence> match_except_reqs(d->_imp->env->package_database()->query(
- query::Matches(*a.without_additional_requirements()), qo_whatever));
+ std::tr1::shared_ptr<const PackageIDSequence> match_except_reqs((*d->_imp->env)[selection::AllVersionsUnsorted(
+ generator::Matches(*a.without_additional_requirements()))]);
for (PackageIDSequence::ConstIterator i(match_except_reqs->begin()),
i_end(match_except_reqs->end()) ; i != i_end ; ++i)
@@ -618,13 +615,12 @@ DepList::AddVisitor::visit_leaf(const PackageDepSpec & a)
case dl_downgrade_warning:
{
std::tr1::shared_ptr<const PackageIDSequence> are_we_downgrading(
- d->_imp->env->package_database()->query(
- query::SupportsAction<InstalledAction>() &
- query::Matches(make_package_dep_spec()
+ (*d->_imp->env)[selection::AllVersionsSorted(
+ generator::Matches(make_package_dep_spec()
.package(best_visible_candidate->name())
.slot_requirement(make_shared_ptr(new UserSlotExactRequirement(best_visible_candidate->slot())))
- ),
- qo_order_by_version));
+ ) |
+ filter::SupportsAction<InstalledAction>())]);
if (are_we_downgrading->empty())
break;
@@ -829,10 +825,9 @@ DepList::AddVisitor::visit_leaf(const BlockDepSpec & a)
if (a.blocked_spec()->package_ptr())
{
PackageDepSpec just_package(make_package_dep_spec().package(*a.blocked_spec()->package_ptr()));
- already_installed = d->_imp->env->package_database()->query(
- query::SupportsAction<InstalledAction>() &
- query::Matches(just_package),
- qo_whatever);
+ already_installed = (*d->_imp->env)[selection::AllVersionsUnsorted(
+ generator::Matches(just_package) |
+ filter::SupportsAction<InstalledAction>())];
MatchDepListEntryAgainstPackageDepSpec m(d->_imp->env, just_package);
for (std::pair<MergeListIndex::const_iterator, MergeListIndex::const_iterator> p(
@@ -856,9 +851,8 @@ DepList::AddVisitor::visit_leaf(const BlockDepSpec & a)
{
check_whole_list = true;
/* TODO: InstalledAtRoot? */
- already_installed = d->_imp->env->package_database()->query(
- query::SupportsAction<InstalledAction>(),
- qo_whatever);
+ already_installed = (*d->_imp->env)[selection::AllVersionsUnsorted(
+ generator::All() | filter::SupportsAction<InstalledAction>())];
}
if (already_installed->empty() && will_be_installed.empty() && ! check_whole_list)
diff --git a/paludis/environment.cc b/paludis/environment.cc
index 03280f3ad..cb482d915 100644
--- a/paludis/environment.cc
+++ b/paludis/environment.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2005, 2006, 2007 Ciaran McCreesh
+ * Copyright (c) 2005, 2006, 2007, 2008 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
diff --git a/paludis/environment.hh b/paludis/environment.hh
index a691f3a98..b2104ae10 100644
--- a/paludis/environment.hh
+++ b/paludis/environment.hh
@@ -32,6 +32,7 @@
#include <paludis/package_id-fwd.hh>
#include <paludis/mask-fwd.hh>
#include <paludis/package_database-fwd.hh>
+#include <paludis/selection-fwd.hh>
/** \file
* Declarations for the Environment class.
@@ -167,6 +168,12 @@ namespace paludis
virtual std::tr1::shared_ptr<const PackageDatabase> package_database() const
PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
+ /**
+ * Select some packages.
+ */
+ virtual std::tr1::shared_ptr<PackageIDSequence> operator[] (const Selection &) const
+ PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
+
///\}
///\name System information
diff --git a/paludis/environment_implementation.cc b/paludis/environment_implementation.cc
index e3739279c..721521622 100644
--- a/paludis/environment_implementation.cc
+++ b/paludis/environment_implementation.cc
@@ -30,6 +30,7 @@
#include <paludis/util/kc.hh>
#include <paludis/hook.hh>
#include <paludis/distribution.hh>
+#include <paludis/selection.hh>
#include <algorithm>
#include "config.h"
@@ -188,3 +189,9 @@ EnvironmentImplementation::is_paludis_package(const QualifiedPackageName & n) co
return stringify(n) == (*DistributionData::get_instance()->distribution_from_string(default_distribution()))[k::paludis_package()];
}
+std::tr1::shared_ptr<PackageIDSequence>
+EnvironmentImplementation::operator[] (const Selection & selection) const
+{
+ return selection.perform_select(this);
+}
+
diff --git a/paludis/environment_implementation.hh b/paludis/environment_implementation.hh
index a463747e2..aa0ede745 100644
--- a/paludis/environment_implementation.hh
+++ b/paludis/environment_implementation.hh
@@ -90,6 +90,9 @@ namespace paludis
virtual bool is_paludis_package(const QualifiedPackageName &) const
PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual std::tr1::shared_ptr<PackageIDSequence> operator[] (const Selection &) const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
};
}
diff --git a/paludis/environments/adapted/adapted_environment.cc b/paludis/environments/adapted/adapted_environment.cc
index 046a6b630..2ec858eae 100644
--- a/paludis/environments/adapted/adapted_environment.cc
+++ b/paludis/environments/adapted/adapted_environment.cc
@@ -263,3 +263,9 @@ AdaptedEnvironment::remove_from_world(const SetName & s) const
_imp->env->remove_from_world(s);
}
+std::tr1::shared_ptr<PackageIDSequence>
+AdaptedEnvironment::operator[] (const Selection & s) const
+{
+ return _imp->env->operator[] (s);
+}
+
diff --git a/paludis/environments/adapted/adapted_environment.hh b/paludis/environments/adapted/adapted_environment.hh
index a4861fabd..3ce233bfd 100644
--- a/paludis/environments/adapted/adapted_environment.hh
+++ b/paludis/environments/adapted/adapted_environment.hh
@@ -58,6 +58,9 @@ namespace paludis
///\}
+ virtual std::tr1::shared_ptr<PackageIDSequence> operator[] (const Selection &) const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+
virtual bool query_use(const UseFlagName &, const PackageID &) const
PALUDIS_ATTRIBUTE((warn_unused_result));
diff --git a/paludis/environments/paludis/paludis_environment_TEST.cc b/paludis/environments/paludis/paludis_environment_TEST.cc
index 7c785ee6b..96fb7adb2 100644
--- a/paludis/environments/paludis/paludis_environment_TEST.cc
+++ b/paludis/environments/paludis/paludis_environment_TEST.cc
@@ -24,9 +24,12 @@
#include <paludis/util/set.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/options.hh>
-#include <paludis/query.hh>
#include <paludis/package_id.hh>
#include <paludis/user_dep_spec.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/selection.hh>
#include <test/test_runner.hh>
#include <test/test_framework.hh>
#include <cstdlib>
@@ -46,10 +49,10 @@ namespace test_cases
unsetenv("PALUDIS_SKIP_CONFIG");
std::tr1::shared_ptr<Environment> env(new PaludisEnvironment(""));
- const std::tr1::shared_ptr<const PackageID> one(*env->package_database()->query(
- query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1", UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
- const std::tr1::shared_ptr<const PackageID> three(*env->package_database()->query(
- query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-two-3", UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> one(*(*env)[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1", UserPackageDepSpecOptions()))))]->begin());
+ const std::tr1::shared_ptr<const PackageID> three(*(*env)[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-two-3", UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(env->query_use(UseFlagName("foo"), *one));
TEST_CHECK(! env->query_use(UseFlagName("foofoo"), *one));
@@ -78,8 +81,8 @@ namespace test_cases
std::tr1::shared_ptr<Environment> env(new PaludisEnvironment(""));
- const std::tr1::shared_ptr<const PackageID> one(*env->package_database()->query(
- query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1", UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> one(*(*env)[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1", UserPackageDepSpecOptions()))))]->begin());
std::tr1::shared_ptr<const UseFlagNameSet> k1(env->known_use_expand_names(UseFlagName("foo_cards"), *one));
TEST_CHECK_EQUAL(join(k1->begin(), k1->end(), " "), "foo_cards_one foo_cards_three foo_cards_two");
}
@@ -96,10 +99,10 @@ namespace test_cases
std::tr1::shared_ptr<Environment> env(new PaludisEnvironment(""));
- const std::tr1::shared_ptr<const PackageID> one(*env->package_database()->query(
- query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1", UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
- const std::tr1::shared_ptr<const PackageID> three(*env->package_database()->query(
- query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-two-3", UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> one(*(*env)[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1", UserPackageDepSpecOptions()))))]->begin());
+ const std::tr1::shared_ptr<const PackageID> three(*(*env)[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-two-3", UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(env->query_use(UseFlagName("foo"), *one));
TEST_CHECK(! env->query_use(UseFlagName("foofoo"), *one));
@@ -127,10 +130,10 @@ namespace test_cases
std::tr1::shared_ptr<Environment> env(new PaludisEnvironment(""));
- const std::tr1::shared_ptr<const PackageID> one(*env->package_database()->query(
- query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1", UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
- const std::tr1::shared_ptr<const PackageID> three(*env->package_database()->query(
- query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-two-3", UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> one(*(*env)[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1", UserPackageDepSpecOptions()))))]->begin());
+ const std::tr1::shared_ptr<const PackageID> three(*(*env)[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-two-3", UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(env->query_use(UseFlagName("foo"), *one));
TEST_CHECK(! env->query_use(UseFlagName("foofoo"), *one));
diff --git a/paludis/environments/portage/portage_environment_TEST.cc b/paludis/environments/portage/portage_environment_TEST.cc
index 1d70b20d4..e53a6d28e 100644
--- a/paludis/environments/portage/portage_environment_TEST.cc
+++ b/paludis/environments/portage/portage_environment_TEST.cc
@@ -26,11 +26,14 @@
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/options.hh>
#include <paludis/package_id.hh>
-#include <paludis/query.hh>
#include <paludis/package_database.hh>
#include <paludis/dep_spec.hh>
#include <paludis/name.hh>
#include <paludis/user_dep_spec.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/selection.hh>
using namespace paludis;
using namespace test;
@@ -68,11 +71,11 @@ namespace test_cases
{
PortageEnvironment env("portage_environment_TEST_dir/query_use");
- const std::tr1::shared_ptr<const PackageID> idx(*env.package_database()->query(
- query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-x-1", UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> idx(*env[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-x-1", UserPackageDepSpecOptions()))))]->begin());
- const std::tr1::shared_ptr<const PackageID> id1(*env.package_database()->query(
- query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1", UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> id1(*env[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1", UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(env.query_use(UseFlagName("one"), *idx));
TEST_CHECK(env.query_use(UseFlagName("two"), *idx));
@@ -96,8 +99,8 @@ namespace test_cases
{
PortageEnvironment env("portage_environment_TEST_dir/known_use_expand_names");
- const std::tr1::shared_ptr<const PackageID> id1(*env.package_database()->query(
- query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1", UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> id1(*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1", UserPackageDepSpecOptions()))))]->begin());
std::tr1::shared_ptr<const UseFlagNameSet> k1(env.known_use_expand_names(UseFlagName("foo_cards"), *id1));
TEST_CHECK_EQUAL(join(k1->begin(), k1->end(), " "), "foo_cards_one foo_cards_three");
}
@@ -111,36 +114,36 @@ namespace test_cases
{
TestPortageEnvironment env("portage_environment_TEST_dir/accept_keywords");
- const std::tr1::shared_ptr<const PackageID> idx(*env.package_database()->query(
- query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-x-1", UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> idx(*env[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-x-1", UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(accept_keyword(env, KeywordName("arch"), *idx));
TEST_CHECK(accept_keyword(env, KeywordName("other_arch"), *idx));
TEST_CHECK(! accept_keyword(env, KeywordName("~arch"), *idx));
- const std::tr1::shared_ptr<const PackageID> id1(*env.package_database()->query(
- query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1", UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> id1(*env[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1", UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(accept_keyword(env, KeywordName("arch"), *id1));
TEST_CHECK(accept_keyword(env, KeywordName("other_arch"), *id1));
TEST_CHECK(accept_keyword(env, KeywordName("~arch"), *id1));
- const std::tr1::shared_ptr<const PackageID> id2(*env.package_database()->query(
- query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-two-1", UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> id2(*env[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-two-1", UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(accept_keyword(env, KeywordName("other_arch"), *id2));
TEST_CHECK(accept_keyword(env, KeywordName("arch"), *id2));
TEST_CHECK(accept_keyword(env, KeywordName("~arch"), *id2));
- const std::tr1::shared_ptr<const PackageID> id3(*env.package_database()->query(
- query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-three-1", UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> id3(*env[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-three-1", UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(! accept_keyword(env, KeywordName("other_arch"), *id3));
TEST_CHECK(! accept_keyword(env, KeywordName("arch"), *id3));
TEST_CHECK(! accept_keyword(env, KeywordName("~arch"), *id3));
- const std::tr1::shared_ptr<const PackageID> id4(*env.package_database()->query(
- query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-four-1", UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> id4(*env[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-four-1", UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(accept_keyword(env, KeywordName("fred"), *id4));
}
} test_accept_keywords;
diff --git a/paludis/files.m4 b/paludis/files.m4
index 3366f790a..ca337b4af 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -10,6 +10,7 @@ dnl on this file at present...
add(`about', `hh', `test')
add(`action', `hh', `cc', `fwd', `se')
+add(`action_names', `hh', `cc', `fwd')
add(`condition_tracker', `hh', `cc')
add(`contents', `hh', `cc', `fwd')
add(`dep_label', `hh', `cc', `fwd')
@@ -29,9 +30,13 @@ add(`elike_use_requirement', `hh', `cc', `fwd', `se')
add(`environment', `hh', `fwd', `cc')
add(`environment_implementation', `hh', `cc')
add(`environment_maker', `hh', `cc')
+add(`filter', `hh', `cc', `fwd', `test')
+add(`filtered_generator', `hh', `cc', `fwd', `test')
add(`find_unused_packages_task', `hh', `cc')
add(`fuzzy_finder', `hh', `cc', `test')
add(`formatter', `hh', `fwd', `cc')
+add(`generator', `hh', `cc', `fwd', `test')
+add(`generator_handler', `hh', `cc', `fwd')
add(`handled_information', `hh', `fwd', `cc')
add(`hook', `hh', `cc', `fwd',`se', `sr')
add(`hooker', `hh', `cc', `test', `testscript')
@@ -49,18 +54,17 @@ add(`ndbam', `hh', `cc', `fwd')
add(`ndbam_merger', `hh', `cc')
add(`ndbam_unmerger', `hh', `cc')
add(`override_functions', `hh', `cc')
-add(`package_database', `hh', `cc', `fwd', `test', `se')
+add(`package_database', `hh', `cc', `fwd', `test')
add(`package_id', `hh', `cc', `fwd', `se')
add(`paludis', `hh')
add(`qa', `hh', `cc', `fwd', `se', `sr')
-add(`query', `hh', `cc', `fwd')
-add(`query_delegate', `hh', `cc', `fwd')
add(`query_visitor', `hh', `cc')
add(`range_rewriter', `hh', `cc', `test')
add(`report_task', `hh', `cc')
add(`repository', `hh', `fwd', `cc')
add(`repository_maker', `hh', `cc')
add(`repository_name_cache', `hh', `cc', `test', `testscript')
+add(`selection', `hh', `cc', `fwd', `test')
add(`set_file', `hh', `cc', `se', `sr', `test', `testscript')
add(`show_suggest_visitor', `hh', `cc')
add(`slot_requirement', `hh', `fwd', `cc')
diff --git a/paludis/filter-fwd.hh b/paludis/filter-fwd.hh
new file mode 100644
index 000000000..8e678e75a
--- /dev/null
+++ b/paludis/filter-fwd.hh
@@ -0,0 +1,43 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_FILTER_FWD_HH
+#define PALUDIS_GUARD_PALUDIS_FILTER_FWD_HH 1
+
+#include <paludis/util/attributes.hh>
+#include <iosfwd>
+
+namespace paludis
+{
+ class Filter;
+
+ namespace filter
+ {
+ class All;
+ template <typename> class SupportsAction;
+ class NotMasked;
+ class InstalledAtRoot;
+ class And;
+ }
+
+ std::ostream & operator<< (std::ostream &, const Filter &)
+ PALUDIS_VISIBLE;
+}
+
+#endif
diff --git a/paludis/filter.cc b/paludis/filter.cc
new file mode 100644
index 000000000..5049d89c6
--- /dev/null
+++ b/paludis/filter.cc
@@ -0,0 +1,388 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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/filter.hh>
+#include <paludis/name.hh>
+#include <paludis/action.hh>
+#include <paludis/environment.hh>
+#include <paludis/package_id.hh>
+#include <paludis/package_database.hh>
+#include <paludis/metadata_key.hh>
+#include <paludis/util/private_implementation_pattern-impl.hh>
+#include <paludis/util/set.hh>
+#include <paludis/util/sequence.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/wrapped_output_iterator.hh>
+#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/fs_entry.hh>
+#include <paludis/action_names.hh>
+
+using namespace paludis;
+
+namespace paludis
+{
+ class PALUDIS_VISIBLE FilterHandler
+ {
+ public:
+ virtual ~FilterHandler() = 0;
+
+ virtual std::string as_string() const = 0;
+
+ virtual std::tr1::shared_ptr<const RepositoryNameSet> repositories(
+ const Environment * const,
+ const std::tr1::shared_ptr<const RepositoryNameSet> &) const = 0;
+
+ virtual std::tr1::shared_ptr<const CategoryNamePartSet> categories(
+ const Environment * const,
+ const std::tr1::shared_ptr<const RepositoryNameSet> &,
+ const std::tr1::shared_ptr<const CategoryNamePartSet> &) const = 0;
+
+ virtual std::tr1::shared_ptr<const QualifiedPackageNameSet> packages(
+ const Environment * const,
+ const std::tr1::shared_ptr<const RepositoryNameSet> &,
+ const std::tr1::shared_ptr<const QualifiedPackageNameSet> &) const = 0;
+
+ virtual std::tr1::shared_ptr<const PackageIDSet> ids(
+ const Environment * const,
+ const std::tr1::shared_ptr<const PackageIDSet> &) const = 0;
+ };
+
+ template <>
+ struct Implementation<Filter>
+ {
+ std::tr1::shared_ptr<const FilterHandler> handler;
+
+ Implementation(const std::tr1::shared_ptr<const FilterHandler> & h) :
+ handler(h)
+ {
+ }
+ };
+}
+
+FilterHandler::~FilterHandler()
+{
+}
+
+Filter::Filter(const std::tr1::shared_ptr<const FilterHandler> & h) :
+ PrivateImplementationPattern<Filter>(new Implementation<Filter>(h))
+{
+}
+
+Filter::Filter(const Filter & other) :
+ PrivateImplementationPattern<Filter>(new Implementation<Filter>(other._imp->handler))
+{
+}
+
+Filter &
+Filter::operator= (const Filter & other)
+{
+ if (this != &other)
+ _imp->handler = other._imp->handler;
+ return *this;
+}
+
+Filter::~Filter()
+{
+}
+
+std::tr1::shared_ptr<const RepositoryNameSet>
+Filter::repositories(
+ const Environment * const env,
+ const std::tr1::shared_ptr<const RepositoryNameSet> & r) const
+{
+ return _imp->handler->repositories(env, r);
+}
+
+std::tr1::shared_ptr<const CategoryNamePartSet>
+Filter::categories(
+ const Environment * const env,
+ const std::tr1::shared_ptr<const RepositoryNameSet> & r,
+ const std::tr1::shared_ptr<const CategoryNamePartSet> & c) const
+{
+ return _imp->handler->categories(env, r, c);
+}
+
+std::tr1::shared_ptr<const QualifiedPackageNameSet>
+Filter::packages(
+ const Environment * const env,
+ const std::tr1::shared_ptr<const RepositoryNameSet> & r,
+ const std::tr1::shared_ptr<const QualifiedPackageNameSet> & c) const
+{
+ return _imp->handler->packages(env, r, c);
+}
+
+std::tr1::shared_ptr<const PackageIDSet>
+Filter::ids(
+ const Environment * const env,
+ const std::tr1::shared_ptr<const PackageIDSet> & i) const
+{
+ return _imp->handler->ids(env, i);
+}
+
+std::string
+Filter::as_string() const
+{
+ return _imp->handler->as_string();
+}
+
+namespace
+{
+ struct AllFilterHandler :
+ FilterHandler
+ {
+ virtual std::tr1::shared_ptr<const RepositoryNameSet> repositories(
+ const Environment * const,
+ const std::tr1::shared_ptr<const RepositoryNameSet> & s) const
+ {
+ return s;
+ }
+
+ virtual std::tr1::shared_ptr<const CategoryNamePartSet> categories(
+ const Environment * const,
+ const std::tr1::shared_ptr<const RepositoryNameSet> &,
+ const std::tr1::shared_ptr<const CategoryNamePartSet> & s) const
+ {
+ return s;
+ }
+
+ virtual std::tr1::shared_ptr<const QualifiedPackageNameSet> packages(
+ const Environment * const,
+ const std::tr1::shared_ptr<const RepositoryNameSet> &,
+ const std::tr1::shared_ptr<const QualifiedPackageNameSet> & s) const
+ {
+ return s;
+ }
+
+ virtual std::tr1::shared_ptr<const PackageIDSet> ids(
+ const Environment * const,
+ const std::tr1::shared_ptr<const PackageIDSet> & s) const
+ {
+ return s;
+ }
+
+ virtual std::string as_string() const
+ {
+ return "all matches";
+ }
+ };
+
+ template <typename A_>
+ struct SupportsActionFilterHandler :
+ AllFilterHandler
+ {
+ virtual std::tr1::shared_ptr<const RepositoryNameSet> repositories(
+ const Environment * const env,
+ const std::tr1::shared_ptr<const RepositoryNameSet> & repos) const
+ {
+ std::tr1::shared_ptr<RepositoryNameSet> result(new RepositoryNameSet);
+
+ for (RepositoryNameSet::ConstIterator r(repos->begin()), r_end(repos->end()) ;
+ r != r_end ; ++r)
+ {
+ if (env->package_database()->fetch_repository(*r)->some_ids_might_support_action(SupportsActionTest<A_>()))
+ result->insert(*r);
+ }
+
+ return result;
+ }
+
+ virtual std::tr1::shared_ptr<const PackageIDSet> ids(
+ const Environment * const,
+ 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 ((*i)->supports_action(SupportsActionTest<A_>()))
+ result->insert(*i);
+ }
+
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return "supports action " + stringify(ActionNames<A_>::value);
+ }
+ };
+
+ struct NotMaskedFilterHandler :
+ AllFilterHandler
+ {
+ virtual std::tr1::shared_ptr<const PackageIDSet> ids(
+ const Environment * const,
+ 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 (! (*i)->masked())
+ result->insert(*i);
+
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return "not masked";
+ }
+ };
+
+ struct InstalledAtRootFilterHandler :
+ AllFilterHandler
+ {
+ const FSEntry root;
+
+ InstalledAtRootFilterHandler(const FSEntry & r) :
+ root(r)
+ {
+ }
+
+ virtual std::tr1::shared_ptr<const RepositoryNameSet> repositories(
+ const Environment * const env,
+ const std::tr1::shared_ptr<const RepositoryNameSet> & repos) const
+ {
+ std::tr1::shared_ptr<RepositoryNameSet> result(new RepositoryNameSet);
+
+ for (RepositoryNameSet::ConstIterator r(repos->begin()), r_end(repos->end()) ;
+ r != r_end ; ++r)
+ {
+ const std::tr1::shared_ptr<const Repository> repo(env->package_database()->fetch_repository(*r));
+ if (repo->installed_root_key() && root == repo->installed_root_key()->value() &&
+ repo->some_ids_might_support_action(SupportsActionTest<InstalledAction>()))
+ result->insert(*r);
+ }
+
+ return result;
+ }
+ virtual std::tr1::shared_ptr<const PackageIDSet> ids(
+ const Environment * const,
+ 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 ((*i)->supports_action(SupportsActionTest<InstalledAction>()))
+ result->insert(*i);
+
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return "installed at root " + stringify(root);
+ }
+ };
+
+ struct AndFilterHandler :
+ FilterHandler
+ {
+ const Filter f1;
+ const Filter f2;
+
+ AndFilterHandler(const Filter & a1, const Filter & a2) :
+ f1(a1),
+ f2(a2)
+ {
+ }
+
+ virtual std::tr1::shared_ptr<const RepositoryNameSet> repositories(
+ const Environment * const env,
+ const std::tr1::shared_ptr<const RepositoryNameSet> & s) const
+ {
+ return f2.repositories(env, f1.repositories(env, s));
+ }
+
+ virtual std::tr1::shared_ptr<const CategoryNamePartSet> categories(
+ const Environment * const env,
+ const std::tr1::shared_ptr<const RepositoryNameSet> & r,
+ const std::tr1::shared_ptr<const CategoryNamePartSet> & c) const
+ {
+ return f2.categories(env, r, f1.categories(env, r, c));
+ }
+
+ virtual std::tr1::shared_ptr<const QualifiedPackageNameSet> packages(
+ const Environment * const env,
+ const std::tr1::shared_ptr<const RepositoryNameSet> & r,
+ const std::tr1::shared_ptr<const QualifiedPackageNameSet> & q) const
+ {
+ return f2.packages(env, r, f1.packages(env, r, q));
+ }
+
+ virtual std::tr1::shared_ptr<const PackageIDSet> ids(
+ const Environment * const env,
+ const std::tr1::shared_ptr<const PackageIDSet> & s) const
+ {
+ return f2.ids(env, f1.ids(env, s));
+ }
+
+ virtual std::string as_string() const
+ {
+ return stringify(f1) + " filtered through " + stringify(f2);
+ }
+ };
+}
+
+filter::All::All() :
+ Filter(make_shared_ptr(new AllFilterHandler))
+{
+}
+
+template <typename A_>
+filter::SupportsAction<A_>::SupportsAction() :
+ Filter(make_shared_ptr(new SupportsActionFilterHandler<A_>))
+{
+}
+
+filter::NotMasked::NotMasked() :
+ Filter(make_shared_ptr(new NotMaskedFilterHandler()))
+{
+}
+
+filter::InstalledAtRoot::InstalledAtRoot(const FSEntry & r) :
+ Filter(make_shared_ptr(new InstalledAtRootFilterHandler(r)))
+{
+}
+
+filter::And::And(const Filter & f1, const Filter & f2) :
+ Filter(make_shared_ptr(new AndFilterHandler(f1, f2)))
+{
+}
+
+std::ostream &
+paludis::operator<< (std::ostream & s, const Filter & f)
+{
+ s << f.as_string();
+ return s;
+}
+
+template class PrivateImplementationPattern<Filter>;
+template class filter::SupportsAction<InstallAction>;
+template class filter::SupportsAction<InstalledAction>;
+template class filter::SupportsAction<UninstallAction>;
+template class filter::SupportsAction<PretendAction>;
+template class filter::SupportsAction<ConfigAction>;
+template class filter::SupportsAction<FetchAction>;
+template class filter::SupportsAction<InfoAction>;
+template class filter::SupportsAction<PretendFetchAction>;
+
diff --git a/paludis/filter.hh b/paludis/filter.hh
new file mode 100644
index 000000000..c73692682
--- /dev/null
+++ b/paludis/filter.hh
@@ -0,0 +1,126 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_FILTER_HH
+#define PALUDIS_GUARD_PALUDIS_FILTER_HH 1
+
+#include <paludis/filter-fwd.hh>
+#include <paludis/util/attributes.hh>
+#include <paludis/util/private_implementation_pattern.hh>
+#include <paludis/util/set-fwd.hh>
+#include <paludis/util/fs_entry-fwd.hh>
+#include <paludis/name-fwd.hh>
+#include <paludis/environment-fwd.hh>
+#include <paludis/package_id-fwd.hh>
+#include <paludis/action-fwd.hh>
+#include <tr1/memory>
+
+namespace paludis
+{
+ class FilterHandler;
+
+ class PALUDIS_VISIBLE Filter :
+ private PrivateImplementationPattern<Filter>
+ {
+ protected:
+ Filter(const std::tr1::shared_ptr<const FilterHandler> &);
+
+ public:
+ Filter(const Filter &);
+ Filter & operator= (const Filter &);
+ ~Filter();
+
+ std::string as_string() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ std::tr1::shared_ptr<const RepositoryNameSet> repositories(
+ const Environment * const,
+ const std::tr1::shared_ptr<const RepositoryNameSet> &) const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ std::tr1::shared_ptr<const CategoryNamePartSet> categories(
+ const Environment * const,
+ const std::tr1::shared_ptr<const RepositoryNameSet> &,
+ const std::tr1::shared_ptr<const CategoryNamePartSet> &) const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ std::tr1::shared_ptr<const QualifiedPackageNameSet> packages(
+ const Environment * const,
+ const std::tr1::shared_ptr<const RepositoryNameSet> &,
+ const std::tr1::shared_ptr<const QualifiedPackageNameSet> &) const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ std::tr1::shared_ptr<const PackageIDSet> ids(
+ const Environment * const,
+ const std::tr1::shared_ptr<const PackageIDSet> &) const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+ };
+
+ namespace filter
+ {
+ class PALUDIS_VISIBLE All :
+ public Filter
+ {
+ public:
+ All();
+ };
+
+ template <typename>
+ class PALUDIS_VISIBLE SupportsAction :
+ public Filter
+ {
+ public:
+ SupportsAction();
+ };
+
+ class PALUDIS_VISIBLE NotMasked :
+ public Filter
+ {
+ public:
+ NotMasked();
+ };
+
+ class PALUDIS_VISIBLE InstalledAtRoot :
+ public Filter
+ {
+ public:
+ InstalledAtRoot(const FSEntry &);
+ };
+
+ class PALUDIS_VISIBLE And :
+ public Filter
+ {
+ public:
+ And(const Filter &, const Filter &);
+ };
+ }
+
+#ifdef PALUDIS_HAVE_EXTERN_TEMPLATE
+ extern template class PrivateImplementationPattern<Filter>;
+ extern template class filter::SupportsAction<InstallAction>;
+ extern template class filter::SupportsAction<InstalledAction>;
+ extern template class filter::SupportsAction<UninstallAction>;
+ extern template class filter::SupportsAction<PretendAction>;
+ extern template class filter::SupportsAction<ConfigAction>;
+ extern template class filter::SupportsAction<FetchAction>;
+ extern template class filter::SupportsAction<InfoAction>;
+ extern template class filter::SupportsAction<PretendFetchAction>;
+#endif
+}
+
+#endif
diff --git a/paludis/filter_TEST.cc b/paludis/filter_TEST.cc
new file mode 100644
index 000000000..e443ce64f
--- /dev/null
+++ b/paludis/filter_TEST.cc
@@ -0,0 +1,221 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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/filter.hh>
+#include <paludis/generator.hh>
+#include <paludis/selection.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/package_database.hh>
+#include <paludis/user_dep_spec.hh>
+#include <paludis/environments/test/test_environment.hh>
+#include <paludis/repositories/fake/fake_package_id.hh>
+#include <paludis/repositories/fake/fake_repository.hh>
+#include <paludis/repositories/fake/fake_installed_repository.hh>
+#include <paludis/util/sequence.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <test/test_runner.hh>
+#include <test/test_framework.hh>
+#include <test/test_concepts.hh>
+
+using namespace paludis;
+using namespace test;
+
+namespace test_cases
+{
+ TESTCASE_SEMIREGULAR(Filter, filter::All());
+ TESTCASE_STRINGIFYABLE(Filter, filter::All(), "all matches");
+
+ struct FilterTestCaseBase : TestCase
+ {
+ Filter filter;
+ TestEnvironment env;
+ std::tr1::shared_ptr<FakeRepository> repo1;
+ std::tr1::shared_ptr<FakeRepository> repo2;
+ std::tr1::shared_ptr<FakeInstalledRepository> inst_repo1;
+
+ FilterTestCaseBase(const std::string & s, const Filter & f) :
+ TestCase("filter " + s + " with " + stringify(f)),
+ filter(f),
+ repo1(new FakeRepository(&env, RepositoryName("repo1"))),
+ repo2(new FakeRepository(&env, RepositoryName("repo2"))),
+ inst_repo1(new FakeInstalledRepository(&env, RepositoryName("inst_repo1")))
+ {
+ env.package_database()->add_repository(1, repo1);
+ env.package_database()->add_repository(10, repo2);
+ env.package_database()->add_repository(0, inst_repo1);
+
+ repo1->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("1"));
+ repo1->add_version(CategoryNamePart("cat") + PackageNamePart("b"), VersionSpec("2"));
+
+ repo2->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("1"));
+ repo2->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("2"))->keywords_key()->set_from_string("");
+ repo2->add_version(CategoryNamePart("cat") + PackageNamePart("c"), VersionSpec("3"));
+
+ inst_repo1->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("1"));
+ }
+
+ virtual std::string get_expected() const = 0;
+
+ void run()
+ {
+ const std::string expected(get_expected());
+ std::tr1::shared_ptr<const PackageIDSequence> got(env[selection::AllVersionsSorted(generator::All() | filter)]);
+
+ TEST_CHECK(got);
+ TEST_CHECK_EQUAL(join(indirect_iterator(got->begin()), indirect_iterator(got->end()), ", "), expected);
+
+ std::tr1::shared_ptr<const PackageIDSequence> got_none(env[selection::AllVersionsSorted(
+ generator::Matches(parse_user_package_dep_spec("not/exist", UserPackageDepSpecOptions())) | filter)]);
+ TEST_CHECK(got_none);
+ TEST_CHECK_EQUAL(join(indirect_iterator(got_none->begin()), indirect_iterator(got_none->end()), ", "), "");
+ }
+ };
+
+ struct AllFilterTestCase : FilterTestCaseBase
+ {
+ AllFilterTestCase() :
+ FilterTestCaseBase("all", filter::All())
+ {
+ }
+
+ 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";
+ }
+ } all_filter_test;
+
+ struct SupportsInstallActionFilterTestCase : FilterTestCaseBase
+ {
+ SupportsInstallActionFilterTestCase() :
+ FilterTestCaseBase("supports install action", filter::SupportsAction<InstallAction>())
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return
+ "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";
+ }
+ } supports_install_action_filter_test;
+
+ struct SupportsInstalledActionFilterTestCase : FilterTestCaseBase
+ {
+ SupportsInstalledActionFilterTestCase() :
+ FilterTestCaseBase("supports installed action", filter::SupportsAction<InstalledAction>())
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return
+ "cat/a-1:0::inst_repo1";
+ }
+ } supports_installed_action_filter_test;
+
+ struct SupportsInstalledAtRootFilterTestCase : FilterTestCaseBase
+ {
+ SupportsInstalledAtRootFilterTestCase() :
+ FilterTestCaseBase("installed at root /", filter::InstalledAtRoot(FSEntry("/")))
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return
+ "cat/a-1:0::inst_repo1";
+ }
+ } supports_installed_at_root_slash;
+
+ struct SupportsInstalledAtRootOtherFilterTestCase : FilterTestCaseBase
+ {
+ SupportsInstalledAtRootOtherFilterTestCase() :
+ FilterTestCaseBase("installed at root /blah", filter::InstalledAtRoot(FSEntry("/blah")))
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return "";
+ }
+ } supports_installed_at_root_other;
+
+ struct NotMaskedFilterTestCase : FilterTestCaseBase
+ {
+ NotMaskedFilterTestCase() :
+ FilterTestCaseBase("not masked", filter::NotMasked())
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return
+ "cat/a-1:0::inst_repo1, "
+ "cat/a-1:0::repo1, "
+ "cat/a-1:0::repo2, "
+ "cat/b-2:0::repo1, "
+ "cat/c-3:0::repo2";
+ }
+ } not_masked_filter_test;
+
+ struct InstallableAndNotMaskedFilterTestCase : FilterTestCaseBase
+ {
+ InstallableAndNotMaskedFilterTestCase() :
+ FilterTestCaseBase("installable and not masked", filter::And(filter::SupportsAction<InstallAction>(), filter::NotMasked()))
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return
+ "cat/a-1:0::repo1, "
+ "cat/a-1:0::repo2, "
+ "cat/b-2:0::repo1, "
+ "cat/c-3:0::repo2";
+ }
+ } installable_and_not_masked_filter_test;
+
+ struct NotMaskedAndInstallableFilterTestCase : FilterTestCaseBase
+ {
+ NotMaskedAndInstallableFilterTestCase() :
+ FilterTestCaseBase("not masked and installable", filter::And(filter::NotMasked(), filter::SupportsAction<InstallAction>()))
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return
+ "cat/a-1:0::repo1, "
+ "cat/a-1:0::repo2, "
+ "cat/b-2:0::repo1, "
+ "cat/c-3:0::repo2";
+ }
+ } not_masked_and_installable_filter_test;
+}
+
diff --git a/paludis/filtered_generator-fwd.hh b/paludis/filtered_generator-fwd.hh
new file mode 100644
index 000000000..93e3f7bb4
--- /dev/null
+++ b/paludis/filtered_generator-fwd.hh
@@ -0,0 +1,38 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_FILTERED_GENERATOR_FWD_HH
+#define PALUDIS_GUARD_PALUDIS_FILTERED_GENERATOR_FWD_HH 1
+
+#include <paludis/filter-fwd.hh>
+#include <paludis/util/attributes.hh>
+#include <iosfwd>
+
+namespace paludis
+{
+ class FilteredGenerator;
+
+ FilteredGenerator operator| (const FilteredGenerator &, const Filter &)
+ PALUDIS_ATTRIBUTE((warn_unused_result)) PALUDIS_VISIBLE;
+
+ std::ostream & operator<< (std::ostream &, const FilteredGenerator &)
+ PALUDIS_VISIBLE;
+}
+
+#endif
diff --git a/paludis/filtered_generator.cc b/paludis/filtered_generator.cc
new file mode 100644
index 000000000..620ee32cb
--- /dev/null
+++ b/paludis/filtered_generator.cc
@@ -0,0 +1,100 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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/filtered_generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/generator.hh>
+#include <paludis/util/private_implementation_pattern-impl.hh>
+#include <ostream>
+
+using namespace paludis;
+
+namespace paludis
+{
+ template <>
+ struct Implementation<FilteredGenerator>
+ {
+ Generator generator;
+ Filter filter;
+
+ Implementation(const Generator & g, const Filter & f) :
+ generator(g),
+ filter(f)
+ {
+ }
+ };
+}
+
+FilteredGenerator::FilteredGenerator(const FilteredGenerator & other) :
+ PrivateImplementationPattern<FilteredGenerator>(new Implementation<FilteredGenerator>(other._imp->generator, other._imp->filter))
+{
+}
+
+FilteredGenerator::FilteredGenerator(const Generator & g, const Filter & f) :
+ PrivateImplementationPattern<FilteredGenerator>(new Implementation<FilteredGenerator>(g, f))
+{
+}
+
+FilteredGenerator::FilteredGenerator(const FilteredGenerator & g, const Filter & f) :
+ PrivateImplementationPattern<FilteredGenerator>(new Implementation<FilteredGenerator>(g.generator(), filter::And(g.filter(), f)))
+{
+}
+
+FilteredGenerator::~FilteredGenerator()
+{
+}
+
+FilteredGenerator &
+FilteredGenerator::operator= (const FilteredGenerator & other)
+{
+ if (this != &other)
+ {
+ _imp->generator = other._imp->generator;
+ _imp->filter = other._imp->filter;
+ }
+ return *this;
+}
+
+const Generator &
+FilteredGenerator::generator() const
+{
+ return _imp->generator;
+}
+
+const Filter &
+FilteredGenerator::filter() const
+{
+ return _imp->filter;
+}
+
+FilteredGenerator
+paludis::operator| (const FilteredGenerator & g, const Filter & f)
+{
+ return FilteredGenerator(g, f);
+}
+
+std::ostream &
+paludis::operator<< (std::ostream & s, const FilteredGenerator & fg)
+{
+ s << fg.generator() << " with filter " << fg.filter();
+ return s;
+}
+
+template class PrivateImplementationPattern<FilteredGenerator>;
+
diff --git a/paludis/filtered_generator.hh b/paludis/filtered_generator.hh
new file mode 100644
index 000000000..961207dbb
--- /dev/null
+++ b/paludis/filtered_generator.hh
@@ -0,0 +1,49 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_FILTERED_GENERATOR_HH
+#define PALUDIS_GUARD_PALUDIS_FILTERED_GENERATOR_HH 1
+
+#include <paludis/filtered_generator-fwd.hh>
+#include <paludis/util/private_implementation_pattern.hh>
+#include <paludis/filter-fwd.hh>
+#include <paludis/generator-fwd.hh>
+
+namespace paludis
+{
+ class PALUDIS_VISIBLE FilteredGenerator :
+ private PrivateImplementationPattern<FilteredGenerator>
+ {
+ public:
+ FilteredGenerator(const FilteredGenerator &);
+ FilteredGenerator(const Generator &, const Filter &);
+ FilteredGenerator(const FilteredGenerator &, const Filter &);
+ FilteredGenerator & operator= (const FilteredGenerator &);
+ ~FilteredGenerator();
+
+ const Generator & generator() const PALUDIS_ATTRIBUTE((warn_unused_result));
+ const Filter & filter() const PALUDIS_ATTRIBUTE((warn_unused_result));
+ };
+
+#ifdef PALUDIS_HAVE_EXTERN_TEMPLATE
+ extern template class PrivateImplementationPattern<FilteredGenerator>;
+#endif
+}
+
+#endif
diff --git a/paludis/filtered_generator_TEST.cc b/paludis/filtered_generator_TEST.cc
new file mode 100644
index 000000000..c033452cc
--- /dev/null
+++ b/paludis/filtered_generator_TEST.cc
@@ -0,0 +1,34 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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/filtered_generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/generator.hh>
+#include <test/test_runner.hh>
+#include <test/test_framework.hh>
+#include <test/test_concepts.hh>
+
+using namespace paludis;
+using namespace test;
+
+namespace test_cases
+{
+ TESTCASE_SEMIREGULAR(FilteredGenerator, generator::All() | filter::All());
+}
+
diff --git a/paludis/find_unused_packages_task.cc b/paludis/find_unused_packages_task.cc
index ba0a8a263..2a1944852 100644
--- a/paludis/find_unused_packages_task.cc
+++ b/paludis/find_unused_packages_task.cc
@@ -17,14 +17,16 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "find_unused_packages_task.hh"
-
+#include <paludis/find_unused_packages_task.hh>
#include <paludis/environment.hh>
#include <paludis/repository.hh>
-#include <paludis/query.hh>
#include <paludis/package_database.hh>
#include <paludis/metadata_key.hh>
#include <paludis/package_id.hh>
+#include <paludis/selection.hh>
+#include <paludis/filter.hh>
+#include <paludis/generator.hh>
+#include <paludis/filtered_generator.hh>
#include <paludis/util/wrapped_forward_iterator-impl.hh>
#include <paludis/util/tokeniser.hh>
#include <paludis/util/sequence.hh>
@@ -42,11 +44,11 @@ std::tr1::shared_ptr<const PackageIDSequence>
FindUnusedPackagesTask::execute(const QualifiedPackageName & package)
{
std::tr1::shared_ptr<PackageIDSequence> result(new PackageIDSequence);
- std::tr1::shared_ptr<const PackageIDSequence> packages(_env->package_database()->query(
- query::Matches(make_package_dep_spec()
+ std::tr1::shared_ptr<const PackageIDSequence> packages((*_env)[selection::AllVersionsGroupedBySlot(
+ generator::Matches(make_package_dep_spec()
.package(package)
- .repository(_repo->name())),
- qo_group_by_slot));
+ .repository(_repo->name()))
+ )]);
SlotName old_slot("I_am_a_slot");
std::set<KeywordName> keywords;
diff --git a/paludis/fuzzy_finder.cc b/paludis/fuzzy_finder.cc
index 595c83c39..4e81c0ad3 100644
--- a/paludis/fuzzy_finder.cc
+++ b/paludis/fuzzy_finder.cc
@@ -22,14 +22,18 @@
#include <paludis/util/wrapped_forward_iterator-impl.hh>
#include <paludis/util/damerau_levenshtein.hh>
#include <paludis/util/options.hh>
+#include <paludis/util/make_shared_ptr.hh>
#include <paludis/package_database.hh>
#include <paludis/environment.hh>
#include <paludis/repository.hh>
#include <paludis/package_id.hh>
#include <paludis/name.hh>
-#include <paludis/query.hh>
-#include <paludis/query_delegate.hh>
#include <paludis/user_dep_spec.hh>
+#include <paludis/generator.hh>
+#include <paludis/generator_handler.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/selection.hh>
#include <paludis/util/set.hh>
#include <paludis/util/sequence.hh>
#include <list>
@@ -59,8 +63,8 @@ namespace
return res2;
}
- class FuzzyPackageNameDelegate :
- public QueryDelegate
+ class FuzzyPackageNameGeneratorHandler :
+ public AllGeneratorHandlerBase
{
private:
std::string _package;
@@ -69,7 +73,7 @@ namespace
char _first_char;
public:
- FuzzyPackageNameDelegate(const std::string & package) :
+ FuzzyPackageNameGeneratorHandler(const std::string & package) :
_package(package),
_distance_calculator(tolower_0_cost(package)),
_threshold(package.length() <= 4 ? 1 : 2),
@@ -77,27 +81,28 @@ namespace
{
}
- virtual std::tr1::shared_ptr<QualifiedPackageNameSet> packages(const Environment &,
- std::tr1::shared_ptr<const RepositoryNameSequence>,
- std::tr1::shared_ptr<const CategoryNamePartSet>) const;
+ virtual std::tr1::shared_ptr<const QualifiedPackageNameSet> packages(
+ const Environment * const,
+ const std::tr1::shared_ptr<const RepositoryNameSet> &,
+ const std::tr1::shared_ptr<const CategoryNamePartSet> &) const;
- std::string as_human_readable_string() const
+ virtual std::string as_string() const
{
- return "package name fuzzy-matches '" + _package + "'";
+ return "packages fuzzily like " + _package;
}
};
- std::tr1::shared_ptr<QualifiedPackageNameSet>
- FuzzyPackageNameDelegate::packages(const Environment & e,
- std::tr1::shared_ptr<const RepositoryNameSequence> repos,
- std::tr1::shared_ptr<const CategoryNamePartSet> cats) const
+ std::tr1::shared_ptr<const QualifiedPackageNameSet>
+ FuzzyPackageNameGeneratorHandler::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<QualifiedPackageNameSet> result(new QualifiedPackageNameSet);
- for (RepositoryNameSequence::ConstIterator r(repos->begin()),
+ for (RepositoryNameSet::ConstIterator r(repos->begin()),
r_end(repos->end()); r_end != r; ++r)
{
- std::tr1::shared_ptr<const Repository> repo(e.package_database()->fetch_repository(*r));
+ std::tr1::shared_ptr<const Repository> repo(env->package_database()->fetch_repository(*r));
for (CategoryNamePartSet::ConstIterator c(cats->begin()),
c_end(cats->end()); c_end != c; ++c)
@@ -115,11 +120,11 @@ namespace
}
class FuzzyPackageName :
- public Query
+ public Generator
{
public:
FuzzyPackageName(const std::string & p) :
- Query(std::tr1::shared_ptr<QueryDelegate>(new FuzzyPackageNameDelegate(p)))
+ Generator(make_shared_ptr(new FuzzyPackageNameGeneratorHandler(p)))
{
}
};
@@ -134,10 +139,10 @@ namespace paludis
};
}
-FuzzyCandidatesFinder::FuzzyCandidatesFinder(const Environment & e, const std::string & name, const Query & generator) :
+FuzzyCandidatesFinder::FuzzyCandidatesFinder(const Environment & e, const std::string & name, const Filter & filter) :
PrivateImplementationPattern<FuzzyCandidatesFinder>(new Implementation<FuzzyCandidatesFinder>)
{
- Query real_generator(generator);
+ Generator g = generator::All();
std::string package(name);
if (std::string::npos != name.find('/'))
@@ -146,15 +151,15 @@ FuzzyCandidatesFinder::FuzzyCandidatesFinder(const Environment & e, const std::s
if (pds.package_ptr())
{
- real_generator = real_generator & query::Category(pds.package_ptr()->category);
+ g = g & generator::Category(pds.package_ptr()->category);
package = stringify(pds.package_ptr()->package);
}
if (pds.repository_ptr())
- real_generator = real_generator & query::Repository(*pds.repository_ptr());
+ g = g & generator::Repository(*pds.repository_ptr());
}
- std::tr1::shared_ptr<const PackageIDSequence> ids(e.package_database()->query(real_generator & FuzzyPackageName(package), qo_best_version_only));
+ std::tr1::shared_ptr<const PackageIDSequence> ids(e[selection::BestVersionOnly(g & FuzzyPackageName(package) | filter)]);
for (PackageIDSequence::ConstIterator i(ids->begin()), i_end(ids->end())
; i != i_end ; ++i)
@@ -224,3 +229,4 @@ FuzzyRepositoriesFinder::end() const
{
return RepositoriesConstIterator(_imp->candidates.end());
}
+
diff --git a/paludis/fuzzy_finder.hh b/paludis/fuzzy_finder.hh
index c1afb4a68..ca008b820 100644
--- a/paludis/fuzzy_finder.hh
+++ b/paludis/fuzzy_finder.hh
@@ -23,8 +23,8 @@
#include <paludis/environment-fwd.hh>
#include <paludis/util/private_implementation_pattern.hh>
#include <paludis/util/wrapped_forward_iterator-fwd.hh>
-#include <paludis/query-fwd.hh>
#include <paludis/name.hh>
+#include <paludis/filter-fwd.hh>
#include <string>
/** \file
@@ -47,7 +47,7 @@ namespace paludis
///\name Basic Operations
///\{
- FuzzyCandidatesFinder(const Environment & e, const std::string & name, const Query & generator);
+ FuzzyCandidatesFinder(const Environment & e, const std::string & name, const Filter & filter);
~FuzzyCandidatesFinder();
///\}
diff --git a/paludis/fuzzy_finder_TEST.cc b/paludis/fuzzy_finder_TEST.cc
index 9781cfab8..b37646779 100644
--- a/paludis/fuzzy_finder_TEST.cc
+++ b/paludis/fuzzy_finder_TEST.cc
@@ -18,6 +18,7 @@
*/
#include <paludis/fuzzy_finder.hh>
+#include <paludis/filter.hh>
#include <paludis/environments/test/test_environment.hh>
#include <paludis/repositories/fake/fake_repository.hh>
#include <paludis/repositories/fake/fake_installed_repository.hh>
@@ -50,22 +51,22 @@ namespace test_cases
std::tr1::shared_ptr<FakeRepository> r2(new FakeRepository(&e, RepositoryName("r2")));
e.package_database()->add_repository(2, r2);
- FuzzyCandidatesFinder f1(e, std::string("some-cat/one-two-thee"), query::All());
+ FuzzyCandidatesFinder f1(e, std::string("some-cat/one-two-thee"), filter::All());
TEST_CHECK_EQUAL(std::distance(f1.begin(), f1.end()), 1);
- FuzzyCandidatesFinder f2(e, std::string("fio"), query::All());
+ FuzzyCandidatesFinder f2(e, std::string("fio"), filter::All());
TEST_CHECK_EQUAL(std::distance(f2.begin(), f2.end()), 2);
- FuzzyCandidatesFinder f3(e, std::string("bra"), query::All());
+ FuzzyCandidatesFinder f3(e, std::string("bra"), filter::All());
TEST_CHECK_EQUAL(std::distance(f3.begin(), f3.end()), 1);
- FuzzyCandidatesFinder f4(e, std::string("foobarandfriends"), query::All());
+ FuzzyCandidatesFinder f4(e, std::string("foobarandfriends"), filter::All());
TEST_CHECK_EQUAL(std::distance(f4.begin(), f4.end()), 0);
- FuzzyCandidatesFinder f5(e, std::string("some-cat/foo::r2"), query::All());
+ FuzzyCandidatesFinder f5(e, std::string("some-cat/foo::r2"), filter::All());
TEST_CHECK_EQUAL(std::distance(f5.begin(), f5.end()), 0);
- FuzzyCandidatesFinder f6(e, std::string("some-cat/OnE-tWo-THEE"), query::All());
+ FuzzyCandidatesFinder f6(e, std::string("some-cat/OnE-tWo-THEE"), filter::All());
TEST_CHECK_EQUAL(std::distance(f6.begin(), f6.end()), 1);
}
diff --git a/paludis/query-fwd.hh b/paludis/generator-fwd.hh
index 2548bb4f0..1bc52dc57 100644
--- a/paludis/query-fwd.hh
+++ b/paludis/generator-fwd.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007 Ciaran McCreesh
+ * Copyright (c) 2008 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
@@ -17,52 +17,32 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef PALUDIS_GUARD_PALUDIS_QUERY_FWD_HH
-#define PALUDIS_GUARD_PALUDIS_QUERY_FWD_HH 1
+#ifndef PALUDIS_GUARD_PALUDIS_GENERATOR_FWD_HH
+#define PALUDIS_GUARD_PALUDIS_GENERATOR_FWD_HH 1
-#include <iosfwd>
#include <paludis/util/attributes.hh>
-
-/** \file
- * Forward declarations for paludis/query.hh .
- *
- * \ingroup g_query
- */
+#include <iosfwd>
namespace paludis
{
- class Query;
+ class Generator;
- namespace query
+ namespace generator
{
+ class All;
class Matches;
class Package;
class Repository;
class Category;
- class NotMasked;
- template <typename A_> class SupportsAction;
- template <typename A_> class MaybeSupportsAction;
- class InstalledAtRoot;
- class All;
+ class Union;
+ template <typename> class SomeIDsMightSupportAction;
}
- /**
- * Create a Query that returns packages for which both Query parameters
- * hold.
- *
- * \see Query
- * \see PackageDatabase::query
- * \ingroup g_query
- */
- Query operator& (const Query &, const Query &) PALUDIS_VISIBLE;
+ Generator operator& (const Generator &, const Generator &)
+ PALUDIS_ATTRIBUTE((warn_unused_result)) PALUDIS_VISIBLE;
- /**
- * Output a human-readable description of a Query.
- *
- * \see Query
- * \ingroup g_query
- */
- std::ostream & operator<< (std::ostream &, const Query &) PALUDIS_VISIBLE;
+ std::ostream & operator<< (std::ostream &, const Generator &)
+ PALUDIS_VISIBLE;
}
#endif
diff --git a/paludis/generator.cc b/paludis/generator.cc
new file mode 100644
index 000000000..7ef28c47e
--- /dev/null
+++ b/paludis/generator.cc
@@ -0,0 +1,545 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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/generator.hh>
+#include <paludis/generator_handler.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/action_names.hh>
+#include <paludis/action.hh>
+#include <paludis/match_package.hh>
+#include <paludis/util/private_implementation_pattern-impl.hh>
+#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/set.hh>
+#include <paludis/util/sequence.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/wrapped_output_iterator.hh>
+#include <paludis/environment.hh>
+#include <paludis/package_database.hh>
+#include <paludis/package_id.hh>
+#include <algorithm>
+#include <tr1/functional>
+
+using namespace paludis;
+
+namespace paludis
+{
+ template <>
+ struct Implementation<Generator>
+ {
+ std::tr1::shared_ptr<const GeneratorHandler> handler;
+
+ Implementation(const std::tr1::shared_ptr<const GeneratorHandler> & h) :
+ handler(h)
+ {
+ }
+ };
+}
+
+Generator::Generator(const std::tr1::shared_ptr<const GeneratorHandler> & h) :
+ PrivateImplementationPattern<Generator>(new Implementation<Generator>(h))
+{
+}
+
+Generator::Generator(const Generator & other) :
+ PrivateImplementationPattern<Generator>(new Implementation<Generator>(other._imp->handler))
+{
+}
+
+Generator &
+Generator::operator= (const Generator & other)
+{
+ if (this != &other)
+ _imp->handler = other._imp->handler;
+ return *this;
+}
+
+Generator::~Generator()
+{
+}
+
+Generator::operator FilteredGenerator () const
+{
+ return FilteredGenerator(*this, filter::All());
+}
+
+std::tr1::shared_ptr<const RepositoryNameSet>
+Generator::repositories(
+ const Environment * const env) const
+{
+ return _imp->handler->repositories(env);
+}
+
+std::tr1::shared_ptr<const CategoryNamePartSet>
+Generator::categories(
+ const Environment * const env,
+ const std::tr1::shared_ptr<const RepositoryNameSet> & r) const
+{
+ return _imp->handler->categories(env, r);
+}
+
+std::tr1::shared_ptr<const QualifiedPackageNameSet>
+Generator::packages(
+ const Environment * const env,
+ const std::tr1::shared_ptr<const RepositoryNameSet> & r,
+ const std::tr1::shared_ptr<const CategoryNamePartSet> & c) const
+{
+ return _imp->handler->packages(env, r, c);
+}
+
+std::tr1::shared_ptr<const PackageIDSet>
+Generator::ids(
+ const Environment * const env,
+ const std::tr1::shared_ptr<const RepositoryNameSet> & r,
+ const std::tr1::shared_ptr<const QualifiedPackageNameSet> & q) const
+{
+ return _imp->handler->ids(env, r, q);
+}
+
+std::string
+Generator::as_string() const
+{
+ return _imp->handler->as_string();
+}
+
+namespace
+{
+ struct RepositoryGeneratorHandler :
+ AllGeneratorHandlerBase
+ {
+ const RepositoryName name;
+
+ RepositoryGeneratorHandler(const RepositoryName & n) :
+ name(n)
+ {
+ }
+
+ virtual std::tr1::shared_ptr<const RepositoryNameSet> repositories(
+ const Environment * const env) const
+ {
+ using namespace std::tr1::placeholders;
+ std::tr1::shared_ptr<RepositoryNameSet> result(new RepositoryNameSet);
+ if (env->package_database()->has_repository_named(name))
+ result->insert(name);
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return "packages with repository " + stringify(name);
+ }
+ };
+
+ struct CategoryGeneratorHandler :
+ AllGeneratorHandlerBase
+ {
+ const CategoryNamePart name;
+
+ CategoryGeneratorHandler(const CategoryNamePart & n) :
+ name(n)
+ {
+ }
+
+ 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<CategoryNamePartSet> result(new CategoryNamePartSet);
+
+ for (RepositoryNameSet::ConstIterator r(repos->begin()), r_end(repos->end()) ;
+ r != r_end ; ++r)
+ if (env->package_database()->fetch_repository(*r)->has_category_named(name))
+ {
+ result->insert(name);
+ break;
+ }
+
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return "packages with category " + stringify(name);
+ }
+ };
+
+ struct PackageGeneratorHandler :
+ AllGeneratorHandlerBase
+ {
+ const QualifiedPackageName name;
+
+ PackageGeneratorHandler(const QualifiedPackageName & n) :
+ name(n)
+ {
+ }
+
+ 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<CategoryNamePartSet> result(new CategoryNamePartSet);
+
+ for (RepositoryNameSet::ConstIterator r(repos->begin()), r_end(repos->end()) ;
+ r != r_end ; ++r)
+ if (env->package_database()->fetch_repository(*r)->has_category_named(name.category))
+ {
+ result->insert(name.category);
+ break;
+ }
+
+ 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<QualifiedPackageNameSet> result(new QualifiedPackageNameSet);
+ for (RepositoryNameSet::ConstIterator r(repos->begin()), r_end(repos->end()) ;
+ r != r_end ; ++r)
+ for (CategoryNamePartSet::ConstIterator c(cats->begin()), c_end(cats->end()) ;
+ c != c_end ; ++c)
+ if (env->package_database()->fetch_repository(*r)->has_package_named(name))
+ result->insert(name);
+
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return "packages named " + stringify(name);
+ }
+ };
+
+ struct MatchesGeneratorHandler :
+ AllGeneratorHandlerBase
+ {
+ const PackageDepSpec spec;
+
+ MatchesGeneratorHandler(const PackageDepSpec & s) :
+ spec(s)
+ {
+ }
+
+ virtual std::tr1::shared_ptr<const RepositoryNameSet> repositories(
+ const Environment * const env) const
+ {
+ if (! spec.repository_ptr())
+ return AllGeneratorHandlerBase::repositories(env);
+
+ std::tr1::shared_ptr<RepositoryNameSet> result(new RepositoryNameSet);
+ if (env->package_database()->has_repository_named(*spec.repository_ptr()))
+ result->insert(*spec.repository_ptr());
+
+ return result;
+ }
+
+ virtual std::tr1::shared_ptr<const CategoryNamePartSet> categories(
+ const Environment * const env,
+ const std::tr1::shared_ptr<const RepositoryNameSet> & repos) const
+ {
+ if (spec.category_name_part_ptr())
+ {
+ std::tr1::shared_ptr<CategoryNamePartSet> result(new CategoryNamePartSet);
+ for (RepositoryNameSet::ConstIterator r(repos->begin()), r_end(repos->end()) ;
+ r != r_end ; ++r)
+ if (env->package_database()->fetch_repository(*r)->has_category_named(*spec.category_name_part_ptr()))
+ {
+ result->insert(*spec.category_name_part_ptr());
+ break;
+ }
+
+ return result;
+ }
+ else if (spec.package_ptr())
+ {
+ std::tr1::shared_ptr<CategoryNamePartSet> result(new CategoryNamePartSet);
+ for (RepositoryNameSet::ConstIterator r(repos->begin()), r_end(repos->end()) ;
+ r != r_end ; ++r)
+ if (env->package_database()->fetch_repository(*r)->has_category_named(spec.package_ptr()->category))
+ {
+ result->insert(spec.package_ptr()->category);
+ break;
+ }
+
+ return result;
+ }
+ else
+ return AllGeneratorHandlerBase::categories(env, repos);
+ }
+
+ 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
+ {
+ if (spec.package_name_part_ptr())
+ {
+ std::tr1::shared_ptr<QualifiedPackageNameSet> result(new QualifiedPackageNameSet);
+ for (RepositoryNameSet::ConstIterator r(repos->begin()), r_end(repos->end()) ;
+ r != r_end ; ++r)
+ for (CategoryNamePartSet::ConstIterator c(cats->begin()), c_end(cats->end()) ;
+ c != c_end ; ++c)
+ if (env->package_database()->fetch_repository(*r)->has_package_named(*c + *spec.package_name_part_ptr()))
+ result->insert(*c + *spec.package_name_part_ptr());
+
+ return result;
+ }
+ else if (spec.package_ptr())
+ {
+ std::tr1::shared_ptr<QualifiedPackageNameSet> result(new QualifiedPackageNameSet);
+ for (RepositoryNameSet::ConstIterator r(repos->begin()), r_end(repos->end()) ;
+ r != r_end ; ++r)
+ for (CategoryNamePartSet::ConstIterator c(cats->begin()), c_end(cats->end()) ;
+ c != c_end ; ++c)
+ if (env->package_database()->fetch_repository(*r)->has_package_named(*spec.package_ptr()))
+ result->insert(*spec.package_ptr());
+
+ return result;
+ }
+ else
+ return AllGeneratorHandlerBase::packages(env, repos, cats);
+ }
+
+ 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<PackageIDSet> result(new PackageIDSet);
+
+ for (RepositoryNameSet::ConstIterator r(repos->begin()), r_end(repos->end()) ;
+ r != r_end ; ++r)
+ {
+ for (QualifiedPackageNameSet::ConstIterator q(qpns->begin()), q_end(qpns->end()) ;
+ q != q_end ; ++q)
+ {
+ std::tr1::shared_ptr<const PackageIDSequence> id(
+ env->package_database()->fetch_repository(*r)->package_ids(*q));
+ for (PackageIDSequence::ConstIterator i(id->begin()), i_end(id->end()) ;
+ i != i_end ; ++i)
+ if (match_package(*env, spec, **i))
+ result->insert(*i);
+ }
+ }
+
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return "packages matching " + stringify(spec);
+ }
+ };
+
+ 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));
+ if (r1->empty())
+ return r1;
+
+ std::tr1::shared_ptr<const RepositoryNameSet> r2(g2.repositories(env));
+ if (r2->empty())
+ return r2;
+
+ std::tr1::shared_ptr<RepositoryNameSet> result(new RepositoryNameSet);
+ std::set_intersection(
+ 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));
+ if (c1->empty())
+ return c1;
+
+ std::tr1::shared_ptr<const CategoryNamePartSet> c2(g2.categories(env, repos));
+ if (c2->empty())
+ return c2;
+
+ std::tr1::shared_ptr<CategoryNamePartSet> result(new CategoryNamePartSet);
+ std::set_intersection(
+ 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));
+ if (q1->empty())
+ return q1;
+
+ std::tr1::shared_ptr<const QualifiedPackageNameSet> q2(g2.packages(env, repos, cats));
+ if (q2->empty())
+ return q2;
+
+ std::tr1::shared_ptr<QualifiedPackageNameSet> result(new QualifiedPackageNameSet);
+ std::set_intersection(
+ 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));
+ if (i1->empty())
+ return i1;
+
+ std::tr1::shared_ptr<const PackageIDSet> i2(g2.ids(env, repos, qpns));
+ if (i2->empty())
+ return i2;
+
+ std::tr1::shared_ptr<PackageIDSet> result(new PackageIDSet);
+ std::set_intersection(
+ i1->begin(), i1->end(),
+ i2->begin(), i2->end(),
+ result->inserter(),
+ PackageIDSetComparator());
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return stringify(g1) + " intersected with " + stringify(g2);
+ }
+ };
+
+ struct AllGeneratorHandler :
+ AllGeneratorHandlerBase
+ {
+ virtual std::string as_string() const
+ {
+ return "all packages";
+ }
+ };
+
+ template <typename A_>
+ struct SomeIDsMightSupportActionGeneratorHandler :
+ AllGeneratorHandlerBase
+ {
+ virtual std::tr1::shared_ptr<const RepositoryNameSet> repositories(
+ const Environment * const env) const
+ {
+ std::tr1::shared_ptr<RepositoryNameSet> result(new RepositoryNameSet);
+ for (PackageDatabase::RepositoryConstIterator i(env->package_database()->begin_repositories()),
+ i_end(env->package_database()->end_repositories()) ; i != i_end ; ++i)
+ if ((*i)->some_ids_might_support_action(SupportsActionTest<A_>()))
+ result->insert((*i)->name());
+
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return "packages that might support action " + stringify(ActionNames<A_>::value);
+ }
+ };
+}
+
+generator::All::All() :
+ Generator(make_shared_ptr(new AllGeneratorHandler))
+{
+}
+
+generator::Repository::Repository(const RepositoryName & n) :
+ Generator(make_shared_ptr(new RepositoryGeneratorHandler(n)))
+{
+}
+
+generator::Category::Category(const CategoryNamePart & n) :
+ Generator(make_shared_ptr(new CategoryGeneratorHandler(n)))
+{
+}
+
+generator::Package::Package(const QualifiedPackageName & n) :
+ Generator(make_shared_ptr(new PackageGeneratorHandler(n)))
+{
+}
+
+generator::Matches::Matches(const PackageDepSpec & spec) :
+ Generator(make_shared_ptr(new MatchesGeneratorHandler(spec)))
+{
+}
+
+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_>))
+{
+}
+
+Generator
+paludis::operator& (const Generator & g1, const Generator & g2)
+{
+ return generator::Union(g1, g2);
+}
+
+std::ostream &
+paludis::operator<< (std::ostream & s, const Generator & g)
+{
+ s << g.as_string();
+ return s;
+}
+
+template class PrivateImplementationPattern<Generator>;
+template class generator::SomeIDsMightSupportAction<InstallAction>;
+template class generator::SomeIDsMightSupportAction<InstalledAction>;
+template class generator::SomeIDsMightSupportAction<UninstallAction>;
+template class generator::SomeIDsMightSupportAction<PretendAction>;
+template class generator::SomeIDsMightSupportAction<ConfigAction>;
+template class generator::SomeIDsMightSupportAction<FetchAction>;
+template class generator::SomeIDsMightSupportAction<InfoAction>;
+template class generator::SomeIDsMightSupportAction<PretendFetchAction>;
+
diff --git a/paludis/generator.hh b/paludis/generator.hh
new file mode 100644
index 000000000..d00524099
--- /dev/null
+++ b/paludis/generator.hh
@@ -0,0 +1,131 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_GENERATOR_HH
+#define PALUDIS_GUARD_PALUDIS_GENERATOR_HH 1
+
+#include <paludis/generator-fwd.hh>
+#include <paludis/generator_handler-fwd.hh>
+#include <paludis/util/private_implementation_pattern.hh>
+#include <paludis/filtered_generator-fwd.hh>
+#include <paludis/name-fwd.hh>
+#include <paludis/environment-fwd.hh>
+#include <paludis/package_id-fwd.hh>
+#include <paludis/dep_spec-fwd.hh>
+#include <tr1/memory>
+
+namespace paludis
+{
+ class PALUDIS_VISIBLE Generator :
+ private PrivateImplementationPattern<Generator>
+ {
+ protected:
+ Generator(const std::tr1::shared_ptr<const GeneratorHandler> &);
+
+ public:
+ Generator(const Generator &);
+ Generator & operator= (const Generator &);
+ ~Generator();
+
+ operator FilteredGenerator () const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ std::string as_string() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ std::tr1::shared_ptr<const RepositoryNameSet> repositories(
+ const Environment * const) const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ std::tr1::shared_ptr<const CategoryNamePartSet> categories(
+ const Environment * const,
+ const std::tr1::shared_ptr<const RepositoryNameSet> &) const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ std::tr1::shared_ptr<const QualifiedPackageNameSet> packages(
+ const Environment * const,
+ const std::tr1::shared_ptr<const RepositoryNameSet> &,
+ const std::tr1::shared_ptr<const CategoryNamePartSet> &) const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ std::tr1::shared_ptr<const PackageIDSet> ids(
+ const Environment * const,
+ const std::tr1::shared_ptr<const RepositoryNameSet> &,
+ const std::tr1::shared_ptr<const QualifiedPackageNameSet> &) const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+ };
+
+ namespace generator
+ {
+ class PALUDIS_VISIBLE All :
+ public Generator
+ {
+ public:
+ All();
+ };
+
+ class PALUDIS_VISIBLE Matches :
+ public Generator
+ {
+ public:
+ Matches(const PackageDepSpec &);
+ };
+
+ class PALUDIS_VISIBLE Package :
+ public Generator
+ {
+ public:
+ Package(const QualifiedPackageName &);
+ };
+
+ class PALUDIS_VISIBLE Repository :
+ public Generator
+ {
+ public:
+ Repository(const RepositoryName &);
+ };
+
+ class PALUDIS_VISIBLE Category :
+ public Generator
+ {
+ public:
+ Category(const CategoryNamePart &);
+ };
+
+ class PALUDIS_VISIBLE Union :
+ public Generator
+ {
+ public:
+ Union(const Generator &, const Generator &);
+ };
+
+ template <typename>
+ class PALUDIS_VISIBLE SomeIDsMightSupportAction :
+ public Generator
+ {
+ public:
+ SomeIDsMightSupportAction();
+ };
+ }
+
+#ifdef PALUDIS_HAVE_EXTERN_TEMPLATE
+ extern template class PrivateImplementationPattern<Generator>;
+#endif
+
+}
+
+#endif
diff --git a/paludis/generator_TEST.cc b/paludis/generator_TEST.cc
new file mode 100644
index 000000000..6b81906ed
--- /dev/null
+++ b/paludis/generator_TEST.cc
@@ -0,0 +1,326 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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/filter.hh>
+#include <paludis/generator.hh>
+#include <paludis/selection.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/package_database.hh>
+#include <paludis/user_dep_spec.hh>
+#include <paludis/environments/test/test_environment.hh>
+#include <paludis/repositories/fake/fake_package_id.hh>
+#include <paludis/repositories/fake/fake_repository.hh>
+#include <paludis/repositories/fake/fake_installed_repository.hh>
+#include <paludis/util/sequence.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <test/test_runner.hh>
+#include <test/test_framework.hh>
+#include <test/test_concepts.hh>
+
+using namespace paludis;
+using namespace test;
+
+namespace test_cases
+{
+ TESTCASE_SEMIREGULAR(Generator, generator::All());
+ TESTCASE_STRINGIFYABLE(Generator, generator::All(), "all packages");
+
+ struct GeneratorTestCaseBase : TestCase
+ {
+ Generator generator;
+ TestEnvironment env;
+ std::tr1::shared_ptr<FakeRepository> repo1;
+ std::tr1::shared_ptr<FakeRepository> repo2;
+ std::tr1::shared_ptr<FakeInstalledRepository> inst_repo1;
+
+ GeneratorTestCaseBase(const std::string & s, const Generator & f) :
+ TestCase("generator " + s + " with " + stringify(f)),
+ generator(f),
+ repo1(new FakeRepository(&env, RepositoryName("repo1"))),
+ repo2(new FakeRepository(&env, RepositoryName("repo2"))),
+ inst_repo1(new FakeInstalledRepository(&env, RepositoryName("inst_repo1")))
+ {
+ env.package_database()->add_repository(1, repo1);
+ env.package_database()->add_repository(10, repo2);
+ env.package_database()->add_repository(0, inst_repo1);
+
+ repo1->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("1"));
+ repo1->add_version(CategoryNamePart("cat") + PackageNamePart("b"), VersionSpec("2"));
+
+ repo2->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("1"));
+ repo2->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("2"))->keywords_key()->set_from_string("");
+ repo2->add_version(CategoryNamePart("cat") + PackageNamePart("c"), VersionSpec("3"));
+
+ inst_repo1->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("1"));
+ }
+
+ virtual std::string get_expected() const = 0;
+
+ void run()
+ {
+ const std::string expected(get_expected());
+ std::tr1::shared_ptr<const PackageIDSequence> got(env[selection::AllVersionsSorted(generator)]);
+
+ TEST_CHECK(got);
+ TEST_CHECK_EQUAL(join(indirect_iterator(got->begin()), indirect_iterator(got->end()), ", "), expected);
+
+ std::tr1::shared_ptr<const PackageIDSequence> got_none(env[selection::AllVersionsSorted(generator |
+ filter::SupportsAction<InstallAction>() | filter::SupportsAction<UninstallAction>())]);
+ TEST_CHECK(got_none);
+ TEST_CHECK_EQUAL(join(indirect_iterator(got_none->begin()), indirect_iterator(got_none->end()), ", "), "");
+ }
+ };
+
+ struct AllGeneratorTestCase : GeneratorTestCaseBase
+ {
+ AllGeneratorTestCase() :
+ GeneratorTestCaseBase("all", generator::All())
+ {
+ }
+
+ 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";
+ }
+ } all_generator_test;
+
+ struct MatchesGeneratorTestCase : GeneratorTestCaseBase
+ {
+ MatchesGeneratorTestCase() :
+ GeneratorTestCaseBase("matches", generator::Matches(parse_user_package_dep_spec("cat/a", UserPackageDepSpecOptions())))
+ {
+ }
+
+ 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_generator_test;
+
+ struct MatchesCatWildcardGeneratorTestCase : GeneratorTestCaseBase
+ {
+ MatchesCatWildcardGeneratorTestCase() :
+ GeneratorTestCaseBase("matches cat wildcard", generator::Matches(parse_user_package_dep_spec("*/a",
+ UserPackageDepSpecOptions() + updso_allow_wildcards)))
+ {
+ }
+
+ 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_generator_test;
+
+ struct MatchesPkgWildcardGeneratorTestCase : GeneratorTestCaseBase
+ {
+ MatchesPkgWildcardGeneratorTestCase() :
+ GeneratorTestCaseBase("matches pkg wildcard", generator::Matches(parse_user_package_dep_spec("cat/*",
+ UserPackageDepSpecOptions() + updso_allow_wildcards)))
+ {
+ }
+
+ 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_generator_test;
+
+ struct MatchesAllWildcardGeneratorTestCase : GeneratorTestCaseBase
+ {
+ MatchesAllWildcardGeneratorTestCase() :
+ GeneratorTestCaseBase("matches all wildcard", generator::Matches(
+ parse_user_package_dep_spec(">=*/*-2", UserPackageDepSpecOptions() + updso_allow_wildcards)))
+ {
+ }
+
+ 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_generator_test;
+
+ struct PackageGeneratorTestCase : GeneratorTestCaseBase
+ {
+ PackageGeneratorTestCase() :
+ GeneratorTestCaseBase("package", generator::Package(QualifiedPackageName("cat/a")))
+ {
+ }
+
+ 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";
+ }
+ } package_generator_test;
+
+ struct NoPackageGeneratorTestCase : GeneratorTestCaseBase
+ {
+ NoPackageGeneratorTestCase() :
+ GeneratorTestCaseBase("package", generator::Package(QualifiedPackageName("cat/d")))
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return "";
+ }
+ } no_package_generator_test;
+
+ struct RepositoryGeneratorTestCase : GeneratorTestCaseBase
+ {
+ RepositoryGeneratorTestCase() :
+ GeneratorTestCaseBase("repository", generator::Repository(RepositoryName("repo1")))
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return
+ "cat/a-1:0::repo1, "
+ "cat/b-2:0::repo1";
+ }
+ } repository_generator_test;
+
+ struct NoRepositoryGeneratorTestCase : GeneratorTestCaseBase
+ {
+ NoRepositoryGeneratorTestCase() :
+ GeneratorTestCaseBase("no repository", generator::Repository(RepositoryName("repo3")))
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return "";
+ }
+ } no_repository_generator_test;
+
+ struct CategoryGeneratorTestCase : GeneratorTestCaseBase
+ {
+ CategoryGeneratorTestCase() :
+ GeneratorTestCaseBase("category", generator::Category(CategoryNamePart("cat")))
+ {
+ }
+
+ 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";
+ }
+ } category_generator_test;
+
+ struct NoCategoryGeneratorTestCase : GeneratorTestCaseBase
+ {
+ NoCategoryGeneratorTestCase() :
+ GeneratorTestCaseBase("no category", generator::Category(CategoryNamePart("a")))
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return "";
+ }
+ } no_category_generator_test;
+
+ struct UnionGeneratorTestCase : GeneratorTestCaseBase
+ {
+ UnionGeneratorTestCase() :
+ GeneratorTestCaseBase("union", generator::Union(
+ generator::Matches(parse_user_package_dep_spec("*/a", UserPackageDepSpecOptions() + updso_allow_wildcards)),
+ generator::Matches(parse_user_package_dep_spec("cat/*", UserPackageDepSpecOptions() + updso_allow_wildcards))
+ ))
+ {
+ }
+
+ 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";
+ }
+ } union_generator_test;
+
+ struct SomeIDsMightSupportInstallActionGeneratorTestCase : GeneratorTestCaseBase
+ {
+ SomeIDsMightSupportInstallActionGeneratorTestCase() :
+ GeneratorTestCaseBase("some IDs might support install",
+ generator::SomeIDsMightSupportAction<InstallAction>())
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return
+ "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";
+ }
+ } some_ids_might_support_install_action_generator_test;
+
+ struct SomeIDsMightSupportInstalledActionGeneratorTestCase : GeneratorTestCaseBase
+ {
+ SomeIDsMightSupportInstalledActionGeneratorTestCase() :
+ GeneratorTestCaseBase("some IDs might support installed",
+ generator::SomeIDsMightSupportAction<InstalledAction>())
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return
+ "cat/a-1:0::inst_repo1";
+ }
+ } some_ids_might_support_installed_action_generator_test;
+}
+
diff --git a/paludis/generator_handler-fwd.hh b/paludis/generator_handler-fwd.hh
new file mode 100644
index 000000000..e8fd081ff
--- /dev/null
+++ b/paludis/generator_handler-fwd.hh
@@ -0,0 +1,29 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_GENERATOR_HANDLER_FWD_HH
+#define PALUDIS_GUARD_PALUDIS_GENERATOR_HANDLER_FWD_HH 1
+
+namespace paludis
+{
+ struct GeneratorHandler;
+ struct AllGeneratorHandlerBase;
+}
+
+#endif
diff --git a/paludis/generator_handler.cc b/paludis/generator_handler.cc
new file mode 100644
index 000000000..3d55c22b3
--- /dev/null
+++ b/paludis/generator_handler.cc
@@ -0,0 +1,110 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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/generator_handler.hh>
+#include <paludis/util/set.hh>
+#include <paludis/util/sequence.hh>
+#include <paludis/util/wrapped_output_iterator.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/name.hh>
+#include <paludis/environment.hh>
+#include <paludis/package_database.hh>
+#include <tr1/functional>
+#include <algorithm>
+
+using namespace paludis;
+
+GeneratorHandler::~GeneratorHandler()
+{
+}
+
+std::tr1::shared_ptr<const RepositoryNameSet>
+AllGeneratorHandlerBase::repositories(
+ const Environment * const env) const
+{
+ using namespace std::tr1::placeholders;
+ std::tr1::shared_ptr<RepositoryNameSet> result(new RepositoryNameSet);
+ std::transform(env->package_database()->begin_repositories(), env->package_database()->end_repositories(),
+ result->inserter(), std::tr1::bind(&Repository::name, _1));
+ return result;
+}
+
+std::tr1::shared_ptr<const CategoryNamePartSet>
+AllGeneratorHandlerBase::categories(
+ const Environment * const env,
+ const std::tr1::shared_ptr<const RepositoryNameSet> & repos) const
+{
+ std::tr1::shared_ptr<CategoryNamePartSet> result(new CategoryNamePartSet);
+
+ for (RepositoryNameSet::ConstIterator r(repos->begin()), r_end(repos->end()) ;
+ r != r_end ; ++r)
+ {
+ std::tr1::shared_ptr<const CategoryNamePartSet> cats(env->package_database()->fetch_repository(*r)->category_names());
+ std::copy(cats->begin(), cats->end(), result->inserter());
+ }
+
+ return result;
+}
+
+std::tr1::shared_ptr<const QualifiedPackageNameSet>
+AllGeneratorHandlerBase::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<QualifiedPackageNameSet> result(new QualifiedPackageNameSet);
+
+ for (RepositoryNameSet::ConstIterator r(repos->begin()), r_end(repos->end()) ;
+ r != r_end ; ++r)
+ {
+ for (CategoryNamePartSet::ConstIterator c(cats->begin()), c_end(cats->end()) ;
+ c != c_end ; ++c)
+ {
+ std::tr1::shared_ptr<const QualifiedPackageNameSet> pkgs(
+ env->package_database()->fetch_repository(*r)->package_names(*c));
+ std::copy(pkgs->begin(), pkgs->end(), result->inserter());
+ }
+ }
+
+ return result;
+}
+
+std::tr1::shared_ptr<const PackageIDSet>
+AllGeneratorHandlerBase::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<PackageIDSet> result(new PackageIDSet);
+
+ for (RepositoryNameSet::ConstIterator r(repos->begin()), r_end(repos->end()) ;
+ r != r_end ; ++r)
+ {
+ for (QualifiedPackageNameSet::ConstIterator q(qpns->begin()), q_end(qpns->end()) ;
+ q != q_end ; ++q)
+ {
+ std::tr1::shared_ptr<const PackageIDSequence> i(
+ env->package_database()->fetch_repository(*r)->package_ids(*q));
+ std::copy(i->begin(), i->end(), result->inserter());
+ }
+ }
+
+ return result;
+}
+
diff --git a/paludis/generator_handler.hh b/paludis/generator_handler.hh
new file mode 100644
index 000000000..4206f5302
--- /dev/null
+++ b/paludis/generator_handler.hh
@@ -0,0 +1,85 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_GENERATOR_HANDLER_HH
+#define PALUDIS_GUARD_PALUDIS_GENERATOR_HANDLER_HH 1
+
+#include <paludis/generator_handler-fwd.hh>
+#include <paludis/name-fwd.hh>
+#include <paludis/environment-fwd.hh>
+#include <paludis/package_id-fwd.hh>
+#include <paludis/util/attributes.hh>
+#include <tr1/memory>
+
+namespace paludis
+{
+ class PALUDIS_VISIBLE GeneratorHandler
+ {
+ protected:
+ virtual ~GeneratorHandler() = 0;
+
+ public:
+ virtual std::tr1::shared_ptr<const RepositoryNameSet> repositories(
+ const Environment * const) const
+ PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
+
+ virtual std::tr1::shared_ptr<const CategoryNamePartSet> categories(
+ const Environment * const,
+ const std::tr1::shared_ptr<const RepositoryNameSet> &) const
+ PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
+
+ virtual std::tr1::shared_ptr<const QualifiedPackageNameSet> packages(
+ const Environment * const,
+ const std::tr1::shared_ptr<const RepositoryNameSet> &,
+ const std::tr1::shared_ptr<const CategoryNamePartSet> &) const
+ PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
+
+ virtual std::tr1::shared_ptr<const PackageIDSet> ids(
+ const Environment * const,
+ const std::tr1::shared_ptr<const RepositoryNameSet> &,
+ const std::tr1::shared_ptr<const QualifiedPackageNameSet> &) const
+ PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
+
+ virtual std::string as_string() const = 0;
+ };
+
+ class PALUDIS_VISIBLE AllGeneratorHandlerBase :
+ public GeneratorHandler
+ {
+ public:
+ virtual std::tr1::shared_ptr<const RepositoryNameSet> repositories(
+ const Environment * const env) const;
+
+ virtual std::tr1::shared_ptr<const CategoryNamePartSet> categories(
+ const Environment * const env,
+ const std::tr1::shared_ptr<const RepositoryNameSet> & repos) const;
+
+ 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;
+
+ 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;
+ };
+}
+
+#endif
diff --git a/paludis/install_task.cc b/paludis/install_task.cc
index 00cfa9003..f1e6f148a 100644
--- a/paludis/install_task.cc
+++ b/paludis/install_task.cc
@@ -24,7 +24,6 @@
#include <paludis/metadata_key.hh>
#include <paludis/util/exception.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
-#include <paludis/query.hh>
#include <paludis/hook.hh>
#include <paludis/repository.hh>
#include <paludis/match_package.hh>
@@ -32,6 +31,10 @@
#include <paludis/package_id.hh>
#include <paludis/version_requirements.hh>
#include <paludis/tasks_exceptions.hh>
+#include <paludis/selection.hh>
+#include <paludis/filter.hh>
+#include <paludis/generator.hh>
+#include <paludis/filtered_generator.hh>
#include <paludis/util/visitor-impl.hh>
#include <paludis/util/tokeniser.hh>
#include <paludis/util/set.hh>
@@ -175,9 +178,8 @@ namespace
case 'D':
return make_shared_ptr(new DepListEntryHandledSkippedDependent(
- *env->package_database()->query(query::Matches(
- parse_user_package_dep_spec(s.substr(1), UserPackageDepSpecOptions())),
- qo_require_exactly_one)->begin()));
+ *(*env)[selection::RequireExactlyOne(generator::Matches(
+ parse_user_package_dep_spec(s.substr(1), UserPackageDepSpecOptions())))]->begin()));
case 'F':
if (s.length() != 1)
@@ -221,8 +223,8 @@ InstallTask::set_targets_from_serialisation(const std::string & format, const st
if (tokens.empty())
throw InternalError(PALUDIS_HERE, "Serialised value '" + *s + "' too short: no package_id");
- const std::tr1::shared_ptr<const PackageID> package_id(*_imp->env->package_database()->query(
- query::Matches(parse_user_package_dep_spec(*tokens.begin(), UserPackageDepSpecOptions())), qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> package_id(*(*_imp->env)[selection::RequireExactlyOne(
+ generator::Matches(parse_user_package_dep_spec(*tokens.begin(), UserPackageDepSpecOptions())))]->begin());
tokens.pop_front();
if (tokens.empty())
@@ -432,7 +434,7 @@ InstallTask::_add_target(const std::string & target)
try
{
QualifiedPackageName q(_imp->env->package_database()->fetch_unique_qualified_package_name(
- PackageNamePart(target), query::MaybeSupportsAction<InstallAction>()));
+ PackageNamePart(target), filter::SupportsAction<InstallAction>()));
modified_target = stringify(q);
std::tr1::shared_ptr<PackageDepSpec> spec(new PackageDepSpec(make_package_dep_spec().package(q)));
spec->set_tag(std::tr1::shared_ptr<const DepTag>(new TargetDepTag));
@@ -745,13 +747,12 @@ InstallTask::_one(const DepList::Iterator dep, const int x, const int y, const i
std::tr1::shared_ptr<const PackageIDSequence> collision_list;
if (dep->destination)
- collision_list = _imp->env->package_database()->query(
- query::Matches(make_package_dep_spec()
+ collision_list = (*_imp->env)[selection::AllVersionsSorted(
+ generator::Matches(make_package_dep_spec()
.package(dep->package_id->name())
.slot_requirement(make_shared_ptr(new UserSlotExactRequirement(dep->package_id->slot())))
- .repository(dep->destination->name())) &
- query::SupportsAction<UninstallAction>(),
- qo_order_by_version);
+ .repository(dep->destination->name())) |
+ filter::SupportsAction<UninstallAction>())];
// don't clean the thing we just installed
PackageIDSequence clean_list;
@@ -1305,7 +1306,7 @@ namespace
void visit_leaf(const PackageDepSpec & a)
{
if (! failure)
- if (env->package_database()->query(query::Matches(a) & query::SupportsAction<InstalledAction>(), qo_whatever)->empty())
+ if ((*env)[selection::SomeArbitraryVersion(generator::Matches(a) | filter::SupportsAction<InstalledAction>())]->empty())
failure.reset(new PackageDepSpec(a));
}
@@ -1495,10 +1496,9 @@ namespace
/* no match on the dep list, fall back to installed packages. if
* there are no matches here it's not a problem because of or-deps. */
- std::tr1::shared_ptr<const PackageIDSequence> installed(env->package_database()->query(
- query::Matches(a) &
- query::SupportsAction<InstalledAction>(),
- qo_whatever));
+ std::tr1::shared_ptr<const PackageIDSequence> installed((*env)[selection::AllVersionsUnsorted(
+ generator::Matches(a) |
+ filter::SupportsAction<InstalledAction>())]);
for (PackageIDSequence::ConstIterator i(installed->begin()), i_end(installed->end()) ;
i != i_end ; ++i)
diff --git a/paludis/name-fwd.hh b/paludis/name-fwd.hh
index b94ca1041..ae3a0fa6f 100644
--- a/paludis/name-fwd.hh
+++ b/paludis/name-fwd.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2005, 2006, 2007 Ciaran McCreesh
+ * Copyright (c) 2005, 2006, 2007, 2008 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
@@ -163,6 +163,13 @@ namespace paludis
class RepositoryNameComparator;
+ /**
+ * Holds an arbitrarily ordered collection of RepositoryName instances.
+ *
+ * \ingroup g_names
+ */
+ typedef Set<RepositoryName, RepositoryNameComparator> RepositoryNameSet;
+
class KeywordNameValidator;
class KeywordNameError;
class KeywordNameComparator;
diff --git a/paludis/name.cc b/paludis/name.cc
index 3ae62f358..8919b98a4 100644
--- a/paludis/name.cc
+++ b/paludis/name.cc
@@ -38,6 +38,10 @@ using namespace paludis;
template struct Sequence<RepositoryName>;
template struct WrappedForwardIterator<Sequence<RepositoryName>::ConstIteratorTag, const RepositoryName>;
+template struct Set<RepositoryName, RepositoryNameComparator>;
+template struct WrappedForwardIterator<Set<RepositoryName, RepositoryNameComparator>::ConstIteratorTag, const RepositoryName>;
+template struct WrappedOutputIterator<Set<RepositoryName, RepositoryNameComparator>::InserterTag, RepositoryName>;
+
template struct Set<PackageNamePart>;
template struct WrappedForwardIterator<Set<PackageNamePart>::ConstIteratorTag, const PackageNamePart>;
template struct WrappedOutputIterator<Set<PackageNamePart>::InserterTag, PackageNamePart>;
diff --git a/paludis/package_database-fwd.hh b/paludis/package_database-fwd.hh
index 15509c780..eea66d8a1 100644
--- a/paludis/package_database-fwd.hh
+++ b/paludis/package_database-fwd.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2005, 2006, 2007 Ciaran McCreesh
+ * Copyright (c) 2005, 2006, 2007, 2008 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
@@ -20,9 +20,6 @@
#ifndef PALUDIS_GUARD_PALUDIS_PACKAGE_DATABASE_FWD_HH
#define PALUDIS_GUARD_PALUDIS_PACKAGE_DATABASE_FWD_HH 1
-#include <iosfwd>
-#include <paludis/util/attributes.hh>
-
/** \file
* Forward declarations for paludis/package_database.hh .
*
@@ -36,11 +33,8 @@ namespace paludis
class AmbiguousPackageNameError;
class DuplicateRepositoryError;
class NoSuchPackageError;
- class NonUniqueQueryResultError;
class NoSuchRepositoryError;
-#include <paludis/package_database-se.hh>
-
class PackageDatabase;
}
diff --git a/paludis/package_database.cc b/paludis/package_database.cc
index f7aed323d..6bda3a95e 100644
--- a/paludis/package_database.cc
+++ b/paludis/package_database.cc
@@ -22,6 +22,10 @@
#include <paludis/package_database.hh>
#include <paludis/package_id.hh>
#include <paludis/environment.hh>
+#include <paludis/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
#include <paludis/util/log.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/stringify.hh>
@@ -36,7 +40,6 @@
#include <paludis/util/sequence-impl.hh>
#include <paludis/util/wrapped_forward_iterator-impl.hh>
#include <paludis/util/member_iterator.hh>
-#include <paludis/query.hh>
#include <tr1/functional>
#include <algorithm>
#include <list>
@@ -48,8 +51,6 @@ using namespace paludis;
template class WrappedForwardIterator<AmbiguousPackageNameError::OptionsConstIteratorTag, const std::string>;
template class WrappedForwardIterator<PackageDatabase::RepositoryConstIteratorTag, const std::tr1::shared_ptr<Repository> >;
-#include "package_database-se.cc"
-
PackageDatabaseError::PackageDatabaseError(const std::string & our_message) throw () :
Exception(our_message)
{
@@ -71,14 +72,6 @@ NoSuchPackageError::NoSuchPackageError(const std::string & our_name) throw () :
{
}
-NonUniqueQueryResultError::NonUniqueQueryResultError(const Query & q,
- const std::tr1::shared_ptr<const PackageIDSequence> & r) throw () :
- PackageDatabaseLookupError("Query '" + stringify(q) + "' returned " +
- (r->empty() ? "empty result set" : "'" + join(indirect_iterator(r->begin()), indirect_iterator(r->end()), " ")
- + "'") + " but qo_require_exactly_one was specified")
-{
-}
-
NoSuchRepositoryError::NoSuchRepositoryError(const RepositoryName & n) throw () :
PackageDatabaseLookupError("Could not find repository '" + stringify(n) + "'"),
_name(n)
@@ -203,12 +196,10 @@ namespace
struct IsInstalled
{
- const FSEntry _root;
- const std::tr1::shared_ptr<const PackageDatabase> _db;
+ const Environment * const _env;
IsInstalled(const Environment * e) :
- _root(e->root()),
- _db(e->package_database())
+ _env(e)
{
}
@@ -217,7 +208,7 @@ namespace
bool operator() (const QualifiedPackageName & qpn) const
{
- return (! _db->query(query::Package(qpn) & query::InstalledAtRoot(_root), qo_whatever)->empty());
+ return ! (*_env)[selection::SomeArbitraryVersion(generator::Package(qpn) | filter::InstalledAtRoot(_env->root()))]->empty();
}
};
@@ -242,13 +233,10 @@ namespace
}
QualifiedPackageName
-PackageDatabase::fetch_unique_qualified_package_name(
- const PackageNamePart & p, const Query & q) const
+PackageDatabase::fetch_unique_qualified_package_name(const PackageNamePart & p, const Filter & f) const
{
Context context("When disambiguating package name '" + stringify(p) + "':");
- const Query & real_q(q & query::Matches(make_package_dep_spec().package_name_part(p)));
-
// Map matching QualifiedPackageNames with a flag specifying that
// at least one repository containing the package things the
// category is important
@@ -256,11 +244,14 @@ PackageDatabase::fetch_unique_qualified_package_name(
std::tr1::shared_ptr<QPNIMap> result(new QPNIMap);
std::set<std::pair<CategoryNamePart, RepositoryName>, CategoryRepositoryNamePairComparator> checked;
- std::tr1::shared_ptr<const PackageIDSequence> pkgs(query(real_q, qo_whatever));
+ std::tr1::shared_ptr<const PackageIDSequence> pkgs((*_imp->environment)[selection::AllVersionsUnsorted(
+ generator::Matches(make_package_dep_spec().package_name_part(p)) | f)]);
+
for (IndirectIterator<PackageIDSequence::ConstIterator> it(pkgs->begin()),
it_end(pkgs->end()); it_end != it; ++it)
{
- Context local_context("When checking category '" + stringify(it->name().category) + "' in repository '" + stringify(it->repository()->name()) + "':");
+ Context local_context("When checking category '" + stringify(it->name().category) + "' in repository '" +
+ stringify(it->repository()->name()) + "':");
if (! checked.insert(std::make_pair(it->name().category, it->repository()->name())).second)
continue;
@@ -323,193 +314,6 @@ PackageDatabase::fetch_unique_qualified_package_name(
return result->begin()->first;
}
-const std::tr1::shared_ptr<const PackageIDSequence>
-PackageDatabase::query(const Query & q, const QueryOrder query_order) const
-{
- using namespace std::tr1::placeholders;
-
- std::tr1::shared_ptr<PackageIDSequence> result(new PackageIDSequence);
-
- std::tr1::shared_ptr<RepositoryNameSequence> repos(q.repositories(*_imp->environment));
- if (! repos)
- {
- repos.reset(new RepositoryNameSequence);
- for (RepositoryConstIterator r(begin_repositories()), r_end(end_repositories()) ;
- r != r_end ; ++r)
- repos->push_back((*r)->name());
- }
- if (repos->empty())
- {
- if (qo_require_exactly_one == query_order)
- throw NonUniqueQueryResultError(q, result);
- else
- return result;
- }
-
- std::tr1::shared_ptr<CategoryNamePartSet> cats(q.categories(*_imp->environment, repos));
- if (! cats)
- {
- cats.reset(new CategoryNamePartSet);
- for (RepositoryNameSequence::ConstIterator r(repos->begin()), r_end(repos->end()) ;
- r != r_end ; ++r)
- {
- std::tr1::shared_ptr<const CategoryNamePartSet> local_cats(fetch_repository(*r)->category_names());
- std::copy(local_cats->begin(), local_cats->end(), cats->inserter());
- }
- }
- if (cats->empty())
- {
- if (qo_require_exactly_one == query_order)
- throw NonUniqueQueryResultError(q, result);
- else
- return result;
- }
-
- std::tr1::shared_ptr<QualifiedPackageNameSet> pkgs(q.packages(*_imp->environment, repos, cats));
- if (! pkgs)
- {
- pkgs.reset(new QualifiedPackageNameSet);
- for (RepositoryNameSequence::ConstIterator r(repos->begin()), r_end(repos->end()) ;
- r != r_end ; ++r)
- for (CategoryNamePartSet::ConstIterator c(cats->begin()), c_end(cats->end()) ;
- c != c_end ; ++c)
- {
- std::tr1::shared_ptr<const QualifiedPackageNameSet> local_pkgs(fetch_repository(*r)->package_names(*c));
- std::copy(local_pkgs->begin(), local_pkgs->end(), pkgs->inserter());
- }
- }
- if (pkgs->empty())
- {
- if (qo_require_exactly_one == query_order)
- throw NonUniqueQueryResultError(q, result);
- else
- return result;
- }
-
- std::tr1::shared_ptr<PackageIDSequence> ids(q.ids(*_imp->environment, repos, pkgs));
- if (! ids)
- {
- for (RepositoryNameSequence::ConstIterator r(repos->begin()), r_end(repos->end()) ;
- r != r_end ; ++r)
- for (QualifiedPackageNameSet::ConstIterator p(pkgs->begin()), p_end(pkgs->end()) ;
- p != p_end ; ++p)
- {
- std::tr1::shared_ptr<const PackageIDSequence> local_ids(fetch_repository(*r)->package_ids(*p));
- std::copy(local_ids->begin(), local_ids->end(), result->back_inserter());
- }
- }
- else
- {
- if (ids->empty())
- {
- if (qo_require_exactly_one == query_order)
- throw NonUniqueQueryResultError(q, result);
- else
- return result;
- }
-
- std::copy(ids->begin(), ids->end(), result->back_inserter());
- }
-
- do
- {
- switch (query_order)
- {
- case qo_order_by_version:
- {
- PackageIDComparator c(this);
- result->sort(std::tr1::bind(std::tr1::mem_fn(&PackageIDComparator::operator()), &c, _1, _2));
- }
- continue;
-
- case qo_group_by_slot:
- {
- /* if someone's bored, they can rewrite this to be a lot faster */
- PackageIDComparator c(this);
- std::set<std::tr1::shared_ptr<const PackageID>, std::tr1::function<bool (std::tr1::shared_ptr<const PackageID>,
- std::tr1::shared_ptr<const PackageID>)> > s(
- result->begin(), result->end(), std::tr1::bind(&PackageIDComparator::operator(), std::tr1::cref(c), _2, _1));
- result.reset(new PackageIDSequence);
-
- while (! s.empty())
- {
- result->push_front(*s.begin());
- s.erase(s.begin());
-
- for (std::set<std::tr1::shared_ptr<const PackageID>, std::tr1::function<bool (std::tr1::shared_ptr<const PackageID>,
- std::tr1::shared_ptr<const PackageID>)> >::iterator
- i(s.begin()) ; i != s.end() ; )
- {
- if ((*i)->name() == (*result->begin())->name() && (*i)->slot() == (*result->begin())->slot())
- {
- result->push_front(*i);
- s.erase(i++);
- }
- else
- ++i;
- }
- }
- }
- continue;
-
- case qo_best_version_only:
- {
- std::map<QualifiedPackageName, std::tr1::shared_ptr<const PackageID> > best;
- PackageIDComparator c(this);
- for (PackageIDSequence::ConstIterator r(result->begin()), r_end(result->end()) ;
- r != r_end ; ++r)
- {
- std::pair<std::map<QualifiedPackageName, std::tr1::shared_ptr<const PackageID> >::iterator, bool> p(
- best.insert(std::make_pair((*r)->name(), *r)));
- if ((! p.second) && c(p.first->second, *r))
- p.first->second = *r;
- }
-
- result.reset(new PackageIDSequence);
- std::copy(second_iterator(best.begin()), second_iterator(best.end()), result->back_inserter());
- }
- continue;
-
- case qo_best_version_in_slot_only:
- {
- std::map<std::pair<QualifiedPackageName, SlotName>, std::tr1::shared_ptr<const PackageID> > best;
- PackageIDComparator c(this);
- for (PackageIDSequence::ConstIterator r(result->begin()), r_end(result->end()) ;
- r != r_end ; ++r)
- {
- std::pair<std::map<std::pair<QualifiedPackageName, SlotName>, std::tr1::shared_ptr<const PackageID> >::iterator, bool> p(
- best.insert(std::make_pair(std::make_pair((*r)->name(), (*r)->slot()), *r)));
- if ((! p.second) && c(p.first->second, *r))
- p.first->second = *r;
- }
-
- result.reset(new PackageIDSequence);
- std::copy(second_iterator(best.begin()), second_iterator(best.end()), result->back_inserter());
- result->sort(std::tr1::bind(std::tr1::mem_fn(&PackageIDComparator::operator()), &c, _1, _2));
- }
- continue;
-
- case qo_require_exactly_one:
- if (result->empty() || (next(result->begin()) != result->end()))
- throw NonUniqueQueryResultError(q, result);
- continue;
-
- case qo_whatever:
- continue;
-
- case last_qo:
- break;
- };
-
- throw InternalError(PALUDIS_HERE, "Bad query_order");
- }
- while (false);
-
- return result;
-
-}
-
-
std::tr1::shared_ptr<const Repository>
PackageDatabase::fetch_repository(const RepositoryName & n) const
{
@@ -587,3 +391,10 @@ PackageDatabase::end_repositories() const
return RepositoryConstIterator(_imp->repositories.end());
}
+const Filter &
+PackageDatabase::all_filter()
+{
+ static const Filter result((filter::All()));
+ return result;
+}
+
diff --git a/paludis/package_database.hh b/paludis/package_database.hh
index b67987bd8..9b98f9a5c 100644
--- a/paludis/package_database.hh
+++ b/paludis/package_database.hh
@@ -24,7 +24,8 @@
#include <paludis/dep_spec.hh>
#include <paludis/name.hh>
#include <paludis/repository.hh>
-#include <paludis/query.hh>
+#include <paludis/selection-fwd.hh>
+#include <paludis/filter-fwd.hh>
#include <paludis/util/exception.hh>
#include <paludis/util/instantiation_policy.hh>
#include <paludis/util/join.hh>
@@ -44,8 +45,6 @@
* \section Examples
*
* - \ref example_package_database.cc "example_package_database.cc"
- * - \ref example_query.cc "example_query.cc"
- * - \ref example_query_delegate.cc "example_query_delegate.cc"
*/
namespace paludis
@@ -186,23 +185,6 @@ namespace paludis
};
/**
- * Thrown if a PackageDatabase::query() with qo_require_exactly_one does not
- * get exactly one result.
- *
- * \ingroup g_exceptions
- * \ingroup g_package_database
- */
- class PALUDIS_VISIBLE NonUniqueQueryResultError :
- public PackageDatabaseLookupError
- {
- public:
- /**
- * Constructor.
- */
- NonUniqueQueryResultError(const Query &, const std::tr1::shared_ptr<const PackageIDSequence> &) throw ();
- };
-
- /**
* Thrown if there is no Repository in a RepositoryDatabase with the given
* name.
*
@@ -240,6 +222,9 @@ namespace paludis
private PrivateImplementationPattern<PackageDatabase>,
private InstantiationPolicy<PackageDatabase, instantiation_method::NonCopyableTag>
{
+ private:
+ static const Filter & all_filter() PALUDIS_ATTRIBUTE((warn_unused_result));
+
public:
///\name Basic operations
///\{
@@ -289,21 +274,14 @@ namespace paludis
PALUDIS_ATTRIBUTE((warn_unused_result));
/**
- * Disambiguate a package name. If a query is specified,
+ * Disambiguate a package name. If a filter is specified,
* limit the potential results to packages that match.
*
* \throw AmbiguousPackageNameError if there is no unambiguous
* disambiguation.
*/
QualifiedPackageName fetch_unique_qualified_package_name(
- const PackageNamePart &, const Query & = query::All()) const
- PALUDIS_ATTRIBUTE((warn_unused_result));
-
- /**
- * Query the repository.
- */
- const std::tr1::shared_ptr<const PackageIDSequence> query(
- const Query &, const QueryOrder) const
+ const PackageNamePart &, const Filter & = all_filter()) const
PALUDIS_ATTRIBUTE((warn_unused_result));
/**
diff --git a/paludis/package_database.se b/paludis/package_database.se
deleted file mode 100644
index 8bd92dfee..000000000
--- a/paludis/package_database.se
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/bin/bash
-# vim: set sw=4 sts=4 et ft=sh :
-
-make_enum_QueryOrder()
-{
- prefix qo
-
- key qo_order_by_version "Order by version"
- key qo_group_by_slot "Order by version, with like slots grouped"
- key qo_best_version_only "Only the best version"
- key qo_best_version_in_slot_only "Only the best version in each slot"
- key qo_require_exactly_one "Throw if there is not exactly one result"
- key qo_whatever "Arbitrary ordering"
-
- doxygen_comment << "END"
- /**
- * How to order paludis::PackageDatabase::query() results.
- *
- * \see PackageDatabase
- * \ingroup g_package_database
- */
-END
-}
-
-
diff --git a/paludis/package_database_TEST.cc b/paludis/package_database_TEST.cc
index cd7dbe929..82ed0360f 100644
--- a/paludis/package_database_TEST.cc
+++ b/paludis/package_database_TEST.cc
@@ -18,8 +18,8 @@
*/
#include <paludis/package_database.hh>
-#include <paludis/query.hh>
#include <paludis/user_dep_spec.hh>
+#include <paludis/filter.hh>
#include <paludis/environments/test/test_environment.hh>
#include <paludis/repositories/fake/fake_repository.hh>
#include <paludis/repositories/fake/fake_installed_repository.hh>
@@ -42,10 +42,6 @@ using namespace test;
namespace test_cases
{
- /**
- * \test PackageDatabase repository tests.
- *
- */
struct PackageDatabaseRepositoryTest : TestCase
{
PackageDatabaseRepositoryTest() : TestCase("package database repository") { }
@@ -94,165 +90,6 @@ namespace test_cases
}
} package_database_repository_test;
- /**
- * \test PackageDatabase query tests.
- *
- */
- struct PackageDatabaseQueryTest : TestCase
- {
- PackageDatabaseQueryTest() : TestCase("package database query") { }
-
- void run()
- {
- TestEnvironment e;
- PackageDatabase & p(*e.package_database());
-
- std::tr1::shared_ptr<FakeRepository> r1(new FakeRepository(&e, RepositoryName("repo1")));
- r1->add_version("r1c1", "r1c1p1", "1");
- r1->add_version("r1c1", "r1c1p2", "1");
- r1->add_version("r1c1", "r1c1p2", "2");
- r1->add_version("rac1", "rac1pa", "1");
- r1->add_version("rac1", "rac1pa", "2");
- p.add_repository(11, r1);
- TEST_CHECK(true);
-
- std::tr1::shared_ptr<FakeRepository> r2(new FakeRepository(&e, RepositoryName("repo2")));
- r2->add_version("rac1", "rac1pa", "1");
- r2->add_version("rac1", "rac1pa", "3");
- p.add_repository(10, r2);
- TEST_CHECK(true);
-
- PackageDepSpec d1(parse_user_package_dep_spec("r1c1/r1c1p1", UserPackageDepSpecOptions()));
- const std::tr1::shared_ptr<const PackageIDSequence> q1(p.query(
- query::Matches(d1), qo_order_by_version));
- TEST_CHECK_EQUAL(std::distance(q1->begin(), q1->end()), 1);
-
- PackageDepSpec d2(parse_user_package_dep_spec("r1c1/r1c1p2", UserPackageDepSpecOptions()));
- const std::tr1::shared_ptr<const PackageIDSequence> q2(p.query(
- query::Matches(d2), qo_order_by_version));
- TEST_CHECK_EQUAL(std::distance(q2->begin(), q2->end()), 2);
-
- PackageDepSpec d3(parse_user_package_dep_spec(">=r1c1/r1c1p2-1", UserPackageDepSpecOptions()));
- const std::tr1::shared_ptr<const PackageIDSequence> q3(p.query(
- query::Matches(d3), qo_order_by_version));
- TEST_CHECK_EQUAL(std::distance(q3->begin(), q3->end()), 2);
-
- PackageDepSpec d4(parse_user_package_dep_spec(">=r1c1/r1c1p2-2", UserPackageDepSpecOptions()));
- const std::tr1::shared_ptr<const PackageIDSequence> q4(p.query(
- query::Matches(d4), qo_order_by_version));
- TEST_CHECK_EQUAL(join(indirect_iterator(q4->begin()), indirect_iterator(q4->end()), " "),
- "r1c1/r1c1p2-2:0::repo1");
- TEST_CHECK_EQUAL(std::distance(q4->begin(), q4->end()), 1);
-
- PackageDepSpec d5(parse_user_package_dep_spec(">=r1c1/r1c1p2-3", UserPackageDepSpecOptions()));
- const std::tr1::shared_ptr<const PackageIDSequence> q5(p.query(
- query::Matches(d5), qo_order_by_version));
- TEST_CHECK_EQUAL(std::distance(q5->begin(), q5->end()), 0);
-
- PackageDepSpec d6(parse_user_package_dep_spec("<r1c1/r1c1p2-3", UserPackageDepSpecOptions()));
- const std::tr1::shared_ptr<const PackageIDSequence> q6(p.query(
- query::Matches(d6), qo_order_by_version));
- TEST_CHECK_EQUAL(std::distance(q6->begin(), q6->end()), 2);
-
- PackageDepSpec d7(parse_user_package_dep_spec("rac1/rac1pa", UserPackageDepSpecOptions()));
- const std::tr1::shared_ptr<const PackageIDSequence> q7(p.query(
- query::Matches(d7), qo_order_by_version));
- TEST_CHECK_EQUAL(std::distance(q7->begin(), q7->end()), 4);
-
- PackageDepSpec d8(parse_user_package_dep_spec("foo/bar", UserPackageDepSpecOptions()));
- const std::tr1::shared_ptr<const PackageIDSequence> q8(p.query(
- query::Matches(d8), qo_order_by_version));
- TEST_CHECK_EQUAL(std::distance(q8->begin(), q8->end()), 0);
-
- PackageDepSpec d9(parse_user_package_dep_spec("r1c1/r1c1p1", UserPackageDepSpecOptions()));
- const std::tr1::shared_ptr<const PackageIDSequence> q9(p.query(
- query::Matches(d9) & query::SupportsAction<InstallAction>(), qo_order_by_version));
- TEST_CHECK_EQUAL(std::distance(q9->begin(), q9->end()), 1);
- }
- } package_database_query_test;
-
- struct PackageDatabaseQueryOrderTest : TestCase
- {
- PackageDatabaseQueryOrderTest() : TestCase("package database query order") { }
-
- void run()
- {
- TestEnvironment e;
- PackageDatabase & p(*e.package_database());
-
- std::tr1::shared_ptr<FakeRepository> r1(new FakeRepository(&e, RepositoryName("repo1")));
- r1->add_version("cat", "pkg", "1")->set_slot(SlotName("a"));
- r1->add_version("cat", "pkg", "2")->set_slot(SlotName("c"));
- r1->add_version("cat", "pkg", "3")->set_slot(SlotName("c"));
- r1->add_version("cat", "pkg", "4")->set_slot(SlotName("a"));
- p.add_repository(10, r1);
- TEST_CHECK(true);
-
- std::tr1::shared_ptr<FakeRepository> r2(new FakeRepository(&e, RepositoryName("repo2")));
- r2->add_version("cat", "pkg", "1")->set_slot(SlotName("a"));
- r2->add_version("cat", "pkg", "3")->set_slot(SlotName("b"));
- p.add_repository(5, r2);
- TEST_CHECK(true);
-
- PackageDepSpec d(parse_user_package_dep_spec("cat/pkg", UserPackageDepSpecOptions()));
-
- const std::tr1::shared_ptr<const PackageIDSequence> q1(p.query(query::Matches(d), qo_order_by_version));
- TEST_CHECK_EQUAL(join(indirect_iterator(q1->begin()), indirect_iterator(q1->end()), " "),
- "cat/pkg-1:a::repo2 cat/pkg-1:a::repo1 cat/pkg-2:c::repo1 cat/pkg-3:b::repo2 cat/pkg-3:c::repo1 cat/pkg-4:a::repo1");
-
- const std::tr1::shared_ptr<const PackageIDSequence> q2(p.query(query::Matches(d), qo_group_by_slot));
- TEST_CHECK_EQUAL(join(indirect_iterator(q2->begin()), indirect_iterator(q2->end()), " "),
- "cat/pkg-3:b::repo2 cat/pkg-2:c::repo1 cat/pkg-3:c::repo1 cat/pkg-1:a::repo2 cat/pkg-1:a::repo1 cat/pkg-4:a::repo1");
-
- const std::tr1::shared_ptr<const PackageIDSequence> q3(p.query(query::Matches(d), qo_best_version_only));
- TEST_CHECK_EQUAL(join(indirect_iterator(q3->begin()), indirect_iterator(q3->end()), " "),
- "cat/pkg-4:a::repo1");
-
- const std::tr1::shared_ptr<const PackageIDSequence> q4(p.query(query::Matches(d), qo_best_version_in_slot_only));
- TEST_CHECK_EQUAL(join(indirect_iterator(q4->begin()), indirect_iterator(q4->end()), " "),
- "cat/pkg-3:b::repo2 cat/pkg-3:c::repo1 cat/pkg-4:a::repo1");
-
- std::tr1::shared_ptr<FakeRepository> r3(new FakeRepository(&e, RepositoryName("repo3")));
- r3->add_version("cat", "other", "1")->set_slot(SlotName("a"));
- p.add_repository(5, r3);
- TEST_CHECK(true);
-
- PackageDepSpec c(parse_user_package_dep_spec("cat/*", UserPackageDepSpecOptions() + updso_allow_wildcards));
-
- const std::tr1::shared_ptr<const PackageIDSequence> q5(p.query(query::Matches(c), qo_order_by_version));
- TEST_CHECK_EQUAL(join(indirect_iterator(q5->begin()), indirect_iterator(q5->end()), " "),
- "cat/other-1:a::repo3 cat/pkg-1:a::repo2 cat/pkg-1:a::repo1 cat/pkg-2:c::repo1 "
- "cat/pkg-3:b::repo2 cat/pkg-3:c::repo1 cat/pkg-4:a::repo1");
-
- const std::tr1::shared_ptr<const PackageIDSequence> q6(p.query(query::Matches(c), qo_group_by_slot));
- TEST_CHECK_EQUAL(join(indirect_iterator(q6->begin()), indirect_iterator(q6->end()), " "),
- "cat/other-1:a::repo3 cat/pkg-3:b::repo2 cat/pkg-2:c::repo1 cat/pkg-3:c::repo1 "
- "cat/pkg-1:a::repo2 cat/pkg-1:a::repo1 cat/pkg-4:a::repo1");
-
- const std::tr1::shared_ptr<const PackageIDSequence> q7(p.query(query::Matches(c), qo_best_version_only));
- TEST_CHECK_EQUAL(join(indirect_iterator(q7->begin()), indirect_iterator(q7->end()), " "),
- "cat/other-1:a::repo3 cat/pkg-4:a::repo1");
-
- const std::tr1::shared_ptr<const PackageIDSequence> q8(p.query(query::Matches(c), qo_best_version_in_slot_only));
- TEST_CHECK_EQUAL(join(indirect_iterator(q8->begin()), indirect_iterator(q8->end()), " "),
- "cat/other-1:a::repo3 cat/pkg-3:b::repo2 cat/pkg-3:c::repo1 cat/pkg-4:a::repo1");
-
- PackageDepSpec b(parse_user_package_dep_spec("cat/pkg:a", UserPackageDepSpecOptions()));
- const std::tr1::shared_ptr<const PackageIDSequence> q9(p.query(query::Matches(b), qo_group_by_slot));
- TEST_CHECK_EQUAL(join(indirect_iterator(q9->begin()), indirect_iterator(q9->end()), " "),
- "cat/pkg-1:a::repo2 cat/pkg-1:a::repo1 cat/pkg-4:a::repo1");
-
- PackageDepSpec a(parse_user_package_dep_spec("cat/pkg[=1|=3]", UserPackageDepSpecOptions()));
- const std::tr1::shared_ptr<const PackageIDSequence> q10(p.query(query::Matches(a), qo_group_by_slot));
- TEST_CHECK_EQUAL(join(indirect_iterator(q10->begin()), indirect_iterator(q10->end()), " "),
- "cat/pkg-1:a::repo2 cat/pkg-1:a::repo1 cat/pkg-3:b::repo2 cat/pkg-3:c::repo1");
- }
- } package_database_query_order_test;
-
- /**
- * \test PackageDatabase disambiguate tests.
- *
- */
struct PackageDatabaseDisambiguateTest : TestCase
{
PackageDatabaseDisambiguateTest() : TestCase("package database disambiguate") { }
@@ -352,12 +189,12 @@ namespace test_cases
NoSuchPackageError);
TEST_CHECK_THROWS(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-one"),
- query::SupportsAction<InstalledAction>()),
+ filter::SupportsAction<InstalledAction>()),
NoSuchPackageError);
TEST_CHECK_STRINGIFY_EQUAL(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-foo")),
"inst-cat/pkg-foo");
TEST_CHECK_STRINGIFY_EQUAL(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-foo"),
- query::SupportsAction<InstallAction>()),
+ filter::SupportsAction<InstallAction>()),
"avail-cat/pkg-foo");
}
diff --git a/paludis/query.cc b/paludis/query.cc
deleted file mode 100644
index 43036b975..000000000
--- a/paludis/query.cc
+++ /dev/null
@@ -1,609 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2007, 2008 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/query.hh>
-#include <paludis/query_delegate.hh>
-#include <paludis/util/fs_entry.hh>
-#include <paludis/util/sequence.hh>
-#include <paludis/util/set.hh>
-#include <paludis/util/make_shared_ptr.hh>
-#include <paludis/util/visitor-impl.hh>
-#include <paludis/package_database.hh>
-#include <paludis/environment.hh>
-#include <paludis/match_package.hh>
-#include <paludis/action.hh>
-#include <paludis/package_id.hh>
-#include <paludis/metadata_key.hh>
-#include <tr1/functional>
-#include <algorithm>
-#include <set>
-
-using namespace paludis;
-
-Query::Query(std::tr1::shared_ptr<const QueryDelegate> d) :
- _d(d)
-{
-}
-
-Query::~Query()
-{
-}
-
-std::tr1::shared_ptr<RepositoryNameSequence>
-Query::repositories(const Environment & e) const
-{
- return _d->repositories(e);
-}
-
-std::tr1::shared_ptr<CategoryNamePartSet>
-Query::categories(const Environment & e, std::tr1::shared_ptr<const RepositoryNameSequence> r) const
-{
- return _d->categories(e, r);
-}
-
-std::tr1::shared_ptr<QualifiedPackageNameSet>
-Query::packages(const Environment & e,
- std::tr1::shared_ptr<const RepositoryNameSequence> r,
- std::tr1::shared_ptr<const CategoryNamePartSet> c) const
-{
- return _d->packages(e, r, c);
-}
-
-std::tr1::shared_ptr<PackageIDSequence>
-Query::ids(const Environment & e,
- std::tr1::shared_ptr<const RepositoryNameSequence> r,
- std::tr1::shared_ptr<const QualifiedPackageNameSet> q) const
-{
- return _d->ids(e, r, q);
-}
-
-namespace
-{
- struct MatchesDelegate :
- QueryDelegate
- {
- const PackageDepSpec spec;
-
- MatchesDelegate(const PackageDepSpec & a) :
- spec(a)
- {
- }
-
- std::string
- as_human_readable_string() const
- {
- return "matches '" + stringify(spec) + "'";
- }
-
- std::tr1::shared_ptr<RepositoryNameSequence>
- repositories(const Environment & e) const
- {
- if (spec.repository_ptr())
- {
- std::tr1::shared_ptr<RepositoryNameSequence> result(new RepositoryNameSequence);
-
- for (PackageDatabase::RepositoryConstIterator i(e.package_database()->begin_repositories()),
- i_end(e.package_database()->end_repositories()) ; i != i_end ; ++i)
- if ((*i)->name() == *spec.repository_ptr())
- {
- result->push_back((*i)->name());
- break;
- }
-
- return result;
- }
-
- return QueryDelegate::repositories(e);
- }
-
- std::tr1::shared_ptr<CategoryNamePartSet>
- categories(const Environment & e,
- std::tr1::shared_ptr<const RepositoryNameSequence> r) const
- {
- if (spec.package_ptr())
- {
- std::tr1::shared_ptr<CategoryNamePartSet> result(new CategoryNamePartSet);
- result->insert(spec.package_ptr()->category);
- return result;
- }
- else if (spec.category_name_part_ptr())
- {
- std::tr1::shared_ptr<CategoryNamePartSet> result(new CategoryNamePartSet);
- result->insert(*spec.category_name_part_ptr());
- return result;
- }
- else if (spec.package_name_part_ptr())
- {
- std::tr1::shared_ptr<CategoryNamePartSet> result(new CategoryNamePartSet);
- for (RepositoryNameSequence::ConstIterator it(r->begin()),
- it_end(r->end()); it_end != it; ++it)
- {
- std::tr1::shared_ptr<const CategoryNamePartSet> cats(
- e.package_database()->fetch_repository(*it)
- ->category_names_containing_package(*spec.package_name_part_ptr()));
- std::copy(cats->begin(), cats->end(), result->inserter());
- }
- return result;
- }
- else
- return QueryDelegate::categories(e, r);
- }
-
- std::tr1::shared_ptr<QualifiedPackageNameSet>
- packages(const Environment & e,
- std::tr1::shared_ptr<const RepositoryNameSequence> repos,
- std::tr1::shared_ptr<const CategoryNamePartSet> cats) const
- {
- if (spec.package_ptr())
- {
- std::tr1::shared_ptr<QualifiedPackageNameSet> result(
- new QualifiedPackageNameSet);
- result->insert(*spec.package_ptr());
- return result;
- }
- else if (spec.package_name_part_ptr())
- {
- std::tr1::shared_ptr<QualifiedPackageNameSet> result(
- new QualifiedPackageNameSet);
- for (RepositoryNameSequence::ConstIterator r(repos->begin()), r_end(repos->end()) ;
- r != r_end ; ++r)
- for (CategoryNamePartSet::ConstIterator c(cats->begin()), c_end(cats->end()) ;
- c != c_end ; ++c)
- if (e.package_database()->fetch_repository(*r)->has_package_named(*c +
- *spec.package_name_part_ptr()))
- result->insert(*c + *spec.package_name_part_ptr());
- return result;
- }
- else
- return QueryDelegate::packages(e, repos, cats);
- }
-
- std::tr1::shared_ptr<PackageIDSequence>
- ids(const Environment & e,
- std::tr1::shared_ptr<const RepositoryNameSequence> repos,
- std::tr1::shared_ptr<const QualifiedPackageNameSet> pkgs) const
- {
- std::tr1::shared_ptr<PackageIDSequence> result(new PackageIDSequence);
- for (RepositoryNameSequence::ConstIterator r(repos->begin()), r_end(repos->end()) ;
- r != r_end ; ++r)
- {
- std::tr1::shared_ptr<const Repository> repo(e.package_database()->fetch_repository(*r));
-
- for (QualifiedPackageNameSet::ConstIterator p(pkgs->begin()), p_end(pkgs->end()) ;
- p != p_end ; ++p)
- {
- std::tr1::shared_ptr<const PackageIDSequence> i(repo->package_ids(*p));
- for (PackageIDSequence::ConstIterator v(i->begin()), v_end(i->end()) ;
- v != v_end ; ++v)
- if (match_package(e, spec, **v))
- result->push_back(*v);
- }
- }
-
- return result;
- }
- };
-}
-
-query::Matches::Matches(const PackageDepSpec & a) :
- Query(std::tr1::shared_ptr<QueryDelegate>(new MatchesDelegate(a)))
-{
-}
-
-query::Package::Package(const QualifiedPackageName & a) :
- Query(std::tr1::shared_ptr<QueryDelegate>(new MatchesDelegate(PackageDepSpec(make_package_dep_spec().package(a)))))
-{
-}
-
-query::Repository::Repository(const RepositoryName & a) :
- Query(std::tr1::shared_ptr<QueryDelegate>(new MatchesDelegate(make_package_dep_spec().repository(a))))
-{
-}
-
-query::Category::Category(const CategoryNamePart & a) :
- Query(std::tr1::shared_ptr<QueryDelegate>(new MatchesDelegate(make_package_dep_spec().category_name_part(a))))
-{
-}
-
-namespace
-{
- struct NotMaskedDelegate :
- QueryDelegate
- {
- std::string
- as_human_readable_string() const
- {
- return "not masked";
- }
-
- std::tr1::shared_ptr<PackageIDSequence>
- ids(const Environment & e,
- std::tr1::shared_ptr<const RepositoryNameSequence> repos,
- std::tr1::shared_ptr<const QualifiedPackageNameSet> pkgs) const
- {
- std::tr1::shared_ptr<PackageIDSequence> result(new PackageIDSequence);
- for (RepositoryNameSequence::ConstIterator r(repos->begin()), r_end(repos->end()) ;
- r != r_end ; ++r)
- {
- std::tr1::shared_ptr<const Repository> repo(e.package_database()->fetch_repository(*r));
-
- for (QualifiedPackageNameSet::ConstIterator p(pkgs->begin()), p_end(pkgs->end()) ;
- p != p_end ; ++p)
- {
- std::tr1::shared_ptr<const PackageIDSequence> i(repo->package_ids(*p));
- for (PackageIDSequence::ConstIterator v(i->begin()), v_end(i->end()) ;
- v != v_end ; ++v)
- if (! ((*v)->masked()))
- result->push_back(*v);
- }
- }
-
- return result;
- }
- };
-}
-
-query::NotMasked::NotMasked() :
- Query(std::tr1::shared_ptr<QueryDelegate>(new NotMaskedDelegate))
-{
-}
-
-namespace
-{
- struct InstalledAtRootDelegate :
- QueryDelegate
- {
- const FSEntry root;
-
- std::string
- as_human_readable_string() const
- {
- return "installed at root '" + stringify(root) + "'";
- }
-
- InstalledAtRootDelegate(const FSEntry & r) :
- root(r)
- {
- }
-
- std::tr1::shared_ptr<RepositoryNameSequence>
- repositories(const Environment & e) const
- {
- std::tr1::shared_ptr<RepositoryNameSequence> result(new RepositoryNameSequence);
-
- for (PackageDatabase::RepositoryConstIterator i(e.package_database()->begin_repositories()),
- i_end(e.package_database()->end_repositories()) ; i != i_end ; ++i)
- if ((*i)->installed_root_key())
- if (root == (*i)->installed_root_key()->value())
- result->push_back((*i)->name());
-
- return result;
- }
- };
-}
-
-query::InstalledAtRoot::InstalledAtRoot(const FSEntry & r) :
- Query(std::tr1::shared_ptr<QueryDelegate>(
- new InstalledAtRootDelegate(r)))
-{
-}
-
-namespace
-{
- struct RepositoryNameComparator
- {
- bool operator() (const RepositoryName & l, const RepositoryName & r) const
- {
- return stringify(l) < stringify(r);
- }
- };
-
- struct AndQueryDelegate :
- QueryDelegate
- {
- std::tr1::shared_ptr<const QueryDelegate> q1, q2;
-
- std::string
- as_human_readable_string() const
- {
- return q1->as_human_readable_string()+ " & " + q2->as_human_readable_string();
- }
-
- AndQueryDelegate(std::tr1::shared_ptr<const QueryDelegate> qq1,
- std::tr1::shared_ptr<const QueryDelegate> qq2) :
- q1(qq1),
- q2(qq2)
- {
- }
-
- std::tr1::shared_ptr<RepositoryNameSequence>
- repositories(const Environment & e) const
- {
- std::tr1::shared_ptr<RepositoryNameSequence>
- r1(q1->repositories(e)),
- r2(q2->repositories(e));
-
- if (r1 && r2)
- {
- std::set<RepositoryName, RepositoryNameComparator> s1(r1->begin(), r1->end()), s2(r2->begin(), r2->end());
- std::tr1::shared_ptr<RepositoryNameSequence> result(new RepositoryNameSequence);
- std::set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), result->back_inserter(),
- RepositoryNameComparator());
- return result;
- }
- else if (r1)
- return r1;
- else
- return r2;
- }
-
- std::tr1::shared_ptr<CategoryNamePartSet>
- categories(const Environment & e, std::tr1::shared_ptr<const RepositoryNameSequence> r) const
- {
- std::tr1::shared_ptr<CategoryNamePartSet>
- r1(q1->categories(e, r)),
- r2(q2->categories(e, r));
-
- if (r1 && r2)
- {
- std::tr1::shared_ptr<CategoryNamePartSet> result(new CategoryNamePartSet);
- std::set_intersection(r1->begin(), r1->end(), r2->begin(), r2->end(), result->inserter());
- return result;
- }
- else if (r1)
- return r1;
- else
- return r2;
- }
-
- std::tr1::shared_ptr<QualifiedPackageNameSet>
- packages(const Environment & e, std::tr1::shared_ptr<const RepositoryNameSequence> r,
- std::tr1::shared_ptr<const CategoryNamePartSet> c) const
- {
- std::tr1::shared_ptr<QualifiedPackageNameSet>
- r1(q1->packages(e, r, c)),
- r2(q2->packages(e, r, c));
-
- if (r1 && r2)
- {
- std::tr1::shared_ptr<QualifiedPackageNameSet> result(new QualifiedPackageNameSet);
- std::set_intersection(r1->begin(), r1->end(), r2->begin(), r2->end(), result->inserter());
- return result;
- }
- else if (r1)
- return r1;
- else
- return r2;
- }
-
- std::tr1::shared_ptr<PackageIDSequence>
- ids(const Environment & e, std::tr1::shared_ptr<const RepositoryNameSequence> r,
- std::tr1::shared_ptr<const QualifiedPackageNameSet> q) const
- {
- std::tr1::shared_ptr<PackageIDSequence>
- r1(q1->ids(e, r, q)),
- r2(q2->ids(e, r, q));
-
- if (r1 && r2)
- {
- std::set<std::tr1::shared_ptr<const PackageID>, PackageIDSetComparator>
- s1(r1->begin(), r1->end()), s2(r2->begin(), r2->end());
- std::tr1::shared_ptr<PackageIDSequence> result(new PackageIDSequence);
- std::set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), result->back_inserter(), PackageIDSetComparator());
- return result;
- }
- else if (r1)
- return r1;
- else
- return r2;
- }
- };
-}
-
-Query
-paludis::operator& (const Query & q1, const Query & q2)
-{
- return Query(std::tr1::shared_ptr<QueryDelegate>(new AndQueryDelegate(q1._d, q2._d)));
-}
-
-std::ostream &
-paludis::operator<< (std::ostream & s, const Query & q)
-{
- s << q._d->as_human_readable_string();
- return s;
-}
-
-namespace
-{
- struct AllDelegate :
- QueryDelegate
- {
- AllDelegate()
- {
- }
-
- std::string
- as_human_readable_string() const
- {
- return "all";
- }
-
- };
-}
-
-query::All::All() :
- Query(std::tr1::shared_ptr<QueryDelegate>(
- new AllDelegate))
-{
-}
-
-namespace
-{
- template <typename T_>
- struct SupportsNames;
-
- template <>
- struct SupportsNames<InstallAction>
- {
- static const std::string name()
- {
- return "supports install action";
- }
- };
-
- template <>
- struct SupportsNames<InstalledAction>
- {
- static const std::string name()
- {
- return "supports installed action";
- }
- };
-
- template <>
- struct SupportsNames<UninstallAction>
- {
- static const std::string name()
- {
- return "supports uninstall action";
- }
- };
-
- template <>
- struct SupportsNames<ConfigAction>
- {
- static const std::string name()
- {
- return "supports config action";
- }
- };
-
- template <>
- struct SupportsNames<PretendAction>
- {
- static const std::string name()
- {
- return "supports pretend action";
- }
- };
-
- template <typename T_>
- struct SupportsDelegate :
- QueryDelegate
- {
- std::string
- as_human_readable_string() const
- {
- return SupportsNames<T_>::name();
- }
-
- std::tr1::shared_ptr<RepositoryNameSequence>
- repositories(const Environment & e) const
- {
- SupportsActionTest<T_> t;
-
- std::tr1::shared_ptr<RepositoryNameSequence> result(new RepositoryNameSequence);
-
- for (PackageDatabase::RepositoryConstIterator i(e.package_database()->begin_repositories()),
- i_end(e.package_database()->end_repositories()) ; i != i_end ; ++i)
- if ((*i)->some_ids_might_support_action(t))
- result->push_back((*i)->name());
-
- return result;
- }
-
- std::tr1::shared_ptr<PackageIDSequence>
- ids(const Environment & e,
- std::tr1::shared_ptr<const RepositoryNameSequence> repos,
- std::tr1::shared_ptr<const QualifiedPackageNameSet> pkgs) const
- {
- SupportsActionTest<T_> t;
-
- std::tr1::shared_ptr<PackageIDSequence> result(new PackageIDSequence);
- for (RepositoryNameSequence::ConstIterator r(repos->begin()), r_end(repos->end()) ;
- r != r_end ; ++r)
- {
- std::tr1::shared_ptr<const Repository> repo(e.package_database()->fetch_repository(*r));
-
- for (QualifiedPackageNameSet::ConstIterator p(pkgs->begin()), p_end(pkgs->end()) ;
- p != p_end ; ++p)
- {
- std::tr1::shared_ptr<const PackageIDSequence> i(repo->package_ids(*p));
- for (PackageIDSequence::ConstIterator v(i->begin()), v_end(i->end()) ;
- v != v_end ; ++v)
- if ((*v)->supports_action(t))
- result->push_back(*v);
- }
- }
-
- return result;
- }
- };
-
- template <typename T_>
- struct MaybeSupportsDelegate :
- QueryDelegate
- {
- std::string
- as_human_readable_string() const
- {
- return "maybe " + SupportsNames<T_>::name();
- }
-
- std::tr1::shared_ptr<RepositoryNameSequence>
- repositories(const Environment & e) const
- {
- SupportsActionTest<T_> t;
-
- std::tr1::shared_ptr<RepositoryNameSequence> result(new RepositoryNameSequence);
-
- for (PackageDatabase::RepositoryConstIterator i(e.package_database()->begin_repositories()),
- i_end(e.package_database()->end_repositories()) ; i != i_end ; ++i)
- if ((*i)->some_ids_might_support_action(t))
- result->push_back((*i)->name());
-
- return result;
- }
- };
-}
-
-template <typename A_>
-query::SupportsAction<A_>::SupportsAction() :
- Query(std::tr1::shared_ptr<QueryDelegate>(new SupportsDelegate<A_>))
-{
-}
-
-template <typename A_>
-query::MaybeSupportsAction<A_>::MaybeSupportsAction() :
- Query(std::tr1::shared_ptr<QueryDelegate>(new MaybeSupportsDelegate<A_>))
-{
-}
-
-template class query::SupportsAction<InstallAction>;
-template class query::SupportsAction<UninstallAction>;
-template class query::SupportsAction<InstalledAction>;
-template class query::SupportsAction<PretendAction>;
-template class query::SupportsAction<ConfigAction>;
-
-template class query::MaybeSupportsAction<InstallAction>;
-template class query::MaybeSupportsAction<UninstallAction>;
-template class query::MaybeSupportsAction<InstalledAction>;
-template class query::MaybeSupportsAction<PretendAction>;
-template class query::MaybeSupportsAction<ConfigAction>;
-
diff --git a/paludis/query.hh b/paludis/query.hh
deleted file mode 100644
index 813d15bf3..000000000
--- a/paludis/query.hh
+++ /dev/null
@@ -1,292 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2007, 2008 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
- */
-
-#ifndef PALUDIS_GUARD_PALUDIS_QUERY_HH
-#define PALUDIS_GUARD_PALUDIS_QUERY_HH 1
-
-#include <paludis/name-fwd.hh>
-#include <paludis/query-fwd.hh>
-#include <paludis/package_id-fwd.hh>
-#include <paludis/environment-fwd.hh>
-#include <paludis/dep_spec-fwd.hh>
-#include <paludis/query_delegate-fwd.hh>
-#include <paludis/util/fs_entry-fwd.hh>
-#include <iosfwd>
-
-/** \file
- * Declarations for Query and the various query:: classes.
- *
- * \ingroup g_query
- *
- * \section Examples
- *
- * - \ref example_query.cc "example_query.cc"
- * - \ref example_query_delegate.cc "example_query_delegate.cc"
- * - \ref example_match_package.cc "example_match_package.cc"
- */
-
-namespace paludis
-{
- /**
- * Parameter for a PackageDatabase query.
- *
- * Holds a QueryDelegate to perform actual operations, so that it can be
- * copied without splicing problems.
- *
- * \see QueryDelegate
- * \see PackageDatabase::query
- * \ingroup g_query
- * \nosubgrouping
- */
- class PALUDIS_VISIBLE Query
- {
- friend Query operator& (const Query &, const Query &);
- friend std::ostream & operator<< (std::ostream &, const Query &);
-
- private:
- std::tr1::shared_ptr<const QueryDelegate> _d;
-
- protected:
- ///\name Basic operations
- ///\{
-
- Query(std::tr1::shared_ptr<const QueryDelegate>);
-
- public:
- ~Query();
-
- ///\}
-
- ///\name Delegate-implemented functions
- ///\{
-
- std::tr1::shared_ptr<RepositoryNameSequence> repositories(const Environment & e) const;
-
- std::tr1::shared_ptr<CategoryNamePartSet> categories(const Environment & e,
- std::tr1::shared_ptr<const RepositoryNameSequence> r) const;
-
- std::tr1::shared_ptr<QualifiedPackageNameSet> packages(const Environment & e,
- std::tr1::shared_ptr<const RepositoryNameSequence> r,
- std::tr1::shared_ptr<const CategoryNamePartSet> c) const;
-
- std::tr1::shared_ptr<PackageIDSequence> ids(const Environment & e,
- std::tr1::shared_ptr<const RepositoryNameSequence> r,
- std::tr1::shared_ptr<const QualifiedPackageNameSet> q) const;
-
- ///\}
- };
-
- /**
- * Various Query classes.
- *
- * \see Query
- * \ingroup g_query
- */
- namespace query
- {
- /**
- * Fetch packages matching a given PackageDepSpec.
- *
- * \see Query
- * \see PackageDatabase::query
- * \ingroup g_query
- * \nosubgrouping
- */
- class PALUDIS_VISIBLE Matches :
- public Query
- {
- public:
- ///\name Basic operations
- ///\{
-
- Matches(const PackageDepSpec &);
-
- ///\}
- };
-
- /**
- * Fetch packages with a given package name.
- *
- * \see Query
- * \see PackageDatabase::query
- * \ingroup g_query
- * \nosubgrouping
- */
- class PALUDIS_VISIBLE Package :
- public Query
- {
- public:
- ///\name Basic operations
- ///\{
-
- Package(const QualifiedPackageName &);
-
- ///\}
- };
-
- /**
- * Fetch packages in a given repository.
- *
- * \see Query
- * \see PackageDatabase::query
- * \ingroup g_query
- * \nosubgrouping
- */
- class PALUDIS_VISIBLE Repository :
- public Query
- {
- public:
- ///\name Basic operations
- ///\{
-
- Repository(const RepositoryName &);
-
- ///\}
- };
-
- /**
- * Fetch packages in a given category.
- *
- * \see Query
- * \see PackageDatabase::query
- * \ingroup g_query
- * \nosubgrouping
- */
- class PALUDIS_VISIBLE Category :
- public Query
- {
- public:
- ///\name Basic operations
- ///\{
-
- Category(const CategoryNamePart &);
-
- ///\}
- };
-
- /**
- * Fetch packages that are not masked.
- *
- * \see Query
- * \see PackageDatabase::query
- * \ingroup g_query
- * \nosubgrouping
- */
- class PALUDIS_VISIBLE NotMasked :
- public Query
- {
- public:
- ///\name Basic operations
- ///\{
-
- NotMasked();
-
- ///\}
- };
-
- /**
- * Fetch packages that support a particular action.
- *
- * \see Query
- * \see PackageDatabase::query
- * \ingroup g_query
- * \nosubgrouping
- */
- template <typename A_>
- class PALUDIS_VISIBLE SupportsAction :
- public Query
- {
- public:
- ///\name Basic operations
- ///\{
-
- SupportsAction();
-
- ///\}
- };
-
- /**
- * Fetch packages that maybe support a particular action.
- *
- * A full SupportsAction<> on an ebuild ID requires a metadata load,
- * since unsupported EAPIs don't support any actions. MaybeSupportsAction,
- * on the other hand, only uses Repository::some_ids_might_support_action,
- * so it does not incur a penalty but may return additional results.
- *
- * \see Query
- * \see PackageDatabase::query
- * \ingroup g_query
- * \nosubgrouping
- */
- template <typename A_>
- class PALUDIS_VISIBLE MaybeSupportsAction :
- public Query
- {
- public:
- ///\name Basic operations
- ///\{
-
- MaybeSupportsAction();
-
- ///\}
- };
-
- /**
- * Fetch packages that are installed at a particular root.
- *
- * \see Query
- * \see PackageDatabase::query
- * \ingroup g_query
- * \nosubgrouping
- */
- class PALUDIS_VISIBLE InstalledAtRoot :
- public Query
- {
- public:
- ///\name Basic operations
- ///\{
-
- InstalledAtRoot(const FSEntry &);
-
- ///}
- };
-
- /**
- * Fetch all packages.
- *
- * \see Query
- * \see PackageDatabase::query
- * \ingroup g_query
- * \nosubgrouping
- */
- class PALUDIS_VISIBLE All :
- public Query
- {
- public:
- ///\name Basic operations
- ///\{
-
- All();
-
- ///}
- };
- }
-}
-
-#endif
diff --git a/paludis/query_delegate.cc b/paludis/query_delegate.cc
deleted file mode 100644
index 33cce371b..000000000
--- a/paludis/query_delegate.cc
+++ /dev/null
@@ -1,58 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2007, 2008 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/query_delegate.hh>
-
-using namespace paludis;
-
-QueryDelegate::QueryDelegate()
-{
-}
-
-QueryDelegate::~QueryDelegate()
-{
-}
-
-std::tr1::shared_ptr<RepositoryNameSequence>
-QueryDelegate::repositories(const Environment &) const
-{
- return std::tr1::shared_ptr<RepositoryNameSequence>();
-}
-
-std::tr1::shared_ptr<CategoryNamePartSet>
-QueryDelegate::categories(const Environment &, std::tr1::shared_ptr<const RepositoryNameSequence>) const
-{
- return std::tr1::shared_ptr<CategoryNamePartSet>();
-}
-
-std::tr1::shared_ptr<QualifiedPackageNameSet>
-QueryDelegate::packages(const Environment &, std::tr1::shared_ptr<const RepositoryNameSequence>,
- std::tr1::shared_ptr<const CategoryNamePartSet>) const
-{
- return std::tr1::shared_ptr<QualifiedPackageNameSet>();
-}
-
-std::tr1::shared_ptr<PackageIDSequence>
-QueryDelegate::ids(const Environment &, std::tr1::shared_ptr<const RepositoryNameSequence>,
- std::tr1::shared_ptr<const QualifiedPackageNameSet>) const
-{
- return std::tr1::shared_ptr<PackageIDSequence>();
-}
-
-
diff --git a/paludis/query_delegate.hh b/paludis/query_delegate.hh
deleted file mode 100644
index 66e34b27c..000000000
--- a/paludis/query_delegate.hh
+++ /dev/null
@@ -1,112 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2007, 2008 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
- */
-
-#ifndef PALUDIS_GUARD_PALUDIS_QUERY_DELEGATE_HH
-#define PALUDIS_GUARD_PALUDIS_QUERY_DELEGATE_HH 1
-
-#include <paludis/name-fwd.hh>
-#include <paludis/query_delegate-fwd.hh>
-#include <paludis/package_id-fwd.hh>
-#include <paludis/environment-fwd.hh>
-#include <paludis/query_delegate-fwd.hh>
-
-/** \file
- * Declarations for QueryDelegate.
- *
- * \ingroup g_query
- *
- * \section Examples
- *
- * - \ref example_query_delegate.cc "example_query_delegate.cc"
- * - \ref example_query.cc "example_query.cc"
- * - \ref example_match_package.cc "example_match_package.cc"
- */
-
-namespace paludis
-{
- /**
- * A QueryDelegate subclass is used by Query to provide the information
- * needed by PackageDatabase::query.
- *
- * \see Query
- * \ingroup g_query
- */
- class PALUDIS_VISIBLE QueryDelegate
- {
- protected:
- ///\name Basic operations
- ///\{
-
- QueryDelegate();
-
- public:
- virtual ~QueryDelegate();
-
- ///\}
-
- /**
- * Fetch the names of repositories potentially containing matches.
- * All returned repositories must exist.
- *
- * Default behaviour: return all repositories.
- */
- virtual std::tr1::shared_ptr<RepositoryNameSequence> repositories(const Environment &) const;
-
- /**
- * Fetch the names of categories potentially containing matches.
- *
- * Default behaviour: return all categories in the provided
- * repository collection.
- */
- virtual std::tr1::shared_ptr<CategoryNamePartSet> categories(const Environment &,
- std::tr1::shared_ptr<const RepositoryNameSequence>) const;
-
- /**
- * Fetch the names of packages potentially containing matches.
- *
- * Default behaviour: return all packages in the provided repository
- * in the provided categories.
- *
- * Note that some entries in the categories collection (but not in
- * the repositories collection) may not exist.
- */
- virtual std::tr1::shared_ptr<QualifiedPackageNameSet> packages(const Environment &,
- std::tr1::shared_ptr<const RepositoryNameSequence>,
- std::tr1::shared_ptr<const CategoryNamePartSet>) const;
-
- /**
- * Fetch the IDs of matching packages.
- *
- * Default behaviour: return all IDs in the provided packages.
- *
- * Note that some entries in the qualified package name collection
- * (but not in the repositories collection) may not exist.
- */
- virtual std::tr1::shared_ptr<PackageIDSequence> ids(const Environment &,
- std::tr1::shared_ptr<const RepositoryNameSequence>,
- std::tr1::shared_ptr<const QualifiedPackageNameSet>) const;
-
- /**
- * Fetch a string representation of our query.
- */
- virtual std::string as_human_readable_string() const = 0;
- };
-}
-
-#endif
diff --git a/paludis/query_visitor.cc b/paludis/query_visitor.cc
index a3849db60..c22fa3d3e 100644
--- a/paludis/query_visitor.cc
+++ b/paludis/query_visitor.cc
@@ -21,7 +21,10 @@
#include <paludis/dep_list.hh>
#include <paludis/range_rewriter.hh>
#include <paludis/package_database.hh>
-#include <paludis/query.hh>
+#include <paludis/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
#include <paludis/util/sequence.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/log.hh>
@@ -84,8 +87,8 @@ QueryVisitor::visit_leaf(const PackageDepSpec & a)
_imp->result = false;
// TODO: check destinations
- std::tr1::shared_ptr<const PackageIDSequence> matches(_imp->environment->package_database()->query(
- query::InstalledAtRoot(_imp->environment->root()) & query::Matches(a), qo_whatever));
+ std::tr1::shared_ptr<const PackageIDSequence> matches((*_imp->environment)[selection::AllVersionsUnsorted(
+ generator::Matches(a) | filter::InstalledAtRoot(_imp->environment->root()))]);
if (indirect_iterator(matches->end()) != std::find_if(indirect_iterator(matches->begin()), indirect_iterator(matches->end()),
std::tr1::bind(std::tr1::mem_fn(&DepList::replaced), _imp->dep_list, _1)))
diff --git a/paludis/report_task.cc b/paludis/report_task.cc
index f646e74b7..89b47f797 100644
--- a/paludis/report_task.cc
+++ b/paludis/report_task.cc
@@ -21,10 +21,13 @@
#include <paludis/util/log.hh>
#include <paludis/uninstall_list.hh>
#include <paludis/environment.hh>
-#include <paludis/query.hh>
#include <paludis/metadata_key.hh>
#include <paludis/dep_tag.hh>
#include <paludis/package_id.hh>
+#include <paludis/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/visitor-impl.hh>
#include <paludis/util/visitor_cast.hh>
@@ -92,8 +95,7 @@ namespace
void
VulnerableChecker::visit_leaf(const PackageDepSpec & a)
{
- std::tr1::shared_ptr<const PackageIDSequence> insecure(
- _env.package_database()->query(query::Matches(a), qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> insecure(_env[selection::AllVersionsSorted(generator::Matches(a))]);
for (PackageIDSequence::ConstIterator i(insecure->begin()),
i_end(insecure->end()) ; i != i_end ; ++i)
if (a.tag() && visitor_cast<const GLSADepTag>(*a.tag()))
@@ -200,13 +202,12 @@ ReportTask::execute()
repo_name.reset(new RepositoryName((*v)->source_origin_key()->value()));
std::tr1::shared_ptr<const PackageIDSequence> installable(
- e->package_database()->query(
- query::Matches(make_package_dep_spec()
+ (*e)[selection::BestVersionOnly(
+ generator::Matches(make_package_dep_spec()
.package((*v)->name())
.version_requirement(VersionRequirement(vo_equal, (*v)->version()))
- .repository(*repo_name)) &
- query::SupportsAction<InstallAction>(),
- qo_best_version_only));
+ .repository(*repo_name)) |
+ filter::SupportsAction<InstallAction>())]);
if (installable->empty())
is_missing = ! ((*v)->transient_key() && (*v)->transient_key()->value());
diff --git a/paludis/repositories/cran/dep_spec_pretty_printer.cc b/paludis/repositories/cran/dep_spec_pretty_printer.cc
index 0d7d7117b..26f2f20fa 100644
--- a/paludis/repositories/cran/dep_spec_pretty_printer.cc
+++ b/paludis/repositories/cran/dep_spec_pretty_printer.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007 Ciaran McCreesh
+ * Copyright (c) 2007, 2008 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
@@ -21,9 +21,13 @@
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/stringify.hh>
#include <paludis/util/visitor-impl.hh>
+#include <paludis/util/fs_entry.hh>
#include <paludis/environment.hh>
-#include <paludis/query.hh>
-#include <paludis/package_database.hh>
+#include <paludis/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/action-fwd.hh>
#include <ostream>
#include <sstream>
@@ -79,11 +83,11 @@ DepSpecPrettyPrinter::visit_leaf(const PackageDepSpec & p)
if (_imp->env)
{
- if (! _imp->env->package_database()->query(query::Matches(p) &
- query::InstalledAtRoot(_imp->env->root()), qo_whatever)->empty())
+ if (! (*_imp->env)[selection::SomeArbitraryVersion(generator::Matches(p) |
+ filter::InstalledAtRoot(_imp->env->root()))]->empty())
_imp->s << _imp->formatter.format(p, format::Installed());
- else if (! _imp->env->package_database()->query(query::Matches(p) &
- query::SupportsAction<InstallAction>() & query::NotMasked(), qo_whatever)->empty())
+ else if (! (*_imp->env)[selection::SomeArbitraryVersion(generator::Matches(p) |
+ filter::SupportsAction<InstallAction>() | filter::NotMasked())]->empty())
_imp->s << _imp->formatter.format(p, format::Installable());
else
_imp->s << _imp->formatter.format(p, format::Plain());
diff --git a/paludis/repositories/e/dep_spec_pretty_printer.cc b/paludis/repositories/e/dep_spec_pretty_printer.cc
index 4bde9a301..2052ee212 100644
--- a/paludis/repositories/e/dep_spec_pretty_printer.cc
+++ b/paludis/repositories/e/dep_spec_pretty_printer.cc
@@ -17,19 +17,23 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <algorithm>
-#include <sstream>
+#include <paludis/repositories/e/dep_spec_pretty_printer.hh>
#include <paludis/dep_spec.hh>
#include <paludis/metadata_key.hh>
#include <paludis/formatter.hh>
-#include <paludis/repositories/e/dep_spec_pretty_printer.hh>
#include <paludis/util/save.hh>
#include <paludis/util/visitor-impl.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/stringify.hh>
+#include <paludis/util/fs_entry.hh>
#include <paludis/environment.hh>
-#include <paludis/query.hh>
-#include <paludis/package_database.hh>
+#include <paludis/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/action-fwd.hh>
+#include <algorithm>
+#include <sstream>
/** \file
* Implementation of dep_spec_pretty_printer.hh.
@@ -216,11 +220,11 @@ DepSpecPrettyPrinter::visit_leaf(const PackageDepSpec & p)
if (_imp->env)
{
- if (! _imp->env->package_database()->query(query::Matches(p) &
- query::InstalledAtRoot(_imp->env->root()), qo_whatever)->empty())
+ if (! (*_imp->env)[selection::SomeArbitraryVersion(generator::Matches(p) |
+ filter::InstalledAtRoot(_imp->env->root()))]->empty())
_imp->s << _imp->formatter.format(p, format::Installed());
- else if (! _imp->env->package_database()->query(query::Matches(p) &
- query::SupportsAction<InstallAction>() & query::NotMasked(), qo_whatever)->empty())
+ else if (! (*_imp->env)[selection::SomeArbitraryVersion(generator::Matches(p) |
+ filter::SupportsAction<InstallAction>() | filter::NotMasked())]->empty())
_imp->s << _imp->formatter.format(p, format::Installable());
else
_imp->s << _imp->formatter.format(p, format::Plain());
diff --git a/paludis/repositories/e/e_repository.cc b/paludis/repositories/e/e_repository.cc
index 716bf222f..57f09cd57 100644
--- a/paludis/repositories/e/e_repository.cc
+++ b/paludis/repositories/e/e_repository.cc
@@ -46,13 +46,16 @@
#include <paludis/environment.hh>
#include <paludis/hook.hh>
#include <paludis/match_package.hh>
-#include <paludis/query.hh>
#include <paludis/repository_name_cache.hh>
#include <paludis/syncer.hh>
#include <paludis/action.hh>
#include <paludis/mask.hh>
#include <paludis/qa.hh>
#include <paludis/elike_package_dep_spec.hh>
+#include <paludis/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
#include <paludis/util/fs_entry.hh>
#include <paludis/util/log.hh>
@@ -145,14 +148,12 @@ namespace
i_end(info_pkgs.end()) ; i != i_end ; ++i)
{
std::tr1::shared_ptr<MetadataKey> key;
- std::tr1::shared_ptr<const PackageIDSequence> q(
- _env->package_database()->query(
- query::Matches(parse_elike_package_dep_spec(*i,
+ std::tr1::shared_ptr<const PackageIDSequence> q((*_env)[selection::AllVersionsSorted(
+ generator::Matches(parse_elike_package_dep_spec(*i,
(*(*erepository::EAPIData::get_instance()->eapi_from_string(_p))
[k::supported()])[k::package_dep_spec_parse_options()],
- std::tr1::shared_ptr<const PackageID>())) &
- query::InstalledAtRoot(_env->root()),
- qo_order_by_version));
+ std::tr1::shared_ptr<const PackageID>())) |
+ filter::InstalledAtRoot(_env->root()))]);
if (q->empty())
key.reset(new LiteralMetadataValueKey<std::string>(*i, *i, mkt_normal, "(none)"));
else
diff --git a/paludis/repositories/e/e_repository_TEST.cc b/paludis/repositories/e/e_repository_TEST.cc
index eb1cca034..7937f3a4c 100644
--- a/paludis/repositories/e/e_repository_TEST.cc
+++ b/paludis/repositories/e/e_repository_TEST.cc
@@ -36,10 +36,13 @@
#include <paludis/util/kc.hh>
#include <paludis/package_id.hh>
#include <paludis/metadata_key.hh>
-#include <paludis/query.hh>
#include <paludis/action.hh>
#include <paludis/stringify_formatter.hh>
#include <paludis/user_dep_spec.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/selection.hh>
#include <test/test_framework.hh>
#include <test/test_runner.hh>
#include <tr1/functional>
@@ -490,9 +493,9 @@ namespace test_cases
for (int pass = 1 ; pass <= 2 ; ++pass)
{
TestMessageSuffix pass_suffix(stringify(pass), true);
- std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
+ UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(id->short_description_key());
TEST_CHECK_EQUAL(id->short_description_key()->value(), "the-description");
@@ -535,9 +538,9 @@ namespace test_cases
{
TestMessageSuffix pass_suffix("pass=" + stringify(pass), true);
- std::tr1::shared_ptr<const PackageID> id1(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id1(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
+ UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(id1->end_metadata() != id1->find_metadata("EAPI"));
TEST_CHECK(id1->short_description_key());
@@ -552,9 +555,9 @@ namespace test_cases
id1->run_dependencies_key()->value()->accept(pr);
TEST_CHECK_STRINGIFY_EQUAL(pr, "foo/bar");
- std::tr1::shared_ptr<const PackageID> id2(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id2(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-2",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
+ UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(id2->end_metadata() != id2->find_metadata("EAPI"));
TEST_CHECK(id2->short_description_key());
@@ -603,9 +606,9 @@ namespace test_cases
{
TestMessageSuffix pass_suffix("pass=" + stringify(pass), true);
- std::tr1::shared_ptr<const PackageID> id1(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id1(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat-one/stale-pkg-1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
+ UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(id1->end_metadata() != id1->find_metadata("EAPI"));
TEST_CHECK(id1->short_description_key());
@@ -616,9 +619,9 @@ namespace test_cases
{
TestMessageSuffix pass_suffix("pass=" + stringify(pass), true);
- std::tr1::shared_ptr<const PackageID> id1(*env.package_database()->query(query::Matches(
- PackageDepSpec(parse_user_package_dep_spec("=cat-one/stale-pkg-2",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> id1(*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat-one/stale-pkg-1",
+ UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(id1->end_metadata() != id1->find_metadata("EAPI"));
TEST_CHECK(id1->short_description_key());
@@ -663,9 +666,9 @@ namespace test_cases
{
TestMessageSuffix pass_suffix(stringify(pass), true);
- std::tr1::shared_ptr<const PackageID> id1(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id1(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-two-1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin());
+ UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(id1->end_metadata() != id1->find_metadata("EAPI"));
TEST_CHECK_EQUAL((*std::tr1::static_pointer_cast<const erepository::ERepositoryID>(id1)->eapi())[k::name()], "UNKNOWN");
@@ -699,15 +702,15 @@ namespace test_cases
{
TestMessageSuffix pass_suffix(stringify(pass), true);
- std::tr1::shared_ptr<const PackageID> p1(*env.package_database()->query(query::Matches(PackageDepSpec(
- parse_user_package_dep_spec("=cat-one/pkg-one-1", UserPackageDepSpecOptions()))),
- qo_require_exactly_one)->begin());
- std::tr1::shared_ptr<const PackageID> p2(*env.package_database()->query(query::Matches(PackageDepSpec(
- parse_user_package_dep_spec("=cat-two/pkg-two-1", UserPackageDepSpecOptions()))),
- qo_require_exactly_one)->begin());
- std::tr1::shared_ptr<const PackageID> p4(*env.package_database()->query(query::Matches(PackageDepSpec(
- parse_user_package_dep_spec("=cat-one/pkg-one-2", UserPackageDepSpecOptions()))),
- qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> p1(*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1",
+ UserPackageDepSpecOptions()))))]->begin());
+ const std::tr1::shared_ptr<const PackageID> p2(*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat-two/pkg-two-1",
+ UserPackageDepSpecOptions()))))]->begin());
+ const std::tr1::shared_ptr<const PackageID> p4(*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-2",
+ UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(repo->query_use(UseFlagName("flag1"), *p1) == use_enabled);
TEST_CHECK(repo->query_use(UseFlagName("flag2"), *p1) == use_disabled);
@@ -757,23 +760,31 @@ namespace test_cases
std::tr1::shared_ptr<ERepository> repo19(make_ebuild_repository(&env, keys19));
env.package_database()->add_repository(1, repo19);
- TEST_CHECK((*env.package_database()->query(query::Matches(PackageDepSpec(parse_user_package_dep_spec("=category/package-1::test-repo-18",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin())->masked());
- TEST_CHECK((*env.package_database()->query(query::Matches(PackageDepSpec(parse_user_package_dep_spec("=category/package-2::test-repo-18",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin())->masked());
- TEST_CHECK(! (*env.package_database()->query(query::Matches(PackageDepSpec(parse_user_package_dep_spec("=category/package-3::test-repo-18",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin())->masked());
- TEST_CHECK(! (*env.package_database()->query(query::Matches(PackageDepSpec(parse_user_package_dep_spec("=category/package-4::test-repo-18",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin())->masked());
-
- TEST_CHECK((*env.package_database()->query(query::Matches(PackageDepSpec(parse_user_package_dep_spec("=category/package-1::test-repo-19",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin())->masked());
- TEST_CHECK(! (*env.package_database()->query(query::Matches(PackageDepSpec(parse_user_package_dep_spec("=category/package-2::test-repo-19",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin())->masked());
- TEST_CHECK((*env.package_database()->query(query::Matches(PackageDepSpec(parse_user_package_dep_spec("=category/package-3::test-repo-19",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin())->masked());
- TEST_CHECK(! (*env.package_database()->query(query::Matches(PackageDepSpec(parse_user_package_dep_spec("=category/package-4::test-repo-19",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->begin())->masked());
+ TEST_CHECK((*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=category/package-1::test-repo-18",
+ UserPackageDepSpecOptions()))))]->begin())->masked());
+ TEST_CHECK((*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=category/package-2::test-repo-18",
+ UserPackageDepSpecOptions()))))]->begin())->masked());
+ TEST_CHECK(! (*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=category/package-3::test-repo-18",
+ UserPackageDepSpecOptions()))))]->begin())->masked());
+ TEST_CHECK(! (*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=category/package-4::test-repo-18",
+ UserPackageDepSpecOptions()))))]->begin())->masked());
+
+ TEST_CHECK((*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=category/package-1::test-repo-19",
+ UserPackageDepSpecOptions()))))]->begin())->masked());
+ TEST_CHECK(! (*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=category/package-2::test-repo-19",
+ UserPackageDepSpecOptions()))))]->begin())->masked());
+ TEST_CHECK((*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=category/package-3::test-repo-19",
+ UserPackageDepSpecOptions()))))]->begin())->masked());
+ TEST_CHECK(! (*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=category/package-4::test-repo-19",
+ UserPackageDepSpecOptions()))))]->begin())->masked());
}
} test_e_repository_repository_masks;
@@ -802,15 +813,15 @@ namespace test_cases
{
TestMessageSuffix pass_suffix(stringify(pass), true);
- TEST_CHECK((*env.package_database()->query(query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat/masked-0",
- UserPackageDepSpecOptions()))),
- qo_require_exactly_one)->begin())->masked());
- TEST_CHECK(! (*env.package_database()->query(query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat/was_masked-0",
- UserPackageDepSpecOptions()))),
- qo_require_exactly_one)->begin())->masked());
- TEST_CHECK(! (*env.package_database()->query(query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat/not_masked-0",
- UserPackageDepSpecOptions()))),
- qo_require_exactly_one)->begin())->masked());
+ TEST_CHECK((*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat/masked-0",
+ UserPackageDepSpecOptions()))))]->begin())->masked());
+ TEST_CHECK(! (*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat/was_masked-0",
+ UserPackageDepSpecOptions()))))]->begin())->masked());
+ TEST_CHECK(! (*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat/not_masked-0",
+ UserPackageDepSpecOptions()))))]->begin())->masked());
}
}
} test_e_repository_query_profile_masks;
@@ -836,17 +847,17 @@ namespace test_cases
std::tr1::shared_ptr<ERepository> repo(make_ebuild_repository(&env, keys));
env.package_database()->add_repository(1, repo);
- TEST_CHECK((*env.package_database()->query(query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat/was_masked-0",
- UserPackageDepSpecOptions()))),
- qo_require_exactly_one)->begin())->masked());
+ TEST_CHECK((*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat/was_masked-0",
+ UserPackageDepSpecOptions()))))]->begin())->masked());
repo->set_profile(repo->find_profile(repo->params().location / "profiles/profile/subprofile"));
- TEST_CHECK(! (*env.package_database()->query(query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat/was_masked-0",
- UserPackageDepSpecOptions()))),
- qo_require_exactly_one)->begin())->masked());
+ TEST_CHECK(! (*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat/was_masked-0",
+ UserPackageDepSpecOptions()))))]->begin())->masked());
repo->set_profile(repo->find_profile(repo->params().location / "profiles/profile"));
- TEST_CHECK((*env.package_database()->query(query::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat/was_masked-0",
- UserPackageDepSpecOptions()))),
- qo_require_exactly_one)->begin())->masked());
+ TEST_CHECK((*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat/was_masked-0",
+ UserPackageDepSpecOptions()))))]->begin())->masked());
}
} test_e_repository_invalidate_masks;
@@ -1002,9 +1013,9 @@ namespace test_cases
{
TestMessageSuffix suffix("no files", true);
- const std::tr1::shared_ptr<const PackageID> no_files_id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> no_files_id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("cat/no-files",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(no_files_id);
TEST_CHECK(no_files_id->short_description_key());
TEST_CHECK_EQUAL(no_files_id->short_description_key()->value(), "The Description");
@@ -1013,9 +1024,9 @@ namespace test_cases
{
TestMessageSuffix suffix("fetched files", true);
- const std::tr1::shared_ptr<const PackageID> fetched_files_id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> fetched_files_id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("cat/fetched-files",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(fetched_files_id);
TEST_CHECK((FSEntry("e_repository_TEST_dir") / "distdir" / "already-fetched.txt").is_regular_file());
fetched_files_id->perform_action(action);
@@ -1025,9 +1036,9 @@ namespace test_cases
{
TestMessageSuffix suffix("fetchable files", true);
TEST_CHECK(! (FSEntry("e_repository_TEST_dir") / "distdir" / "fetchable-1.txt").is_regular_file());
- const std::tr1::shared_ptr<const PackageID> fetchable_files_id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> fetchable_files_id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("cat/fetchable-files",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(fetchable_files_id);
fetchable_files_id->perform_action(action);
TEST_CHECK((FSEntry("e_repository_TEST_dir") / "distdir" / "fetchable-1.txt").is_regular_file());
@@ -1036,9 +1047,9 @@ namespace test_cases
{
TestMessageSuffix suffix("arrow files", true);
TEST_CHECK(! (FSEntry("e_repository_TEST_dir") / "distdir" / "arrowed.txt").is_regular_file());
- const std::tr1::shared_ptr<const PackageID> arrow_files_id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> arrow_files_id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("cat/arrow-files",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(arrow_files_id);
arrow_files_id->perform_action(action);
TEST_CHECK((FSEntry("e_repository_TEST_dir") / "distdir" / "arrowed.txt").is_regular_file());
@@ -1046,33 +1057,33 @@ namespace test_cases
{
TestMessageSuffix suffix("unfetchable files", true);
- const std::tr1::shared_ptr<const PackageID> unfetchable_files_id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> unfetchable_files_id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("cat/unfetchable-files",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(unfetchable_files_id);
TEST_CHECK_THROWS(unfetchable_files_id->perform_action(action), FetchActionError);
}
{
- const std::tr1::shared_ptr<const PackageID> no_files_restricted_id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> no_files_restricted_id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("cat/no-files-restricted",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(no_files_restricted_id);
no_files_restricted_id->perform_action(action);
}
{
- const std::tr1::shared_ptr<const PackageID> fetched_files_restricted_id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> fetched_files_restricted_id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("cat/fetched-files-restricted",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(fetched_files_restricted_id);
fetched_files_restricted_id->perform_action(action);
}
{
- const std::tr1::shared_ptr<const PackageID> fetchable_files_restricted_id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> fetchable_files_restricted_id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("cat/fetchable-files-restricted",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(fetchable_files_restricted_id);
TEST_CHECK_THROWS(fetchable_files_restricted_id->perform_action(action), FetchActionError);
}
@@ -1102,9 +1113,9 @@ namespace test_cases
(k::safe_resume(), true)
);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::AllVersionsSorted(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("category/package",
- UserPackageDepSpecOptions()))), qo_order_by_version)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
repo->make_manifest(id->name());
id->perform_action(action);
@@ -1163,62 +1174,62 @@ namespace test_cases
);
{
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=virtual/virtual-pretend-installed-0",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
}
{
TestMessageSuffix suffix("in-ebuild die", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("cat/in-ebuild-die",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
TEST_CHECK_THROWS(id->perform_action(action), InstallActionError);
}
{
TestMessageSuffix suffix("in-subshell die", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("cat/in-subshell-die",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
TEST_CHECK_THROWS(id->perform_action(action), InstallActionError);
}
{
TestMessageSuffix suffix("success", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("cat/success",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
id->perform_action(action);
}
{
TestMessageSuffix suffix("unpack die", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("cat/unpack-die",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
TEST_CHECK_THROWS(id->perform_action(action), InstallActionError);
}
{
TestMessageSuffix suffix("emake fail", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("cat/emake-fail",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
id->perform_action(action);
}
{
TestMessageSuffix suffix("econf source 0", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/econf-source-0",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
TEST_CHECK_EQUAL(visitor_cast<const MetadataValueKey<std::string> >(**id->find_metadata("EAPI"))->value(), "0");
TEST_CHECK_THROWS(id->perform_action(action), InstallActionError);
@@ -1226,45 +1237,45 @@ namespace test_cases
{
TestMessageSuffix suffix("best version", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/best-version-0",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
id->perform_action(action);
}
{
TestMessageSuffix suffix("has version", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/has-version-0",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
id->perform_action(action);
}
{
TestMessageSuffix suffix("match", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/match-0",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
id->perform_action(action);
}
{
TestMessageSuffix suffix("vars", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/vars-0",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
id->perform_action(action);
}
{
TestMessageSuffix suffix("expand vars", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/expand-vars-0",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
id->perform_action(action);
}
@@ -1315,9 +1326,9 @@ namespace test_cases
{
TestMessageSuffix suffix("econf source 1", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/econf-source-1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
TEST_CHECK_EQUAL(visitor_cast<const MetadataValueKey<std::string> >(**id->find_metadata("EAPI"))->value(), "1");
id->perform_action(action);
@@ -1325,9 +1336,9 @@ namespace test_cases
{
TestMessageSuffix suffix("dosym success 1", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/dosym-success-1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
TEST_CHECK_EQUAL(visitor_cast<const MetadataValueKey<std::string> >(**id->find_metadata("EAPI"))->value(), "1");
id->perform_action(action);
@@ -1379,9 +1390,9 @@ namespace test_cases
{
TestMessageSuffix suffix("econf source kdebuild-1", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/econf-source-kdebuild-1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
TEST_CHECK_EQUAL(visitor_cast<const MetadataValueKey<std::string> >(**id->find_metadata("EAPI"))->value(), "kdebuild-1");
id->perform_action(action);
@@ -1389,9 +1400,9 @@ namespace test_cases
{
TestMessageSuffix suffix("banned functions kdebuild-1", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/banned-functions-kdebuild-1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
TEST_CHECK_EQUAL(visitor_cast<const MetadataValueKey<std::string> >(**id->find_metadata("EAPI"))->value(), "kdebuild-1");
TEST_CHECK_THROWS(id->perform_action(action), InstallActionError);
@@ -1399,18 +1410,18 @@ namespace test_cases
{
TestMessageSuffix suffix("banned vars kdebuild-1", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/banned-vars-kdebuild-1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
TEST_CHECK_EQUAL(visitor_cast<const MetadataValueKey<std::string> >(**id->find_metadata("EAPI"))->value(), "UNKNOWN");
}
{
TestMessageSuffix suffix("dosym success kdebuild-1", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/dosym-success-kdebuild-1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
TEST_CHECK_EQUAL(visitor_cast<const MetadataValueKey<std::string> >(**id->find_metadata("EAPI"))->value(), "kdebuild-1");
id->perform_action(action);
@@ -1418,9 +1429,9 @@ namespace test_cases
{
TestMessageSuffix suffix("dosym fail kdebuild-1", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/dosym-fail-kdebuild-1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
TEST_CHECK_EQUAL(visitor_cast<const MetadataValueKey<std::string> >(**id->find_metadata("EAPI"))->value(), "kdebuild-1");
TEST_CHECK_THROWS(id->perform_action(action), InstallActionError);
@@ -1467,9 +1478,9 @@ namespace test_cases
{
TestMessageSuffix suffix("info success kdebuild-1", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/info-success-kdebuild-1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
TEST_CHECK_EQUAL(visitor_cast<const MetadataValueKey<std::string> >(**id->find_metadata("EAPI"))->value(), "kdebuild-1");
id->perform_action(action);
@@ -1477,9 +1488,9 @@ namespace test_cases
{
TestMessageSuffix suffix("info fail kdebuild-1", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/info-fail-kdebuild-1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
TEST_CHECK_EQUAL(visitor_cast<const MetadataValueKey<std::string> >(**id->find_metadata("EAPI"))->value(), "kdebuild-1");
TEST_CHECK_THROWS(id->perform_action(action), InfoActionError);
@@ -1539,81 +1550,81 @@ namespace test_cases
{
TestMessageSuffix suffix("in-ebuild die", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("cat/in-ebuild-die",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
TEST_CHECK_THROWS(id->perform_action(action), InstallActionError);
}
{
TestMessageSuffix suffix("in-subshell die", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("cat/in-subshell-die",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
TEST_CHECK_THROWS(id->perform_action(action), InstallActionError);
}
{
TestMessageSuffix suffix("success", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("cat/success",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
id->perform_action(action);
}
{
TestMessageSuffix suffix("unpack die", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("cat/unpack-die",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
TEST_CHECK_THROWS(id->perform_action(action), InstallActionError);
}
{
TestMessageSuffix suffix("emake fail", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("cat/emake-fail",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
TEST_CHECK_THROWS(id->perform_action(action), InstallActionError);
}
{
TestMessageSuffix suffix("best version", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/best-version-0",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
id->perform_action(action);
}
{
TestMessageSuffix suffix("has version", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/has-version-0",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
id->perform_action(action);
}
{
TestMessageSuffix suffix("match", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/match-0",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
TEST_CHECK_THROWS(id->perform_action(action), InstallActionError);
}
{
TestMessageSuffix suffix("ever", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/ever-1.3",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
TEST_CHECK(id->short_description_key());
TEST_CHECK_EQUAL(id->short_description_key()->value(), "The Description");
@@ -1622,27 +1633,27 @@ namespace test_cases
{
TestMessageSuffix suffix("econf phase", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/econf-phase-0",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
TEST_CHECK_THROWS(id->perform_action(action), InstallActionError);
}
{
TestMessageSuffix suffix("econf vars", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/econf-vars-0",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
id->perform_action(action);
}
{
TestMessageSuffix suffix("expand vars", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/expand-vars-0",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
id->perform_action(action);
}
@@ -1667,10 +1678,9 @@ namespace test_cases
&env, keys));
env.package_database()->add_repository(1, repo);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->
- query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("category/package",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
StringifyFormatter ff;
@@ -1742,9 +1752,9 @@ namespace test_cases
(k::destination(), installed_repo)
);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("cat/pkg",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->last());
TEST_CHECK(id);
id->perform_action(action);
diff --git a/paludis/repositories/e/e_repository_news.cc b/paludis/repositories/e/e_repository_news.cc
index 71cba9f9d..a285ff588 100644
--- a/paludis/repositories/e/e_repository_news.cc
+++ b/paludis/repositories/e/e_repository_news.cc
@@ -31,8 +31,11 @@
#include <paludis/util/sequence.hh>
#include <paludis/util/options.hh>
#include <paludis/util/wrapped_forward_iterator-impl.hh>
-#include <paludis/query.hh>
#include <paludis/elike_package_dep_spec.hh>
+#include <paludis/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
#include <set>
#include <ostream>
@@ -136,13 +139,12 @@ ERepositoryNews::update_news() const
bool local_show(false);
for (NewsFile::DisplayIfInstalledConstIterator i(news.begin_display_if_installed()),
i_end(news.end_display_if_installed()) ; i != i_end ; ++i)
- if (! _imp->environment->package_database()->query(
- query::Matches(PackageDepSpec(parse_elike_package_dep_spec(*i,
+ if (! (*_imp->environment)[selection::SomeArbitraryVersion(
+ generator::Matches(PackageDepSpec(parse_elike_package_dep_spec(*i,
(*(*erepository::EAPIData::get_instance()->eapi_from_string(
_imp->e_repository->params().profile_eapi))[k::supported()])[k::package_dep_spec_parse_options()],
- std::tr1::shared_ptr<const PackageID>()))) &
- query::SupportsAction<InstalledAction>(),
- qo_whatever)->empty())
+ std::tr1::shared_ptr<const PackageID>()))) |
+ filter::SupportsAction<InstalledAction>())]->empty())
local_show = true;
show &= local_show;
}
diff --git a/paludis/repositories/e/e_repository_sets.cc b/paludis/repositories/e/e_repository_sets.cc
index 1cfee8969..82ccaf2aa 100644
--- a/paludis/repositories/e/e_repository_sets.cc
+++ b/paludis/repositories/e/e_repository_sets.cc
@@ -25,7 +25,6 @@
#include <paludis/environment.hh>
#include <paludis/util/config_file.hh>
-#include <paludis/query.hh>
#include <paludis/set_file.hh>
#include <paludis/dep_tag.hh>
#include <paludis/package_id.hh>
@@ -45,6 +44,11 @@
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/dep_spec.hh>
#include <paludis/elike_slot_requirement.hh>
+#include <paludis/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/action-fwd.hh>
#include <tr1/functional>
#include <algorithm>
#include <list>
@@ -257,12 +261,11 @@ ERepositorySets::security_set(bool insecurity) const
{
std::tr1::shared_ptr<const PackageIDSequence> candidates;
if (insecurity)
- candidates = _imp->environment->package_database()->query(query::Package(glsa_pkg->name()), qo_order_by_version);
+ candidates = (*_imp->environment)[selection::AllVersionsSorted(generator::Package(glsa_pkg->name()))];
else
- candidates = _imp->environment->package_database()->query(
- query::Package(glsa_pkg->name()) &
- query::SupportsAction<InstalledAction>(),
- qo_order_by_version);
+ candidates = (*_imp->environment)[selection::AllVersionsSorted(
+ generator::Package(glsa_pkg->name()) |
+ filter::SupportsAction<InstalledAction>())];
for (PackageIDSequence::ConstIterator c(candidates->begin()), c_end(candidates->end()) ;
c != c_end ; ++c)
@@ -294,13 +297,12 @@ ERepositorySets::security_set(bool insecurity) const
* that's in the same slot as our vulnerable installed package. */
bool ok(false);
std::tr1::shared_ptr<const PackageIDSequence> available(
- _imp->environment->package_database()->query(
- query::Matches(make_package_dep_spec()
+ (*_imp->environment)[selection::AllVersionsSorted(
+ generator::Matches(make_package_dep_spec()
.package(glsa_pkg->name())
- .slot_requirement(make_shared_ptr(new ELikeSlotExactRequirement((*c)->slot(), false)))) &
- query::SupportsAction<InstallAction>() &
- query::NotMasked(),
- qo_order_by_version));
+ .slot_requirement(make_shared_ptr(new ELikeSlotExactRequirement((*c)->slot(), false)))) |
+ filter::SupportsAction<InstallAction>() |
+ filter::NotMasked())]);
for (PackageIDSequence::ReverseConstIterator r(available->rbegin()), r_end(available->rend()) ; r != r_end ; ++r)
{
diff --git a/paludis/repositories/e/fetch_visitor_TEST.cc b/paludis/repositories/e/fetch_visitor_TEST.cc
index 4274c86b9..4cb7f5cfa 100644
--- a/paludis/repositories/e/fetch_visitor_TEST.cc
+++ b/paludis/repositories/e/fetch_visitor_TEST.cc
@@ -27,8 +27,11 @@
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/util/visitor-impl.hh>
#include <paludis/package_database.hh>
-#include <paludis/query.hh>
#include <paludis/user_dep_spec.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/selection.hh>
#include <test/test_runner.hh>
#include <test/test_framework.hh>
#include <fstream>
@@ -55,8 +58,8 @@ namespace test_cases
TEST_CHECK(! FSEntry("fetch_visitor_TEST_dir/out/input1").exists());
const std::tr1::shared_ptr<const EAPI> eapi(EAPIData::get_instance()->eapi_from_string("exheres-0"));
- FetchVisitor v(&env, *env.package_database()->query(query::Matches(parse_user_package_dep_spec("=cat/pkg-1", UserPackageDepSpecOptions())),
- qo_require_exactly_one)->begin(),
+ FetchVisitor v(&env, *env[selection::RequireExactlyOne(
+ generator::Matches(parse_user_package_dep_spec("=cat/pkg-1", UserPackageDepSpecOptions())))]->begin(),
*eapi, FSEntry("fetch_visitor_TEST_dir/out"),
false, false, "test", make_shared_ptr(new URIListedThenMirrorsLabel("listed-then-mirrors")), false);
parse_fetchable_uri("file:///" + stringify(FSEntry("fetch_visitor_TEST_dir/in/input1").realpath()), &env, id, *eapi)->accept(v);
diff --git a/paludis/repositories/e/fix_locked_dependencies.cc b/paludis/repositories/e/fix_locked_dependencies.cc
index f1bcadbc4..27e09eed4 100644
--- a/paludis/repositories/e/fix_locked_dependencies.cc
+++ b/paludis/repositories/e/fix_locked_dependencies.cc
@@ -27,11 +27,14 @@
#include <paludis/util/fs_entry.hh>
#include <paludis/util/options.hh>
#include <paludis/dep_spec.hh>
-#include <paludis/query.hh>
#include <paludis/environment.hh>
#include <paludis/package_database.hh>
#include <paludis/package_id.hh>
#include <paludis/elike_slot_requirement.hh>
+#include <paludis/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
#include <tr1/functional>
#include <algorithm>
#include <list>
@@ -138,8 +141,8 @@ namespace
if (! r)
break;
- std::tr1::shared_ptr<const PackageIDSequence> matches(env->package_database()->query(
- query::Matches(s) & query::InstalledAtRoot(FSEntry("/")), qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> matches((*env)[selection::AllVersionsSorted(
+ generator::Matches(s) | filter::InstalledAtRoot(FSEntry("/")))]);
if (matches->empty())
break;
diff --git a/paludis/repositories/e/pipe_command_handler.cc b/paludis/repositories/e/pipe_command_handler.cc
index 09d268e63..770978c21 100644
--- a/paludis/repositories/e/pipe_command_handler.cc
+++ b/paludis/repositories/e/pipe_command_handler.cc
@@ -38,6 +38,10 @@
#include <paludis/package_database.hh>
#include <paludis/metadata_key.hh>
#include <paludis/stringify_formatter.hh>
+#include <paludis/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
#include <vector>
using namespace paludis;
@@ -105,8 +109,8 @@ paludis::erepository::pipe_command_handler(const Environment * const environment
PackageDepSpec spec(parse_elike_package_dep_spec(tokens[2], (*(*eapi)[k::supported()])[k::package_dep_spec_parse_options()],
package_id));
- std::tr1::shared_ptr<const PackageIDSequence> entries(environment->package_database()->query(
- query::Matches(spec) & query::InstalledAtRoot(environment->root()), qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> entries((*environment)[selection::AllVersionsSorted(
+ generator::Matches(spec) | filter::InstalledAtRoot(environment->root()))]);
if ((*(*eapi)[k::supported()])[k::pipe_commands()][k::rewrite_virtuals()] && (! entries->empty()) &&
(*entries->last())->virtual_for_key())
{
@@ -145,8 +149,8 @@ paludis::erepository::pipe_command_handler(const Environment * const environment
PackageDepSpec spec(parse_elike_package_dep_spec(tokens[2], (*(*eapi)[k::supported()])[k::package_dep_spec_parse_options()],
package_id));
- std::tr1::shared_ptr<const PackageIDSequence> entries(environment->package_database()->query(
- query::Matches(spec) & query::InstalledAtRoot(environment->root()), qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> entries((*environment)[selection::SomeArbitraryVersion(
+ generator::Matches(spec) | filter::InstalledAtRoot(environment->root()))]);
if (entries->empty())
return "O1;";
else
@@ -168,8 +172,8 @@ paludis::erepository::pipe_command_handler(const Environment * const environment
PackageDepSpec spec(parse_elike_package_dep_spec(tokens[2], (*(*eapi)[k::supported()])[k::package_dep_spec_parse_options()],
package_id));
- std::tr1::shared_ptr<const PackageIDSequence> entries(environment->package_database()->query(
- query::Matches(spec) & query::InstalledAtRoot(environment->root()), qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> entries((*environment)[selection::AllVersionsSorted(
+ generator::Matches(spec) | filter::InstalledAtRoot(environment->root()))]);
if ((*(*eapi)[k::supported()])[k::pipe_commands()][k::rewrite_virtuals()] && (! entries->empty()))
{
std::tr1::shared_ptr<PackageIDSequence> new_entries(new PackageIDSequence);
diff --git a/paludis/repositories/e/qa/visibility.cc b/paludis/repositories/e/qa/visibility.cc
index 565265332..4601e86cd 100644
--- a/paludis/repositories/e/qa/visibility.cc
+++ b/paludis/repositories/e/qa/visibility.cc
@@ -27,7 +27,6 @@
#include <paludis/util/visitor-impl.hh>
#include <paludis/util/create_iterator-impl.hh>
#include <paludis/util/make_shared_ptr.hh>
-#include <paludis/query.hh>
#include <paludis/qa.hh>
#include <paludis/dep_spec.hh>
#include <paludis/environment.hh>
@@ -37,6 +36,10 @@
#include <paludis/metadata_key.hh>
#include <paludis/stringify_formatter.hh>
#include <paludis/elike_conditional_dep_spec.hh>
+#include <paludis/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
#include <set>
#include <algorithm>
@@ -138,8 +141,8 @@ namespace
}
}
- const std::tr1::shared_ptr<const PackageIDSequence> matches(env->package_database()->query(
- query::Matches(*p) & query::SupportsAction<InstallAction>(), qo_order_by_version));
+ const std::tr1::shared_ptr<const PackageIDSequence> matches((*env)[selection::AllVersionsSorted(
+ generator::Matches(*p) | filter::SupportsAction<InstallAction>())]);
if (matches->empty())
{
if (reporter)
diff --git a/paludis/repositories/e/qa/visibility_TEST.cc b/paludis/repositories/e/qa/visibility_TEST.cc
index 727e9a86f..74b845103 100644
--- a/paludis/repositories/e/qa/visibility_TEST.cc
+++ b/paludis/repositories/e/qa/visibility_TEST.cc
@@ -26,9 +26,12 @@
#include <paludis/util/sequence.hh>
#include <paludis/util/options.hh>
#include <paludis/qa.hh>
-#include <paludis/query.hh>
#include <paludis/package_database.hh>
#include <paludis/user_dep_spec.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/selection.hh>
#include <test/test_framework.hh>
#include <test/test_runner.hh>
@@ -81,32 +84,32 @@ namespace test_cases
env.package_database()->add_repository(1, repo);
{
- std::tr1::shared_ptr<const PackageID> id1(*env.package_database()->query(query::Matches(parse_user_package_dep_spec(
- "=cat-one/visible-1", UserPackageDepSpecOptions())), qo_require_exactly_one)->begin());
+ std::tr1::shared_ptr<const PackageID> id1(*env[selection::RequireExactlyOne(generator::Matches(parse_user_package_dep_spec(
+ "=cat-one/visible-1", UserPackageDepSpecOptions())))]->begin());
TestReporter r1;
TEST_CHECK(visibility_check(FSEntry("/var/empty"), r1, &env, repo, id1, "visibility"));
TEST_CHECK_EQUAL(r1.count, 0u);
}
{
- std::tr1::shared_ptr<const PackageID> id2(*env.package_database()->query(query::Matches(parse_user_package_dep_spec(
- "=cat-one/visible-2", UserPackageDepSpecOptions())), qo_require_exactly_one)->begin());
+ std::tr1::shared_ptr<const PackageID> id2(*env[selection::RequireExactlyOne(generator::Matches(parse_user_package_dep_spec(
+ "=cat-one/visible-2", UserPackageDepSpecOptions())))]->begin());
TestReporter r2;
TEST_CHECK(visibility_check(FSEntry("/var/empty"), r2, &env, repo, id2, "visibility"));
TEST_CHECK_EQUAL(r2.count, 0u);
}
{
- std::tr1::shared_ptr<const PackageID> id3(*env.package_database()->query(query::Matches(parse_user_package_dep_spec(
- "=cat-one/masked-1", UserPackageDepSpecOptions())), qo_require_exactly_one)->begin());
+ std::tr1::shared_ptr<const PackageID> id3(*env[selection::RequireExactlyOne(generator::Matches(parse_user_package_dep_spec(
+ "=cat-one/masked-1", UserPackageDepSpecOptions())))]->begin());
TestReporter r3;
TEST_CHECK(visibility_check(FSEntry("/var/empty"), r3, &env, repo, id3, "visibility"));
TEST_CHECK_EQUAL(r3.count, 0u);
}
{
- std::tr1::shared_ptr<const PackageID> id4(*env.package_database()->query(query::Matches(parse_user_package_dep_spec(
- "=cat-one/needs-masked-1", UserPackageDepSpecOptions())), qo_require_exactly_one)->begin());
+ std::tr1::shared_ptr<const PackageID> id4(*env[selection::RequireExactlyOne(generator::Matches(parse_user_package_dep_spec(
+ "=cat-one/needs-masked-1", UserPackageDepSpecOptions())))]->begin());
TestReporter r4;
TEST_CHECK(visibility_check(FSEntry("/var/empty"), r4, &env, repo, id4, "visibility"));
TestMessageSuffix s4(r4.messages);
@@ -114,8 +117,8 @@ namespace test_cases
}
{
- std::tr1::shared_ptr<const PackageID> id5(*env.package_database()->query(query::Matches(parse_user_package_dep_spec(
- "=cat-one/use-masking-1", UserPackageDepSpecOptions())), qo_require_exactly_one)->begin());
+ std::tr1::shared_ptr<const PackageID> id5(*env[selection::RequireExactlyOne(generator::Matches(parse_user_package_dep_spec(
+ "=cat-one/use-masking-1", UserPackageDepSpecOptions())))]->begin());
TestReporter r5;
TEST_CHECK(visibility_check(FSEntry("/var/empty"), r5, &env, repo, id5, "visibility"));
TestMessageSuffix s5(r5.messages);
@@ -123,8 +126,8 @@ namespace test_cases
}
{
- std::tr1::shared_ptr<const PackageID> id6(*env.package_database()->query(query::Matches(parse_user_package_dep_spec(
- "=cat-one/use-masking-2", UserPackageDepSpecOptions())), qo_require_exactly_one)->begin());
+ std::tr1::shared_ptr<const PackageID> id6(*env[selection::RequireExactlyOne(generator::Matches(parse_user_package_dep_spec(
+ "=cat-one/use-masking-2", UserPackageDepSpecOptions())))]->begin());
TestReporter r6;
TEST_CHECK(visibility_check(FSEntry("/var/empty"), r6, &env, repo, id6, "visibility"));
TestMessageSuffix s6(r6.messages);
@@ -132,32 +135,32 @@ namespace test_cases
}
{
- std::tr1::shared_ptr<const PackageID> id7(*env.package_database()->query(query::Matches(parse_user_package_dep_spec(
- "=cat-one/use-masking-3", UserPackageDepSpecOptions())), qo_require_exactly_one)->begin());
+ std::tr1::shared_ptr<const PackageID> id7(*env[selection::RequireExactlyOne(generator::Matches(parse_user_package_dep_spec(
+ "=cat-one/use-masking-3", UserPackageDepSpecOptions())))]->begin());
TestReporter r7;
TEST_CHECK(visibility_check(FSEntry("/var/empty"), r7, &env, repo, id7, "visibility"));
TEST_CHECK_EQUAL(r7.count, 0u);
}
{
- std::tr1::shared_ptr<const PackageID> id8(*env.package_database()->query(query::Matches(parse_user_package_dep_spec(
- "=cat-one/use-masking-4", UserPackageDepSpecOptions())), qo_require_exactly_one)->begin());
+ std::tr1::shared_ptr<const PackageID> id8(*env[selection::RequireExactlyOne(generator::Matches(parse_user_package_dep_spec(
+ "=cat-one/use-masking-4", UserPackageDepSpecOptions())))]->begin());
TestReporter r8;
TEST_CHECK(visibility_check(FSEntry("/var/empty"), r8, &env, repo, id8, "visibility"));
TEST_CHECK_EQUAL(r8.count, 0u);
}
{
- std::tr1::shared_ptr<const PackageID> id9(*env.package_database()->query(query::Matches(parse_user_package_dep_spec(
- "=cat-one/use-masking-5", UserPackageDepSpecOptions())), qo_require_exactly_one)->begin());
+ std::tr1::shared_ptr<const PackageID> id9(*env[selection::RequireExactlyOne(generator::Matches(parse_user_package_dep_spec(
+ "=cat-one/use-masking-5", UserPackageDepSpecOptions())))]->begin());
TestReporter r9;
TEST_CHECK(visibility_check(FSEntry("/var/empty"), r9, &env, repo, id9, "visibility"));
TEST_CHECK_EQUAL(r9.count, 0u);
}
{
- std::tr1::shared_ptr<const PackageID> id10(*env.package_database()->query(query::Matches(parse_user_package_dep_spec(
- "=cat-one/use-masking-6", UserPackageDepSpecOptions())), qo_require_exactly_one)->begin());
+ std::tr1::shared_ptr<const PackageID> id10(*env[selection::RequireExactlyOne(generator::Matches(parse_user_package_dep_spec(
+ "=cat-one/use-masking-6", UserPackageDepSpecOptions())))]->begin());
TestReporter r10;
TEST_CHECK(visibility_check(FSEntry("/var/empty"), r10, &env, repo, id10, "visibility"));
TEST_CHECK_EQUAL(r10.count, 0u);
diff --git a/paludis/repositories/e/vdb_repository_TEST.cc b/paludis/repositories/e/vdb_repository_TEST.cc
index 5c2f2b7ec..9f3f580b4 100644
--- a/paludis/repositories/e/vdb_repository_TEST.cc
+++ b/paludis/repositories/e/vdb_repository_TEST.cc
@@ -28,7 +28,10 @@
#include <paludis/util/visitor-impl.hh>
#include <paludis/util/options.hh>
#include <paludis/util/dir_iterator.hh>
-#include <paludis/query.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/selection.hh>
#include <paludis/dep_spec.hh>
#include <paludis/user_dep_spec.hh>
#include <paludis/stringify_formatter.hh>
@@ -125,9 +128,8 @@ namespace test_cases
std::tr1::shared_ptr<Repository> repo(VDBRepository::make_vdb_repository(&env, keys));
env.package_database()->add_repository(1, repo);
- std::tr1::shared_ptr<const PackageID> e1(*env.package_database()->query(query::Matches(
- PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1", UserPackageDepSpecOptions()))),
- qo_require_exactly_one)->begin());
+ std::tr1::shared_ptr<const PackageID> e1(*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1", UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK((*repo)[k::use_interface()]->query_use(UseFlagName("flag1"), *e1) == use_enabled);
TEST_CHECK((*repo)[k::use_interface()]->query_use(UseFlagName("flag2"), *e1) == use_enabled);
@@ -207,9 +209,8 @@ namespace test_cases
&env, keys));
env.package_database()->add_repository(1, repo);
- std::tr1::shared_ptr<const PackageID> e1(*env.package_database()->query(query::Matches(
- PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1", UserPackageDepSpecOptions()))),
- qo_require_exactly_one)->begin());
+ std::tr1::shared_ptr<const PackageID> e1(*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1", UserPackageDepSpecOptions()))))]->begin());
ContentsGatherer gatherer;
std::for_each(indirect_iterator(e1->contents_key()->value()->begin()),
indirect_iterator(e1->contents_key()->value()->end()),
@@ -262,10 +263,9 @@ namespace test_cases
&env, keys));
env.package_database()->add_repository(1, repo);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->
- query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("category/package",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
StringifyFormatter ff;
@@ -351,9 +351,9 @@ namespace test_cases
{
TestMessageSuffix suffix("install", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/target-" + eapi + "::srcrepo",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(id);
id->perform_action(install_action);
}
@@ -362,9 +362,9 @@ namespace test_cases
{
TestMessageSuffix suffix("reinstall", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/target-" + eapi + "::srcrepo",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(id);
id->perform_action(install_action);
}
@@ -373,27 +373,27 @@ namespace test_cases
{
TestMessageSuffix suffix("info", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/target-" + eapi + "::installed",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(id);
id->perform_action(info_action);
}
{
TestMessageSuffix suffix("config", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/target-" + eapi + "::installed",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(id);
id->perform_action(config_action);
}
{
TestMessageSuffix suffix("uninstall", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/target-" + eapi + "::installed",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(id);
id->perform_action(uninstall_action);
}
@@ -466,9 +466,9 @@ namespace test_cases
{
TestMessageSuffix suffix("vars", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
- PackageDepSpec(parse_user_package_dep_spec("=cat/vars-" + eapi + "::srcrepo",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat/target-" + eapi + "::srcrepo",
+ UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(id);
id->perform_action(install_action);
}
@@ -477,9 +477,9 @@ namespace test_cases
{
TestMessageSuffix suffix("reinstall", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
- PackageDepSpec(parse_user_package_dep_spec("=cat/vars-" + eapi + "::srcrepo",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat/target-" + eapi + "::srcrepo",
+ UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(id);
id->perform_action(install_action);
}
@@ -488,27 +488,27 @@ namespace test_cases
{
TestMessageSuffix suffix("info", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
- PackageDepSpec(parse_user_package_dep_spec("=cat/vars-" + eapi + "::installed",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat/target-" + eapi + "::installed",
+ UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(id);
id->perform_action(info_action);
}
{
TestMessageSuffix suffix("config", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
- PackageDepSpec(parse_user_package_dep_spec("=cat/vars-" + eapi + "::installed",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat/target-" + eapi + "::installed",
+ UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(id);
id->perform_action(config_action);
}
{
TestMessageSuffix suffix("uninstall", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
- PackageDepSpec(parse_user_package_dep_spec("=cat/vars-" + eapi + "::installed",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat/target-" + eapi + "::installed",
+ UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(id);
id->perform_action(uninstall_action);
}
@@ -584,9 +584,9 @@ namespace test_cases
{
TestMessageSuffix suffix("install", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg1-1::namesincrtest_src",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
id->perform_action(install_action);
vdb_repo->invalidate();
@@ -599,9 +599,9 @@ namespace test_cases
{
TestMessageSuffix suffix("reinstall", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg1-1::namesincrtest_src",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
id->perform_action(install_action);
vdb_repo->invalidate();
@@ -614,12 +614,12 @@ namespace test_cases
{
TestMessageSuffix suffix("upgrade", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg1-1.1::namesincrtest_src",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
- const std::tr1::shared_ptr<const PackageID> inst_id(*env.package_database()->query(query::Matches(
+ UserPackageDepSpecOptions()))))]->begin());
+ const std::tr1::shared_ptr<const PackageID> inst_id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg1-1::installed",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
id->perform_action(install_action);
vdb_repo->invalidate();
inst_id->perform_action(uninstall_action);
@@ -634,12 +634,12 @@ namespace test_cases
{
TestMessageSuffix suffix("downgrade", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg1-1::namesincrtest_src",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
- const std::tr1::shared_ptr<const PackageID> inst_id(*env.package_database()->query(query::Matches(
+ UserPackageDepSpecOptions()))))]->begin());
+ const std::tr1::shared_ptr<const PackageID> inst_id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg1-1.1::installed",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
id->perform_action(install_action);
vdb_repo->invalidate();
inst_id->perform_action(uninstall_action);
@@ -654,9 +654,9 @@ namespace test_cases
{
TestMessageSuffix suffix("new slot", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg1-2::namesincrtest_src",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
id->perform_action(install_action);
vdb_repo->invalidate();
@@ -669,9 +669,9 @@ namespace test_cases
{
TestMessageSuffix suffix("remove other slot", true);
- const std::tr1::shared_ptr<const PackageID> inst_id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> inst_id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg1-2::installed",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
inst_id->perform_action(uninstall_action);
vdb_repo->invalidate();
@@ -684,9 +684,9 @@ namespace test_cases
{
TestMessageSuffix suffix("new package", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg2-1::namesincrtest_src",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
id->perform_action(install_action);
vdb_repo->invalidate();
@@ -701,9 +701,9 @@ namespace test_cases
{
TestMessageSuffix suffix("remove other package", true);
- const std::tr1::shared_ptr<const PackageID> inst_id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> inst_id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg2-1::installed",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
inst_id->perform_action(uninstall_action);
vdb_repo->invalidate();
@@ -716,9 +716,9 @@ namespace test_cases
{
TestMessageSuffix suffix("new category", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat2/pkg1-1::namesincrtest_src",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
id->perform_action(install_action);
vdb_repo->invalidate();
@@ -731,9 +731,9 @@ namespace test_cases
{
TestMessageSuffix suffix("remove other category", true);
- const std::tr1::shared_ptr<const PackageID> inst_id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> inst_id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat2/pkg1-1::installed",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
inst_id->perform_action(uninstall_action);
vdb_repo->invalidate();
@@ -746,9 +746,9 @@ namespace test_cases
{
TestMessageSuffix suffix("uninstall", true);
- const std::tr1::shared_ptr<const PackageID> inst_id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> inst_id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg1-1::installed",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
inst_id->perform_action(uninstall_action);
vdb_repo->invalidate();
@@ -938,9 +938,9 @@ namespace test_cases
{
TestMessageSuffix suffix("install", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg1-1::providesincrtest_src1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
id->perform_action(install_action);
vdb_repo->invalidate();
@@ -949,9 +949,9 @@ namespace test_cases
{
TestMessageSuffix suffix("reinstall", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg1-1::providesincrtest_src1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
id->perform_action(install_action);
vdb_repo->invalidate();
@@ -960,12 +960,12 @@ namespace test_cases
{
TestMessageSuffix suffix("upgrade", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg1-1.1::providesincrtest_src1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
- const std::tr1::shared_ptr<const PackageID> inst_id(*env.package_database()->query(query::Matches(
+ UserPackageDepSpecOptions()))))]->begin());
+ const std::tr1::shared_ptr<const PackageID> inst_id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg1-1::installed",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
id->perform_action(install_action);
vdb_repo->invalidate();
inst_id->perform_action(uninstall_action);
@@ -976,9 +976,9 @@ namespace test_cases
{
TestMessageSuffix suffix("reinstall equivalent", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg1-1.1::providesincrtest_src2",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
id->perform_action(install_action);
vdb_repo->invalidate();
@@ -987,12 +987,12 @@ namespace test_cases
{
TestMessageSuffix suffix("downgrade", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg1-1::providesincrtest_src1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
- const std::tr1::shared_ptr<const PackageID> inst_id(*env.package_database()->query(query::Matches(
+ UserPackageDepSpecOptions()))))]->begin());
+ const std::tr1::shared_ptr<const PackageID> inst_id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg1-1.1::installed",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
id->perform_action(install_action);
vdb_repo->invalidate();
inst_id->perform_action(uninstall_action);
@@ -1003,9 +1003,9 @@ namespace test_cases
{
TestMessageSuffix suffix("reinstall different PROVIDE", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg1-1::providesincrtest_src2",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
id->perform_action(install_action);
vdb_repo->invalidate();
@@ -1014,9 +1014,9 @@ namespace test_cases
{
TestMessageSuffix suffix("new slot", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg1-2::providesincrtest_src1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
id->perform_action(install_action);
vdb_repo->invalidate();
@@ -1025,9 +1025,9 @@ namespace test_cases
{
TestMessageSuffix suffix("remove other slot", true);
- const std::tr1::shared_ptr<const PackageID> inst_id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> inst_id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg1-2::installed",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
inst_id->perform_action(uninstall_action);
vdb_repo->invalidate();
@@ -1036,9 +1036,9 @@ namespace test_cases
{
TestMessageSuffix suffix("new package", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg2-1::providesincrtest_src1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
id->perform_action(install_action);
vdb_repo->invalidate();
@@ -1047,9 +1047,9 @@ namespace test_cases
{
TestMessageSuffix suffix("remove other package", true);
- const std::tr1::shared_ptr<const PackageID> inst_id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> inst_id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg2-1::installed",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
inst_id->perform_action(uninstall_action);
vdb_repo->invalidate();
@@ -1058,9 +1058,9 @@ namespace test_cases
{
TestMessageSuffix suffix("uninstall", true);
- const std::tr1::shared_ptr<const PackageID> inst_id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> inst_id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat1/pkg1-1::installed",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
inst_id->perform_action(uninstall_action);
vdb_repo->invalidate();
@@ -1147,9 +1147,9 @@ namespace test_cases
{
TestMessageSuffix suffix("install", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/pkg-1::reinstalltest_src1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
id->perform_action(install_action);
vdb_repo->invalidate();
@@ -1159,9 +1159,9 @@ namespace test_cases
{
TestMessageSuffix suffix("reinstall", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/pkg-1::reinstalltest_src1",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
id->perform_action(install_action);
vdb_repo->invalidate();
@@ -1171,9 +1171,9 @@ namespace test_cases
{
TestMessageSuffix suffix("reinstall equivalent", true);
- const std::tr1::shared_ptr<const PackageID> id(*env.package_database()->query(query::Matches(
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
PackageDepSpec(parse_user_package_dep_spec("=cat/pkg-1::reinstalltest_src2",
- UserPackageDepSpecOptions()))), qo_require_exactly_one)->last());
+ UserPackageDepSpecOptions()))))]->begin());
id->perform_action(install_action);
vdb_repo->invalidate();
diff --git a/paludis/repositories/fake/fake_package_id.hh b/paludis/repositories/fake/fake_package_id.hh
index 97c6b502d..95d513e25 100644
--- a/paludis/repositories/fake/fake_package_id.hh
+++ b/paludis/repositories/fake/fake_package_id.hh
@@ -239,12 +239,12 @@ namespace paludis
virtual const std::tr1::shared_ptr<const MetadataValueKey<bool> > transient_key() const;
const std::tr1::shared_ptr<const MetadataSpecTreeKey<LicenseSpecTree> > license_key() const;
- const std::tr1::shared_ptr<FakeMetadataKeywordSetKey> keywords_key();
- const std::tr1::shared_ptr<FakeMetadataIUseSetKey> iuse_key();
///\name Modifiable keys
///\{
+ const std::tr1::shared_ptr<FakeMetadataKeywordSetKey> keywords_key();
+ const std::tr1::shared_ptr<FakeMetadataIUseSetKey> iuse_key();
const std::tr1::shared_ptr<FakeMetadataSpecTreeKey<ProvideSpecTree> > provide_key();
const std::tr1::shared_ptr<FakeMetadataSpecTreeKey<DependencySpecTree> > build_dependencies_key();
const std::tr1::shared_ptr<FakeMetadataSpecTreeKey<DependencySpecTree> > run_dependencies_key();
diff --git a/paludis/repositories/unpackaged/dep_printer.cc b/paludis/repositories/unpackaged/dep_printer.cc
index af114bd67..70e9176ad 100644
--- a/paludis/repositories/unpackaged/dep_printer.cc
+++ b/paludis/repositories/unpackaged/dep_printer.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007 Ciaran McCreesh
+ * Copyright (c) 2007, 2008 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
@@ -20,9 +20,13 @@
#include <paludis/repositories/unpackaged/dep_printer.hh>
#include <paludis/util/visitor-impl.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
+#include <paludis/util/fs_entry.hh>
#include <paludis/environment.hh>
-#include <paludis/package_database.hh>
-#include <paludis/query.hh>
+#include <paludis/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/action.hh>
#include <sstream>
using namespace paludis;
@@ -77,11 +81,11 @@ DepPrinter::visit_leaf(const PackageDepSpec & p)
if (_imp->env)
{
- if (! _imp->env->package_database()->query(query::Matches(p) &
- query::InstalledAtRoot(_imp->env->root()), qo_whatever)->empty())
+ if (! (*_imp->env)[selection::SomeArbitraryVersion(generator::Matches(p) |
+ filter::InstalledAtRoot(_imp->env->root()))]->empty())
_imp->s << _imp->formatter.format(p, format::Installed());
- else if (! _imp->env->package_database()->query(query::Matches(p) &
- query::SupportsAction<InstallAction>() & query::NotMasked(), qo_whatever)->empty())
+ else if (! (*_imp->env)[selection::SomeArbitraryVersion(generator::Matches(p) |
+ filter::SupportsAction<InstallAction>() | filter::NotMasked())]->empty())
_imp->s << _imp->formatter.format(p, format::Installable());
else
_imp->s << _imp->formatter.format(p, format::Plain());
diff --git a/paludis/repositories/unpackaged/installed_repository_TEST.cc b/paludis/repositories/unpackaged/installed_repository_TEST.cc
index 1081c99ef..b4171bc6d 100644
--- a/paludis/repositories/unpackaged/installed_repository_TEST.cc
+++ b/paludis/repositories/unpackaged/installed_repository_TEST.cc
@@ -21,11 +21,14 @@
#include <paludis/repositories/unpackaged/installed_repository.hh>
#include <paludis/environments/test/test_environment.hh>
#include <paludis/package_database.hh>
-#include <paludis/query.hh>
#include <paludis/package_id.hh>
#include <paludis/action.hh>
#include <paludis/user_dep_spec.hh>
#include <paludis/metadata_key.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/selection.hh>
#include <paludis/util/sequence.hh>
#include <paludis/util/join.hh>
#include <paludis/util/visitor-impl.hh>
@@ -97,7 +100,7 @@ namespace test_cases
env.package_database()->add_repository(1, repo);
const std::tr1::shared_ptr<const PackageIDSequence> ids(
- env.package_database()->query(query::All(), qo_order_by_version));
+ env[selection::AllVersionsSorted(generator::All())]);
TEST_CHECK_EQUAL(join(indirect_iterator(ids->begin()), indirect_iterator(ids->end()), " "),
"cat-one/foo-1:0::installed-unpackaged cat-one/foo-2:1::installed-unpackaged");
}
@@ -119,9 +122,8 @@ namespace test_cases
));
env.package_database()->add_repository(1, repo);
- const std::tr1::shared_ptr<const PackageID> id1(
- *env.package_database()->query(query::Matches(parse_user_package_dep_spec("cat-one/foo:0", UserPackageDepSpecOptions())),
- qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> id1(*env[selection::RequireExactlyOne(
+ generator::Matches(parse_user_package_dep_spec("cat-one/foo:0", UserPackageDepSpecOptions())))]->begin());
TEST_CHECK_EQUAL(id1->version(), VersionSpec("1"));
TEST_CHECK_EQUAL(id1->slot(), SlotName("0"));
@@ -137,9 +139,8 @@ namespace test_cases
indirect_iterator(id1->contents_key()->value()->end()), accept_visitor(d1));
TEST_CHECK_EQUAL(d1.s.str(), "dir</fnord>");
- const std::tr1::shared_ptr<const PackageID> id2(
- *env.package_database()->query(query::Matches(parse_user_package_dep_spec("cat-one/foo:1", UserPackageDepSpecOptions())),
- qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> id2(*env[selection::RequireExactlyOne(
+ generator::Matches(parse_user_package_dep_spec("cat-one/foo:1", UserPackageDepSpecOptions())))]->begin());
TEST_CHECK_EQUAL(id2->version(), VersionSpec("2"));
TEST_CHECK_EQUAL(id2->slot(), SlotName("1"));
@@ -173,15 +174,13 @@ namespace test_cases
));
env.package_database()->add_repository(1, repo);
- const std::tr1::shared_ptr<const PackageID> id1(
- *env.package_database()->query(query::Matches(parse_user_package_dep_spec("cat-one/foo:0", UserPackageDepSpecOptions())),
- qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> id1(*env[selection::RequireExactlyOne(
+ generator::Matches(parse_user_package_dep_spec("cat-one/foo:0", UserPackageDepSpecOptions())))]->begin());
TEST_CHECK(! id1->masked());
- const std::tr1::shared_ptr<const PackageID> id2(
- *env.package_database()->query(query::Matches(parse_user_package_dep_spec("cat-one/foo:1", UserPackageDepSpecOptions())),
- qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> id2(*env[selection::RequireExactlyOne(
+ generator::Matches(parse_user_package_dep_spec("cat-one/foo:1", UserPackageDepSpecOptions())))]->begin());
TEST_CHECK(! id2->masked());
}
@@ -210,9 +209,8 @@ namespace test_cases
TEST_CHECK(repo->some_ids_might_support_action(SupportsActionTest<UninstallAction>()));
TEST_CHECK(repo->some_ids_might_support_action(SupportsActionTest<InstalledAction>()));
- const std::tr1::shared_ptr<const PackageID> id1(
- *env.package_database()->query(query::Matches(parse_user_package_dep_spec("cat-one/foo:1", UserPackageDepSpecOptions())),
- qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> id1(*env[selection::RequireExactlyOne(
+ generator::Matches(parse_user_package_dep_spec("cat-one/foo:1", UserPackageDepSpecOptions())))]->begin());
TEST_CHECK(! id1->supports_action(SupportsActionTest<InstallAction>()));
TEST_CHECK(! id1->supports_action(SupportsActionTest<ConfigAction>()));
@@ -240,8 +238,7 @@ namespace test_cases
));
env.package_database()->add_repository(1, repo);
- const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(
- env.package_database()->query(query::All(), qo_order_by_version));
+ const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(env[selection::AllVersionsSorted(generator::All())]);
TEST_CHECK_EQUAL(join(indirect_iterator(pre_ids->begin()), indirect_iterator(pre_ids->end()), " "),
"cat-one/foo-1.2.3:fred::installed-unpackaged");
@@ -251,8 +248,7 @@ namespace test_cases
TEST_CHECK(FSEntry("installed_repository_TEST_dir/repo2/indices/categories/cat-one/foo").is_symbolic_link());
TEST_CHECK(FSEntry("installed_repository_TEST_dir/repo2/indices/packages/foo/cat-one").is_symbolic_link());
- const std::tr1::shared_ptr<const PackageID> id(
- *env.package_database()->query(query::All(), qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::All())]->begin());
UninstallAction action(UninstallActionOptions::named_create()
(k::no_config_protect(), false)
@@ -267,8 +263,7 @@ namespace test_cases
repo->invalidate();
- const std::tr1::shared_ptr<const PackageIDSequence> post_ids(
- env.package_database()->query(query::All(), qo_order_by_version));
+ const std::tr1::shared_ptr<const PackageIDSequence> post_ids(env[selection::AllVersionsSorted(generator::All())]);
TEST_CHECK_EQUAL(join(indirect_iterator(post_ids->begin()), indirect_iterator(post_ids->end()), " "), "");
}
@@ -295,17 +290,15 @@ namespace test_cases
));
env.package_database()->add_repository(1, repo);
- const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(
- env.package_database()->query(query::All(), qo_order_by_version));
+ const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(env[selection::AllVersionsSorted(generator::All())]);
TEST_CHECK_EQUAL(join(indirect_iterator(pre_ids->begin()), indirect_iterator(pre_ids->end()), " "),
"cat-one/foo-1.2.3:fred::installed-unpackaged cat-one/foo-3.2.1:barney::installed-unpackaged");
TEST_CHECK(FSEntry("installed_repository_TEST_dir/repo3/indices/categories/cat-one/foo").is_symbolic_link());
TEST_CHECK(FSEntry("installed_repository_TEST_dir/repo3/indices/packages/foo/cat-one").is_symbolic_link());
- const std::tr1::shared_ptr<const PackageID> id(
- *env.package_database()->query(query::Matches(parse_user_package_dep_spec("cat-one/foo:fred", UserPackageDepSpecOptions())),
- qo_require_exactly_one)->begin());
+ const std::tr1::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(
+ generator::Matches(parse_user_package_dep_spec("cat-one/foo:fred", UserPackageDepSpecOptions())))]->begin());
UninstallAction action(UninstallActionOptions::named_create()
(k::no_config_protect(), false)
@@ -317,8 +310,7 @@ namespace test_cases
repo->invalidate();
- const std::tr1::shared_ptr<const PackageIDSequence> post_ids(
- env.package_database()->query(query::All(), qo_order_by_version));
+ const std::tr1::shared_ptr<const PackageIDSequence> post_ids(env[selection::AllVersionsSorted(generator::All())]);
TEST_CHECK_EQUAL(join(indirect_iterator(post_ids->begin()), indirect_iterator(post_ids->end()), " "),
"cat-one/foo-3.2.1:barney::installed-unpackaged");
}
@@ -348,8 +340,7 @@ namespace test_cases
));
env.package_database()->add_repository(1, repo);
- const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(
- env.package_database()->query(query::All(), qo_order_by_version));
+ const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(env[selection::AllVersionsSorted(generator::All())]);
TEST_CHECK_EQUAL(join(indirect_iterator(pre_ids->begin()), indirect_iterator(pre_ids->end()), " "), "");
TEST_CHECK(! FSEntry("installed_repository_TEST_dir/root4/dir").exists());
@@ -384,8 +375,8 @@ namespace test_cases
env.package_database()->add_repository(1, source_repo);
{
- const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(
- env.package_database()->query(query::Repository(RepositoryName("installed-unpackaged")), qo_order_by_version));
+ const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(env[selection::AllVersionsSorted(
+ generator::Repository(RepositoryName("installed-unpackaged")))]);
TEST_CHECK_EQUAL(join(indirect_iterator(pre_ids->begin()), indirect_iterator(pre_ids->end()), " "), "");
}
@@ -396,16 +387,15 @@ namespace test_cases
(k::no_config_protect(), false)
(k::checks(), iaco_default)
(k::debug_build(), iado_none));
- (*env.package_database()->query(query::Repository(RepositoryName("unpackaged")),
- qo_require_exactly_one)->begin())->perform_action(action);
+ (*env[selection::RequireExactlyOne(generator::Repository(RepositoryName("unpackaged")))]->begin())->perform_action(action);
TEST_CHECK(FSEntry("installed_repository_TEST_dir/root4/dir").is_directory());
TEST_CHECK(FSEntry("installed_repository_TEST_dir/root4/dir/4a").is_regular_file());
repo->invalidate();
{
- const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(
- env.package_database()->query(query::Repository(RepositoryName("installed-unpackaged")), qo_order_by_version));
+ const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(env[selection::AllVersionsSorted(
+ generator::Repository(RepositoryName("installed-unpackaged")))]);
TEST_CHECK_EQUAL(join(indirect_iterator(pre_ids->begin()), indirect_iterator(pre_ids->end()), " "),
"cat/pkg4a-1.0:foo::installed-unpackaged");
}
@@ -440,8 +430,8 @@ namespace test_cases
env.package_database()->add_repository(1, source_repo);
{
- const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(
- env.package_database()->query(query::Repository(RepositoryName("installed-unpackaged")), qo_order_by_version));
+ const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(env[selection::AllVersionsSorted(
+ generator::Repository(RepositoryName("installed-unpackaged")))]);
TEST_CHECK_EQUAL(join(indirect_iterator(pre_ids->begin()), indirect_iterator(pre_ids->end()), " "),
"cat/pkg4a-1.0:foo::installed-unpackaged");
}
@@ -451,8 +441,7 @@ namespace test_cases
(k::no_config_protect(), false)
(k::checks(), iaco_default)
(k::debug_build(), iado_none));
- (*env.package_database()->query(query::Repository(RepositoryName("unpackaged")),
- qo_require_exactly_one)->begin())->perform_action(action);
+ (*env[selection::RequireExactlyOne(generator::Repository(RepositoryName("unpackaged")))]->begin())->perform_action(action);
TEST_CHECK(FSEntry("installed_repository_TEST_dir/root4/dir").is_directory());
TEST_CHECK(FSEntry("installed_repository_TEST_dir/root4/dir/4a").is_regular_file());
@@ -462,8 +451,8 @@ namespace test_cases
repo->invalidate();
{
- const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(
- env.package_database()->query(query::Repository(RepositoryName("installed-unpackaged")), qo_order_by_version));
+ const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(env[selection::AllVersionsSorted(
+ generator::Repository(RepositoryName("installed-unpackaged")))]);
TEST_CHECK_EQUAL(join(indirect_iterator(pre_ids->begin()), indirect_iterator(pre_ids->end()), " "),
"cat/pkg4a-1.0:foo::installed-unpackaged cat/pkg4b-1.0:foo::installed-unpackaged");
}
@@ -498,8 +487,8 @@ namespace test_cases
env.package_database()->add_repository(1, source_repo);
{
- const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(
- env.package_database()->query(query::Repository(RepositoryName("installed-unpackaged")), qo_order_by_version));
+ const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(env[selection::AllVersionsSorted(
+ generator::Repository(RepositoryName("installed-unpackaged")))]);
TEST_CHECK_EQUAL(join(indirect_iterator(pre_ids->begin()), indirect_iterator(pre_ids->end()), " "),
"cat/pkg4a-1.0:foo::installed-unpackaged cat/pkg4b-1.0:foo::installed-unpackaged");
}
@@ -509,8 +498,7 @@ namespace test_cases
(k::no_config_protect(), false)
(k::checks(), iaco_default)
(k::debug_build(), iado_none));
- (*env.package_database()->query(query::Repository(RepositoryName("unpackaged")),
- qo_require_exactly_one)->begin())->perform_action(action);
+ (*env[selection::RequireExactlyOne(generator::Repository(RepositoryName("unpackaged")))]->begin())->perform_action(action);
TEST_CHECK(FSEntry("installed_repository_TEST_dir/root4/dir").is_directory());
TEST_CHECK(FSEntry("installed_repository_TEST_dir/root4/dir/4a").is_regular_file());
@@ -520,8 +508,8 @@ namespace test_cases
repo->invalidate();
{
- const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(
- env.package_database()->query(query::Repository(RepositoryName("installed-unpackaged")), qo_order_by_version));
+ const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(env[selection::AllVersionsSorted(
+ generator::Repository(RepositoryName("installed-unpackaged")))]);
TEST_CHECK_EQUAL(join(indirect_iterator(pre_ids->begin()), indirect_iterator(pre_ids->end()), " "),
"cat/pkg4a-1.0:foo::installed-unpackaged cat/pkg4b-1.0:foo::installed-unpackaged");
}
@@ -541,16 +529,16 @@ namespace test_cases
env.package_database()->add_repository(0, repo);
{
- const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(
- env.package_database()->query(query::Repository(RepositoryName("installed-unpackaged")), qo_order_by_version));
+ const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(env[selection::AllVersionsSorted(
+ generator::Repository(RepositoryName("installed-unpackaged")))]);
TEST_CHECK_EQUAL(join(indirect_iterator(pre_ids->begin()), indirect_iterator(pre_ids->end()), " "),
"cat/pkg4a-1.0:foo::installed-unpackaged cat/pkg4b-1.0:foo::installed-unpackaged");
}
UninstallAction action(UninstallActionOptions::named_create()
(k::no_config_protect(), false));
- (*env.package_database()->query(query::Matches(parse_user_package_dep_spec("cat/pkg4a", UserPackageDepSpecOptions())),
- qo_require_exactly_one)->begin())->perform_action(action);
+ (*env[selection::RequireExactlyOne(generator::Matches(
+ parse_user_package_dep_spec("cat/pkg4a", UserPackageDepSpecOptions())))]->begin())->perform_action(action);
TEST_CHECK(FSEntry("installed_repository_TEST_dir/root4/dir").is_directory());
TEST_CHECK(! FSEntry("installed_repository_TEST_dir/root4/dir/4a").is_regular_file());
@@ -561,7 +549,7 @@ namespace test_cases
repo->invalidate();
{
const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(
- env.package_database()->query(query::Repository(RepositoryName("installed-unpackaged")), qo_order_by_version));
+ env[selection::RequireExactlyOne(generator::Repository(RepositoryName("installed-unpackaged")))]);
TEST_CHECK_EQUAL(join(indirect_iterator(pre_ids->begin()), indirect_iterator(pre_ids->end()), " "),
"cat/pkg4b-1.0:foo::installed-unpackaged");
}
@@ -581,23 +569,23 @@ namespace test_cases
env.package_database()->add_repository(0, repo);
{
- const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(
- env.package_database()->query(query::Repository(RepositoryName("installed-unpackaged")), qo_order_by_version));
+ const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(env[selection::AllVersionsSorted(
+ generator::Repository(RepositoryName("installed-unpackaged")))]);
TEST_CHECK_EQUAL(join(indirect_iterator(pre_ids->begin()), indirect_iterator(pre_ids->end()), " "),
"cat/pkg4b-1.0:foo::installed-unpackaged");
}
UninstallAction action(UninstallActionOptions::named_create()
(k::no_config_protect(), false));
- (*env.package_database()->query(query::Matches(parse_user_package_dep_spec("cat/pkg4b", UserPackageDepSpecOptions())),
- qo_require_exactly_one)->begin())->perform_action(action);
+ (*env[selection::RequireExactlyOne(generator::Matches(
+ parse_user_package_dep_spec("cat/pkg4b", UserPackageDepSpecOptions())))]->begin())->perform_action(action);
TEST_CHECK(! FSEntry("installed_repository_TEST_dir/root4/dir").is_directory());
repo->invalidate();
{
- const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(
- env.package_database()->query(query::Repository(RepositoryName("installed-unpackaged")), qo_order_by_version));
+ const std::tr1::shared_ptr<const PackageIDSequence> pre_ids(env[selection::AllVersionsSorted(
+ generator::Repository(RepositoryName("installed-unpackaged")))]);
TEST_CHECK_EQUAL(join(indirect_iterator(pre_ids->begin()), indirect_iterator(pre_ids->end()), " "),
"");
}
diff --git a/paludis/repositories/unpackaged/unpackaged_repository_TEST.cc b/paludis/repositories/unpackaged/unpackaged_repository_TEST.cc
index 3a66f7be6..bbff7506a 100644
--- a/paludis/repositories/unpackaged/unpackaged_repository_TEST.cc
+++ b/paludis/repositories/unpackaged/unpackaged_repository_TEST.cc
@@ -22,10 +22,13 @@
#include <paludis/environments/test/test_environment.hh>
#include <paludis/package_database.hh>
#include <paludis/util/visitor-impl.hh>
-#include <paludis/query.hh>
#include <paludis/package_id.hh>
#include <paludis/action.hh>
#include <paludis/metadata_key.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/selection.hh>
#include <paludis/util/sequence.hh>
#include <paludis/util/join.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
@@ -62,7 +65,7 @@ namespace test_cases
env.package_database()->add_repository(1, repo);
const std::tr1::shared_ptr<const PackageIDSequence> ids(
- env.package_database()->query(query::All(), qo_order_by_version));
+ env[selection::AllVersionsSorted(generator::All())]);
TEST_CHECK_EQUAL(join(indirect_iterator(ids->begin()), indirect_iterator(ids->end()), " "),
"cat/pkg-1.0:foo::unpackaged");
}
@@ -91,7 +94,7 @@ namespace test_cases
env.package_database()->add_repository(1, repo);
const std::tr1::shared_ptr<const PackageID> id(
- *env.package_database()->query(query::All(), qo_require_exactly_one)->begin());
+ *env[selection::RequireExactlyOne(generator::All())]->begin());
TEST_CHECK_EQUAL(id->version(), VersionSpec("1.0"));
TEST_CHECK_EQUAL(id->slot(), SlotName("foo"));
@@ -125,7 +128,7 @@ namespace test_cases
env.package_database()->add_repository(1, repo);
const std::tr1::shared_ptr<const PackageID> id(
- *env.package_database()->query(query::All(), qo_require_exactly_one)->begin());
+ *env[selection::RequireExactlyOne(generator::All())]->begin());
TEST_CHECK(! id->masked());
}
@@ -161,7 +164,7 @@ namespace test_cases
TEST_CHECK(! repo->some_ids_might_support_action(SupportsActionTest<InstalledAction>()));
const std::tr1::shared_ptr<const PackageID> id(
- *env.package_database()->query(query::All(), qo_require_exactly_one)->begin());
+ *env[selection::RequireExactlyOne(generator::All())]->begin());
TEST_CHECK(id->supports_action(SupportsActionTest<InstallAction>()));
TEST_CHECK(! id->supports_action(SupportsActionTest<ConfigAction>()));
@@ -207,7 +210,7 @@ namespace test_cases
TEST_CHECK(! FSEntry("unpackaged_repository_TEST_dir/root/first").is_regular_file());
const std::tr1::shared_ptr<const PackageID> id(
- *env.package_database()->query(query::All(), qo_require_exactly_one)->begin());
+ *env[selection::RequireExactlyOne(generator::All())]->begin());
InstallAction action(InstallActionOptions::named_create()
(k::no_config_protect(), false)
@@ -261,7 +264,7 @@ namespace test_cases
TEST_CHECK(! FSEntry("unpackaged_repository_TEST_dir/under_root/magic/pixie/first").is_regular_file());
const std::tr1::shared_ptr<const PackageID> id(
- *env.package_database()->query(query::All(), qo_require_exactly_one)->begin());
+ *env[selection::RequireExactlyOne(generator::All())]->begin());
InstallAction action(InstallActionOptions::named_create()
(k::no_config_protect(), false)
diff --git a/paludis/repositories/virtuals/package_id.cc b/paludis/repositories/virtuals/package_id.cc
index f4fe4bb44..bb598ad59 100644
--- a/paludis/repositories/virtuals/package_id.cc
+++ b/paludis/repositories/virtuals/package_id.cc
@@ -36,9 +36,12 @@
#include <paludis/action.hh>
#include <paludis/mask.hh>
#include <paludis/package_database.hh>
-#include <paludis/query.hh>
#include <paludis/literal_metadata_key.hh>
#include <paludis/user_dep_spec.hh>
+#include <paludis/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
using namespace paludis;
using namespace paludis::virtuals;
@@ -100,11 +103,11 @@ VirtualsDepKey::pretty_print(const DependencySpecTree::ItemFormatter & f) const
{
if (_imp->env)
{
- if (! _imp->env->package_database()->query(query::Matches(*_imp->value->item()) &
- query::InstalledAtRoot(_imp->env->root()), qo_whatever)->empty())
+ if (! (*_imp->env)[selection::SomeArbitraryVersion(generator::Matches(*_imp->value->item()) |
+ filter::InstalledAtRoot(_imp->env->root()))]->empty())
return f.format(*_imp->value->item(), format::Installed());
- else if (! _imp->env->package_database()->query(query::Matches(*_imp->value->item()) &
- query::SupportsAction<InstallAction>() & query::NotMasked(), qo_whatever)->empty())
+ else if (! (*_imp->env)[selection::SomeArbitraryVersion(generator::Matches(*_imp->value->item()) |
+ filter::SupportsAction<InstallAction>() | filter::NotMasked())]->empty())
return f.format(*_imp->value->item(), format::Installable());
else
return f.format(*_imp->value->item(), format::Plain());
@@ -116,19 +119,7 @@ VirtualsDepKey::pretty_print(const DependencySpecTree::ItemFormatter & f) const
std::string
VirtualsDepKey::pretty_print_flat(const DependencySpecTree::ItemFormatter & f) const
{
- if (_imp->env)
- {
- if (! _imp->env->package_database()->query(query::Matches(*_imp->value->item()) &
- query::InstalledAtRoot(_imp->env->root()), qo_whatever)->empty())
- return f.format(*_imp->value->item(), format::Installed());
- else if (! _imp->env->package_database()->query(query::Matches(*_imp->value->item()) &
- query::SupportsAction<InstallAction>() & query::NotMasked(), qo_whatever)->empty())
- return f.format(*_imp->value->item(), format::Installable());
- else
- return f.format(*_imp->value->item(), format::Plain());
- }
- else
- return f.format(*_imp->value->item(), format::Plain());
+ return pretty_print(f);
}
const std::tr1::shared_ptr<const DependencyLabelSequence>
diff --git a/paludis/repositories/virtuals/virtuals_repository.cc b/paludis/repositories/virtuals/virtuals_repository.cc
index 3fb06fc35..112db8868 100644
--- a/paludis/repositories/virtuals/virtuals_repository.cc
+++ b/paludis/repositories/virtuals/virtuals_repository.cc
@@ -23,9 +23,12 @@
#include <paludis/environment.hh>
#include <paludis/match_package.hh>
#include <paludis/package_database.hh>
-#include <paludis/query.hh>
#include <paludis/action.hh>
#include <paludis/literal_metadata_key.hh>
+#include <paludis/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
#include <paludis/util/log.hh>
#include <paludis/util/make_shared_ptr.hh>
@@ -222,10 +225,9 @@ VirtualsRepository::need_ids() const
for (std::vector<std::pair<QualifiedPackageName, std::tr1::shared_ptr<const PackageDepSpec> > >::const_iterator
v(_imp->names.begin()), v_end(_imp->names.end()) ; v != v_end ; ++v)
{
- std::tr1::shared_ptr<const PackageIDSequence> matches(_imp->env->package_database()->query(
- query::Matches(*v->second) &
- query::SupportsAction<InstallAction>(),
- qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> matches((*_imp->env)[selection::AllVersionsSorted(
+ generator::Matches(*v->second) |
+ filter::SupportsAction<InstallAction>())]);
if (matches->empty())
Log::get_instance()->message("virtuals.no_match", ll_warning, lc_context) << "No packages matching '"
diff --git a/paludis/repositories/virtuals/virtuals_repository_TEST.cc b/paludis/repositories/virtuals/virtuals_repository_TEST.cc
index 71b6f8a45..44bdff699 100644
--- a/paludis/repositories/virtuals/virtuals_repository_TEST.cc
+++ b/paludis/repositories/virtuals/virtuals_repository_TEST.cc
@@ -26,12 +26,15 @@
#include <paludis/repositories/virtuals/virtuals_repository.hh>
#include <paludis/environments/test/test_environment.hh>
#include <paludis/package_database.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/selection.hh>
#include <paludis/util/sequence.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/indirect_iterator-impl.hh>
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/util/options.hh>
-#include <paludis/query.hh>
#include <paludis/user_dep_spec.hh>
using namespace test;
@@ -67,7 +70,7 @@ namespace test_cases
TEST_CHECK(virtuals->has_category_named(CategoryNamePart("virtual")));
TEST_CHECK(virtuals->has_package_named(QualifiedPackageName("virtual/pkg")));
- std::tr1::shared_ptr<const PackageIDSequence> r(env.package_database()->query(query::All(), qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> r(env[selection::AllVersionsSorted(generator::All())]);
TEST_CHECK_STRINGIFY_EQUAL(join(indirect_iterator(r->begin()), indirect_iterator(r->end()), " | "),
"cat/pkg-1:0::repo | cat/pkg-2:0::repo | virtual/pkg-2::virtuals (virtual for cat/pkg-2:0::repo)");
}
@@ -105,7 +108,7 @@ namespace test_cases
TEST_CHECK(virtuals->has_category_named(CategoryNamePart("virtual")));
TEST_CHECK(virtuals->has_package_named(QualifiedPackageName("virtual/pkg")));
- std::tr1::shared_ptr<const PackageIDSequence> r(env.package_database()->query(query::All(), qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> r(env[selection::AllVersionsSorted(generator::All())]);
TEST_CHECK_STRINGIFY_EQUAL(join(indirect_iterator(r->begin()), indirect_iterator(r->end()), " | "),
"cat/pkg-1:0::repo1 | cat/pkg-2:0::repo1 | "
"virtual/foo-1::virtuals (virtual for cat/pkg-1:0::repo1) | "
@@ -140,7 +143,7 @@ namespace test_cases
TEST_CHECK(virtuals->has_category_named(CategoryNamePart("virtual")));
TEST_CHECK(virtuals->has_package_named(QualifiedPackageName("virtual/pkg")));
- std::tr1::shared_ptr<const PackageIDSequence> r(env.package_database()->query(query::All(), qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> r(env[selection::AllVersionsSorted(generator::All())]);
TEST_CHECK_STRINGIFY_EQUAL(join(indirect_iterator(r->begin()), indirect_iterator(r->end()), " | "),
"virtual/gkp-1:0::repo1 | virtual/pkg-1::virtuals (virtual for virtual/gkp-1:0::repo1) | "
"virtual/pkg-2:0::repo2 | virtual/pkg-2::virtuals (virtual for virtual/pkg-2:0::repo2)");
diff --git a/paludis/selection-fwd.hh b/paludis/selection-fwd.hh
new file mode 100644
index 000000000..cf4a5d72f
--- /dev/null
+++ b/paludis/selection-fwd.hh
@@ -0,0 +1,46 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_SELECTION_FWD_HH
+#define PALUDIS_GUARD_PALUDIS_SELECTION_FWD_HH 1
+
+#include <iosfwd>
+#include <paludis/util/attributes.hh>
+
+namespace paludis
+{
+ class Selection;
+
+ namespace selection
+ {
+ class SomeArbitraryVersion;
+ class BestVersionOnly;
+ class BestVersionInEachSlot;
+ class AllVersionsSorted;
+ class AllVersionsGroupedBySlot;
+ class AllVersionsUnsorted;
+ class RequireExactlyOne;
+ }
+
+ class DidNotGetExactlyOneError;
+
+ std::ostream & operator<< (std::ostream &, const Selection &) PALUDIS_VISIBLE;
+}
+
+#endif
diff --git a/paludis/selection.cc b/paludis/selection.cc
new file mode 100644
index 000000000..9f9e7cc45
--- /dev/null
+++ b/paludis/selection.cc
@@ -0,0 +1,516 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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/selection.hh>
+#include <paludis/util/private_implementation_pattern-impl.hh>
+#include <paludis/util/sequence-impl.hh>
+#include <paludis/util/set.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/wrapped_output_iterator.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/util/iterator_funcs.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <paludis/util/join.hh>
+#include <paludis/name.hh>
+#include <paludis/version_spec.hh>
+#include <paludis/package_id.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/environment.hh>
+#include <algorithm>
+#include <functional>
+#include <tr1/functional>
+#include <map>
+
+using namespace paludis;
+
+DidNotGetExactlyOneError::DidNotGetExactlyOneError(const std::string & s, const std::tr1::shared_ptr<const PackageIDSet> & r) throw () :
+ Exception("Did not get unique result for '" + stringify(s) + "' (got { " + join(indirect_iterator(r->begin()),
+ indirect_iterator(r->end()), ", ") + "})")
+{
+}
+
+namespace paludis
+{
+ class SelectionHandler :
+ private InstantiationPolicy<SelectionHandler, instantiation_method::NonCopyableTag>
+ {
+ protected:
+ const FilteredGenerator _fg;
+
+ SelectionHandler(const FilteredGenerator & g) :
+ _fg(g)
+ {
+ }
+
+ public:
+ virtual ~SelectionHandler() = 0;
+
+ virtual std::string as_string() const = 0;
+
+ virtual std::tr1::shared_ptr<PackageIDSequence> perform_select(const Environment * const) const
+ PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
+ };
+
+ template <>
+ struct Implementation<Selection>
+ {
+ std::tr1::shared_ptr<const SelectionHandler> handler;
+
+ Implementation(const std::tr1::shared_ptr<const SelectionHandler> & h) :
+ handler(h)
+ {
+ }
+ };
+}
+
+Selection::Selection(const std::tr1::shared_ptr<const SelectionHandler> & h) :
+ PrivateImplementationPattern<Selection>(new Implementation<Selection>(h))
+{
+}
+
+Selection::Selection(const Selection & other) :
+ PrivateImplementationPattern<Selection>(new Implementation<Selection>(other._imp->handler))
+{
+}
+
+Selection::~Selection()
+{
+}
+
+Selection &
+Selection::operator= (const Selection & other)
+{
+ if (this != &other)
+ _imp->handler = other._imp->handler;
+ return *this;
+}
+
+std::tr1::shared_ptr<PackageIDSequence>
+Selection::perform_select(const Environment * const env) const
+{
+ Context context("When finding " + _imp->handler->as_string() + ":");
+ return _imp->handler->perform_select(env);
+}
+
+SelectionHandler::~SelectionHandler()
+{
+}
+
+std::string
+Selection::as_string() const
+{
+ return _imp->handler->as_string();
+}
+
+namespace
+{
+ class SomeArbitraryVersionSelectionHandler :
+ public SelectionHandler
+ {
+ public:
+ SomeArbitraryVersionSelectionHandler(const FilteredGenerator & g) :
+ SelectionHandler(g)
+ {
+ }
+
+ virtual std::tr1::shared_ptr<PackageIDSequence> perform_select(const Environment * const env) const
+ {
+ std::tr1::shared_ptr<PackageIDSequence> result(new PackageIDSequence);
+
+ std::tr1::shared_ptr<const RepositoryNameSet> r(_fg.filter().repositories(env, _fg.generator().repositories(env)));
+ if (r->empty())
+ return result;
+
+ std::tr1::shared_ptr<const CategoryNamePartSet> c(_fg.filter().categories(env, r, _fg.generator().categories(env, r)));
+ if (c->empty())
+ return result;
+
+ std::tr1::shared_ptr<const QualifiedPackageNameSet> p(_fg.filter().packages(env, r, _fg.generator().packages(env, r, c)));
+ if (p->empty())
+ return result;
+
+ for (QualifiedPackageNameSet::ConstIterator q(p->begin()), q_end(p->end()) ; q != q_end ; ++q)
+ {
+ std::tr1::shared_ptr<QualifiedPackageNameSet> s(new QualifiedPackageNameSet);
+ s->insert(*q);
+ std::tr1::shared_ptr<const PackageIDSet> i(_fg.filter().ids(env, _fg.generator().ids(env, r, s)));
+ if (! i->empty())
+ {
+ result->push_back(*i->begin());
+ break;
+ }
+ }
+
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return "some arbitrary version from " + stringify(_fg);
+ }
+ };
+
+ class BestVersionOnlySelectionHandler :
+ public SelectionHandler
+ {
+ public:
+ BestVersionOnlySelectionHandler(const FilteredGenerator & g) :
+ SelectionHandler(g)
+ {
+ }
+
+ virtual std::tr1::shared_ptr<PackageIDSequence> perform_select(const Environment * const env) const
+ {
+ using namespace std::tr1::placeholders;
+
+ std::tr1::shared_ptr<PackageIDSequence> result(new PackageIDSequence);
+
+ std::tr1::shared_ptr<const RepositoryNameSet> r(_fg.filter().repositories(env, _fg.generator().repositories(env)));
+ if (r->empty())
+ return result;
+
+ std::tr1::shared_ptr<const CategoryNamePartSet> c(_fg.filter().categories(env, r, _fg.generator().categories(env, r)));
+ if (c->empty())
+ return result;
+
+ std::tr1::shared_ptr<const QualifiedPackageNameSet> p(_fg.filter().packages(env, r, _fg.generator().packages(env, r, c)));
+ if (p->empty())
+ return result;
+
+ for (QualifiedPackageNameSet::ConstIterator q(p->begin()), q_end(p->end()) ; q != q_end ; ++q)
+ {
+ std::tr1::shared_ptr<QualifiedPackageNameSet> s(new QualifiedPackageNameSet);
+ s->insert(*q);
+ std::tr1::shared_ptr<const PackageIDSet> i(_fg.filter().ids(env, _fg.generator().ids(env, r, s)));
+ if (! i->empty())
+ result->push_back(*std::max_element(i->begin(), i->end(), PackageIDComparator(env->package_database().get())));
+ }
+
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return "best version of each package from " + stringify(_fg);
+ }
+ };
+
+ class AllVersionsSortedSelectionHandler :
+ public SelectionHandler
+ {
+ public:
+ AllVersionsSortedSelectionHandler(const FilteredGenerator & g) :
+ SelectionHandler(g)
+ {
+ }
+
+ virtual std::tr1::shared_ptr<PackageIDSequence> perform_select(const Environment * const env) const
+ {
+ using namespace std::tr1::placeholders;
+
+ std::tr1::shared_ptr<PackageIDSequence> result(new PackageIDSequence);
+
+ std::tr1::shared_ptr<const RepositoryNameSet> r(_fg.filter().repositories(env, _fg.generator().repositories(env)));
+ if (r->empty())
+ return result;
+
+ std::tr1::shared_ptr<const CategoryNamePartSet> c(_fg.filter().categories(env, r, _fg.generator().categories(env, r)));
+ if (c->empty())
+ return result;
+
+ std::tr1::shared_ptr<const QualifiedPackageNameSet> p(_fg.filter().packages(env, r, _fg.generator().packages(env, r, c)));
+ if (p->empty())
+ return result;
+
+ std::tr1::shared_ptr<const PackageIDSet> i(_fg.filter().ids(env, _fg.generator().ids(env, r, p)));
+ std::copy(i->begin(), i->end(), result->back_inserter());
+ result->sort(PackageIDComparator(env->package_database().get()));
+
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return "all versions sorted from " + stringify(_fg);
+ }
+ };
+
+ class AllVersionsUnsortedSelectionHandler :
+ public SelectionHandler
+ {
+ public:
+ AllVersionsUnsortedSelectionHandler(const FilteredGenerator & g) :
+ SelectionHandler(g)
+ {
+ }
+
+ virtual std::tr1::shared_ptr<PackageIDSequence> perform_select(const Environment * const env) const
+ {
+ using namespace std::tr1::placeholders;
+
+ std::tr1::shared_ptr<PackageIDSequence> result(new PackageIDSequence);
+
+ std::tr1::shared_ptr<const RepositoryNameSet> r(_fg.filter().repositories(env, _fg.generator().repositories(env)));
+ if (r->empty())
+ return result;
+
+ std::tr1::shared_ptr<const CategoryNamePartSet> c(_fg.filter().categories(env, r, _fg.generator().categories(env, r)));
+ if (c->empty())
+ return result;
+
+ std::tr1::shared_ptr<const QualifiedPackageNameSet> p(_fg.filter().packages(env, r, _fg.generator().packages(env, r, c)));
+ if (p->empty())
+ return result;
+
+ std::tr1::shared_ptr<const PackageIDSet> i(_fg.filter().ids(env, _fg.generator().ids(env, r, p)));
+ std::copy(i->begin(), i->end(), result->back_inserter());
+
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return "all versions in some arbitrary order from " + stringify(_fg);
+ }
+ };
+
+ class AllVersionsGroupedBySlotSelectioHandler :
+ public SelectionHandler
+ {
+ public:
+ AllVersionsGroupedBySlotSelectioHandler(const FilteredGenerator & g) :
+ SelectionHandler(g)
+ {
+ }
+
+ virtual std::tr1::shared_ptr<PackageIDSequence> perform_select(const Environment * const env) const
+ {
+ using namespace std::tr1::placeholders;
+
+ std::tr1::shared_ptr<PackageIDSequence> result(new PackageIDSequence);
+
+ std::tr1::shared_ptr<const RepositoryNameSet> r(_fg.filter().repositories(env, _fg.generator().repositories(env)));
+ if (r->empty())
+ return result;
+
+ std::tr1::shared_ptr<const CategoryNamePartSet> c(_fg.filter().categories(env, r, _fg.generator().categories(env, r)));
+ if (c->empty())
+ return result;
+
+ std::tr1::shared_ptr<const QualifiedPackageNameSet> p(_fg.filter().packages(env, r, _fg.generator().packages(env, r, c)));
+ if (p->empty())
+ return result;
+
+ std::tr1::shared_ptr<const PackageIDSet> id(_fg.filter().ids(env, _fg.generator().ids(env, r, p)));
+
+ typedef std::map<std::pair<QualifiedPackageName, SlotName>, std::tr1::shared_ptr<PackageIDSequence> > SlotMap;
+ SlotMap by_slot;
+ for (PackageIDSet::ConstIterator i(id->begin()), i_end(id->end()) ;
+ i != i_end ; ++i)
+ {
+ SlotMap::iterator m(by_slot.find(std::make_pair((*i)->name(), (*i)->slot())));
+ if (m == by_slot.end())
+ m = by_slot.insert(std::make_pair(std::make_pair((*i)->name(), (*i)->slot()),
+ make_shared_ptr(new PackageIDSequence))).first;
+ m->second->push_back(*i);
+ }
+
+ PackageIDComparator comparator(env->package_database().get());
+ for (SlotMap::iterator i(by_slot.begin()), i_end(by_slot.end()) ;
+ i != i_end ; ++i)
+ i->second->sort(comparator);
+
+ while (! by_slot.empty())
+ {
+ SlotMap::iterator m(by_slot.begin());
+ for (SlotMap::iterator n(by_slot.begin()), n_end(by_slot.end()) ; n != n_end ; ++n)
+ if (! comparator(*m->second->last(), *n->second->last()))
+ m = n;
+
+ std::copy(m->second->begin(), m->second->end(), result->back_inserter());
+ by_slot.erase(m);
+ }
+
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return "all versions grouped by slot from " + stringify(_fg);
+ }
+ };
+
+ class BestVersionInEachSlotSelectionHandler :
+ public SelectionHandler
+ {
+ public:
+ BestVersionInEachSlotSelectionHandler(const FilteredGenerator & g) :
+ SelectionHandler(g)
+ {
+ }
+
+ virtual std::tr1::shared_ptr<PackageIDSequence> perform_select(const Environment * const env) const
+ {
+ using namespace std::tr1::placeholders;
+
+ std::tr1::shared_ptr<PackageIDSequence> result(new PackageIDSequence);
+
+ std::tr1::shared_ptr<const RepositoryNameSet> r(_fg.filter().repositories(env, _fg.generator().repositories(env)));
+ if (r->empty())
+ return result;
+
+ std::tr1::shared_ptr<const CategoryNamePartSet> c(_fg.filter().categories(env, r, _fg.generator().categories(env, r)));
+ if (c->empty())
+ return result;
+
+ std::tr1::shared_ptr<const QualifiedPackageNameSet> p(_fg.filter().packages(env, r, _fg.generator().packages(env, r, c)));
+ if (p->empty())
+ return result;
+
+ std::tr1::shared_ptr<const PackageIDSet> id(_fg.filter().ids(env, _fg.generator().ids(env, r, p)));
+
+ typedef std::map<std::pair<QualifiedPackageName, SlotName>, std::tr1::shared_ptr<PackageIDSequence> > SlotMap;
+ SlotMap by_slot;
+ for (PackageIDSet::ConstIterator i(id->begin()), i_end(id->end()) ;
+ i != i_end ; ++i)
+ {
+ SlotMap::iterator m(by_slot.find(std::make_pair((*i)->name(), (*i)->slot())));
+ if (m == by_slot.end())
+ m = by_slot.insert(std::make_pair(std::make_pair((*i)->name(), (*i)->slot()),
+ make_shared_ptr(new PackageIDSequence))).first;
+ m->second->push_back(*i);
+ }
+
+ PackageIDComparator comparator(env->package_database().get());
+ for (SlotMap::iterator i(by_slot.begin()), i_end(by_slot.end()) ;
+ i != i_end ; ++i)
+ i->second->sort(comparator);
+
+ while (! by_slot.empty())
+ {
+ SlotMap::iterator m(by_slot.begin());
+ for (SlotMap::iterator n(by_slot.begin()), n_end(by_slot.end()) ; n != n_end ; ++n)
+ if (! comparator(*m->second->last(), *n->second->last()))
+ m = n;
+
+ std::copy(m->second->last(), m->second->end(), result->back_inserter());
+ by_slot.erase(m);
+ }
+
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return "best version in each slot from " + stringify(_fg);
+ }
+ };
+
+ class RequireExactlyOneSelectionHandler :
+ public SelectionHandler
+ {
+ public:
+ RequireExactlyOneSelectionHandler(const FilteredGenerator & g) :
+ SelectionHandler(g)
+ {
+ }
+
+ virtual std::tr1::shared_ptr<PackageIDSequence> perform_select(const Environment * const env) const
+ {
+ using namespace std::tr1::placeholders;
+
+ std::tr1::shared_ptr<PackageIDSequence> result(new PackageIDSequence);
+
+ std::tr1::shared_ptr<const RepositoryNameSet> r(_fg.filter().repositories(env, _fg.generator().repositories(env)));
+ if (r->empty())
+ throw DidNotGetExactlyOneError(as_string(), make_shared_ptr(new PackageIDSet));
+
+ std::tr1::shared_ptr<const CategoryNamePartSet> c(_fg.filter().categories(env, r, _fg.generator().categories(env, r)));
+ if (c->empty())
+ throw DidNotGetExactlyOneError(as_string(), make_shared_ptr(new PackageIDSet));
+
+ std::tr1::shared_ptr<const QualifiedPackageNameSet> p(_fg.filter().packages(env, r, _fg.generator().packages(env, r, c)));
+ if (p->empty())
+ throw DidNotGetExactlyOneError(as_string(), make_shared_ptr(new PackageIDSet));
+
+ std::tr1::shared_ptr<const PackageIDSet> i(_fg.filter().ids(env, _fg.generator().ids(env, r, p)));
+
+ if (i->empty() || next(i->begin()) != i->end())
+ throw DidNotGetExactlyOneError(as_string(), i);
+
+ result->push_back(*i->begin());
+
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return "the single version from " + stringify(_fg);
+ }
+ };
+}
+
+selection::SomeArbitraryVersion::SomeArbitraryVersion(const FilteredGenerator & f) :
+ Selection(make_shared_ptr(new SomeArbitraryVersionSelectionHandler(f)))
+{
+}
+
+selection::BestVersionOnly::BestVersionOnly(const FilteredGenerator & f) :
+ Selection(make_shared_ptr(new BestVersionOnlySelectionHandler(f)))
+{
+}
+
+selection::AllVersionsSorted::AllVersionsSorted(const FilteredGenerator & f) :
+ Selection(make_shared_ptr(new AllVersionsSortedSelectionHandler(f)))
+{
+}
+
+selection::AllVersionsUnsorted::AllVersionsUnsorted(const FilteredGenerator & f) :
+ Selection(make_shared_ptr(new AllVersionsUnsortedSelectionHandler(f)))
+{
+}
+
+selection::AllVersionsGroupedBySlot::AllVersionsGroupedBySlot(const FilteredGenerator & f) :
+ Selection(make_shared_ptr(new AllVersionsGroupedBySlotSelectioHandler(f)))
+{
+}
+
+selection::BestVersionInEachSlot::BestVersionInEachSlot(const FilteredGenerator & f) :
+ Selection(make_shared_ptr(new BestVersionInEachSlotSelectionHandler(f)))
+{
+}
+
+selection::RequireExactlyOne::RequireExactlyOne(const FilteredGenerator & f) :
+ Selection(make_shared_ptr(new RequireExactlyOneSelectionHandler(f)))
+{
+}
+
+std::ostream &
+paludis::operator<< (std::ostream & s, const Selection & g)
+{
+ s << g.as_string();
+ return s;
+}
+
+template class PrivateImplementationPattern<Selection>;
+
diff --git a/paludis/selection.hh b/paludis/selection.hh
new file mode 100644
index 000000000..f169a4259
--- /dev/null
+++ b/paludis/selection.hh
@@ -0,0 +1,121 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_SELECTION_HH
+#define PALUDIS_GUARD_PALUDIS_SELECTION_HH 1
+
+#include <paludis/selection-fwd.hh>
+#include <paludis/filtered_generator-fwd.hh>
+#include <paludis/filter-fwd.hh>
+#include <paludis/generator-fwd.hh>
+#include <paludis/dep_spec-fwd.hh>
+#include <paludis/util/fs_entry-fwd.hh>
+#include <paludis/util/private_implementation_pattern.hh>
+#include <paludis/util/exception.hh>
+#include <paludis/name-fwd.hh>
+#include <paludis/package_id-fwd.hh>
+#include <paludis/environment-fwd.hh>
+
+namespace paludis
+{
+ class SelectionHandler;
+
+ class DidNotGetExactlyOneError :
+ public Exception
+ {
+ public:
+ DidNotGetExactlyOneError(const std::string &,
+ const std::tr1::shared_ptr<const PackageIDSet> &) throw ();
+ };
+
+ class PALUDIS_VISIBLE Selection :
+ private PrivateImplementationPattern<Selection>
+ {
+ protected:
+ Selection(const std::tr1::shared_ptr<const SelectionHandler> &);
+
+ public:
+ Selection(const Selection &);
+ ~Selection();
+ Selection & operator= (const Selection &);
+
+ std::string as_string() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ std::tr1::shared_ptr<PackageIDSequence> perform_select(const Environment * const) const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+ };
+
+ namespace selection
+ {
+ class PALUDIS_VISIBLE SomeArbitraryVersion :
+ public Selection
+ {
+ public:
+ SomeArbitraryVersion(const FilteredGenerator &);
+ };
+
+ class PALUDIS_VISIBLE BestVersionOnly :
+ public Selection
+ {
+ public:
+ BestVersionOnly(const FilteredGenerator &);
+ };
+
+ class PALUDIS_VISIBLE BestVersionInEachSlot :
+ public Selection
+ {
+ public:
+ BestVersionInEachSlot(const FilteredGenerator &);
+ };
+
+ class PALUDIS_VISIBLE AllVersionsSorted :
+ public Selection
+ {
+ public:
+ AllVersionsSorted(const FilteredGenerator &);
+ };
+
+ class PALUDIS_VISIBLE AllVersionsGroupedBySlot :
+ public Selection
+ {
+ public:
+ AllVersionsGroupedBySlot(const FilteredGenerator &);
+ };
+
+ class PALUDIS_VISIBLE AllVersionsUnsorted :
+ public Selection
+ {
+ public:
+ AllVersionsUnsorted(const FilteredGenerator &);
+ };
+
+ class PALUDIS_VISIBLE RequireExactlyOne :
+ public Selection
+ {
+ public:
+ RequireExactlyOne(const FilteredGenerator &);
+ };
+ };
+
+#ifdef PALUDIS_HAVE_EXTERN_TEMPLATE
+ extern template class PrivateImplementationPattern<Selection>;
+#endif
+}
+
+#endif
diff --git a/paludis/selection_TEST.cc b/paludis/selection_TEST.cc
new file mode 100644
index 000000000..98490ca8f
--- /dev/null
+++ b/paludis/selection_TEST.cc
@@ -0,0 +1,184 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/environments/test/test_environment.hh>
+#include <paludis/repositories/fake/fake_repository.hh>
+#include <paludis/repositories/fake/fake_package_id.hh>
+#include <paludis/user_dep_spec.hh>
+#include <paludis/package_database.hh>
+#include <paludis/util/sequence.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <test/test_runner.hh>
+#include <test/test_framework.hh>
+#include <test/test_concepts.hh>
+
+using namespace paludis;
+using namespace test;
+
+namespace test_cases
+{
+ TESTCASE_SEMIREGULAR(Selection, selection::AllVersionsSorted(generator::All()));
+
+ struct BasicSelectionsTest : TestCase
+ {
+ BasicSelectionsTest() : TestCase("basic selections") { }
+
+ void run()
+ {
+ TestEnvironment e;
+
+ std::tr1::shared_ptr<FakeRepository> r1(new FakeRepository(&e, RepositoryName("repo1")));
+ r1->add_version("r1c1", "r1c1p1", "1");
+ r1->add_version("r1c1", "r1c1p2", "1");
+ r1->add_version("r1c1", "r1c1p2", "2");
+ r1->add_version("rac1", "rac1pa", "1");
+ r1->add_version("rac1", "rac1pa", "2");
+ e.package_database()->add_repository(11, r1);
+ TEST_CHECK(true);
+
+ std::tr1::shared_ptr<FakeRepository> r2(new FakeRepository(&e, RepositoryName("repo2")));
+ r2->add_version("rac1", "rac1pa", "1");
+ r2->add_version("rac1", "rac1pa", "3");
+ e.package_database()->add_repository(10, r2);
+ TEST_CHECK(true);
+
+ PackageDepSpec d1(parse_user_package_dep_spec("r1c1/r1c1p1", UserPackageDepSpecOptions()));
+ const std::tr1::shared_ptr<const PackageIDSequence> q1(e[selection::AllVersionsSorted(generator::Matches(d1))]);
+ TEST_CHECK_EQUAL(std::distance(q1->begin(), q1->end()), 1);
+
+ PackageDepSpec d2(parse_user_package_dep_spec("r1c1/r1c1p2", UserPackageDepSpecOptions()));
+ const std::tr1::shared_ptr<const PackageIDSequence> q2(e[selection::AllVersionsSorted(generator::Matches(d2))]);
+ TEST_CHECK_EQUAL(std::distance(q2->begin(), q2->end()), 2);
+
+ PackageDepSpec d3(parse_user_package_dep_spec(">=r1c1/r1c1p2-1", UserPackageDepSpecOptions()));
+ const std::tr1::shared_ptr<const PackageIDSequence> q3(e[selection::AllVersionsSorted(generator::Matches(d3))]);
+ TEST_CHECK_EQUAL(std::distance(q3->begin(), q3->end()), 2);
+
+ PackageDepSpec d4(parse_user_package_dep_spec(">=r1c1/r1c1p2-2", UserPackageDepSpecOptions()));
+ const std::tr1::shared_ptr<const PackageIDSequence> q4(e[selection::AllVersionsSorted(generator::Matches(d4))]);
+ TEST_CHECK_EQUAL(join(indirect_iterator(q4->begin()), indirect_iterator(q4->end()), " "),
+ "r1c1/r1c1p2-2:0::repo1");
+ TEST_CHECK_EQUAL(std::distance(q4->begin(), q4->end()), 1);
+
+ PackageDepSpec d5(parse_user_package_dep_spec(">=r1c1/r1c1p2-3", UserPackageDepSpecOptions()));
+ const std::tr1::shared_ptr<const PackageIDSequence> q5(e[selection::AllVersionsSorted(generator::Matches(d5))]);
+ TEST_CHECK_EQUAL(std::distance(q5->begin(), q5->end()), 0);
+
+ PackageDepSpec d6(parse_user_package_dep_spec("<r1c1/r1c1p2-3", UserPackageDepSpecOptions()));
+ const std::tr1::shared_ptr<const PackageIDSequence> q6(e[selection::AllVersionsSorted(generator::Matches(d6))]);
+ TEST_CHECK_EQUAL(std::distance(q6->begin(), q6->end()), 2);
+
+ PackageDepSpec d7(parse_user_package_dep_spec("rac1/rac1pa", UserPackageDepSpecOptions()));
+ const std::tr1::shared_ptr<const PackageIDSequence> q7(e[selection::AllVersionsSorted(generator::Matches(d7))]);
+ TEST_CHECK_EQUAL(std::distance(q7->begin(), q7->end()), 4);
+
+ PackageDepSpec d8(parse_user_package_dep_spec("foo/bar", UserPackageDepSpecOptions()));
+ const std::tr1::shared_ptr<const PackageIDSequence> q8(e[selection::AllVersionsSorted(generator::Matches(d8))]);
+ TEST_CHECK_EQUAL(std::distance(q8->begin(), q8->end()), 0);
+
+ PackageDepSpec d9(parse_user_package_dep_spec("r1c1/r1c1p1", UserPackageDepSpecOptions()));
+ const std::tr1::shared_ptr<const PackageIDSequence> q9(e[selection::AllVersionsSorted(generator::Matches(d9)
+ | filter::SupportsAction<InstallAction>())]);
+ TEST_CHECK_EQUAL(std::distance(q9->begin(), q9->end()), 1);
+ }
+ } basic_selections_test;
+
+ struct SelectionsTest : TestCase
+ {
+ SelectionsTest() : TestCase("selections") { }
+
+ void run()
+ {
+ TestEnvironment e;
+
+ std::tr1::shared_ptr<FakeRepository> r1(new FakeRepository(&e, RepositoryName("repo1")));
+ r1->add_version("cat", "pkg", "1")->set_slot(SlotName("a"));
+ r1->add_version("cat", "pkg", "2")->set_slot(SlotName("c"));
+ r1->add_version("cat", "pkg", "3")->set_slot(SlotName("c"));
+ r1->add_version("cat", "pkg", "4")->set_slot(SlotName("a"));
+ e.package_database()->add_repository(10, r1);
+ TEST_CHECK(true);
+
+ std::tr1::shared_ptr<FakeRepository> r2(new FakeRepository(&e, RepositoryName("repo2")));
+ r2->add_version("cat", "pkg", "1")->set_slot(SlotName("a"));
+ r2->add_version("cat", "pkg", "3")->set_slot(SlotName("b"));
+ e.package_database()->add_repository(5, r2);
+ TEST_CHECK(true);
+
+ PackageDepSpec d(parse_user_package_dep_spec("cat/pkg", UserPackageDepSpecOptions()));
+
+ const std::tr1::shared_ptr<const PackageIDSequence> q1(e[selection::AllVersionsSorted(generator::Matches(d))]);
+ TEST_CHECK_EQUAL(join(indirect_iterator(q1->begin()), indirect_iterator(q1->end()), " "),
+ "cat/pkg-1:a::repo2 cat/pkg-1:a::repo1 cat/pkg-2:c::repo1 cat/pkg-3:b::repo2 cat/pkg-3:c::repo1 cat/pkg-4:a::repo1");
+
+ const std::tr1::shared_ptr<const PackageIDSequence> q2(e[selection::AllVersionsGroupedBySlot(generator::Matches(d))]);
+ TEST_CHECK_EQUAL(join(indirect_iterator(q2->begin()), indirect_iterator(q2->end()), " "),
+ "cat/pkg-3:b::repo2 cat/pkg-2:c::repo1 cat/pkg-3:c::repo1 cat/pkg-1:a::repo2 cat/pkg-1:a::repo1 cat/pkg-4:a::repo1");
+
+ const std::tr1::shared_ptr<const PackageIDSequence> q3(e[selection::BestVersionOnly(generator::Matches(d))]);
+ TEST_CHECK_EQUAL(join(indirect_iterator(q3->begin()), indirect_iterator(q3->end()), " "),
+ "cat/pkg-4:a::repo1");
+
+ const std::tr1::shared_ptr<const PackageIDSequence> q4(e[selection::BestVersionInEachSlot(generator::Matches(d))]);
+ TEST_CHECK_EQUAL(join(indirect_iterator(q4->begin()), indirect_iterator(q4->end()), " "),
+ "cat/pkg-3:b::repo2 cat/pkg-3:c::repo1 cat/pkg-4:a::repo1");
+
+ std::tr1::shared_ptr<FakeRepository> r3(new FakeRepository(&e, RepositoryName("repo3")));
+ r3->add_version("cat", "other", "1")->set_slot(SlotName("a"));
+ e.package_database()->add_repository(5, r3);
+ TEST_CHECK(true);
+
+ PackageDepSpec c(parse_user_package_dep_spec("cat/*", UserPackageDepSpecOptions() + updso_allow_wildcards));
+
+ const std::tr1::shared_ptr<const PackageIDSequence> q5(e[selection::AllVersionsSorted(generator::Matches(c))]);
+ TEST_CHECK_EQUAL(join(indirect_iterator(q5->begin()), indirect_iterator(q5->end()), " "),
+ "cat/other-1:a::repo3 cat/pkg-1:a::repo2 cat/pkg-1:a::repo1 cat/pkg-2:c::repo1 "
+ "cat/pkg-3:b::repo2 cat/pkg-3:c::repo1 cat/pkg-4:a::repo1");
+
+ const std::tr1::shared_ptr<const PackageIDSequence> q6(e[selection::AllVersionsGroupedBySlot(generator::Matches(c))]);
+ TEST_CHECK_EQUAL(join(indirect_iterator(q6->begin()), indirect_iterator(q6->end()), " "),
+ "cat/other-1:a::repo3 cat/pkg-3:b::repo2 cat/pkg-2:c::repo1 cat/pkg-3:c::repo1 "
+ "cat/pkg-1:a::repo2 cat/pkg-1:a::repo1 cat/pkg-4:a::repo1");
+
+ const std::tr1::shared_ptr<const PackageIDSequence> q7(e[selection::BestVersionOnly(generator::Matches(c))]);
+ TEST_CHECK_EQUAL(join(indirect_iterator(q7->begin()), indirect_iterator(q7->end()), " "),
+ "cat/other-1:a::repo3 cat/pkg-4:a::repo1");
+
+ const std::tr1::shared_ptr<const PackageIDSequence> q8(e[selection::BestVersionInEachSlot(generator::Matches(c))]);
+ TEST_CHECK_EQUAL(join(indirect_iterator(q8->begin()), indirect_iterator(q8->end()), " "),
+ "cat/other-1:a::repo3 cat/pkg-3:b::repo2 cat/pkg-3:c::repo1 cat/pkg-4:a::repo1");
+
+ PackageDepSpec b(parse_user_package_dep_spec("cat/pkg:a", UserPackageDepSpecOptions()));
+ const std::tr1::shared_ptr<const PackageIDSequence> q9(e[selection::AllVersionsGroupedBySlot(generator::Matches(b))]);
+ TEST_CHECK_EQUAL(join(indirect_iterator(q9->begin()), indirect_iterator(q9->end()), " "),
+ "cat/pkg-1:a::repo2 cat/pkg-1:a::repo1 cat/pkg-4:a::repo1");
+
+ PackageDepSpec a(parse_user_package_dep_spec("cat/pkg[=1|=3]", UserPackageDepSpecOptions()));
+ const std::tr1::shared_ptr<const PackageIDSequence> q10(e[selection::AllVersionsGroupedBySlot(generator::Matches(a))]);
+ TEST_CHECK_EQUAL(join(indirect_iterator(q10->begin()), indirect_iterator(q10->end()), " "),
+ "cat/pkg-1:a::repo2 cat/pkg-1:a::repo1 cat/pkg-3:b::repo2 cat/pkg-3:c::repo1");
+ }
+ } selections_test;
+}
+
diff --git a/paludis/set_file.cc b/paludis/set_file.cc
index a7b23e5d7..c7e19e4b3 100644
--- a/paludis/set_file.cc
+++ b/paludis/set_file.cc
@@ -17,7 +17,7 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "set_file.hh"
+#include <paludis/set_file.hh>
#include <paludis/util/fs_entry.hh>
#include <paludis/util/log.hh>
#include <paludis/util/tokeniser.hh>
@@ -29,8 +29,11 @@
#include <paludis/util/config_file.hh>
#include <paludis/util/system.hh>
#include <paludis/environment.hh>
-#include <paludis/query.hh>
#include <paludis/package_database.hh>
+#include <paludis/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
#include <list>
#include <vector>
#include <fstream>
@@ -243,8 +246,9 @@ namespace
if (! params.environment)
Log::get_instance()->message("set_file.bad_operator", ll_warning, lc_context)
<< "Line '" << line << "' uses ? operator but no environment is available";
- else if (! params.environment->package_database()->query(query::Package(*spec->package_ptr()) &
- query::InstalledAtRoot(params.environment->root()), qo_whatever)->empty())
+ else if (! (*params.environment)[selection::SomeArbitraryVersion(
+ generator::Package(*spec->package_ptr()) |
+ filter::InstalledAtRoot(params.environment->root()))]->empty())
result->add(std::tr1::shared_ptr<TreeLeaf<SetSpecTree, PackageDepSpec> >(
new TreeLeaf<SetSpecTree, PackageDepSpec>(spec)));
}
@@ -270,11 +274,11 @@ namespace
if (! params.environment)
Log::get_instance()->message("set_file.bad_operator", ll_warning, lc_context)
<< "Line '" << line << "' uses ?: operator but no environment is available";
- else if (! params.environment->package_database()->query(query::Matches(
+ else if (! (*params.environment)[selection::SomeArbitraryVersion(generator::Matches(
make_package_dep_spec()
- .package(*spec->package_ptr())
- .slot_requirement(spec->slot_requirement_ptr())) &
- query::InstalledAtRoot(params.environment->root()), qo_whatever)->empty())
+ .package(*spec->package_ptr())
+ .slot_requirement(spec->slot_requirement_ptr())) |
+ filter::InstalledAtRoot(params.environment->root()))]->empty())
result->add(std::tr1::shared_ptr<TreeLeaf<SetSpecTree, PackageDepSpec> >(
new TreeLeaf<SetSpecTree, PackageDepSpec>(spec)));
}
diff --git a/paludis/show_suggest_visitor.cc b/paludis/show_suggest_visitor.cc
index fd48ad9dc..4252a08e9 100644
--- a/paludis/show_suggest_visitor.cc
+++ b/paludis/show_suggest_visitor.cc
@@ -22,9 +22,12 @@
#include <paludis/condition_tracker.hh>
#include <paludis/dep_spec.hh>
#include <paludis/package_id.hh>
-#include <paludis/query.hh>
#include <paludis/package_database.hh>
#include <paludis/dep_label.hh>
+#include <paludis/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
#include <paludis/util/log.hh>
#include <paludis/util/save.hh>
#include <paludis/util/visitor-impl.hh>
@@ -184,9 +187,8 @@ ShowSuggestVisitor::visit_leaf(const PackageDepSpec & a)
&_imp->conditions, _imp->dependency_tags ?
ConditionTracker(_imp->conditions).add_condition(a) : _imp->conditions);
- std::tr1::shared_ptr<const PackageIDSequence> installed_matches(_imp->environment->package_database()->query(
- query::SupportsAction<InstalledAction>() &
- query::Matches(a), qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> installed_matches((*_imp->environment)[selection::AllVersionsSorted(
+ generator::Matches(a) | filter::SupportsAction<InstalledAction>())]);
if (! installed_matches->empty())
{
Log::get_instance()->message("dep_list.show_suggest_visitor.already_installed", ll_debug, lc_context)
@@ -196,9 +198,8 @@ ShowSuggestVisitor::visit_leaf(const PackageDepSpec & a)
return;
}
- std::tr1::shared_ptr<const PackageIDSequence> matches(_imp->environment->package_database()->query(
- query::SupportsAction<InstallAction>() &
- query::Matches(a), qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> matches((*_imp->environment)[selection::AllVersionsSorted(
+ generator::Matches(a) | filter::SupportsAction<InstallAction>())]);
if (matches->empty())
{
Log::get_instance()->message("dep_list.show_suggest_visitor.nothing_found", ll_warning, lc_context)
diff --git a/paludis/uninstall_list.cc b/paludis/uninstall_list.cc
index 899b33059..bb2963de3 100644
--- a/paludis/uninstall_list.cc
+++ b/paludis/uninstall_list.cc
@@ -36,10 +36,13 @@
#include <paludis/match_package.hh>
#include <paludis/package_database.hh>
#include <paludis/package_id.hh>
-#include <paludis/query.hh>
#include <paludis/metadata_key.hh>
#include <paludis/dep_tag.hh>
#include <paludis/slot_requirement.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/selection.hh>
#include <tr1/unordered_map>
#include <list>
#include <algorithm>
@@ -286,9 +289,10 @@ namespace
if (a.slot_requirement_ptr())
best_only = visitor_cast<const SlotAnyUnlockedRequirement>(*a.slot_requirement_ptr());
- std::tr1::shared_ptr<const PackageIDSequence> m(env->package_database()->query(
- query::Matches(a) & query::InstalledAtRoot(env->root()),
- best_only ? qo_best_version_only : qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> m(
+ best_only ?
+ (*env)[selection::BestVersionOnly(generator::Matches(a) | filter::InstalledAtRoot(env->root()))] :
+ (*env)[selection::AllVersionsSorted(generator::Matches(a) | filter::InstalledAtRoot(env->root()))]);
for (PackageIDSequence::ConstIterator it = m->begin(), it_end = m->end();
it_end != it; ++it)
matches->insert(DepTagEntry(std::tr1::shared_ptr<const DepTag>(new DependencyDepTag(*it, a, conditions)), 0));
diff --git a/paludis/uninstall_task.cc b/paludis/uninstall_task.cc
index e9572830f..4323ef563 100644
--- a/paludis/uninstall_task.cc
+++ b/paludis/uninstall_task.cc
@@ -24,6 +24,10 @@
#include <paludis/dep_spec_flattener.hh>
#include <paludis/tasks_exceptions.hh>
#include <paludis/user_dep_spec.hh>
+#include <paludis/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
#include <paludis/util/visitor-impl.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/stringify.hh>
@@ -32,7 +36,6 @@
#include <paludis/util/wrapped_forward_iterator-impl.hh>
#include <paludis/util/options.hh>
#include <paludis/util/kc.hh>
-#include <paludis/query.hh>
#include <paludis/package_database.hh>
#include <paludis/hook.hh>
#include <paludis/dep_tag.hh>
@@ -192,7 +195,7 @@ UninstallTask::add_target(const std::string & target)
_imp->had_package_targets = false;
std::tr1::shared_ptr<PackageDepSpec> pds(new PackageDepSpec(make_package_dep_spec()
.package(_imp->env->package_database()->fetch_unique_qualified_package_name(
- PackageNamePart(target), query::MaybeSupportsAction<UninstallAction>()))));
+ PackageNamePart(target), filter::SupportsAction<UninstallAction>()))));
pds->set_tag(std::tr1::shared_ptr<const DepTag>(new TargetDepTag));
_imp->targets.push_back(pds);
}
@@ -205,7 +208,7 @@ UninstallTask::add_target(const std::string & target)
_imp->had_package_targets = false;
std::tr1::shared_ptr<PackageDepSpec> pds(new PackageDepSpec(make_package_dep_spec()
.package(_imp->env->package_database()->fetch_unique_qualified_package_name(
- PackageNamePart(target), query::MaybeSupportsAction<UninstallAction>()))));
+ PackageNamePart(target), filter::SupportsAction<UninstallAction>()))));
pds->set_tag(std::tr1::shared_ptr<const DepTag>(new TargetDepTag));
_imp->targets.push_back(pds);
}
@@ -248,10 +251,9 @@ UninstallTask::execute()
{
Context local_context("When looking for target '" + stringify(**t) + "':");
- std::tr1::shared_ptr<const PackageIDSequence> r(_imp->env->package_database()->query(
- query::Matches(**t) &
- query::SupportsAction<UninstallAction>(),
- qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> r((*_imp->env)[selection::AllVersionsSorted(
+ generator::Matches(**t) |
+ filter::SupportsAction<UninstallAction>())]);
if (r->empty())
{
if (! _imp->had_set_targets)
@@ -314,10 +316,10 @@ UninstallTask::execute()
i(being_removed.begin()), i_end(being_removed.end()) ; i != i_end ; ++i)
{
bool remove(true);
- std::tr1::shared_ptr<const PackageIDSequence> installed(
- _imp->env->package_database()->query(query::Matches(make_package_dep_spec().package(i->first)) &
- query::SupportsAction<InstalledAction>(),
- qo_whatever));
+ std::tr1::shared_ptr<const PackageIDSequence> installed((*_imp->env)[selection::AllVersionsUnsorted(
+ generator::Matches(make_package_dep_spec().package(i->first)) |
+ filter::SupportsAction<InstalledAction>()
+ )]);
for (PackageIDSequence::ConstIterator r(installed->begin()), r_end(installed->end()) ;
r != r_end && remove ; ++r)
if (i->second.end() == i->second.find((*r)->version()))
diff --git a/paludis/util/indirect_iterator-impl.hh b/paludis/util/indirect_iterator-impl.hh
index cde8380cc..6e4851dc7 100644
--- a/paludis/util/indirect_iterator-impl.hh
+++ b/paludis/util/indirect_iterator-impl.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007 Ciaran McCreesh
+ * Copyright (c) 2007, 2008 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