aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--NEWS3
-rw-r--r--doc/api/cplusplus/examples/Makefile.am13
-rw-r--r--doc/api/cplusplus/examples/example_action.cc5
-rw-r--r--doc/api/cplusplus/examples/example_contents.cc7
-rw-r--r--doc/api/cplusplus/examples/example_dep_label.cc5
-rw-r--r--doc/api/cplusplus/examples/example_dep_spec.cc3
-rw-r--r--doc/api/cplusplus/examples/example_dep_spec_flattener.cc6
-rw-r--r--doc/api/cplusplus/examples/example_dep_tree.cc5
-rw-r--r--doc/api/cplusplus/examples/example_environment.cc17
-rw-r--r--doc/api/cplusplus/examples/example_formatter.cc7
-rw-r--r--doc/api/cplusplus/examples/example_mask.cc5
-rw-r--r--doc/api/cplusplus/examples/example_match_package.cc5
-rw-r--r--doc/api/cplusplus/examples/example_metadata_key.cc5
-rw-r--r--doc/api/cplusplus/examples/example_package_database.cc3
-rw-r--r--doc/api/cplusplus/examples/example_package_id.cc9
-rw-r--r--doc/api/cplusplus/examples/example_query.cc108
-rw-r--r--doc/api/cplusplus/examples/example_query_delegate.cc165
-rw-r--r--doc/api/cplusplus/examples/example_selection.cc117
-rw-r--r--doc/api/cplusplus/examples/example_stringify_formatter.cc7
-rw-r--r--doc/api/cplusplus/groups.doxygen19
-rw-r--r--doc/api/ruby/Makefile.am2
-rw-r--r--doc/api/ruby/example_action.rb5
-rw-r--r--doc/api/ruby/example_contents.rb7
-rw-r--r--doc/api/ruby/example_dep_spec.rb101
-rw-r--r--doc/api/ruby/example_dep_tree.rb4
-rw-r--r--doc/api/ruby/example_environment.rb23
-rw-r--r--doc/api/ruby/example_mask.rb5
-rw-r--r--doc/api/ruby/example_match_package.rb3
-rw-r--r--doc/api/ruby/example_package_database.rb3
-rw-r--r--doc/api/ruby/example_package_id.rb9
-rw-r--r--doc/api/ruby/example_query.rb47
-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
-rw-r--r--python/Makefile.am33
-rw-r--r--python/environment.cc28
-rwxr-xr-xpython/environment_TEST.py13
-rw-r--r--python/filter.cc95
-rw-r--r--python/filter_TEST.py38
-rw-r--r--python/filtered_generator.cc56
-rw-r--r--python/filtered_generator_TEST.py39
-rw-r--r--python/generator.cc92
-rw-r--r--python/generator_TEST.py38
-rwxr-xr-xpython/mask_TEST.py26
-rw-r--r--python/package_database.cc17
-rwxr-xr-xpython/package_database_TEST.py18
-rw-r--r--python/paludis_python.hh5
-rw-r--r--python/paludis_python_so.cc5
-rw-r--r--python/query.cc356
-rwxr-xr-xpython/query_TEST.py87
-rwxr-xr-xpython/query_TEST_cleanup.sh8
-rwxr-xr-xpython/query_TEST_setup.sh34
-rw-r--r--python/selection.cc89
-rw-r--r--python/selection_TEST.py40
-rw-r--r--ruby/Makefile.am16
-rw-r--r--ruby/action.cc66
-rwxr-xr-xruby/demos/find_unused_distfiles.rb6
-rw-r--r--ruby/dep_list_TEST.rb5
-rw-r--r--ruby/dep_spec_TEST.rb4
-rw-r--r--ruby/dep_tag_TEST.rb2
-rw-r--r--ruby/environment.cc30
-rw-r--r--ruby/environment_TEST.rb118
-rw-r--r--ruby/filter.cc202
-rw-r--r--ruby/filter_TEST.rb100
-rw-r--r--ruby/filtered_generator.cc143
-rw-r--r--ruby/filtered_generator_TEST.rb58
-rw-r--r--ruby/generator.cc285
-rw-r--r--ruby/generator_TEST.rb140
-rw-r--r--ruby/package_database.cc59
-rw-r--r--ruby/package_database_TEST.rb114
-rw-r--r--ruby/paludis_ruby.hh25
-rw-r--r--ruby/paludis_ruby_TEST.rb14
-rw-r--r--ruby/query.cc394
-rw-r--r--ruby/query_TEST.rb244
-rw-r--r--ruby/repository_TEST.rb14
-rw-r--r--ruby/selection.cc122
-rw-r--r--ruby/selection_TEST.rb136
-rw-r--r--src/clients/accerso/accerso.cc13
-rw-r--r--src/clients/adjutrix/downgrade_check.cc13
-rw-r--r--src/clients/adjutrix/find_insecure_packages.cc8
-rw-r--r--src/clients/adjutrix/find_reverse_deps.cc16
-rw-r--r--src/clients/adjutrix/keywords_graph.cc12
-rw-r--r--src/clients/adjutrix/what_needs_keywording.cc4
-rw-r--r--src/clients/contrarius/stage.cc54
-rw-r--r--src/clients/gtkpaludis/libgtkpaludis/categories_list_model.cc6
-rw-r--r--src/clients/gtkpaludis/libgtkpaludis/messages_page.cc1
-rw-r--r--src/clients/gtkpaludis/libgtkpaludis/packages_list_model.cc58
-rw-r--r--src/clients/gtkpaludis/libgtkpaludis/packages_package_filter.cc1
-rw-r--r--src/clients/gtkpaludis/libgtkpaludis/packages_package_filter_model.cc2
-rw-r--r--src/clients/gtkpaludis/libgtkpaludis/packages_page.cc9
-rw-r--r--src/clients/gtkpaludis/libgtkpaludis/packages_page.hh6
-rw-r--r--src/clients/gtkpaludis/libgtkpaludis/packages_repository_filter.cc6
-rw-r--r--src/clients/gtkpaludis/libgtkpaludis/packages_repository_filter_model.cc15
-rw-r--r--src/clients/gtkpaludis/libgtkpaludis/packages_repository_filter_model.hh5
-rw-r--r--src/clients/gtkpaludis/libgtkpaludis/packages_text_filter_source.cc2
-rw-r--r--src/clients/gtkpaludis/libgtkpaludis/packages_text_filter_source_model.cc2
-rw-r--r--src/clients/gtkpaludis/libgtkpaludis/sets_list_model.cc6
-rw-r--r--src/clients/gtkpaludis/libgtkpaludis/version_info_model.cc1
-rw-r--r--src/clients/gtkpaludis/libgtkpaludis/versions_list_model.cc10
-rw-r--r--src/clients/importare/importare.cc8
-rw-r--r--src/clients/importare/install.cc1
-rw-r--r--src/clients/inquisitio/do_search.cc1
-rw-r--r--src/clients/instruo/instruo.cc9
-rw-r--r--src/clients/paludis/applets.cc18
-rw-r--r--src/clients/paludis/do_config.cc6
-rw-r--r--src/clients/paludis/do_contents.cc7
-rw-r--r--src/clients/paludis/do_executables.cc7
-rw-r--r--src/clients/paludis/info.cc16
-rw-r--r--src/clients/paludis/install.cc1
-rw-r--r--src/clients/paludis/query.cc3
-rw-r--r--src/clients/paludis/uninstall.cc6
-rw-r--r--src/clients/reconcilio/broken_linkage_finder/broken_linkage_finder.cc12
-rw-r--r--src/output/console_install_task.cc59
-rw-r--r--src/output/console_query_task.cc11
-rw-r--r--test/Makefile.am6
-rw-r--r--test/test_concepts.hh56
188 files changed, 6398 insertions, 4277 deletions
diff --git a/NEWS b/NEWS
index c1f0595..277cb1d 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,9 @@ trunk/:
(ticket:568). Symlink rewriting now works when builddir contains symlinks
(ticket:571). The dreaded Ruby bindings segfaults are fixed (ticket:558).
+ * New Selection + Filter + Generator interface using Environment, replacing
+ the old PackageDatabase Query (ticket:559).
+
0.26.1:
* Bug fix: if we install a directory using rename(), call utime() on all
file children.
diff --git a/doc/api/cplusplus/examples/Makefile.am b/doc/api/cplusplus/examples/Makefile.am
index 789621e..c6b51c4 100644
--- a/doc/api/cplusplus/examples/Makefile.am
+++ b/doc/api/cplusplus/examples/Makefile.am
@@ -26,9 +26,8 @@ noinst_PROGRAMS = \
example_mask \
example_repository \
example_match_package \
- example_query \
- example_query_delegate \
example_package_database \
+ example_selection \
example_version_operator \
example_version_spec \
example_name
@@ -138,14 +137,8 @@ example_match_package_LDADD = \
$(top_builddir)/paludis/libpaludis.la \
$(top_builddir)/paludis/args/libpaludisargs.la
-example_query_delegate_SOURCES = example_query_delegate.cc
-example_query_delegate_LDADD = \
- libpaludisexamples.a \
- $(top_builddir)/paludis/libpaludis.la \
- $(top_builddir)/paludis/args/libpaludisargs.la
-
-example_query_SOURCES = example_query.cc
-example_query_LDADD = \
+example_selection_SOURCES = example_selection.cc
+example_selection_LDADD = \
libpaludisexamples.a \
$(top_builddir)/paludis/libpaludis.la \
$(top_builddir)/paludis/args/libpaludisargs.la
diff --git a/doc/api/cplusplus/examples/example_action.cc b/doc/api/cplusplus/examples/example_action.cc
index 4faa5b6..34576af 100644
--- a/doc/api/cplusplus/examples/example_action.cc
+++ b/doc/api/cplusplus/examples/example_action.cc
@@ -37,9 +37,8 @@ int main(int argc, char * argv[])
CommandLine::get_instance()->a_environment.argument()));
/* Fetch package IDs for 'sys-apps/paludis'. */
- std::tr1::shared_ptr<const PackageIDSequence> ids(env->package_database()->query(
- query::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))),
- qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsSorted(
+ generator::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))))]);
/* For each ID: */
for (PackageIDSet::ConstIterator i(ids->begin()), i_end(ids->end()) ;
diff --git a/doc/api/cplusplus/examples/example_contents.cc b/doc/api/cplusplus/examples/example_contents.cc
index 69f956d..3997103 100644
--- a/doc/api/cplusplus/examples/example_contents.cc
+++ b/doc/api/cplusplus/examples/example_contents.cc
@@ -79,10 +79,9 @@ int main(int argc, char * argv[])
CommandLine::get_instance()->a_environment.argument()));
/* Fetch package IDs for installed 'sys-apps/paludis'. */
- std::tr1::shared_ptr<const PackageIDSequence> ids(env->package_database()->query(
- query::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))) &
- query::SupportsAction<InstalledAction>(),
- qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsSorted(
+ generator::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))) |
+ filter::SupportsAction<InstalledAction>())]);
/* For each ID: */
for (PackageIDSet::ConstIterator i(ids->begin()), i_end(ids->end()) ;
diff --git a/doc/api/cplusplus/examples/example_dep_label.cc b/doc/api/cplusplus/examples/example_dep_label.cc
index fd4d093..3c26f1a 100644
--- a/doc/api/cplusplus/examples/example_dep_label.cc
+++ b/doc/api/cplusplus/examples/example_dep_label.cc
@@ -159,9 +159,8 @@ int main(int argc, char * argv[])
CommandLine::get_instance()->a_environment.argument()));
/* Fetch package IDs for all installed packages. */
- std::tr1::shared_ptr<const PackageIDSequence> ids(env->package_database()->query(
- query::SupportsAction<InstalledAction>(),
- qo_whatever));
+ std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsUnsorted(
+ generator::All() | filter::SupportsAction<InstalledAction>())]);
/* Store a map from distfile name to whether it is fetch restricted. */
ResultsMap results;
diff --git a/doc/api/cplusplus/examples/example_dep_spec.cc b/doc/api/cplusplus/examples/example_dep_spec.cc
index 85084a3..83a4b12 100644
--- a/doc/api/cplusplus/examples/example_dep_spec.cc
+++ b/doc/api/cplusplus/examples/example_dep_spec.cc
@@ -122,8 +122,7 @@ int main(int argc, char * argv[])
/* And display packages matching that spec */
cout << " " << left << setw(24) << "Matches:" << " ";
- std::tr1::shared_ptr<const PackageIDSequence> ids(
- env->package_database()->query(query::Matches(spec), qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsSorted(generator::Matches(spec))]);
bool need_indent(false);
for (PackageIDSequence::ConstIterator i(ids->begin()), i_end(ids->end()) ;
i != i_end ; ++i)
diff --git a/doc/api/cplusplus/examples/example_dep_spec_flattener.cc b/doc/api/cplusplus/examples/example_dep_spec_flattener.cc
index 52eb8b2..9d3f73a 100644
--- a/doc/api/cplusplus/examples/example_dep_spec_flattener.cc
+++ b/doc/api/cplusplus/examples/example_dep_spec_flattener.cc
@@ -42,10 +42,8 @@ int main(int argc, char * argv[])
CommandLine::get_instance()->a_environment.argument()));
/* Fetch package IDs for all installed packages. */
- std::tr1::shared_ptr<const PackageIDSequence> ids(
- env->package_database()->query(
- query::SupportsAction<InstalledAction>(),
- qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsSorted(
+ generator::All() | filter::SupportsAction<InstalledAction>())]);
/* For each ID: */
for (PackageIDSequence::ConstIterator i(ids->begin()), i_end(ids->end()) ;
diff --git a/doc/api/cplusplus/examples/example_dep_tree.cc b/doc/api/cplusplus/examples/example_dep_tree.cc
index 6a8c518..5b2d74d 100644
--- a/doc/api/cplusplus/examples/example_dep_tree.cc
+++ b/doc/api/cplusplus/examples/example_dep_tree.cc
@@ -194,9 +194,8 @@ int main(int argc, char * argv[])
CommandLine::get_instance()->a_environment.argument()));
/* Fetch package IDs for all installed packages. */
- std::tr1::shared_ptr<const PackageIDSequence> ids(env->package_database()->query(
- query::SupportsAction<InstalledAction>(),
- qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsSorted(
+ generator::All() | filter::SupportsAction<InstalledAction>())]);
ResultsMap results;
diff --git a/doc/api/cplusplus/examples/example_environment.cc b/doc/api/cplusplus/examples/example_environment.cc
index dd4cc8b..7ace844 100644
--- a/doc/api/cplusplus/examples/example_environment.cc
+++ b/doc/api/cplusplus/examples/example_environment.cc
@@ -49,10 +49,12 @@ int main(int argc, char * argv[])
/* A lot of the Environment members aren't very useful to clients. The
* mask related methods are used by PackageID, and shouldn't usually be
* called directly from clients. The system information and mirror
- * functions are mostly for use by Repository subclasses. That leaves
- * the package database, sets and (currently, although this may well
- * change in the future) use flag queries. The package database has its
- * own examples, so we'll start with sets: */
+ * functions are mostly for use by Repository subclasses. The []
+ * operator is covered in \ref example_selection.cc
+ * "example_selection.cc". That leaves the package database, sets and
+ * (currently, although this may well change in the future) use flag
+ * queries. The package database has its own examples, so we'll start
+ * with sets: */
std::tr1::shared_ptr<SetSpecTree::ConstItem> world(env->set(SetName("world")));
if (world)
@@ -65,10 +67,9 @@ int main(int argc, char * argv[])
cout << "No world set defined" << endl;
/* And use flags, for which we need a package IDs: */
- std::tr1::shared_ptr<const PackageIDSequence> ids(env->package_database()->query(
- query::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))) &
- query::SupportsAction<InstalledAction>(),
- qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::BestVersionOnly(
+ generator::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))) |
+ filter::SupportsAction<InstalledAction>())]);
if (! ids->empty())
{
diff --git a/doc/api/cplusplus/examples/example_formatter.cc b/doc/api/cplusplus/examples/example_formatter.cc
index 1e963be..164d2b0 100644
--- a/doc/api/cplusplus/examples/example_formatter.cc
+++ b/doc/api/cplusplus/examples/example_formatter.cc
@@ -159,10 +159,9 @@ int main(int argc, char * argv[])
CommandLine::get_instance()->a_environment.argument()));
/* Fetch package IDs for installable 'sys-apps/paludis'. */
- std::tr1::shared_ptr<const PackageIDSequence> ids(env->package_database()->query(
- query::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))) &
- query::SupportsAction<InstallAction>(),
- qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsSorted(
+ generator::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))) |
+ filter::SupportsAction<InstallAction>())]);
/* Write nice valid XHTML, because we're good like that. */
cout << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" << endl;
diff --git a/doc/api/cplusplus/examples/example_mask.cc b/doc/api/cplusplus/examples/example_mask.cc
index 1461346..45e0318 100644
--- a/doc/api/cplusplus/examples/example_mask.cc
+++ b/doc/api/cplusplus/examples/example_mask.cc
@@ -84,9 +84,8 @@ int main(int argc, char * argv[])
CommandLine::get_instance()->a_environment.argument()));
/* Fetch package IDs for 'sys-apps/paludis'. */
- std::tr1::shared_ptr<const PackageIDSequence> ids(env->package_database()->query(
- query::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))),
- qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsSorted(
+ generator::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))))]);
/* For each ID: */
for (PackageIDSet::ConstIterator i(ids->begin()), i_end(ids->end()) ;
diff --git a/doc/api/cplusplus/examples/example_match_package.cc b/doc/api/cplusplus/examples/example_match_package.cc
index 09266ba..7cd7b06 100644
--- a/doc/api/cplusplus/examples/example_match_package.cc
+++ b/doc/api/cplusplus/examples/example_match_package.cc
@@ -40,9 +40,8 @@ int main(int argc, char * argv[])
CommandLine::get_instance()->a_environment.argument()));
/* Fetch all installed packages. */
- std::tr1::shared_ptr<const PackageIDSequence> ids(env->package_database()->query(
- query::SupportsAction<InstalledAction>(),
- qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsSorted(
+ generator::All() | filter::SupportsAction<InstalledAction>())]);
/* Fetch the 'system' and 'world' sets. Ordinarily we should check for
* zero pointers here, but these two sets will always exist. */
diff --git a/doc/api/cplusplus/examples/example_metadata_key.cc b/doc/api/cplusplus/examples/example_metadata_key.cc
index a5e2379..725e5f1 100644
--- a/doc/api/cplusplus/examples/example_metadata_key.cc
+++ b/doc/api/cplusplus/examples/example_metadata_key.cc
@@ -259,9 +259,8 @@ int main(int argc, char * argv[])
CommandLine::get_instance()->a_environment.argument()));
/* Fetch package IDs for 'sys-apps/paludis'. */
- std::tr1::shared_ptr<const PackageIDSequence> ids(env->package_database()->query(
- query::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))),
- qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsSorted(
+ generator::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))))]);
/* For each ID: */
for (PackageIDSet::ConstIterator i(ids->begin()), i_end(ids->end()) ;
diff --git a/doc/api/cplusplus/examples/example_package_database.cc b/doc/api/cplusplus/examples/example_package_database.cc
index 0aaaba8..d8cd411 100644
--- a/doc/api/cplusplus/examples/example_package_database.cc
+++ b/doc/api/cplusplus/examples/example_package_database.cc
@@ -40,8 +40,7 @@ int main(int argc, char * argv[])
std::tr1::shared_ptr<Environment> env(EnvironmentMaker::get_instance()->make_from_spec(
CommandLine::get_instance()->a_environment.argument()));
- /* The most useful PackageDatabase method is PackageDatabase::query,
- * which is covered in other examples. But there are others: */
+ /* Mostly PackageDatabase is used by Environment. But some methods are useful: */
if (env->package_database()->has_repository_named(RepositoryName("gentoo")))
{
std::tr1::shared_ptr<const Repository> repo(env->package_database()->fetch_repository(RepositoryName("gentoo")));
diff --git a/doc/api/cplusplus/examples/example_package_id.cc b/doc/api/cplusplus/examples/example_package_id.cc
index 0ab51fc..45df420 100644
--- a/doc/api/cplusplus/examples/example_package_id.cc
+++ b/doc/api/cplusplus/examples/example_package_id.cc
@@ -46,9 +46,8 @@ int main(int argc, char * argv[])
CommandLine::get_instance()->a_environment.argument()));
/* Fetch package IDs for 'sys-apps/paludis'. */
- std::tr1::shared_ptr<const PackageIDSequence> ids(env->package_database()->query(
- query::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))),
- qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsSorted(
+ generator::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))))]);
/* For each ID: */
for (PackageIDSet::ConstIterator i(ids->begin()), i_end(ids->end()) ;
@@ -123,7 +122,9 @@ int main(int argc, char * argv[])
/* And various misc methods. Clients don't usually use these
* directly. */
- cout << left << setw(30) << " breaks_portage:" << " " << boolalpha << (*i)->breaks_portage() << endl;
+ std::tr1::shared_ptr<const Set<std::string> > breaks_portage((*i)->breaks_portage());
+ cout << left << setw(30) << " breaks_portage:" << " " << join(breaks_portage->begin(),
+ breaks_portage->end(), ", ") << endl;
cout << left << setw(30) << " extra_hash_value:" << " " << "0x" << hex << (*i)->extra_hash_value() << endl;
cout << endl;
diff --git a/doc/api/cplusplus/examples/example_query.cc b/doc/api/cplusplus/examples/example_query.cc
deleted file mode 100644
index 3640c5f..0000000
--- a/doc/api/cplusplus/examples/example_query.cc
+++ /dev/null
@@ -1,108 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/** \file
- *
- * Example \ref example_query.cc "example_query.cc" .
- *
- * \ingroup g_query
- */
-
-/** \example example_query.cc
- *
- * This example demonstrates how to use the standard Query classes. For custom
- * Query subclasses, see \ref example_query_delegate.cc
- * "example_query_delegate.cc".
- */
-
-#include <paludis/paludis.hh>
-#include "example_command_line.hh"
-#include <iostream>
-#include <algorithm>
-#include <iterator>
-
-using namespace paludis;
-using namespace examples;
-
-using std::cout;
-using std::endl;
-
-namespace
-{
- /* Run a particular query, and show its results. */
- void show_query(const std::tr1::shared_ptr<const Environment> & env, const Query & query)
- {
- /* Queries support a crude form of stringification. */
- cout << query << ":" << endl;
-
- /* Usually the only thing clients will do with a Query object is pass it
- * to PackageDatabase::query. */
- std::tr1::shared_ptr<const PackageIDSequence> ids(env->package_database()->query(query, qo_order_by_version));
-
- /* Show the results */
- if (! ids->empty())
- std::copy(indirect_iterator(ids->begin()), indirect_iterator(ids->end()),
- std::ostream_iterator<const PackageID>(cout, "\n"));
- cout << endl;
- }
-}
-
-int main(int argc, char * argv[])
-{
- int exit_status(0);
-
- try
- {
- CommandLine::get_instance()->run(argc, argv,
- "example_action", "EXAMPLE_ACTION_OPTIONS", "EXAMPLE_ACTION_CMDLINE");
-
- /* We start with an Environment, respecting the user's '--environment' choice. */
- std::tr1::shared_ptr<Environment> env(EnvironmentMaker::get_instance()->make_from_spec(
- CommandLine::get_instance()->a_environment.argument()));
-
- /* Make some queries, and display what they give. */
- show_query(env, query::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))));
-
- /* Queries can be combined. The resulting query is optimised internally,
- * potentially giving better performance than doing things by hand. */
- show_query(env,
- query::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))) &
- query::SupportsAction<InstalledAction>());
-
- /* Usually query::NotMasked should be combined with
- * query::SupportsAction<InstallAction>, since installed packages aren't
- * masked. */
- show_query(env,
- query::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))) &
- query::SupportsAction<InstallAction>() &
- query::NotMasked());
-
- }
- catch (const Exception & e)
- {
- /* Paludis exceptions can provide a handy human-readable backtrace and
- * an explanation message. Where possible, these should be displayed. */
- cout << endl;
- cout << "Unhandled exception:" << endl
- << " * " << e.backtrace("\n * ")
- << e.message() << " (" << e.what() << ")" << endl;
- return EXIT_FAILURE;
- }
- catch (const std::exception & e)
- {
- cout << endl;
- cout << "Unhandled exception:" << endl
- << " * " << e.what() << endl;
- return EXIT_FAILURE;
- }
- catch (...)
- {
- cout << endl;
- cout << "Unhandled exception:" << endl
- << " * Unknown exception type. Ouch..." << endl;
- return EXIT_FAILURE;
- }
-
- return exit_status;
-}
-
-
diff --git a/doc/api/cplusplus/examples/example_query_delegate.cc b/doc/api/cplusplus/examples/example_query_delegate.cc
deleted file mode 100644
index f325dba..0000000
--- a/doc/api/cplusplus/examples/example_query_delegate.cc
+++ /dev/null
@@ -1,165 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/** \file
- *
- * Example \ref example_query_delegate.cc "example_query_delegate.cc" .
- *
- * \ingroup g_query
- */
-
-/** \example example_query_delegate.cc
- *
- * This example demonstrates how to implement a new Query classes. For standard
- * Query classes, see \ref example_query.cc "example_query.cc".
- */
-
-#include <paludis/paludis.hh>
-#include "example_command_line.hh"
-#include <iostream>
-#include <algorithm>
-#include <iterator>
-
-using namespace paludis;
-using namespace examples;
-
-using std::cout;
-using std::endl;
-
-namespace
-{
- /* To implement a custom query, we need two classes. First, the delegate.
- * We only override the QueryDelegate::ids function, since we can't be more
- * helpful at earlier levels. */
- class DescriptionContainsDelegate :
- public QueryDelegate
- {
- private:
- const std::string _pattern;
-
- public:
- DescriptionContainsDelegate(const std::string & pattern) :
- _pattern(pattern)
- {
- }
-
- 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);
-
- /* We have to iterate over every repository by hand... */
- for (RepositoryNameSequence::ConstIterator r(repos->begin()), r_end(repos->end()) ;
- r != r_end ; ++r)
- {
- /* And from each repository, we iterate over packages by
- * hand... */
- 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)
- {
- /* And finally, IDs by hand... */
- 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)
- {
- /* Does our description contain the pattern? We must
- * check for a zero pointer. */
- if ((*v)->short_description_key())
- if (std::string::npos != (*v)->short_description_key()->value().find(_pattern))
- result->push_back(*v);
- }
- }
- }
-
- return result;
- }
-
- std::string
- as_human_readable_string() const
- {
- return "description contains '" + _pattern + "'";
- }
- };
-
- /* Then we implement the Query itself. */
- class DescriptionContains :
- public Query
- {
- public:
- DescriptionContains(const std::string & pattern) :
- Query(std::tr1::shared_ptr<QueryDelegate>(new DescriptionContainsDelegate(pattern)))
- {
- }
- };
-
- /* Run a particular query, and show its results. */
- void show_query(const std::tr1::shared_ptr<const Environment> & env, const Query & query)
- {
- /* Queries support a crude form of stringification. */
- cout << query << ":" << endl;
-
- /* Usually the only thing clients will do with a Query object is pass it
- * to PackageDatabase::query. */
- std::tr1::shared_ptr<const PackageIDSequence> ids(env->package_database()->query(query, qo_order_by_version));
-
- /* Show the results */
- if (! ids->empty())
- std::copy(indirect_iterator(ids->begin()), indirect_iterator(ids->end()),
- std::ostream_iterator<const PackageID>(cout, "\n"));
- cout << endl;
- }
-}
-
-int main(int argc, char * argv[])
-{
- int exit_status(0);
-
- try
- {
- CommandLine::get_instance()->run(argc, argv,
- "example_query_delegate", "EXAMPLE_QUERY_DELEGATE", "EXAMPLE_QUERY_DELEGATE");
-
- /* We start with an Environment, respecting the user's '--environment' choice. */
- std::tr1::shared_ptr<Environment> env(EnvironmentMaker::get_instance()->make_from_spec(
- CommandLine::get_instance()->a_environment.argument()));
-
- /* Make some queries, and display what they give. */
- show_query(env, DescriptionContains("duck"));
-
- /* We can combine custom queries too. */
- show_query(env,
- query::SupportsAction<InstalledAction>() &
- DescriptionContains("cow"));
- }
- catch (const Exception & e)
- {
- /* Paludis exceptions can provide a handy human-readable backtrace and
- * an explanation message. Where possible, these should be displayed. */
- cout << endl;
- cout << "Unhandled exception:" << endl
- << " * " << e.backtrace("\n * ")
- << e.message() << " (" << e.what() << ")" << endl;
- return EXIT_FAILURE;
- }
- catch (const std::exception & e)
- {
- cout << endl;
- cout << "Unhandled exception:" << endl
- << " * " << e.what() << endl;
- return EXIT_FAILURE;
- }
- catch (...)
- {
- cout << endl;
- cout << "Unhandled exception:" << endl
- << " * Unknown exception type. Ouch..." << endl;
- return EXIT_FAILURE;
- }
-
- return exit_status;
-}
-
-
-
diff --git a/doc/api/cplusplus/examples/example_selection.cc b/doc/api/cplusplus/examples/example_selection.cc
new file mode 100644
index 0000000..4059009
--- /dev/null
+++ b/doc/api/cplusplus/examples/example_selection.cc
@@ -0,0 +1,117 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/** \file
+ *
+ * Example \ref example_selection.cc "example_selection.cc" .
+ *
+ * \ingroup g_selection
+ */
+
+/** \example example_selection.cc
+ *
+ * This example demonstrates how to use the standard Selection, Generator and
+ * Filter classes.
+ **/
+
+#include <paludis/paludis.hh>
+#include "example_command_line.hh"
+#include <iostream>
+#include <algorithm>
+#include <iterator>
+
+using namespace paludis;
+using namespace examples;
+
+using std::cout;
+using std::endl;
+
+namespace
+{
+ /* Run a particular selection, and show its results. */
+ void show_selection(const std::tr1::shared_ptr<const Environment> & env, const Selection & query)
+ {
+ /* Selections support a crude form of stringification. */
+ cout << query << ":" << endl;
+
+ /* Usually the only thing clients will do with a Query object is pass it
+ * to Environment::operator[]. */
+ std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[query]);
+
+ /* Show the results */
+ if (! ids->empty())
+ std::copy(indirect_iterator(ids->begin()), indirect_iterator(ids->end()),
+ std::ostream_iterator<const PackageID>(cout, "\n"));
+ cout << endl;
+ }
+}
+
+int main(int argc, char * argv[])
+{
+ int exit_status(0);
+
+ try
+ {
+ CommandLine::get_instance()->run(argc, argv,
+ "example_selection", "EXAMPLE_SELECTION_OPTIONS", "EXAMPLE_SELECTION_CMDLINE");
+
+ /* We start with an Environment, respecting the user's '--environment' choice. */
+ std::tr1::shared_ptr<Environment> env(EnvironmentMaker::get_instance()->make_from_spec(
+ CommandLine::get_instance()->a_environment.argument()));
+
+ /* Make some selections, and display what they give. The selection
+ * object used determines the number and ordering of results. In the
+ * simplest form, it takes a Generator as a parameter. */
+ show_selection(env, selection::AllVersionsSorted(
+ generator::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis")))));
+
+ /* Generators can be passed through a Filter. The Selection optimises
+ * the code internally to avoid doing excess work. */
+ show_selection(env, selection::AllVersionsSorted(
+ generator::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))) |
+ filter::SupportsAction<InstalledAction>()));
+
+ /* Filters can be combined. Usually filter::NotMasked should be combined
+ * with filter::SupportsAction<InstallAction>, since installed packages
+ * aren't masked. */
+ show_selection(env, selection::AllVersionsSorted(
+ generator::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))) |
+ filter::SupportsAction<InstallAction>() |
+ filter::NotMasked()));
+
+ /* selection::AllVersionsSorted can be expensive, particularly if there
+ * is no metadata cache. Consider using other Selection objects if
+ * you only need the best matching or some arbitrary matching ID. */
+ show_selection(env, selection::BestVersionOnly(
+ generator::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))) |
+ filter::SupportsAction<InstallAction>() |
+ filter::NotMasked()));
+ }
+ catch (const Exception & e)
+ {
+ /* Paludis exceptions can provide a handy human-readable backtrace and
+ * an explanation message. Where possible, these should be displayed. */
+ cout << endl;
+ cout << "Unhandled exception:" << endl
+ << " * " << e.backtrace("\n * ")
+ << e.message() << " (" << e.what() << ")" << endl;
+ return EXIT_FAILURE;
+ }
+ catch (const std::exception & e)
+ {
+ cout << endl;
+ cout << "Unhandled exception:" << endl
+ << " * " << e.what() << endl;
+ return EXIT_FAILURE;
+ }
+ catch (...)
+ {
+ cout << endl;
+ cout << "Unhandled exception:" << endl
+ << " * Unknown exception type. Ouch..." << endl;
+ return EXIT_FAILURE;
+ }
+
+ return exit_status;
+}
+
+
diff --git a/doc/api/cplusplus/examples/example_stringify_formatter.cc b/doc/api/cplusplus/examples/example_stringify_formatter.cc
index 298da78..8c92d00 100644
--- a/doc/api/cplusplus/examples/example_stringify_formatter.cc
+++ b/doc/api/cplusplus/examples/example_stringify_formatter.cc
@@ -38,10 +38,9 @@ int main(int argc, char * argv[])
CommandLine::get_instance()->a_environment.argument()));
/* Fetch package IDs for installable 'sys-apps/paludis'. */
- std::tr1::shared_ptr<const PackageIDSequence> ids(env->package_database()->query(
- query::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))) &
- query::SupportsAction<InstallAction>(),
- qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsSorted(
+ generator::Matches(make_package_dep_spec().package(QualifiedPackageName("sys-apps/paludis"))) |
+ filter::SupportsAction<InstallAction>())]);
/* For each ID: */
for (PackageIDSet::ConstIterator i(ids->begin()), i_end(ids->end()) ;
diff --git a/doc/api/cplusplus/groups.doxygen b/doc/api/cplusplus/groups.doxygen
index 8c89c77..a29b187 100644
--- a/doc/api/cplusplus/groups.doxygen
+++ b/doc/api/cplusplus/groups.doxygen
@@ -79,6 +79,7 @@ using namespace paludis;
* \section Examples
*
* - \ref example_environment.cc "example_environment.cc"
+ * - \ref example_selection.cc "example_selection.cc"
*/
/** \defgroup g_exceptions Exceptions
@@ -155,32 +156,16 @@ using namespace paludis;
* - \ref example_repository.cc "example_repository.cc"
*/
-/** \defgroup g_query Query
- *
- * \ingroup g_package_database
- *
- * Queries are used by PackageDatabase::query. They provide a flexible, mergeable,
- * efficient way of specifying which IDs should be returned in the result.
- *
- * \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"
- */
-
/** \defgroup g_package_database Package Database
*
* \ingroup g_paludis
*
* A PackageDatabase, which is owned by an Environment, contains a number of
- * Repository instances and supports various querying methods.
+ * Repository instances.
*
* \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"
*/
/** \defgroup g_names Names and Versions
diff --git a/doc/api/ruby/Makefile.am b/doc/api/ruby/Makefile.am
index da1a920..37250d1 100644
--- a/doc/api/ruby/Makefile.am
+++ b/doc/api/ruby/Makefile.am
@@ -27,14 +27,12 @@ examples = \
example_action.rb \
example_command_line.rb \
example_contents.rb \
- example_dep_spec.rb \
example_dep_tree.rb \
example_environment.rb \
example_package_database.rb \
example_package_id.rb \
example_mask.rb \
example_match_package.rb \
- example_query.rb \
example_repository.rb \
example_version_operator.rb \
example_version_spec.rb
diff --git a/doc/api/ruby/example_action.rb b/doc/api/ruby/example_action.rb
index ca299c2..f1d754e 100644
--- a/doc/api/ruby/example_action.rb
+++ b/doc/api/ruby/example_action.rb
@@ -17,9 +17,8 @@ exit_status = 0
env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment)
# Fetch package IDs for 'sys-apps/paludis'
-ids = env.package_database.query(
- Query::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])),
- QueryOrder::OrderByVersion)
+ids = env[Selection::AllVersionsSorted.new(Generator::Matches.new(
+ Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])))]
# For each ID:
ids.each do | id |
diff --git a/doc/api/ruby/example_contents.rb b/doc/api/ruby/example_contents.rb
index 7020850..c6a4b9b 100644
--- a/doc/api/ruby/example_contents.rb
+++ b/doc/api/ruby/example_contents.rb
@@ -17,10 +17,9 @@ exit_status = 0
env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment)
# Fetch package IDs for installed 'sys-apps/paludis'
-ids = env.package_database.query(
- Query::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])) &
- Query::SupportsInstalledAction.new,
- QueryOrder::OrderByVersion)
+ids = env[Selection::AllVersionsSorted.new(
+ Generator::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])) |
+ Filter::SupportsAction.new(InstalledAction))]
# For each ID:
ids.each do | id |
diff --git a/doc/api/ruby/example_dep_spec.rb b/doc/api/ruby/example_dep_spec.rb
deleted file mode 100644
index 29b0e4a..0000000
--- a/doc/api/ruby/example_dep_spec.rb
+++ /dev/null
@@ -1,101 +0,0 @@
-#!/usr/bin/env ruby
-# vim: set sw=4 sts=4 et tw=100 :
-
-=begin description
-This example demonstrates how to handle dependency specs.
-=end
-
-require 'Paludis'
-require 'example_command_line'
-
-include Paludis
-
-exit_status = 0
-
-# We start with an Environment, respecting the user's '--environment' choice.
-env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment)
-
-# For each command line parameter:
-ARGV.each do | arg |
- # Create a PackageDepSpec from the parameter. The second parameter should be either
- # an empty array or [:allow_wildcards].
- spec = Paludis::parse_user_package_dep_spec(arg, [:allow_wildcards])
-
- # Display information about the PackageDepSpec.
- puts "Information about '#{spec}':"
-
- if spec.package
- puts " Package: #{spec.package}"
- end
-
- if spec.category_name_part
- puts " Category part: #{spec.category_name_part}"
- end
-
- if spec.package_name_part
- puts " Package part: #{spec.package_name_part}"
- end
-
- if spec.version_requirements and not spec.version_requirements.empty?
- print " Version requirements: "
- need_join = false
- spec.version_requirements.each do | r |
- if need_join
- case spec.version_requirements_mode
- when VersionRequirementsMode::And
- print " and "
- when VersionRequirementsMode::Or
- print " or "
- end
- end
-
- print r[:operator], r[:spec]
- need_join = true
- end
- puts
- end
-
- if spec.slot
- puts " Slot: #{spec.slot}"
- end
-
- if spec.repository
- puts " Repository: #{spec.repository}"
- end
-
- if spec.use_requirements and not spec.use_requirements.empty?
- print " Use requirements: "
- need_join = false
- spec.use_requirements.each do | u |
- if need_join
- print " and "
- end
-
- if not u[:state]
- print "-"
- end
-
- print u[:flag]
- need_join = true;
- end
- puts
- end
-
- # And display packages matching that spec
- print " Matches: "
- ids = env.package_database.query(Query::Matches.new(spec), QueryOrder::OrderByVersion)
- need_indent = false
- ids.each do | id |
- if need_indent
- puts
- print " "
- end
- print id
- need_indent = true
- end
- puts
- puts
-end
-
-exit exit_status
-
diff --git a/doc/api/ruby/example_dep_tree.rb b/doc/api/ruby/example_dep_tree.rb
index 40acc96..bddbdcc 100644
--- a/doc/api/ruby/example_dep_tree.rb
+++ b/doc/api/ruby/example_dep_tree.rb
@@ -115,8 +115,8 @@ end
env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment)
# Fetch package IDs for all installed packages.
-ids = env.package_database.query(
- Query::SupportsInstalledAction.new, QueryOrder::OrderByVersion)
+ids = env[Selection::AllVersionsSorted.new(
+ Generator::All.new | Filter::SupportsAction.new(InstalledAction))]
# Our results table, mapping the ID to { :has_dep => ?, :has_ext => ? }
results = { }
diff --git a/doc/api/ruby/example_environment.rb b/doc/api/ruby/example_environment.rb
index 888522e..80b5b0f 100644
--- a/doc/api/ruby/example_environment.rb
+++ b/doc/api/ruby/example_environment.rb
@@ -23,17 +23,16 @@ exit_status = 0
# environment's constructor.
env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment)
-# A lot of the Environment members aren't very useful to clients. The
-# mask related methods are used by PackageID, and shouldn't usually be
-# called directly from clients. The system information and mirror
-# functions are mostly for use by Repository subclasses. That leaves
-# the package database, sets and (currently, although this may well
-# change in the future) use flag queries. The package database has its
-# own examples, so we'll start with sets:
+# A lot of the Environment members aren't very useful to clients. The mask
+# related methods are used by PackageID, and shouldn't usually be called
+# directly from clients. The system information and mirror functions are mostly
+# for use by Repository subclasses. The [] operator, for selections, is covered
+# in other examples. That leaves the package database, sets and (currently,
+# although this may well change in the future) use flag queries. The package
+# database has its own examples, so we'll start with sets:
world = env.set('world')
if (world)
-
# see examples_dep_tree.rb for how to make use of this set
puts "World set exists"
else
@@ -41,13 +40,13 @@ else
end
# And use flags, for which we need package IDs:
-ids = env.package_database.query(
- Query::Matches.new(Paludis::parse_user_package_dep_spec('sys-apps/paludis', [])) &
- Query::SupportsInstalledAction.new,
- QueryOrder::OrderByVersion)
+ids = env[Selection::AllVersionsSorted.new(
+ Generator::Matches.new(Paludis::parse_user_package_dep_spec('sys-apps/paludis', [])) |
+ Filter::SupportsAction.new(InstalledAction))]
if (ids.length > 0)
id = ids.last
print "Use flag 'ruby' for ID '#{id.to_s}' is "
puts env.query_use('ruby', id) ? 'enabled' : 'disabled'
end
+
diff --git a/doc/api/ruby/example_mask.rb b/doc/api/ruby/example_mask.rb
index 1213051..19c0a6b 100644
--- a/doc/api/ruby/example_mask.rb
+++ b/doc/api/ruby/example_mask.rb
@@ -17,9 +17,8 @@ exit_status = 0
env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment)
# Fetch package IDs for 'sys-apps/paludis'
-ids = env.package_database.query(
- Query::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])),
- QueryOrder::OrderByVersion)
+ids = env[Selection::AllVersionsSorted.new(
+ Generator::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])))]
# For each ID:
ids.each do | id |
diff --git a/doc/api/ruby/example_match_package.rb b/doc/api/ruby/example_match_package.rb
index 0c0d359..61788d1 100644
--- a/doc/api/ruby/example_match_package.rb
+++ b/doc/api/ruby/example_match_package.rb
@@ -17,7 +17,8 @@ exit_status = 0
env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment)
# Fetch all installed packages
-ids = env.package_database.query(Query::SupportsInstalledAction.new, QueryOrder::OrderByVersion);
+ids = env[Selection::AllVersionsSorted.new(
+ Generator::All.new | Filter::SupportsAction.new(InstalledAction))]
# Fetch the 'system' and 'world' sets. Ordinarily we should check for
# Nil here, but these two sets will always exist.
diff --git a/doc/api/ruby/example_package_database.rb b/doc/api/ruby/example_package_database.rb
index 913d202..5201d4d 100644
--- a/doc/api/ruby/example_package_database.rb
+++ b/doc/api/ruby/example_package_database.rb
@@ -16,8 +16,7 @@ exit_status = 0
# We start with an Environment, respecting the user's '--environment' choice.
env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment)
-# The most useful PackageDatabase method is PackageDatabase::query,
-# which is covered in other examples. But there are others:
+# Mostly PackageDatabase is used by Environment. But other methods are useful:
if env.package_database.has_repository_named?('gentoo')
repo = env.package_database.fetch_repository('gentoo')
puts "Repository 'gentoo' exists, and has format '" +
diff --git a/doc/api/ruby/example_package_id.rb b/doc/api/ruby/example_package_id.rb
index 68e48de..8fa10a9 100644
--- a/doc/api/ruby/example_package_id.rb
+++ b/doc/api/ruby/example_package_id.rb
@@ -19,9 +19,8 @@ exit_status = 0
env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment)
# Fetch package IDs for installed 'sys-apps/paludis'
-ids = env.package_database.query(
- Query::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])),
- QueryOrder::OrderByVersion)
+ids = env[Selection::AllVersionsSorted.new(
+ Generator::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])))]
# For each ID:
ids.each do | id |
@@ -69,10 +68,6 @@ ids.each do | id |
puts " Actions: ".ljust(40) + actions.join(' ')
- # And various misc methods. Clients don't usually use these
- # directly.
- puts " breaks_portage?: ".ljust(40) + id.breaks_portage?.to_s
-
puts
end
diff --git a/doc/api/ruby/example_query.rb b/doc/api/ruby/example_query.rb
deleted file mode 100644
index 3eecc0b..0000000
--- a/doc/api/ruby/example_query.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/usr/bin/env ruby
-# vim: set sw=4 sts=4 et tw=100 :
-
-=begin description
-This example demonstrates how use the standard Query classes.
-=end
-
-require 'Paludis'
-require 'example_command_line'
-
-include Paludis
-
-# Run a query, and show its results.
-def show_query(env, query)
- # Queries support a crude form of stringification.
- puts "#{query}:"
-
- # Usually the only thing clients will do with a Query object is pass it to
- # PackageDatabase#query.
- ids = env.package_database.query(query, QueryOrder::OrderByVersion)
-
- # Show the results
- ids.each do | id |
- puts " #{id}"
- end
- puts
-end
-
-# We start with an Environment, respecting the user's '--environment' choice.
-env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment)
-
-# Make some queries, and display what they give.
-show_query(env, Query::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])))
-
-# Queries can be combined. The resulting query is optimised internally,
-# potentially giving better performance than doing things by hand.
-show_query(env,
- Query::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])) &
- Query::SupportsInstalledAction.new)
-
-# Usually Query::NotMasked should be combined with Query::SupportsInstallAction,
-# since installed packages aren't masked.
-show_query(env,
- Query::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])) &
- Query::SupportsInstallAction.new &
- Query::NotMasked.new)
-
diff --git a/paludis/action.cc b/paludis/action.cc
index 8cede23..7b36471 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 2466289..0fded6e 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 0000000..f90dec3
--- /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 0000000..0510ddd
--- /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 1222613..515c7f8 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 03280f3..cb482d9 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 a691f3a..b2104ae 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 e373927..7215216 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 a463747..aa0ede7 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 046a6b6..2ec858e 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 a4861fa..3ce233b 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 7c785ee..96fb7ad 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 1d70b20..e53a6d2 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 3366f79..ca337b4 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 0000000..8e678e7
--- /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 0000000..5049d89
--- /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 0000000..c736926
--- /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 0000000..e443ce6
--- /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 0000000..93e3f7b
--- /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 0000000..620ee32
--- /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 0000000..961207d
--- /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 0000000..c033452
--- /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 ba0a8a2..2a19448 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 595c83c..4e81c0a 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 c1afb4a..ca008b8 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 9781cfa..b376467 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 2548bb4..1bc52dc 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 0000000..7ef28c4
--- /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 0000000..d005240
--- /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 0000000..6b81906
--- /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 0000000..e8fd081
--- /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 0000000..3d55c22
--- /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 0000000..4206f53
--- /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 00cfa90..f1e6f14 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 b94ca10..ae3a0fa 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 3ae62f3..8919b98 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 15509c7..eea66d8 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 f7aed32..6bda3a9 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 b67987b..9b98f9a 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 8bd92df..0000000
--- 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 cd7dbe9..82ed036 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 43036b9..0000000
--- 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 813d15b..0000000
--- 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 33cce37..0000000
--- 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 66e34b2..0000000
--- 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 a3849db..c22fa3d 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 f646e74..89b47f7 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 0d7d711..26f2f20 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 4bde9a3..2052ee2 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 716bf22..57f09cd 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 eb1cca0..7937f3a 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 71cba9f..a285ff5 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 1cfee89..82ccaf2 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 4274c86..4cb7f5c 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 f1bcadb..27e09ee 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 09d268e..770978c 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 5652653..4601e86 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 727e9a8..74b8451 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 5c2f2b7..9f3f580 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 97c6b50..95d513e 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 af114bd..70e9176 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 1081c99..b4171bc 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 3a66f7b..bbff750 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 f4fe4bb..bb598ad 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 3fb06fc..112db88 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 71b6f8a..44bdff6 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 0000000..cf4a5d7
--- /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 0000000..9f9e7cc
--- /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 0000000..f169a42
--- /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 0000000..98490ca
--- /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 a7b23e5..c7e19e4 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 fd48ad9..4252a08 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 899b330..bb2963d 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 e957283..4323ef5 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 cde8380..6e4851d 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
diff --git a/python/Makefile.am b/python/Makefile.am
index 61ca0eb..9692e29 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -23,25 +23,28 @@ DISTCLEANFILES = *-nn.hh *-nn.cc
MAINTAINERCLEANFILES = Makefile.in
IF_PYTHON_TESTS = \
- version_spec_TEST.py \
- version_operator_TEST.py \
- version_requirements_TEST.py \
+ action_TEST.py \
contents_TEST.py \
+ dep_label_TEST.py \
+ dep_list_TEST.py \
dep_spec_TEST.py \
dep_tag_TEST.py \
- dep_label_TEST.py \
+ environment_TEST.py \
+ filter_TEST.py \
+ filtered_generator_TEST.py \
+ formatter_TEST.py \
+ generator_TEST.py \
log_TEST.py \
+ mask_TEST.py \
+ metadata_key_TEST.py \
name_TEST.py \
- query_TEST.py \
- environment_TEST.py \
package_database_TEST.py \
- repository_TEST.py \
- action_TEST.py \
- metadata_key_TEST.py \
- mask_TEST.py \
package_id_TEST.py \
- dep_list_TEST.py \
- formatter_TEST.py
+ repository_TEST.py \
+ selection_TEST.py \
+ version_operator_TEST.py \
+ version_requirements_TEST.py \
+ version_spec_TEST.py
IF_PYTHON_QA_TESTS = \
qa_TEST.py
@@ -60,8 +63,11 @@ IF_PYTHON_SOURCES = \
dep_tag.cc \
environment.cc \
exception.hh exception.cc \
+ filter.cc \
+ filtered_generator.cc \
formatter.cc \
fs_entry.cc \
+ generator.cc \
mask.cc \
metadata_key.cc \
mutex.hh mutex.cc \
@@ -70,8 +76,8 @@ IF_PYTHON_SOURCES = \
log.cc \
package_database.cc \
package_id.cc \
- query.cc \
repository.cc \
+ selection.cc \
version_operator.cc \
version_requirements.cc \
version_spec.cc
@@ -93,7 +99,6 @@ EXTRA_DIST = $(IF_PYTHON_TESTS) $(IF_PYTHON_SOURCES) \
nice_names.nn \
package_database_TEST_setup.sh package_database_TEST_cleanup.sh \
package_id_TEST_setup.sh package_id_TEST_cleanup.sh \
- query_TEST_setup.sh query_TEST_cleanup.sh \
repository_TEST_setup.sh repository_TEST_cleanup.sh \
paludis_output_wrapper.py
diff --git a/python/environment.cc b/python/environment.cc
index 51e7f48..cf1c3f6 100644
--- a/python/environment.cc
+++ b/python/environment.cc
@@ -30,6 +30,7 @@
#include <paludis/environments/test/test_environment.hh>
#include <paludis/hook.hh>
#include <paludis/package_id.hh>
+#include <paludis/selection.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
using namespace paludis;
@@ -388,6 +389,22 @@ class EnvironmentImplementationWrapper :
else
throw PythonMethodNotImplemented("EnvironmentImplementation", "world_set");
}
+
+ virtual std::tr1::shared_ptr<PackageIDSequence> operator[] (const Selection & fg) const
+ PALUDIS_ATTRIBUTE((warn_unused_result))
+ {
+ Lock l(get_mutex());
+
+ if (bp::override f = get_override("__getitem__"))
+ return f(fg);
+ return EnvironmentImplementation::operator[] (fg);
+ }
+
+ virtual std::tr1::shared_ptr<PackageIDSequence> default_operator_square_brackets(const Selection & fg) const
+ PALUDIS_ATTRIBUTE((warn_unused_result))
+ {
+ return EnvironmentImplementation::operator[] (fg);
+ }
};
struct NoConfigEnvironmentWrapper :
@@ -495,6 +512,11 @@ void expose_environment()
"[ro] SetNamesIterable\n"
"All known named sets."
)
+
+ .def("__getitem__", &Environment::operator[],
+ "[selection] -> list of PackageID\n"
+ "Return PackageID instances matching a given selection."
+ )
;
/**
@@ -629,6 +651,11 @@ void expose_environment()
"default_distribution() -> str\n"
"NEED_DOC"
)
+
+ .def("__getitem__", &EnvImp::operator[], &EnvImpW::default_operator_square_brackets,
+ "[selection] -> list of PackageID\n"
+ "Return PackageID instances matching a given selection."
+ )
;
/**
@@ -712,3 +739,4 @@ void expose_environment()
bp::init<>("__init__()")
);
}
+
diff --git a/python/environment_TEST.py b/python/environment_TEST.py
index 98f7542..e806cc2 100755
--- a/python/environment_TEST.py
+++ b/python/environment_TEST.py
@@ -52,9 +52,8 @@ class TestCase_01_Environments(unittest.TestCase):
self.assert_(isinstance(NoConfigEnvironment(repo), Environment))
def test_04_query_use(self):
- pid = iter(self.e.package_database.query(Query.Matches(
- parse_user_package_dep_spec("=foo/bar-1.0", [])),
- QueryOrder.REQUIRE_EXACTLY_ONE)).next()
+ pid = iter(self.e[Selection.RequireExactlyOne(Generator.Matches(
+ parse_user_package_dep_spec("=foo/bar-1.0", [])))]).next()
self.assert_(self.e.query_use("enabled", pid))
self.assert_(not self.e.query_use("not_enabled", pid))
@@ -102,9 +101,8 @@ class TestCase_02_AdaptedEnvironment(unittest.TestCase):
def test_02_adapt_use(self):
env = AdaptedEnvironment(EnvironmentMaker.instance.make_from_spec(""))
- pid = iter(env.package_database.query(Query.Matches(
- parse_user_package_dep_spec("=foo/bar-1.0", [])),
- QueryOrder.REQUIRE_EXACTLY_ONE)).next()
+ pid = iter(env[Selection.RequireExactlyOne(Generator.Matches(
+ parse_user_package_dep_spec("=foo/bar-1.0", UserPackageDepSpecOptions())))]).next()
pds = parse_user_package_dep_spec("foo/bar", [])
self.assert_(env.query_use("enabled", pid))
@@ -122,8 +120,7 @@ class TestCase_02_AdaptedEnvironment(unittest.TestCase):
def test_03_clear_adaptions(self):
env = AdaptedEnvironment(EnvironmentMaker.instance.make_from_spec(""))
- pid = iter(env.package_database.query(Query.Matches(parse_user_package_dep_spec("=foo/bar-1.0", [])),
- QueryOrder.REQUIRE_EXACTLY_ONE)).next()
+ pid = iter(env[Selection.RequireExactlyOne(Generator.Matches(parse_user_package_dep_spec("=foo/bar-1.0", [])))]).next()
pds = parse_user_package_dep_spec("foo/bar", [])
self.assert_(env.query_use("enabled", pid))
diff --git a/python/filter.cc b/python/filter.cc
new file mode 100644
index 0000000..d3a98b5
--- /dev/null
+++ b/python/filter.cc
@@ -0,0 +1,95 @@
+/* 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 <python/paludis_python.hh>
+#include <python/exception.hh>
+
+#include <paludis/util/fs_entry.hh>
+#include <paludis/filter.hh>
+
+using namespace paludis;
+using namespace paludis::python;
+namespace bp = boost::python;
+
+namespace
+{
+ template <typename C_>
+ class class_supports_action_filter :
+ public bp::class_<filter::SupportsAction<C_>, bp::bases<Filter> >
+ {
+ public:
+ class_supports_action_filter(const std::string & a) :
+ bp::class_<filter::SupportsAction<C_>, bp::bases<Filter> >(
+ ("Supports" + a + "Action").c_str(),
+ ("Accept packages that support " + a + "Action").c_str(),
+ bp::init<>("__init__()")
+ )
+ {
+ }
+ };
+}
+
+void expose_filter()
+{
+ bp::class_<Filter> filter(
+ "Filter",
+ "Filter for an Environment selection.",
+ bp::no_init
+ );
+
+ filter
+ .def(bp::self_ns::str(bp::self))
+ ;
+
+ bp::scope filter_scope = filter;
+
+ bp::class_<filter::All, bp::bases<Filter> > filter_all(
+ "All",
+ "Accept all packages.",
+ bp::init<>("__init__()")
+ );
+
+ bp::class_<filter::NotMasked, bp::bases<Filter> > filter_not_masked(
+ "NotMasked",
+ "Accept not masked packages.",
+ bp::init<>("__init__()")
+ );
+
+ bp::class_<filter::InstalledAtRoot, bp::bases<Filter> > filter_installed_at_root(
+ "InstalledAtRoot",
+ "Accept packages installed at a particular root.",
+ bp::init<const FSEntry &>("__init__(path)")
+ );
+
+ bp::class_<filter::And, bp::bases<Filter> > filter_and(
+ "And",
+ "Accept packages that match both filters",
+ bp::init<const Filter &, const Filter &>("__init__(filter, filter)")
+ );
+
+ class_supports_action_filter<InstallAction>("Install");
+ class_supports_action_filter<InstalledAction>("Installed");
+ class_supports_action_filter<UninstallAction>("Uninstall");
+ class_supports_action_filter<PretendAction>("Pretend");
+ class_supports_action_filter<ConfigAction>("Config");
+ class_supports_action_filter<FetchAction>("Fetch");
+ class_supports_action_filter<InfoAction>("Info");
+ class_supports_action_filter<PretendFetchAction>("PretendFetch");
+}
+
diff --git a/python/filter_TEST.py b/python/filter_TEST.py
new file mode 100644
index 0000000..df1fbbe
--- /dev/null
+++ b/python/filter_TEST.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+# vim: set fileencoding=utf-8 sw=4 sts=4 et :
+
+#
+# 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
+#
+
+import os
+
+from paludis import *
+import unittest
+
+Log.instance.log_level = LogLevel.WARNING
+
+class TestCase_01_Filter(unittest.TestCase):
+ def test_01_get(self):
+ pass
+
+ def test_02_str(self):
+ self.assertEquals(str(Filter.All()), "all matches")
+
+
+if __name__ == "__main__":
+ unittest.main()
+
diff --git a/python/filtered_generator.cc b/python/filtered_generator.cc
new file mode 100644
index 0000000..6b9b868
--- /dev/null
+++ b/python/filtered_generator.cc
@@ -0,0 +1,56 @@
+/* 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 <python/paludis_python.hh>
+#include <python/exception.hh>
+
+#include <paludis/util/fs_entry.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/generator.hh>
+
+using namespace paludis;
+using namespace paludis::python;
+namespace bp = boost::python;
+
+void expose_filtered_generator()
+{
+ bp::class_<FilteredGenerator> filtered_generator(
+ "FilteredGenerator",
+ "A combined Generator and Filter for an Environment selection.",
+ bp::init<const Generator &, const Filter &>("__init__(generator, filter)")
+ );
+
+ filtered_generator
+ .def("filter", bp::make_function(&FilteredGenerator::filter,
+ bp::return_value_policy<bp::copy_const_reference>()),
+ "Our Filter."
+ )
+ .def("generator", bp::make_function(&FilteredGenerator::generator,
+ bp::return_value_policy<bp::copy_const_reference>()),
+ "Our Generator."
+ )
+ .def("__or__", static_cast<FilteredGenerator (*) (const FilteredGenerator &, const Filter &)>(
+ &paludis::operator| ),
+ "Add a new Filter."
+ )
+ .def(bp::self_ns::str(bp::self))
+ ;
+}
+
diff --git a/python/filtered_generator_TEST.py b/python/filtered_generator_TEST.py
new file mode 100644
index 0000000..edb7edd
--- /dev/null
+++ b/python/filtered_generator_TEST.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+# vim: set fileencoding=utf-8 sw=4 sts=4 et :
+
+#
+# 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
+#
+
+import os
+
+from paludis import *
+import unittest
+
+Log.instance.log_level = LogLevel.WARNING
+
+class TestCase_01_FilteredGenerator(unittest.TestCase):
+ def test_01_get(self):
+ pass
+
+ def test_02_str(self):
+ self.assertEquals(str(FilteredGenerator(Generator.All(), Filter.All())),
+ "all packages with filter all matches")
+
+
+if __name__ == "__main__":
+ unittest.main()
+
diff --git a/python/generator.cc b/python/generator.cc
new file mode 100644
index 0000000..c74426c
--- /dev/null
+++ b/python/generator.cc
@@ -0,0 +1,92 @@
+/* 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 <python/paludis_python.hh>
+#include <python/exception.hh>
+
+#include <paludis/generator.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/dep_spec.hh>
+
+using namespace paludis;
+using namespace paludis::python;
+namespace bp = boost::python;
+
+void expose_generator()
+{
+ bp::class_<Generator> generator(
+ "Generator",
+ "Generator for an Environment selection.",
+ bp::no_init
+ );
+
+ generator
+ .def(bp::self_ns::str(bp::self))
+ .def("__or__", static_cast<FilteredGenerator (*) (const FilteredGenerator &, const Filter &)>(
+ &paludis::operator| ),
+ "Combine with a Filter to produce a FilteredGenerator."
+ )
+ .def("__and__", static_cast<Generator (*) (const Generator &, const Generator &)>(
+ &paludis::operator& ),
+ "Combine with another Generator using a set union."
+ )
+ ;
+
+ bp::implicitly_convertible<Generator, FilteredGenerator>();
+
+ bp::scope generator_scope = generator;
+
+ bp::class_<generator::All, bp::bases<Generator> > generator_all(
+ "All",
+ "Generate all packages.",
+ bp::init<>("__init__()")
+ );
+
+ bp::class_<generator::Matches, bp::bases<Generator> > generator_matches(
+ "Matches",
+ "Generate matching packages.",
+ bp::init<const PackageDepSpec &>("__init__(spec)")
+ );
+
+ bp::class_<generator::Union, bp::bases<Generator> > generator_union(
+ "Union",
+ "Generate packages from a union of two other Generator instances.",
+ bp::init<const Generator &, const Generator &>("__init__(generator, generator)")
+ );
+
+ bp::class_<generator::Package, bp::bases<Generator> > generator_package(
+ "Package",
+ "Generate all named packages.",
+ bp::init<const QualifiedPackageName &>("__init__(name)")
+ );
+
+ bp::class_<generator::Category, bp::bases<Generator> > generator_category(
+ "Category",
+ "Generate all packages in a given category.",
+ bp::init<const CategoryNamePart &>("__init__(category)")
+ );
+
+ bp::class_<generator::Repository, bp::bases<Generator> > generator_repository(
+ "Repository",
+ "Generate all packages in a given repository.",
+ bp::init<const RepositoryName &>("__init__(repository)")
+ );
+}
+
diff --git a/python/generator_TEST.py b/python/generator_TEST.py
new file mode 100644
index 0000000..f0e230e
--- /dev/null
+++ b/python/generator_TEST.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+# vim: set fileencoding=utf-8 sw=4 sts=4 et :
+
+#
+# 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
+#
+
+import os
+
+from paludis import *
+import unittest
+
+Log.instance.log_level = LogLevel.WARNING
+
+class TestCase_01_Generator(unittest.TestCase):
+ def test_01_get(self):
+ pass
+
+ def test_02_str(self):
+ self.assertEquals(str(Generator.All()), "all packages")
+
+
+if __name__ == "__main__":
+ unittest.main()
+
diff --git a/python/mask_TEST.py b/python/mask_TEST.py
index 0d2b8e0..c1f25d6 100755
--- a/python/mask_TEST.py
+++ b/python/mask_TEST.py
@@ -32,11 +32,10 @@ Log.instance.log_level = LogLevel.WARNING
class TestCase_01_Masks(unittest.TestCase):
def setUp(self):
self.e = EnvironmentMaker.instance.make_from_spec("")
- self.db = self.e.package_database
def test_01_user_mask(self):
- q = Query.Matches(parse_user_package_dep_spec("=masked/user-1.0", []))
- pid = iter(self.db.query(q, QueryOrder.REQUIRE_EXACTLY_ONE)).next()
+ q = Selection.RequireExactlyOne(Generator.Matches(parse_user_package_dep_spec("=masked/user-1.0", [])))
+ pid = iter(self.e[q]).next()
m = iter(pid.masks).next()
self.assert_(isinstance(m, Mask))
@@ -46,8 +45,8 @@ class TestCase_01_Masks(unittest.TestCase):
self.assertEquals(m.description(), "user")
def test_02_unaccepted_mask(self):
- q = Query.Matches(parse_user_package_dep_spec("=masked/unaccepted-1.0", []))
- pid = iter(self.db.query(q, QueryOrder.REQUIRE_EXACTLY_ONE)).next()
+ q = Selection.RequireExactlyOne(Generator.Matches(parse_user_package_dep_spec("=masked/unaccepted-1.0", [])))
+ pid = iter(self.e[q]).next()
m = iter(pid.masks).next()
self.assert_(isinstance(m, Mask))
@@ -58,8 +57,8 @@ class TestCase_01_Masks(unittest.TestCase):
self.assert_(isinstance(m.unaccepted_key(), MetadataKeywordNameIterableKey))
def test_03_repository_mask(self):
- q = Query.Matches(parse_user_package_dep_spec("=masked/repo-1.0", []))
- pid = iter(self.db.query(q, QueryOrder.REQUIRE_EXACTLY_ONE)).next()
+ q = Selection.RequireExactlyOne(Generator.Matches(parse_user_package_dep_spec("=masked/repo-1.0", [])))
+ pid = iter(self.e[q]).next()
m = iter(pid.masks).next()
self.assert_(isinstance(m, Mask))
@@ -74,8 +73,8 @@ class TestCase_01_Masks(unittest.TestCase):
self.assert_(isinstance(m.mask_key().value().comment, StringIterable))
def test_04_unsupported_mask(self):
- q = Query.Matches(parse_user_package_dep_spec("=masked/unsupported-1.0", []))
- pid = iter(self.db.query(q, QueryOrder.REQUIRE_EXACTLY_ONE)).next()
+ q = Selection.RequireExactlyOne(Generator.Matches(parse_user_package_dep_spec("=masked/unsupported-1.0", [])))
+ pid = iter(self.e[q]).next()
m = iter(pid.masks).next()
self.assert_(isinstance(m, Mask))
@@ -86,8 +85,8 @@ class TestCase_01_Masks(unittest.TestCase):
self.assertEquals(m.explanation(), "Unsupported EAPI 'unsupported'")
def test_05_association_mask(self):
- q = Query.Matches(parse_user_package_dep_spec("=virtual/association-1.0", []))
- pid = iter(self.db.query(q, QueryOrder.REQUIRE_EXACTLY_ONE)).next()
+ q = Selection.RequireExactlyOne(Generator.Matches(parse_user_package_dep_spec("=virtual/association-1.0", [])))
+ pid = iter(self.e[q]).next()
m = iter(pid.masks).next()
self.assert_(isinstance(m, Mask))
@@ -157,9 +156,8 @@ class TestCase_02_Masks_subclassing(unittest.TestCase):
def associated_package(self):
e = EnvironmentMaker.instance.make_from_spec("")
- db = e.package_database
- q = Query.Matches(parse_user_package_dep_spec("=masked/user-1.0", []))
- pid = iter(db.query(q, QueryOrder.REQUIRE_EXACTLY_ONE)).next()
+ q = Selection.RequireExactlyOne(Generator.Matches(parse_user_package_dep_spec("=masked/user-1.0", [])))
+ pid = iter(e[q]).next()
return pid
test_association_mask(TestAssociationMask())
diff --git a/python/package_database.cc b/python/package_database.cc
index 8eb869f..941816b 100644
--- a/python/package_database.cc
+++ b/python/package_database.cc
@@ -21,8 +21,8 @@
#include <python/exception.hh>
#include <paludis/dep_spec.hh>
-#include <paludis/query.hh>
#include <paludis/environment.hh>
+#include <paludis/filter.hh>
#include <paludis/package_id.hh>
#include <paludis/package_database.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
@@ -60,12 +60,6 @@ void expose_package_database()
"Thrown if there is no Repository in a RepositoryDatabase with the given name.");
/**
- * Enums
- */
- enum_auto("QueryOrder", last_qo,
- "How to order query results.");
-
- /**
* PackageDatabase
*/
register_shared_ptrs_to_python<PackageDatabase>();
@@ -77,11 +71,6 @@ void expose_package_database()
"A PackageDatabase can be queried for Package instances.\n",
bp::no_init
)
- .def("query", &PackageDatabase::query, bp::with_custodian_and_ward_postcall<0, 1>(),
-
- "query(Query, QueryOrder) -> PackageIDIterable\n"
- "Query the repository."
- )
.add_property("favourite_repository", &PackageDatabase::favourite_repository,
"[ro] RepositoryName\n"
@@ -95,8 +84,8 @@ void expose_package_database()
.def("fetch_unique_qualified_package_name", &PackageDatabase::fetch_unique_qualified_package_name,
fetch_unique_qualified_package_name_overloads(
- "fetch_unique_qualified_package_name(PackageNamePart[, Query]) -> QualifiedPackageName\n"
- "Disambiguate a package name. If a query is specified, "
+ "fetch_unique_qualified_package_name(PackageNamePart[, Filter]) -> QualifiedPackageName\n"
+ "Disambiguate a package name. If a filter is specified, "
"limit the potential results to packages that match."
)
)
diff --git a/python/package_database_TEST.py b/python/package_database_TEST.py
index f21c374..933805e 100755
--- a/python/package_database_TEST.py
+++ b/python/package_database_TEST.py
@@ -42,24 +42,15 @@ class TestCase_PackageDatabase(unittest.TestCase):
def test_03_fech_unique_qpn(self):
self.get_db()
self.assertEqual(str(QualifiedPackageName("foo/bar")), str(self.db.fetch_unique_qualified_package_name("bar")))
- self.assertEqual(str(QualifiedPackageName("foo/bar")), str(self.db.fetch_unique_qualified_package_name("bar", Query.SupportsInstallAction())))
+ self.assertEqual(str(QualifiedPackageName("foo/bar")), str(self.db.fetch_unique_qualified_package_name("bar",
+ Filter.SupportsInstallAction())))
def test_04_exceptions(self):
self.get_db()
self.assertRaises(AmbiguousPackageNameError, self.db.fetch_unique_qualified_package_name, "baz")
self.assertRaises(NoSuchPackageError, self.db.fetch_unique_qualified_package_name, "foobarbaz")
- self.assertRaises(NoSuchPackageError, self.db.fetch_unique_qualified_package_name, "bar", Query.SupportsUninstallAction())
-
- def test_5_query(self):
- self.get_db()
- pkgs = list(self.db.query(Query.Package("foo/bar"), QueryOrder.ORDER_BY_VERSION))
- self.assertEqual([x.canonical_form(PackageIDCanonicalForm.FULL) for x in pkgs], [
- "foo/bar-1.0::testrepo",
- "foo/bar-2.0::testrepo"])
-
- pkgs = list(self.db.query(Query.Matches(parse_user_package_dep_spec(">=foo/bar-10", [])),
- QueryOrder.ORDER_BY_VERSION))
- self.assertEqual(len(pkgs), 0)
+ self.assertRaises(NoSuchPackageError, self.db.fetch_unique_qualified_package_name, "bar",
+ Filter.SupportsUninstallAction())
def test_6_repositories(self):
self.get_db()
@@ -71,3 +62,4 @@ class TestCase_PackageDatabase(unittest.TestCase):
if __name__ == "__main__":
unittest.main()
+
diff --git a/python/paludis_python.hh b/python/paludis_python.hh
index 719a398..eb4d4a4 100644
--- a/python/paludis_python.hh
+++ b/python/paludis_python.hh
@@ -179,8 +179,11 @@ void expose_dep_spec() PALUDIS_VISIBLE;
void expose_dep_tag() PALUDIS_VISIBLE;
void expose_environment() PALUDIS_VISIBLE;
void expose_exception() PALUDIS_VISIBLE;
+void expose_filter() PALUDIS_VISIBLE;
+void expose_filtered_generator() PALUDIS_VISIBLE;
void expose_formatter() PALUDIS_VISIBLE;
void expose_fs_entry() PALUDIS_VISIBLE;
+void expose_generator() PALUDIS_VISIBLE;
void expose_log() PALUDIS_VISIBLE;
void expose_mask() PALUDIS_VISIBLE;
void expose_metadata_key() PALUDIS_VISIBLE;
@@ -188,8 +191,8 @@ void expose_name() PALUDIS_VISIBLE;
void expose_package_database() PALUDIS_VISIBLE;
void expose_package_id() PALUDIS_VISIBLE;
void expose_qa() PALUDIS_VISIBLE;
-void expose_query() PALUDIS_VISIBLE;
void expose_repository() PALUDIS_VISIBLE;
+void expose_selection() PALUDIS_VISIBLE;
void expose_version_operator() PALUDIS_VISIBLE;
void expose_version_requirements() PALUDIS_VISIBLE;
void expose_version_spec() PALUDIS_VISIBLE;
diff --git a/python/paludis_python_so.cc b/python/paludis_python_so.cc
index 016f7df..dad112c 100644
--- a/python/paludis_python_so.cc
+++ b/python/paludis_python_so.cc
@@ -42,7 +42,6 @@ BOOST_PYTHON_MODULE(paludis)
expose_dep_list();
expose_name();
expose_log();
- expose_query();
expose_environment();
expose_metadata_key();
expose_mask();
@@ -51,6 +50,10 @@ BOOST_PYTHON_MODULE(paludis)
expose_package_database();
expose_repository();
expose_formatter();
+ expose_filter();
+ expose_filtered_generator();
+ expose_generator();
+ expose_selection();
#ifdef ENABLE_QA
expose_qa();
#endif
diff --git a/python/query.cc b/python/query.cc
deleted file mode 100644
index 6afc04a..0000000
--- a/python/query.cc
+++ /dev/null
@@ -1,356 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2007 Piotr Jaroszyński
- *
- * 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 <python/paludis_python.hh>
-#include <python/exception.hh>
-
-#include <paludis/query.hh>
-#include <paludis/query_delegate.hh>
-#include <paludis/dep_spec.hh>
-#include <paludis/action.hh>
-#include <paludis/util/fs_entry.hh>
-#include <paludis/environment.hh>
-
-using namespace paludis;
-using namespace paludis::python;
-namespace bp = boost::python;
-
-class PythonQueryDelegate;
-
-class PythonQuery :
- public Query
-{
- public:
- PythonQuery();
-
- virtual ~PythonQuery()
- {
- }
-
- virtual std::tr1::shared_ptr<RepositoryNameSequence> repositories(const Environment &) const
- {
- return std::tr1::shared_ptr<RepositoryNameSequence>();
- }
-
- virtual std::tr1::shared_ptr<CategoryNamePartSet> categories(const Environment &,
- std::tr1::shared_ptr<const RepositoryNameSequence>) const
- {
- return std::tr1::shared_ptr<CategoryNamePartSet>();
- }
-
- virtual std::tr1::shared_ptr<QualifiedPackageNameSet> packages(const Environment &,
- std::tr1::shared_ptr<const RepositoryNameSequence>,
- std::tr1::shared_ptr<const CategoryNamePartSet>) const
- {
- return std::tr1::shared_ptr<QualifiedPackageNameSet>();
- }
-
- virtual std::tr1::shared_ptr<PackageIDSequence> ids(const Environment &,
- std::tr1::shared_ptr<const RepositoryNameSequence>,
- std::tr1::shared_ptr<const QualifiedPackageNameSet>) const
- {
- return std::tr1::shared_ptr<PackageIDSequence>();
- }
-
- virtual std::string as_human_readable_string() const = 0;
-};
-
-class PythonQueryDelegate :
- public QueryDelegate
-{
- private:
- PythonQuery * _q;
-
- public:
- PythonQueryDelegate(PythonQuery * pq) :
- _q(pq)
- {
- }
-
- std::tr1::shared_ptr<RepositoryNameSequence> repositories(const Environment & e) const
- {
- return _q->repositories(e);
- }
-
- std::tr1::shared_ptr<CategoryNamePartSet> categories(const Environment & e,
- std::tr1::shared_ptr<const RepositoryNameSequence> r) const
- {
- return _q->categories(e, r);
- }
-
- std::tr1::shared_ptr<QualifiedPackageNameSet> packages(const Environment & e,
- std::tr1::shared_ptr<const RepositoryNameSequence> r,
- std::tr1::shared_ptr<const CategoryNamePartSet> c) const
- {
- return _q->packages(e, r, c);
- }
-
- std::tr1::shared_ptr<PackageIDSequence> ids(const Environment & e,
- std::tr1::shared_ptr<const RepositoryNameSequence> r,
- std::tr1::shared_ptr<const QualifiedPackageNameSet> q) const
- {
- return _q->ids(e, r, q);
- }
-
- std::string as_human_readable_string() const
- {
- return _q->as_human_readable_string();
- }
-};
-
-PythonQuery::PythonQuery() :
- Query(std::tr1::shared_ptr<const PythonQueryDelegate>(new PythonQueryDelegate(this)))
-{
-}
-
-struct PythonQueryWrapper :
- PythonQuery,
- bp::wrapper<PythonQuery>
-{
- std::tr1::shared_ptr<RepositoryNameSequence> repositories(const Environment & e) const
- {
- Lock l(get_mutex());
-
- if (bp::override f = get_override("repositories"))
- return f(boost::cref(e));
- return PythonQuery::repositories(e);
- }
-
- std::tr1::shared_ptr<RepositoryNameSequence> default_repositories(const Environment & e) const
- {
- return PythonQuery::repositories(e);
- }
-
- std::tr1::shared_ptr<CategoryNamePartSet> categories(const Environment & e,
- std::tr1::shared_ptr<const RepositoryNameSequence> r) const
- {
- Lock l(get_mutex());
-
- if (bp::override f = get_override("categories"))
- return f(boost::cref(e), r);
- return PythonQuery::categories(e, r);
- }
-
- std::tr1::shared_ptr<CategoryNamePartSet> default_categories(const Environment & e,
- std::tr1::shared_ptr<const RepositoryNameSequence> r) const
- {
- return PythonQuery::categories(e, r);
- }
-
- std::tr1::shared_ptr<QualifiedPackageNameSet> packages(const Environment & e,
- std::tr1::shared_ptr<const RepositoryNameSequence> r,
- std::tr1::shared_ptr<const CategoryNamePartSet> c) const
- {
- Lock l(get_mutex());
-
- if (bp::override f = get_override("packages"))
- return f(boost::cref(e), r, c);
- return PythonQuery::packages(e, r, c);
- }
-
- std::tr1::shared_ptr<QualifiedPackageNameSet> default_packages(const Environment & e,
- std::tr1::shared_ptr<const RepositoryNameSequence> r,
- std::tr1::shared_ptr<const CategoryNamePartSet> c) const
- {
- return PythonQuery::packages(e, r, c);
- }
-
- std::tr1::shared_ptr<PackageIDSequence> ids(const Environment & e,
- std::tr1::shared_ptr<const RepositoryNameSequence> r,
- std::tr1::shared_ptr<const QualifiedPackageNameSet> q) const
- {
- Lock l(get_mutex());
-
- if (bp::override f = get_override("ids"))
- return f(boost::cref(e), r, q);
- return PythonQuery::ids(e, r, q);
- }
-
- std::tr1::shared_ptr<PackageIDSequence> default_ids(const Environment & e,
- std::tr1::shared_ptr<const RepositoryNameSequence> r,
- std::tr1::shared_ptr<const QualifiedPackageNameSet> q) const
- {
- return PythonQuery::ids(e, r, q);
- }
-
- std::string as_human_readable_string() const
- {
- Lock l(get_mutex());
-
- if (bp::override f = get_override("as_human_readable_string"))
- return f();
- else
- throw PythonMethodNotImplemented("Query", "as_human_readable_string");
- }
-};
-
-template <typename A_>
-class class_supports_action :
- public bp::class_<query::SupportsAction<A_>, bp::bases<Query> >
-{
- public:
- class_supports_action(const std::string & action) :
- bp::class_<query::SupportsAction<A_>, bp::bases<Query> >(
- ("Supports" + action + "Action").c_str(),
- ("Fetch packages that support " + action + "Action.").c_str(),
- bp::init<>("__init__()")
- )
- {
- }
-};
-
-
-void expose_query()
-{
- /**
- * Query
- */
- bp::class_<Query>
- q(
- "Query",
- "Parameter for a PackageDatabase query.",
- bp::no_init
- );
- q.def("__and__", operator&);
-
- /**
- * QueryBase
- */
- bp::class_<PythonQueryWrapper, bp::bases<Query>, boost::noncopyable>
- (
- "QueryBase",
- "Parameter for a PackageDatabase query.\n"
- "This class can be subclassed in Python",
- bp::init<>()
- )
- .def("repositories", &PythonQuery::repositories, &PythonQueryWrapper::default_repositories,
- "repositories(Environment) -> list of RepositoryName\n"
- "Fetch the names of repositories potentially containing matches.\n"
- "All returned repositories must exist.\n\n"
- "Default behaviour: return all repositories."
- )
-
- .def("categories", &PythonQuery::categories, &PythonQueryWrapper::default_categories,
- "categories(Environment, RepositoryNameIterable) -> list of CategoryNamePart\n"
- "Fetch the names of categories potentially containing matches.\n\n"
- "Default behaviour: return all categories in the provided\n"
- "repository collection."
- )
-
- .def("packages", &PythonQuery::packages, &PythonQueryWrapper::default_packages,
- "packages(Environment, RepositoryNameIterable, CategoryNamePartIterable) "
- "-> list of QualifiedPackageName\n"
- "Fetch the names of packages potentially containing matches.\n\n"
- "Default behaviour: return all packages in the provided repository\n"
- "in the provided categories.\n\n"
- "Note that some entries in the categories collection (but not in\n"
- "the repositories collection) may not exist."
- )
-
- .def("ids", &PythonQuery::ids, &PythonQueryWrapper::default_ids,
- "ids(Environment, RepositoryNameIterable, QualifiedPackageNameIterable)\n"
- "Fetch the IDs of matching packages.\n\n"
- "Default behaviour: return all IDs in the provided packages.\n\n"
- "Note that some entries in the qualified package name collection\n"
- "(but not in the repositories collection) may not exist."
- )
- ;
-
- /* I need to think about it yet... */
- bp::scope query = q;
-
- /**
- * Matches
- */
- bp::class_<query::Matches, bp::bases<Query> >
- (
- "Matches",
- "Fetch packages matching a given PackageDepSpec.",
- bp::init<const PackageDepSpec &>("__init__(PackageDepSpec)")
- );
-
- /**
- * Package
- */
- bp::class_<query::Package, bp::bases<Query> >
- (
- "Package",
- "Fetch packages with a given package name.",
- bp::init<const QualifiedPackageName &>("__init__(QualifiedPackageName)")
- );
-
- /**
- * Repository
- */
- bp::class_<query::Repository, bp::bases<Query> >
- (
- "Repository",
- "Fetch packages in a given repository.",
- bp::init<const RepositoryName &>("__init__(RepositoryName)")
- );
-
- /**
- * Category
- */
- bp::class_<query::Category, bp::bases<Query> >
- (
- "Category",
- "Fetch packages in a given Category.",
- bp::init<const CategoryNamePart &>("__init__(CategoryNamePart)")
- );
-
- /**
- * NotMasked
- */
- bp::class_<query::NotMasked, bp::bases<Query> >
- (
- "NotMasked",
- "Fetch packages that are not masked.",
- bp::init<>("__init__()")
- );
-
- /**
- * SupportsAction
- */
- class_supports_action<InstallAction>("Install");
- class_supports_action<UninstallAction>("Uninstall");
- class_supports_action<InstalledAction>("Installed");
- class_supports_action<PretendAction>("Pretend");
- class_supports_action<ConfigAction>("Config");
-
- /**
- * InstalledAtRoot
- */
- bp::class_<query::InstalledAtRoot, bp::bases<Query> >
- (
- "InstalledAtRoot",
- "Fetch packages that are installed at a particular root.",
- bp::init<const FSEntry &>("__init__(path)")
- );
-
- /**
- * All
- */
- bp::class_<query::All, bp::bases<Query> >
- (
- "All",
- "Fetch all packages.",
- bp::init<>("__init__()")
- );
-}
diff --git a/python/query_TEST.py b/python/query_TEST.py
deleted file mode 100755
index 5def69d..0000000
--- a/python/query_TEST.py
+++ /dev/null
@@ -1,87 +0,0 @@
-#!/usr/bin/env python
-# vim: set fileencoding=utf-8 sw=4 sts=4 et :
-
-#
-# Copyright (c) 2007 Piotr Jaroszyński
-#
-# 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
-#
-
-import os
-
-repo_path = os.path.join(os.getcwd(), "query_TEST_dir/testrepo")
-
-from paludis import *
-import unittest
-
-class TestCase_01_Queries(unittest.TestCase):
- def test_1_create(self):
- self.queries = []
- self.queries.append(Query.SupportsInstallAction())
- self.queries.append(Query.SupportsUninstallAction())
- self.queries.append(Query.SupportsInstalledAction())
- self.queries.append(Query.SupportsPretendAction())
- self.queries.append(Query.SupportsConfigAction())
- self.queries.append(Query.InstalledAtRoot("/bar"))
- self.queries.append(Query.NotMasked())
- self.queries.append(Query.Package("foo/bar"))
- self.queries.append(Query.Matches(parse_user_package_dep_spec(">=foo/bar-1", [])))
- self.queries.append(Query.All())
- self.queries.append(Query.Category("cat-foo"))
- self.queries.append(Query.Repository("foo_repo"))
-
- def test_2_create_error(self):
- self.assertRaises(Exception, Query)
-
- def test_3_subclass(self):
- self.test_1_create()
- for query in self.queries:
- self.assert_(isinstance(query, Query))
-
- def test_4_and(self):
- self.test_1_create()
- length = len(self.queries)
- for i in xrange(length):
- for j in xrange(length):
- self.assert_(isinstance(self.queries[i] & self.queries[j], Query))
-
-class TestCase_02_QueryBase(unittest.TestCase):
- class TestQuery(QueryBase):
- def __init__(self):
- QueryBase.__init__(self)
-
- def as_human_readable_string(self):
- return "TestQuery"
-
- def categories(self, e, repos):
- return None
-
- def packages(self, e, repos, cats):
- return QueryBase.packages(self, e, repos, cats)
-
- def ids(self, e, repos, pkgs):
- r = e.package_database.fetch_repository("testrepo")
- return list(r.package_ids(iter(pkgs).next()))
-
- def test_1_create(self):
- e = NoConfigEnvironment(repo_path, "/var/empty")
- db = e.package_database
- q = self.TestQuery()
- q1 = q & Query.Repository("testrepo")
- pid = iter(db.query(q1, QueryOrder.REQUIRE_EXACTLY_ONE)).next()
-
- self.assertEquals(pid.name, "cat/package")
-
-if __name__ == "__main__":
- unittest.main()
diff --git a/python/query_TEST_cleanup.sh b/python/query_TEST_cleanup.sh
deleted file mode 100755
index 9de073e..0000000
--- a/python/query_TEST_cleanup.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/bash
-# vim: set ft=sh sw=4 sts=4 et :
-
-if [ -d query_TEST_dir ] ; then
- rm -fr query_TEST_dir
-else
- true
-fi
diff --git a/python/query_TEST_setup.sh b/python/query_TEST_setup.sh
deleted file mode 100755
index 9ee6f80..0000000
--- a/python/query_TEST_setup.sh
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/bash
-# vim: set ft=sh sw=4 sts=4 et :
-
-mkdir query_TEST_dir || exit 1
-cd query_TEST_dir || exit 1
-
-mkdir -p testrepo/{eclass,distfiles,profiles/testprofile,cat/package} || exit 1
-cd testrepo || exit 1
-echo "testrepo" > profiles/repo_name || exit 1
-cat <<END > profiles/categories || exit 1
-cat
-END
-cat <<END > profiles/profiles.desc
-test testprofile stable
-END
-cat <<END > profiles/testprofile/make.defaults
-ARCH=test
-USERLAND=test
-KERNEL=test
-END
-
-cat <<"END" > cat/package/package-1.0.ebuild || exit 1
-DESCRIPTION="Query for me"
-HOMEPAGE="http://paludis.pioto.org/"
-SRC_URI="http://example.com/${P}.tar.bz2"
-SLOT="0"
-IUSE=""
-LICENSE="GPL-2"
-KEYWORDS="test
-RESTRICT=""
-DEPEND=""
-RDEPEND=""
-END
-
diff --git a/python/selection.cc b/python/selection.cc
new file mode 100644
index 0000000..7c4fe39
--- /dev/null
+++ b/python/selection.cc
@@ -0,0 +1,89 @@
+/* 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 <python/paludis_python.hh>
+#include <python/exception.hh>
+
+#include <paludis/generator.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/selection.hh>
+#include <paludis/dep_spec.hh>
+
+using namespace paludis;
+using namespace paludis::python;
+namespace bp = boost::python;
+
+void expose_selection()
+{
+ bp::class_<Selection> selection(
+ "Selection",
+ "Selection for an Environment selection.",
+ bp::no_init
+ );
+
+ selection
+ .def(bp::self_ns::str(bp::self))
+ ;
+
+ bp::scope selection_scope = selection;
+
+ bp::class_<selection::SomeArbitraryVersion, bp::bases<Selection> > selection_some_arbitrary_version(
+ "SomeArbitraryVersion",
+ "Select some arbitrary version.",
+ bp::init<const FilteredGenerator &>("__init__(filtered_generator)")
+ );
+
+ bp::class_<selection::BestVersionOnly, bp::bases<Selection> > selection_best_version_only(
+ "BestVersionOnly",
+ "Select the best version only.",
+ bp::init<const FilteredGenerator &>("__init__(filtered_generator)")
+ );
+
+ bp::class_<selection::BestVersionInEachSlot, bp::bases<Selection> > selection_best_version_in_each_slot(
+ "BestVersionInEachSlot",
+ "Select the best version in each slot.",
+ bp::init<const FilteredGenerator &>("__init__(filtered_generator)")
+ );
+
+ bp::class_<selection::AllVersionsSorted, bp::bases<Selection> > selection_all_versions_sorted(
+ "AllVersionsSorted",
+ "Select all versions, sorted.",
+ bp::init<const FilteredGenerator &>("__init__(filtered_generator)")
+ );
+
+ bp::class_<selection::AllVersionsGroupedBySlot, bp::bases<Selection> > selection_all_versions_grouped_by_slot(
+ "AllVersionsGroupedBySlot",
+ "All versions grouped by slot.",
+ bp::init<const FilteredGenerator &>("__init__(filtered_generator)")
+ );
+
+ bp::class_<selection::AllVersionsUnsorted, bp::bases<Selection> > selection_all_versions_unsorted(
+ "AllVersionsUnsorted",
+ "All versions, in no particular order.",
+ bp::init<const FilteredGenerator &>("__init__(filtered_generator)")
+ );
+
+ bp::class_<selection::RequireExactlyOne, bp::bases<Selection> > selection_require_exactly_one(
+ "RequireExactlyOne",
+ "Require exactly one matching ID.",
+ bp::init<const FilteredGenerator &>("__init__(filtered_generator)")
+ );
+}
+
diff --git a/python/selection_TEST.py b/python/selection_TEST.py
new file mode 100644
index 0000000..6f4cae0
--- /dev/null
+++ b/python/selection_TEST.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+# vim: set fileencoding=utf-8 sw=4 sts=4 et :
+
+#
+# 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
+#
+
+import os
+
+from paludis import *
+import unittest
+
+Log.instance.log_level = LogLevel.WARNING
+
+class TestCase_01_Sekection(unittest.TestCase):
+ def test_01_get(self):
+ pass
+
+ def test_02_str(self):
+ self.assertEquals(str(Selection.SomeArbitraryVersion(
+ FilteredGenerator(Generator.All(), Filter.All()))),
+ "some arbitrary version from all packages with filter all matches")
+
+
+if __name__ == "__main__":
+ unittest.main()
+
diff --git a/ruby/Makefile.am b/ruby/Makefile.am
index 3b89f35..0014b37 100644
--- a/ruby/Makefile.am
+++ b/ruby/Makefile.am
@@ -24,39 +24,45 @@ IF_RUBY_TESTS = \
dep_spec_TEST.rb \
dep_tag_TEST.rb \
environment_TEST.rb \
+ filter_TEST.rb \
+ filtered_generator_TEST.rb \
find_unused_packages_task_TEST.rb \
+ generator_TEST.rb \
log_TEST.rb \
package_database_TEST.rb \
package_id_TEST.rb \
paludis_ruby_TEST.rb \
qualified_package_name_TEST.rb \
- query_TEST.rb \
repository_TEST.rb \
+ selection_TEST.rb \
version_spec_TEST.rb
IF_RUBY_QA_TESTS = \
qa_TEST.rb
IF_RUBY_SOURCES = \
- paludis_ruby.cc paludis_ruby.hh \
action.cc \
contents.cc \
dep_list.cc \
dep_spec.cc \
dep_tag.cc \
environment.cc \
+ filter.cc \
+ filtered_generator.cc \
find_unused_packages_task.cc \
+ generator.cc \
log.cc \
+ mask.cc \
metadata_key.cc \
name.cc \
nice_names-nn.hh nice_names-nn.cc \
package_database.cc \
package_id.cc \
+ paludis_ruby.cc paludis_ruby.hh \
qualified_package_name.cc \
- query.cc \
repository.cc \
- version_spec.cc \
- mask.cc
+ selection.cc \
+ version_spec.cc
BUILT_SOURCES = \
nice_names-nn.hh nice_names-nn.cc
diff --git a/ruby/action.cc b/ruby/action.cc
index 8fe349d..c846f39 100644
--- a/ruby/action.cc
+++ b/ruby/action.cc
@@ -56,8 +56,12 @@ namespace
static VALUE c_uninstall_action_options;
static VALUE c_uninstall_action;
+ static VALUE c_installed_action;
+
static VALUE c_pretend_action;
+ static VALUE c_pretend_fetch_action;
+
bool
value_to_bool(VALUE v)
{
@@ -992,6 +996,17 @@ namespace
rb_define_method(c_uninstall_action, "options", RUBY_FUNC_CAST(&uninstall_action_options), 0);
/*
+ * Document-class: Paludis::InstalledAction
+ *
+ * An InstalledAction can be used to test whether a PackageID is
+ * installed.
+ */
+ c_installed_action = rb_define_class_under(paludis_module(), "InstalledAction", c_action);
+ rb_define_singleton_method(c_installed_action, "new",
+ RUBY_FUNC_CAST((&EasyActionNew<InstalledAction>::easy_action_new)), 0);
+ rb_define_method(c_installed_action, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
+
+ /*
* Document-class: Paludis::PretendAction
*
* A PretendAction is used by InstallTask to handle install-pretend-phase checks on a PackageID.
@@ -1002,6 +1017,9 @@ namespace
rb_define_method(c_pretend_action, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
rb_define_method(c_pretend_action, "failed?", RUBY_FUNC_CAST(&pretend_action_failed), 0);
rb_define_method(c_pretend_action, "set_failed", RUBY_FUNC_CAST(&pretend_action_set_failed), 0);
+
+ c_pretend_fetch_action = rb_define_class_under(paludis_module(), "PretendFetchAction", c_action);
+ rb_funcall(c_pretend_fetch_action, rb_intern("private_class_method"), 1, rb_str_new2("new"));
}
}
@@ -1051,6 +1069,54 @@ paludis::ruby::fetch_action_failure_to_value(const FetchActionFailure & m)
}
}
+VALUE *
+paludis::ruby::install_action_value_ptr()
+{
+ return &c_install_action;
+}
+
+VALUE *
+paludis::ruby::installed_action_value_ptr()
+{
+ return &c_installed_action;
+}
+
+VALUE *
+paludis::ruby::pretend_action_value_ptr()
+{
+ return &c_pretend_action;
+}
+
+VALUE *
+paludis::ruby::fetch_action_value_ptr()
+{
+ return &c_fetch_action;
+}
+
+VALUE *
+paludis::ruby::config_action_value_ptr()
+{
+ return &c_config_action;
+}
+
+VALUE *
+paludis::ruby::uninstall_action_value_ptr()
+{
+ return &c_uninstall_action;
+}
+
+VALUE *
+paludis::ruby::info_action_value_ptr()
+{
+ return &c_info_action;
+}
+
+VALUE *
+paludis::ruby::pretend_fetch_action_value_ptr()
+{
+ return &c_pretend_fetch_action;
+}
+
RegisterRubyClass::Register paludis_ruby_register_action PALUDIS_ATTRIBUTE((used))
(&do_register_action);
diff --git a/ruby/demos/find_unused_distfiles.rb b/ruby/demos/find_unused_distfiles.rb
index 871a17c..5d461ef 100755
--- a/ruby/demos/find_unused_distfiles.rb
+++ b/ruby/demos/find_unused_distfiles.rb
@@ -120,7 +120,7 @@ end
if mirror_repository then
env = Paludis::NoConfigEnvironment.new(mirror_repository, write_cache_dir, master_repository_dir)
- relevant_packages = Paludis::Query::Repository.new(env.main_repository.name)
+ relevant_packages = Generator::Repository.new(env.main_repository.name)
$check_condition = lambda { true }
$banned_labels = {
Paludis::URIListedOnlyLabel => true,
@@ -129,7 +129,7 @@ if mirror_repository then
}
else
env = Paludis::EnvironmentMaker.instance.make_from_spec(env_spec || "")
- relevant_packages = Paludis::Query::SupportsInstalledAction.new
+ relevant_packages Generator::SupportsAction.new(InstalledAction)
$check_condition = lambda { | spec | spec.condition_met? }
$banned_labels = { }
end
@@ -164,7 +164,7 @@ end
# build up a list of all src_uri things that're used by installed packages
parts = Hash.new
-env.package_database.query(relevant_packages, Paludis::QueryOrder::Whatever).each do | id |
+env[Selection::AllVersionsUnsorted.new(relevant_packages)].each do | id |
key = id.fetches_key
collect_filenames(parts, id, [key.initial_label.class], key.value) if key && key.value
end
diff --git a/ruby/dep_list_TEST.rb b/ruby/dep_list_TEST.rb
index 3e871f7..edba6f1 100644
--- a/ruby/dep_list_TEST.rb
+++ b/ruby/dep_list_TEST.rb
@@ -202,10 +202,7 @@ module Paludis
def test_add_bad_tree
assert_raise TypeError do
- dl.add(env.package_database.
- query(Query::Matches.new(pda),
- QueryOrder::BestVersionOnly).
- last.build_dependencies_key.value, dd)
+ dl.add(env[Selection::BestVersionOnly.new(Generator::Matches.new(pda))].last.build_dependencies_key.value, dd)
end
end
diff --git a/ruby/dep_spec_TEST.rb b/ruby/dep_spec_TEST.rb
index 5abaaf3..9b77651 100644
--- a/ruby/dep_spec_TEST.rb
+++ b/ruby/dep_spec_TEST.rb
@@ -195,7 +195,7 @@ module Paludis
end
def test_composites
- spec = env.package_database.query(Query::Package.new("foo/bar"), QueryOrder::RequireExactlyOne).last.build_dependencies_key.value
+ spec = env[Selection::RequireExactlyOne.new(Generator::Package.new("foo/bar"))].last.build_dependencies_key.value
assert_kind_of AllDepSpec, spec
assert_equal 2, spec.to_a.length
@@ -237,7 +237,7 @@ module Paludis
end
def spec_key
- env.package_database.query(Query::Package.new("bar/foo"), QueryOrder::RequireExactlyOne).last.fetches_key
+ env[Selection::RequireExactlyOne.new(Generator::Package.new("bar/foo"))].last.fetches_key
end
def test_no_create
diff --git a/ruby/dep_tag_TEST.rb b/ruby/dep_tag_TEST.rb
index 36b007f..d45955d 100644
--- a/ruby/dep_tag_TEST.rb
+++ b/ruby/dep_tag_TEST.rb
@@ -37,7 +37,7 @@ module Paludis
end
def get_dt
- DependencyDepTag.new(env.package_database.query(Query::All.new, QueryOrder::RequireExactlyOne).last,
+ DependencyDepTag.new(env[Selection::RequireExactlyOne.new(Generator::All.new)].last,
Paludis::parse_user_package_dep_spec('foo/bar', []))
end
diff --git a/ruby/environment.cc b/ruby/environment.cc
index d5ba4fd..9a16a0c 100644
--- a/ruby/environment.cc
+++ b/ruby/environment.cc
@@ -79,6 +79,31 @@ namespace
/*
* call-seq:
+ * [](Selection) -> Array of PackageID
+ *
+ * Fetch PackageID instances using the supplied Selection.
+ */
+
+ VALUE
+ environment_square_brackets(VALUE self, VALUE selection)
+ {
+ try
+ {
+ std::tr1::shared_ptr<const PackageIDSequence> ids(value_to_environment(self)->operator[] (value_to_selection(selection)));
+ VALUE result(rb_ary_new());
+ for (PackageIDSequence::ConstIterator i(ids->begin()), i_end(ids->end()) ;
+ i != i_end ; ++i)
+ rb_ary_push(result, package_id_to_value(*i));
+ return result;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
+ * call-seq:
* package_database -> PackageDatabase
*
* Fetch our PackageDatabase.
@@ -122,7 +147,7 @@ namespace
/*
* call-seq:
- * accept_license(license, package_id) -> true of false
+ * accept_license(license, package_id) -> true or false
*
* Do we accept a particular license for a particular package?
*/
@@ -510,7 +535,7 @@ namespace
/*
* Document-class: Paludis::Environment
*
- * Represents a working environment, which contains an available packages database and provides
+ * Represents a working environment, which contains an available packages database and provides
* various methods for querying package visibility and options.
*/
c_environment = rb_define_class_under(paludis_module(), "Environment", rb_cObject);
@@ -523,6 +548,7 @@ namespace
rb_define_method(c_environment, "accept_license", RUBY_FUNC_CAST(&environment_accept_license), 2);
rb_define_method(c_environment, "accept_keywords", RUBY_FUNC_CAST(&environment_accept_keywords), 2);
rb_define_method(c_environment, "mirrors", RUBY_FUNC_CAST(&environment_mirrors), 1);
+ rb_define_method(c_environment, "[]", RUBY_FUNC_CAST(&environment_square_brackets), 1);
/*
* Document-class: Paludis::PaludisEnvironment
diff --git a/ruby/environment_TEST.rb b/ruby/environment_TEST.rb
index 642f147..6d53074 100644
--- a/ruby/environment_TEST.rb
+++ b/ruby/environment_TEST.rb
@@ -79,9 +79,8 @@ module Paludis
end
def test_query_use
- pid = env.package_database.query(Query::Matches.new(
- Paludis::parse_user_package_dep_spec('=foo/bar-1.0::testrepo', [])),
- QueryOrder::RequireExactlyOne).first
+ pid = env[Selection::RequireExactlyOne.new(Generator::Matches.new(
+ Paludis::parse_user_package_dep_spec('=foo/bar-1.0::testrepo', [])))].first
assert env.query_use("enabled", pid)
assert ! env.query_use("not_enabled", pid)
@@ -104,17 +103,16 @@ module Paludis
end
def pid
- env.package_database.query(Query::Matches.new(
- Paludis::parse_user_package_dep_spec('=foo/bar-1.0::testrepo', [])),
- QueryOrder::RequireExactlyOne).first
+ env[Selection::RequireExactlyOne.new(Generator::Matches.new(
+ Paludis::parse_user_package_dep_spec('=foo/bar-1.0::testrepo', [])))].first
end
def test_accept_license
assert env.accept_license('GPL-2', pid)
assert !env.accept_license('Failure', pid)
- pid2 = env.package_database.query(Query::Matches.new(
- Paludis::parse_user_package_dep_spec('=foo/baz-1.0::testrepo', [])), QueryOrder::RequireExactlyOne).first
+ pid2 = env[Selection::RequireExactlyOne.new(Generator::Matches.new(
+ Paludis::parse_user_package_dep_spec('=foo/baz-1.0::testrepo', [])))].first
assert env.accept_license('GPL-2', pid2)
assert env.accept_license('Failure', pid2)
end
@@ -132,8 +130,8 @@ module Paludis
end
def pid
- env.package_database.query(Query::Matches.new(
- Paludis::parse_user_package_dep_spec('=foo/bar-1.0::testrepo', [])), QueryOrder::RequireExactlyOne).first
+ env[Selection::RequireExactlyOne.new(Generator::Matches.new(
+ Paludis::parse_user_package_dep_spec('=foo/bar-1.0::testrepo', [])))].first
end
def test_accept_keywords
@@ -161,8 +159,8 @@ module Paludis
end
def test_query_use
- pid = env.package_database.query(Query::Matches.new(
- Paludis::parse_user_package_dep_spec('=foo/bar-1.0::testrepo', [])), QueryOrder::RequireExactlyOne).first
+ pid = env[Selection::RequireExactlyOne.new(Generator::Matches.new(
+ Paludis::parse_user_package_dep_spec('=foo/bar-1.0::testrepo', [])))].first
assert ! env.query_use("foo", pid)
end
@@ -200,8 +198,8 @@ module Paludis
end
def test_adapt_use
- pid = env.package_database.query(Query::Matches.new(
- Paludis::parse_user_package_dep_spec('=foo/bar-1.0::testrepo', [])), QueryOrder::RequireExactlyOne).first
+ pid = env[Selection::RequireExactlyOne.new(
+ Generator::Matches.new(Paludis::parse_user_package_dep_spec('=foo/bar-1.0::testrepo', [])))].first
assert env.query_use("enabled", pid)
assert ! env.query_use("not_enabled", pid)
@@ -231,8 +229,8 @@ module Paludis
end
def test_clear_adaptions
- pid = env.package_database.query(Query::Matches.new(
- Paludis::parse_user_package_dep_spec('=foo/bar-1.0::testrepo', [])), QueryOrder::RequireExactlyOne).first
+ pid = env[Selection::RequireExactlyOne.new(Generator::Matches.new(
+ Paludis::parse_user_package_dep_spec('=foo/bar-1.0::testrepo', [])))].first
assert env.query_use("enabled", pid)
@@ -405,5 +403,93 @@ module Paludis
assert env.mirrors('missingmirror').empty?
end
end
+
+ class TestCase_EnvironmentQuery < Test::Unit::TestCase
+ def env
+ @env or @env = EnvironmentMaker.instance.make_from_spec("")
+ end
+
+ def db
+ return env.package_database
+ end
+
+ def pda
+ Paludis::parse_user_package_dep_spec('=foo/bar-1.0', [])
+ end
+
+ def pda2
+ Paludis::parse_user_package_dep_spec('foo/bar', [])
+ end
+
+ def test_arg_count
+ assert_raise ArgumentError do
+ env[1, 2];
+ end
+ end
+
+ def test_package_database_query
+ a = env[Selection::AllVersionsSorted.new(Generator::Matches.new(pda))]
+ assert_kind_of Array, a
+ assert_equal 1, a.length
+ pid = a.first
+ assert_kind_of PackageID, pid
+ assert_equal 'foo/bar', pid.name
+ assert_equal '1.0', pid.version.to_s
+ assert_equal 'testrepo', pid.repository_name
+
+ a = env[Selection::AllVersionsSorted.new(Generator::Matches.new(pda) | Filter::SupportsAction.new(InstallAction))]
+ assert_kind_of Array, a
+ assert_equal 1, a.length
+ pid = a.first
+ assert_kind_of PackageID, pid
+ assert_equal 'foo/bar', pid.name
+ assert_equal '1.0', pid.version.to_s
+ assert_equal 'testrepo', pid.repository_name
+
+ a = env[Selection::AllVersionsSorted.new(Generator::Matches.new(pda))]
+ assert_kind_of Array, a
+ assert_equal 1, a.length
+ pid = a.first
+ assert_kind_of PackageID, pid
+ assert_equal 'foo/bar', pid.name
+ assert_equal '1.0', pid.version.to_s
+ assert_equal 'testrepo', pid.repository_name
+
+ a = env[Selection::AllVersionsSorted.new(Generator::Matches.new(pda2) | Filter::SupportsAction.new(InstallAction))]
+ assert_kind_of Array, a
+ assert_equal 2, a.length
+ pid = a.shift
+ assert_kind_of PackageID, pid
+ assert_equal 'foo/bar', pid.name
+ assert_equal '1.0', pid.version.to_s
+ assert_equal 'testrepo', pid.repository_name
+ pid2 = a.shift
+ assert_kind_of PackageID, pid2
+ assert_equal pid.name, pid2.name
+ assert_equal '2.0', pid2.version.to_s
+ assert_equal pid.repository_name, pid2.repository_name
+
+ a = env[Selection::AllVersionsSorted.new(Generator::Package.new('foo/bar'))]
+ assert_kind_of Array, a
+ assert_equal 2, a.length
+ pid = a.shift
+ assert_kind_of PackageID, pid
+ assert_equal 'foo/bar', pid.name
+ assert_equal '1.0', pid.version.to_s
+ assert_equal 'testrepo', pid.repository_name
+ pid2 = a.shift
+ assert_kind_of PackageID, pid2
+ assert_equal pid.name, pid2.name
+ assert_equal '2.0', pid2.version.to_s
+ assert_equal pid.repository_name, pid2.repository_name
+
+
+ a = env[Selection::AllVersionsUnsorted.new(Generator::Matches.new(Paludis::parse_user_package_dep_spec('>=foo/bar-27', [])))]
+ assert a.empty?
+
+ a = env[Selection::AllVersionsUnsorted.new(Generator::Matches.new(pda2) | Filter::SupportsAction.new(InstalledAction))]
+ assert a.empty?
+ end
+ end
end
diff --git a/ruby/filter.cc b/ruby/filter.cc
new file mode 100644
index 0000000..af207ec
--- /dev/null
+++ b/ruby/filter.cc
@@ -0,0 +1,202 @@
+/* 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_ruby.hh>
+
+using namespace paludis;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_filter_module;
+ static VALUE c_filter;
+ static VALUE c_filter_all;
+ static VALUE c_filter_supports_action;
+ static VALUE c_filter_not_masked;
+ static VALUE c_filter_installed_at_root;
+ static VALUE c_filter_and;
+
+ VALUE
+ filter_init(int, VALUE *, VALUE self)
+ {
+ return self;
+ }
+
+ VALUE
+ filter_all_new(VALUE self)
+ {
+ Filter * ptr(0);
+ try
+ {
+ ptr = new filter::All();
+ VALUE data(Data_Wrap_Struct(self, 0, &Common<Filter>::free, ptr));
+ rb_obj_call_init(data, 0, &self);
+ return data;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ filter_not_masked_new(VALUE self)
+ {
+ Filter * ptr(0);
+ try
+ {
+ ptr = new filter::NotMasked();
+ VALUE data(Data_Wrap_Struct(self, 0, &Common<Filter>::free, ptr));
+ rb_obj_call_init(data, 0, &self);
+ return data;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ filter_installed_at_root_new(VALUE self, VALUE root_v)
+ {
+ Filter * ptr(0);
+ try
+ {
+ FSEntry root(StringValuePtr(root_v));
+ ptr = new filter::InstalledAtRoot(root);
+ VALUE data(Data_Wrap_Struct(self, 0, &Common<Filter>::free, ptr));
+ rb_obj_call_init(data, 1, &root_v);
+ return data;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ filter_and_new(VALUE self, VALUE f1_v, VALUE f2_v)
+ {
+ Filter * ptr(0);
+ try
+ {
+ Filter f1(value_to_filter(f1_v));
+ Filter f2(value_to_filter(f2_v));
+ ptr = new filter::And(f1, f2);
+ VALUE data(Data_Wrap_Struct(self, 0, &Common<Filter>::free, ptr));
+ rb_obj_call_init(data, 2, &f1_v);
+ return data;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ filter_supports_action_new(VALUE self, VALUE action_class)
+ {
+ Filter * ptr(0);
+ try
+ {
+ if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, install_action_value_ptr()))
+ ptr = new filter::SupportsAction<InstallAction>();
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, installed_action_value_ptr()))
+ ptr = new filter::SupportsAction<InstalledAction>();
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, uninstall_action_value_ptr()))
+ ptr = new filter::SupportsAction<UninstallAction>();
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, pretend_action_value_ptr()))
+ ptr = new filter::SupportsAction<PretendAction>();
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, config_action_value_ptr()))
+ ptr = new filter::SupportsAction<ConfigAction>();
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, fetch_action_value_ptr()))
+ ptr = new filter::SupportsAction<FetchAction>();
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, info_action_value_ptr()))
+ ptr = new filter::SupportsAction<InfoAction>();
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, pretend_fetch_action_value_ptr()))
+ ptr = new filter::SupportsAction<PretendFetchAction>();
+ else
+ rb_raise(rb_eTypeError, "Can't convert %s into an Action subclass", rb_obj_classname(action_class));
+
+ VALUE data(Data_Wrap_Struct(self, 0, &Common<Filter>::free, ptr));
+ rb_obj_call_init(data, 1, &action_class);
+ return data;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ void do_register_filter()
+ {
+ c_filter_module = rb_define_module_under(paludis_module(), "Filter");
+
+ c_filter = rb_define_class_under(c_filter_module, "Filter", rb_cObject);
+ rb_funcall(c_filter, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_filter, "initialize", RUBY_FUNC_CAST(&filter_init), -1);
+ rb_define_method(c_filter, "to_s", RUBY_FUNC_CAST(&Common<Filter>::to_s), 0);
+
+ c_filter_all = rb_define_class_under(c_filter_module, "All", c_filter);
+ rb_define_singleton_method(c_filter_all, "new", RUBY_FUNC_CAST(&filter_all_new), 0);
+
+ c_filter_not_masked = rb_define_class_under(c_filter_module, "NotMasked", c_filter);
+ rb_define_singleton_method(c_filter_not_masked, "new", RUBY_FUNC_CAST(&filter_not_masked_new), 0);
+
+ c_filter_installed_at_root = rb_define_class_under(c_filter_module, "InstalledAtRoot", c_filter);
+ rb_define_singleton_method(c_filter_installed_at_root, "new", RUBY_FUNC_CAST(&filter_installed_at_root_new), 1);
+
+ c_filter_and = rb_define_class_under(c_filter_module, "And", c_filter);
+ rb_define_singleton_method(c_filter_and, "new", RUBY_FUNC_CAST(&filter_and_new), 2);
+
+ c_filter_supports_action = rb_define_class_under(c_filter_module, "SupportsAction", c_filter);
+ rb_define_singleton_method(c_filter_supports_action, "new", RUBY_FUNC_CAST(&filter_supports_action_new), 1);
+ }
+}
+
+Filter
+paludis::ruby::value_to_filter(VALUE v)
+{
+ if (rb_obj_is_kind_of(v, c_filter))
+ {
+ Filter * f_ptr;
+ Data_Get_Struct(v, Filter, f_ptr);
+ return *f_ptr;
+ }
+ else
+ rb_raise(rb_eTypeError, "Can't convert %s into Filter", rb_obj_classname(v));
+}
+
+VALUE
+paludis::ruby::filter_to_value(const Filter & v)
+{
+ Filter * vv(new Filter(v));
+ return Data_Wrap_Struct(c_filter, 0, &Common<Filter>::free, vv);
+}
+
+RegisterRubyClass::Register paludis_ruby_register_filter PALUDIS_ATTRIBUTE((used))
+ (&do_register_filter);
+
diff --git a/ruby/filter_TEST.rb b/ruby/filter_TEST.rb
new file mode 100644
index 0000000..4f1a94a
--- /dev/null
+++ b/ruby/filter_TEST.rb
@@ -0,0 +1,100 @@
+#!/usr/bin/ruby
+# vim: set sw=4 sts=4 et tw=80 :
+
+#
+# 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
+#
+
+require 'test/unit'
+require 'Paludis'
+
+module Paludis
+ class TestCase_Filter < Test::Unit::TestCase
+ def test_no_create
+ assert_raise NoMethodError do
+ Filter::new
+ end
+ end
+ end
+
+ class TestCase_FilterAll < Test::Unit::TestCase
+ def test_create
+ assert_nothing_raised do
+ Filter::All.new
+ end
+ end
+
+ def test_to_s
+ assert_equal Filter::All.new.to_s, "all matches"
+ end
+ end
+
+ class TestCase_FilterNotMasked < Test::Unit::TestCase
+ def test_create
+ assert_nothing_raised do
+ Filter::NotMasked.new
+ end
+ end
+
+ def test_to_s
+ assert_equal Filter::NotMasked.new.to_s, "not masked"
+ end
+ end
+
+ class TestCase_FilterInstalledAtRoot < Test::Unit::TestCase
+ def test_create
+ assert_nothing_raised do
+ Filter::InstalledAtRoot.new("/")
+ end
+ end
+
+ def test_to_s
+ assert_equal Filter::InstalledAtRoot.new("/").to_s, "installed at root /"
+ end
+ end
+
+ class TestCase_FilterSupportsAction < Test::Unit::TestCase
+ def test_create
+ assert_nothing_raised do
+ Filter::SupportsAction.new(InstallAction)
+ end
+ end
+
+ def test_bad_create
+ assert_raise TypeError do
+ Filter::SupportsAction.new(String)
+ end
+ end
+
+ def test_to_s
+ assert_equal Filter::SupportsAction.new(InstallAction).to_s, "supports action install"
+ end
+ end
+
+ class TestCase_FilterAnd < Test::Unit::TestCase
+ def test_create
+ assert_nothing_raised do
+ Filter::And.new(Filter::NotMasked.new, Filter::SupportsAction.new(InstallAction))
+ end
+ end
+
+ def test_to_s
+ assert_equal Filter::And.new(Filter::NotMasked.new, Filter::SupportsAction.new(InstallAction)).to_s,
+ "not masked filtered through supports action install"
+ end
+ end
+end
+
diff --git a/ruby/filtered_generator.cc b/ruby/filtered_generator.cc
new file mode 100644
index 0000000..b2c4126
--- /dev/null
+++ b/ruby/filtered_generator.cc
@@ -0,0 +1,143 @@
+/* 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_ruby.hh>
+
+using namespace paludis;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_filtered_generator;
+
+ VALUE
+ filtered_generator_init(int, VALUE *, VALUE self, VALUE, VALUE)
+ {
+ return self;
+ }
+
+ VALUE
+ filtered_generator_new(VALUE self, VALUE generator, VALUE filter)
+ {
+ FilteredGenerator * ptr(0);
+ try
+ {
+ Generator g(value_to_generator(generator));
+ Filter f(value_to_filter(filter));
+ ptr = new FilteredGenerator(g, f);
+ VALUE data(Data_Wrap_Struct(self, 0, &Common<FilteredGenerator>::free, ptr));
+ rb_obj_call_init(data, 2, &self);
+ return data;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ filtered_generator_bar(VALUE self, VALUE other)
+ {
+ FilteredGenerator * ptr(0);
+ try
+ {
+ FilteredGenerator g1(value_to_filtered_generator(self));
+ Filter f1(value_to_filter(other));
+ return filtered_generator_to_value(g1 | f1);
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ filtered_generator_filter(VALUE self)
+ {
+ FilteredGenerator * ptr(0);
+ try
+ {
+ FilteredGenerator g1(value_to_filtered_generator(self));
+ return filter_to_value(g1.filter());
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ filtered_generator_generator(VALUE self)
+ {
+ FilteredGenerator * ptr(0);
+ try
+ {
+ FilteredGenerator g1(value_to_filtered_generator(self));
+ return generator_to_value(g1.generator());
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ void do_register_filtered_generator()
+ {
+ c_filtered_generator = rb_define_class_under(paludis_module(), "FilteredGenerator", rb_cObject);
+ rb_define_singleton_method(c_filtered_generator, "new", RUBY_FUNC_CAST(&filtered_generator_new), 2);
+ rb_define_method(c_filtered_generator, "initialize", RUBY_FUNC_CAST(&filtered_generator_init), -1);
+ rb_define_method(c_filtered_generator, "to_s", RUBY_FUNC_CAST(&Common<FilteredGenerator>::to_s), 0);
+ rb_define_method(c_filtered_generator, "|", RUBY_FUNC_CAST(&filtered_generator_bar), 1);
+ rb_define_method(c_filtered_generator, "filter", RUBY_FUNC_CAST(&filtered_generator_filter), 0);
+ rb_define_method(c_filtered_generator, "generator", RUBY_FUNC_CAST(&filtered_generator_generator), 0);
+ }
+}
+
+FilteredGenerator
+paludis::ruby::value_to_filtered_generator(VALUE v)
+{
+ if (rb_obj_is_kind_of(v, c_filtered_generator))
+ {
+ FilteredGenerator * f_ptr;
+ Data_Get_Struct(v, FilteredGenerator, f_ptr);
+ return *f_ptr;
+ }
+ else
+ {
+ Generator g(value_to_generator(v));
+ return FilteredGenerator(g);
+ }
+}
+
+VALUE
+paludis::ruby::filtered_generator_to_value(const FilteredGenerator & v)
+{
+ FilteredGenerator * vv(new FilteredGenerator(v));
+ return Data_Wrap_Struct(c_filtered_generator, 0, &Common<FilteredGenerator>::free, vv);
+}
+
+RegisterRubyClass::Register paludis_ruby_register_filtered_generator PALUDIS_ATTRIBUTE((used))
+ (&do_register_filtered_generator);
+
diff --git a/ruby/filtered_generator_TEST.rb b/ruby/filtered_generator_TEST.rb
new file mode 100644
index 0000000..116401d
--- /dev/null
+++ b/ruby/filtered_generator_TEST.rb
@@ -0,0 +1,58 @@
+#!/usr/bin/ruby
+# vim: set sw=4 sts=4 et tw=80 :
+
+#
+# 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
+#
+
+require 'test/unit'
+require 'Paludis'
+
+module Paludis
+ class TestCase_FilteredGenerator < Test::Unit::TestCase
+ def test_create
+ assert_nothing_raised do
+ FilteredGenerator.new(Generator::All.new, Filter::All.new)
+ end
+ end
+
+ def test_to_s
+ assert_equal FilteredGenerator.new(Generator::All.new, Filter::All.new).to_s,
+ "all packages with filter all matches"
+ end
+
+ def test_bar_generator
+ assert_nothing_raised do
+ Generator::All.new | Filter::All.new
+ end
+ end
+
+ def test_bar_filtered_generator
+ assert_nothing_raised do
+ Generator::All.new | Filter::All.new | Filter::All.new
+ end
+ end
+
+ def test_filtered_generator_filter
+ assert_equal (Generator::All.new | Filter::NotMasked.new).filter.to_s, "all matches filtered through not masked"
+ end
+
+ def test_filtered_generator_generator
+ assert_equal (Generator::Category.new("cat") | Filter::NotMasked.new).generator.to_s, "packages with category cat"
+ end
+ end
+end
+
diff --git a/ruby/generator.cc b/ruby/generator.cc
new file mode 100644
index 0000000..09f71e4
--- /dev/null
+++ b/ruby/generator.cc
@@ -0,0 +1,285 @@
+/* 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_ruby.hh>
+
+using namespace paludis;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_generator_module;
+ static VALUE c_generator;
+ static VALUE c_generator_all;
+ static VALUE c_generator_matches;
+ static VALUE c_generator_package;
+ static VALUE c_generator_repository;
+ static VALUE c_generator_category;
+ static VALUE c_generator_union;
+ static VALUE c_generator_some_ids_might_support_action;
+
+ VALUE
+ generator_init(int, VALUE *, VALUE self)
+ {
+ return self;
+ }
+
+ VALUE
+ generator_all_new(VALUE self)
+ {
+ Generator * ptr(0);
+ try
+ {
+ ptr = new generator::All();
+ VALUE data(Data_Wrap_Struct(self, 0, &Common<Generator>::free, ptr));
+ rb_obj_call_init(data, 0, &self);
+ return data;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ generator_ampersand(VALUE self, VALUE other)
+ {
+ Generator * ptr(0);
+ try
+ {
+ Generator g1(value_to_generator(self));
+ Generator g2(value_to_generator(other));
+ return generator_to_value(g1 & g2);
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ generator_bar(VALUE self, VALUE other)
+ {
+ Generator * ptr(0);
+ try
+ {
+ Generator g1(value_to_generator(self));
+ Filter f1(value_to_filter(other));
+ return filtered_generator_to_value(g1 | f1);
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ generator_matches_new(VALUE self, VALUE spec_v)
+ {
+ Generator * ptr(0);
+ try
+ {
+ std::tr1::shared_ptr<const PackageDepSpec> spec(value_to_package_dep_spec(spec_v));
+ ptr = new generator::Matches(*spec);
+ VALUE data(Data_Wrap_Struct(self, 0, &Common<Generator>::free, ptr));
+ rb_obj_call_init(data, 1, &spec_v);
+ return data;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ generator_category_new(VALUE self, VALUE name_v)
+ {
+ Generator * ptr(0);
+ try
+ {
+ CategoryNamePart name(StringValuePtr(name_v));
+ ptr = new generator::Category(name);
+ VALUE data(Data_Wrap_Struct(self, 0, &Common<Generator>::free, ptr));
+ rb_obj_call_init(data, 1, &name_v);
+ return data;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ generator_package_new(VALUE self, VALUE name_v)
+ {
+ Generator * ptr(0);
+ try
+ {
+ QualifiedPackageName name(value_to_qualified_package_name(name_v));
+ ptr = new generator::Package(name);
+ VALUE data(Data_Wrap_Struct(self, 0, &Common<Generator>::free, ptr));
+ rb_obj_call_init(data, 1, &name_v);
+ return data;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ generator_repository_new(VALUE self, VALUE name_v)
+ {
+ Generator * ptr(0);
+ try
+ {
+ RepositoryName name(StringValuePtr(name_v));
+ ptr = new generator::Repository(name);
+ VALUE data(Data_Wrap_Struct(self, 0, &Common<Generator>::free, ptr));
+ rb_obj_call_init(data, 1, &name_v);
+ return data;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ generator_union_new(VALUE self, VALUE f1_v, VALUE f2_v)
+ {
+ Generator * ptr(0);
+ try
+ {
+ Generator f1(value_to_generator(f1_v));
+ Generator f2(value_to_generator(f2_v));
+ ptr = new generator::Union(f1, f2);
+ VALUE data(Data_Wrap_Struct(self, 0, &Common<Generator>::free, ptr));
+ rb_obj_call_init(data, 2, &f1_v);
+ return data;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ generator_some_ids_might_support_action_new(VALUE self, VALUE action_class)
+ {
+ Generator * ptr(0);
+ try
+ {
+ if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, install_action_value_ptr()))
+ ptr = new generator::SomeIDsMightSupportAction<InstallAction>();
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, installed_action_value_ptr()))
+ ptr = new generator::SomeIDsMightSupportAction<InstalledAction>();
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, uninstall_action_value_ptr()))
+ ptr = new generator::SomeIDsMightSupportAction<UninstallAction>();
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, pretend_action_value_ptr()))
+ ptr = new generator::SomeIDsMightSupportAction<PretendAction>();
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, config_action_value_ptr()))
+ ptr = new generator::SomeIDsMightSupportAction<ConfigAction>();
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, fetch_action_value_ptr()))
+ ptr = new generator::SomeIDsMightSupportAction<FetchAction>();
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, info_action_value_ptr()))
+ ptr = new generator::SomeIDsMightSupportAction<InfoAction>();
+ else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, pretend_fetch_action_value_ptr()))
+ ptr = new generator::SomeIDsMightSupportAction<PretendFetchAction>();
+ else
+ rb_raise(rb_eTypeError, "Can't convert %s into an Action subclass", rb_obj_classname(action_class));
+
+ VALUE data(Data_Wrap_Struct(self, 0, &Common<Generator>::free, ptr));
+ rb_obj_call_init(data, 1, &action_class);
+ return data;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ void do_register_generator()
+ {
+ c_generator_module = rb_define_module_under(paludis_module(), "Generator");
+
+ c_generator = rb_define_class_under(c_generator_module, "Generator", rb_cObject);
+ rb_funcall(c_generator, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_generator, "initialize", RUBY_FUNC_CAST(&generator_init), -1);
+ rb_define_method(c_generator, "to_s", RUBY_FUNC_CAST(&Common<Generator>::to_s), 0);
+ rb_define_method(c_generator, "&", RUBY_FUNC_CAST(&generator_ampersand), 1);
+ rb_define_method(c_generator, "|", RUBY_FUNC_CAST(&generator_bar), 1);
+
+ c_generator_all = rb_define_class_under(c_generator_module, "All", c_generator);
+ rb_define_singleton_method(c_generator_all, "new", RUBY_FUNC_CAST(&generator_all_new), 0);
+
+ c_generator_matches = rb_define_class_under(c_generator_module, "Matches", c_generator);
+ rb_define_singleton_method(c_generator_matches, "new", RUBY_FUNC_CAST(&generator_matches_new), 1);
+
+ c_generator_union = rb_define_class_under(c_generator_module, "Union", c_generator);
+ rb_define_singleton_method(c_generator_union, "new", RUBY_FUNC_CAST(&generator_union_new), 2);
+
+ c_generator_package = rb_define_class_under(c_generator_module, "Package", c_generator);
+ rb_define_singleton_method(c_generator_package, "new", RUBY_FUNC_CAST(&generator_package_new), 1);
+
+ c_generator_category = rb_define_class_under(c_generator_module, "Category", c_generator);
+ rb_define_singleton_method(c_generator_category, "new", RUBY_FUNC_CAST(&generator_category_new), 1);
+
+ c_generator_repository = rb_define_class_under(c_generator_module, "Repository", c_generator);
+ rb_define_singleton_method(c_generator_repository, "new", RUBY_FUNC_CAST(&generator_repository_new), 1);
+
+ c_generator_some_ids_might_support_action = rb_define_class_under(c_generator_module, "SomeIDsMightSupportAction", c_generator);
+ rb_define_singleton_method(c_generator_some_ids_might_support_action, "new", RUBY_FUNC_CAST(&generator_some_ids_might_support_action_new), 1);
+ }
+}
+
+Generator
+paludis::ruby::value_to_generator(VALUE v)
+{
+ if (rb_obj_is_kind_of(v, c_generator))
+ {
+ Generator * f_ptr;
+ Data_Get_Struct(v, Generator, f_ptr);
+ return *f_ptr;
+ }
+ else
+ rb_raise(rb_eTypeError, "Can't convert %s into Generator", rb_obj_classname(v));
+}
+
+VALUE
+paludis::ruby::generator_to_value(const Generator & v)
+{
+ Generator * vv(new Generator(v));
+ return Data_Wrap_Struct(c_generator, 0, &Common<Generator>::free, vv);
+}
+
+RegisterRubyClass::Register paludis_ruby_register_generator PALUDIS_ATTRIBUTE((used))
+ (&do_register_generator);
+
diff --git a/ruby/generator_TEST.rb b/ruby/generator_TEST.rb
new file mode 100644
index 0000000..b8ba163
--- /dev/null
+++ b/ruby/generator_TEST.rb
@@ -0,0 +1,140 @@
+#!/usr/bin/ruby
+# vim: set sw=4 sts=4 et tw=80 :
+
+#
+# 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
+#
+
+require 'test/unit'
+require 'Paludis'
+
+module Paludis
+ class TestCase_Generator < Test::Unit::TestCase
+ def test_no_create
+ assert_raise NoMethodError do
+ Generator::new
+ end
+ end
+ end
+
+ class TestCase_GeneratorAll < Test::Unit::TestCase
+ def test_create
+ assert_nothing_raised do
+ Generator::All.new
+ end
+ end
+
+ def test_to_s
+ assert_equal Generator::All.new.to_s, "all packages"
+ end
+ end
+
+ class TestCase_GeneratorMatches < Test::Unit::TestCase
+ def test_create
+ assert_nothing_raised do
+ Generator::Matches.new(Paludis::parse_user_package_dep_spec("a/b", []))
+ end
+ end
+
+ def test_to_s
+ assert_equal Generator::Matches.new(Paludis::parse_user_package_dep_spec("a/b", [])).to_s, "packages matching a/b"
+ end
+ end
+
+ class TestCase_GeneratorCategory < Test::Unit::TestCase
+ def test_create
+ assert_nothing_raised do
+ Generator::Category.new("cat")
+ end
+ end
+
+ def test_to_s
+ assert_equal Generator::Category.new("cat").to_s, "packages with category cat"
+ end
+ end
+
+ class TestCase_GeneratorRepository < Test::Unit::TestCase
+ def test_create
+ assert_nothing_raised do
+ Generator::Repository.new("repo")
+ end
+ end
+
+ def test_to_s
+ assert_equal Generator::Repository.new("repo").to_s, "packages with repository repo"
+ end
+ end
+
+ class TestCase_GeneratorPackage < Test::Unit::TestCase
+ def test_create
+ assert_nothing_raised do
+ Generator::Package.new("cat/pkg")
+ end
+ end
+
+ def test_to_s
+ assert_equal Generator::Package.new("cat/pkg").to_s, "packages named cat/pkg"
+ end
+ end
+
+ class TestCase_GeneratorSomeIDsMightSupportAction < Test::Unit::TestCase
+ def test_create
+ assert_nothing_raised do
+ Generator::SomeIDsMightSupportAction.new(InstallAction)
+ end
+ end
+
+ def test_bad_create
+ assert_raise TypeError do
+ Generator::SomeIDsMightSupportAction.new(String)
+ end
+ end
+
+ def test_to_s
+ assert_equal Generator::SomeIDsMightSupportAction.new(InstallAction).to_s, "packages that might support action install"
+ end
+ end
+
+ class TestCase_GeneratorUnion < Test::Unit::TestCase
+ def test_create
+ assert_nothing_raised do
+ Generator::Union.new(Generator::All.new, Generator::SomeIDsMightSupportAction.new(InstallAction))
+ end
+ end
+
+ def test_to_s
+ assert_equal Generator::Union.new(Generator::All.new, Generator::SomeIDsMightSupportAction.new(InstallAction)).to_s,
+ "all packages intersected with packages that might support action install"
+ end
+ end
+
+ class TestCase_GeneratorAmpersand < Test::Unit::TestCase
+ def test_create
+ g1 = Generator::All.new
+ g2 = Generator::SomeIDsMightSupportAction.new(InstallAction)
+ assert_nothing_raised do
+ g1 & g2
+ end
+ end
+
+ def test_to_s
+ assert_equal (Generator::All.new & Generator::SomeIDsMightSupportAction.new(InstalledAction)).to_s,
+ "all packages intersected with packages that might support action installed"
+ end
+ end
+end
+
+
diff --git a/ruby/package_database.cc b/ruby/package_database.cc
index 6c928a7..4482c59 100644
--- a/ruby/package_database.cc
+++ b/ruby/package_database.cc
@@ -32,7 +32,6 @@ using namespace paludis::ruby;
namespace
{
static VALUE c_package_database;
- static VALUE c_package_database_query_order;
/*
* call-seq:
@@ -58,9 +57,9 @@ namespace
/*
* call-seq:
* fetch_unique_qualified_package_name(package_name) -> QualifiedPackageName
- * fetch_unique_qualified_package_name(package_name, query) -> QualifiedPackageName
+ * fetch_unique_qualified_package_name(package_name, filter) -> QualifiedPackageName
*
- * Disambiguate a package name. If a query is specified, limit
+ * Disambiguate a package name. If a filter is specified, limit
* the potential results to packages that match.
*/
VALUE
@@ -73,7 +72,7 @@ namespace
std::tr1::shared_ptr<PackageDatabase> * self_ptr;
Data_Get_Struct(self, std::tr1::shared_ptr<PackageDatabase>, self_ptr);
return rb_str_new2(stringify((*self_ptr)->fetch_unique_qualified_package_name(
- PackageNamePart(StringValuePtr(argv[0])), 2 == argc ? value_to_query(argv[1]) : query::All())).c_str());
+ PackageNamePart(StringValuePtr(argv[0])), 2 == argc ? value_to_filter(argv[1]) : filter::All())).c_str());
}
else
rb_raise(rb_eArgError, "fetch_unique_qualified_package_name expects one or two arguments, but got %d",argc);
@@ -86,45 +85,6 @@ namespace
/*
* call-seq:
- * query(query, query_order) -> Array
- * query(spec, install_state, query_order) -> Array
- *
- * Query the repository, the first argument is either a PackageDepSpec or a Query.
- * Returns an array of PackageID.
- */
-
- VALUE
- package_database_query(int argc, VALUE *argv, VALUE self)
- {
- std::tr1::shared_ptr<const PackageIDSequence> items;
- try
- {
- if (2 == argc)
- {
- Query q = value_to_query(argv[0]);
- QueryOrder qo = static_cast<QueryOrder>(NUM2INT(argv[1]));
-
- std::tr1::shared_ptr<PackageDatabase> * self_ptr;
- Data_Get_Struct(self, std::tr1::shared_ptr<PackageDatabase>, self_ptr);
-
- items = ((*self_ptr)->query(q, qo));
- }
- else
- rb_raise(rb_eArgError, "query expects two arguments, but got %d",argc);
- }
- catch (const std::exception & e)
- {
- exception_to_ruby_exception(e);
- }
- VALUE result(rb_ary_new());
- for (PackageIDSequence::ConstIterator i(items->begin()),
- i_end(items->end()) ; i != i_end ; ++i)
- rb_ary_push(result, package_id_to_value(*i));
- return result;
- }
-
- /*
- * call-seq:
* repositories -> Array
* repositories {|repository| block } -> Nil
*
@@ -238,8 +198,6 @@ namespace
rb_define_method(c_package_database, "favourite_repository", RUBY_FUNC_CAST(&package_database_favourite_repository), 0);
rb_define_method(c_package_database, "fetch_unique_qualified_package_name",
RUBY_FUNC_CAST(&package_database_fetch_unique_qualified_package_name), -1);
- rb_define_method(c_package_database, "query",
- RUBY_FUNC_CAST(&package_database_query), -1);
rb_define_method(c_package_database, "repositories",
RUBY_FUNC_CAST(&package_database_repositories), 0);
rb_define_method(c_package_database, "fetch_repository",
@@ -249,17 +207,6 @@ namespace
rb_define_method(c_package_database, "has_repository_named?",
RUBY_FUNC_CAST(&package_database_has_repository_named), 1);
- /*
- * Document-module: Paludis::QueryOrder
- *
- * How to order query results.
- */
- c_package_database_query_order = rb_define_module_under(paludis_module(), "QueryOrder");
- for (QueryOrder l(static_cast<QueryOrder>(0)), l_end(last_qo) ; l != l_end ;
- l = static_cast<QueryOrder>(static_cast<int>(l) + 1))
- rb_define_const(c_package_database_query_order, value_case_to_RubyCase(stringify(l)).c_str(), INT2FIX(l));
-
- // cc_enum_special<paludis/package_database-se.hh, QueryOrder, c_package_database_query_order>
}
}
diff --git a/ruby/package_database_TEST.rb b/ruby/package_database_TEST.rb
index 571d160..e79f1f2 100644
--- a/ruby/package_database_TEST.rb
+++ b/ruby/package_database_TEST.rb
@@ -2,7 +2,7 @@
# vim: set sw=4 sts=4 et tw=80 :
#
-# Copyright (c) 2006, 2007 Ciaran McCreesh
+# Copyright (c) 2006, 2007, 2008 Ciaran McCreesh
# Copyright (c) 2007 Richard Brown
#
# This file is part of the Paludis package manager. Paludis is free software;
@@ -56,7 +56,7 @@ module Paludis
def test_package_database_fetch_unique_qualified_package_name
assert_equal "foo/bar", db.fetch_unique_qualified_package_name("bar")
- assert_equal "foo/bar", db.fetch_unique_qualified_package_name("bar", Query::SupportsInstallAction.new)
+ assert_equal "foo/bar", db.fetch_unique_qualified_package_name("bar", Filter::SupportsAction.new(InstallAction))
end
def test_error
@@ -67,7 +67,7 @@ module Paludis
db.fetch_unique_qualified_package_name('foobarbaz')
end
assert_raise NoSuchPackageError do
- db.fetch_unique_qualified_package_name('bar', Query::SupportsInstalledAction.new)
+ db.fetch_unique_qualified_package_name('bar', Filter::SupportsAction.new(InstalledAction))
end
end
@@ -87,114 +87,6 @@ module Paludis
end
end
- class TestCase_PackageDatabaseQuery < Test::Unit::TestCase
- def env
- @env or @env = EnvironmentMaker.instance.make_from_spec("")
- end
-
- def db
- return env.package_database
- end
-
- def pda
- Paludis::parse_user_package_dep_spec('=foo/bar-1.0', [])
- end
-
- def pda2
- Paludis::parse_user_package_dep_spec('foo/bar', [])
- end
-
- def test_arg_count
- assert_raise ArgumentError do
- db.query(1);
- end
-
- assert_nothing_raised do
- db.query(Query::Matches.new(pda), QueryOrder::Whatever)
- end
-
- assert_raise ArgumentError do
- db.query(1,2,3,4);
- end
- end
-
- def test_package_database_query
- a = db.query(Query::Matches.new(pda), QueryOrder::Whatever)
- assert_kind_of Array, a
- assert_equal 1, a.length
- pid = a.first
- assert_kind_of PackageID, pid
- assert_equal 'foo/bar', pid.name
- assert_equal '1.0', pid.version.to_s
- assert_equal 'testrepo', pid.repository_name
-
- a = db.query(Query::Matches.new(pda) & Query::SupportsInstallAction.new,
- QueryOrder::Whatever)
- assert_kind_of Array, a
- assert_equal 1, a.length
- pid = a.first
- assert_kind_of PackageID, pid
- assert_equal 'foo/bar', pid.name
- assert_equal '1.0', pid.version.to_s
- assert_equal 'testrepo', pid.repository_name
-
- a = db.query(Query::Matches.new(pda), QueryOrder::Whatever)
- assert_kind_of Array, a
- assert_equal 1, a.length
- pid = a.first
- assert_kind_of PackageID, pid
- assert_equal 'foo/bar', pid.name
- assert_equal '1.0', pid.version.to_s
- assert_equal 'testrepo', pid.repository_name
-
- a = db.query(Query::Matches.new(pda2) & Query::SupportsInstallAction.new, QueryOrder::OrderByVersion)
- assert_kind_of Array, a
- assert_equal 2, a.length
- pid = a.shift
- assert_kind_of PackageID, pid
- assert_equal 'foo/bar', pid.name
- assert_equal '1.0', pid.version.to_s
- assert_equal 'testrepo', pid.repository_name
- pid2 = a.shift
- assert_kind_of PackageID, pid2
- assert_equal pid.name, pid2.name
- assert_equal '2.0', pid2.version.to_s
- assert_equal pid.repository_name, pid2.repository_name
-
-
- a = db.query(Query::Package.new('foo/bar'), QueryOrder::OrderByVersion)
- assert_kind_of Array, a
- assert_equal 2, a.length
- pid = a.shift
- assert_kind_of PackageID, pid
- assert_equal 'foo/bar', pid.name
- assert_equal '1.0', pid.version.to_s
- assert_equal 'testrepo', pid.repository_name
- pid2 = a.shift
- assert_kind_of PackageID, pid2
- assert_equal pid.name, pid2.name
- assert_equal '2.0', pid2.version.to_s
- assert_equal pid.repository_name, pid2.repository_name
-
-
- a = db.query(Query::Matches.new(Paludis::parse_user_package_dep_spec('>=foo/bar-27', [])),
- QueryOrder::Whatever)
- assert a.empty?
-
- a = db.query(Query::Matches.new(pda2) & Query::SupportsInstalledAction.new, QueryOrder::Whatever)
- assert a.empty?
- end
-
- def test_package_database_query_bad
- assert_raise TypeError do
- db.query(123, QueryOrder::Whatever)
- end
- assert_raise TypeError do
- db.query(pda2, "Either")
- end
- end
- end
-
class TestCase_PackageDatabaseRepositories < Test::Unit::TestCase
def env
@env or @env = EnvironmentMaker.instance.make_from_spec("")
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index 3f41a6a..e3f18ad 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -30,12 +30,15 @@
#include <paludis/util/fs_entry.hh>
#include <paludis/environment.hh>
#include <paludis/environments/no_config/no_config_environment.hh>
-#include <paludis/query.hh>
#include <paludis/repository.hh>
#include <paludis/contents.hh>
#include <paludis/dep_tag.hh>
#include <paludis/mask-fwd.hh>
#include <paludis/metadata_key.hh>
+#include <paludis/selection.hh>
+#include <paludis/filter.hh>
+#include <paludis/generator.hh>
+#include <paludis/filtered_generator.hh>
#include <paludis/util/stringify.hh>
#include <paludis/util/hashes.hh>
@@ -71,8 +74,6 @@ namespace paludis
VALUE paludis_module();
- bool is_kind_of_query(VALUE query);
-
/* constructors */
VALUE package_database_to_value(std::tr1::shared_ptr<PackageDatabase>);
@@ -85,6 +86,9 @@ namespace paludis
VALUE repository_mask_info_to_value(std::tr1::shared_ptr<const RepositoryMaskInfo>);
VALUE metadata_key_to_value(std::tr1::shared_ptr<const MetadataKey> m);
VALUE fetch_action_failure_to_value(const FetchActionFailure &);
+ VALUE generator_to_value(const Generator &);
+ VALUE filter_to_value(const Filter &);
+ VALUE filtered_generator_to_value(const FilteredGenerator &);
#ifdef ENABLE_RUBY_QA
VALUE qa_message_to_value(const QAMessage &);
#endif
@@ -103,11 +107,24 @@ namespace paludis
std::tr1::shared_ptr<Environment> value_to_environment(VALUE v);
std::tr1::shared_ptr<NoConfigEnvironment> value_to_no_config_environment(VALUE v);
RepositoryEInterface::ProfilesDescLine value_to_profiles_desc_line(VALUE v);
- Query value_to_query(VALUE v);
std::tr1::shared_ptr<Repository> value_to_repository(VALUE);
std::tr1::shared_ptr<const SupportsActionTestBase> value_to_supports_action_test_base(VALUE v);
std::tr1::shared_ptr<Action> value_to_action(VALUE v);
+ Filter value_to_filter(VALUE v);
+ Selection value_to_selection(VALUE v);
+ FilteredGenerator value_to_filtered_generator(VALUE v);
+ Generator value_to_generator(VALUE v);
+
+ VALUE * install_action_value_ptr();
+ VALUE * fetch_action_value_ptr();
+ VALUE * info_action_value_ptr();
+ VALUE * config_action_value_ptr();
+ VALUE * uninstall_action_value_ptr();
+ VALUE * pretend_action_value_ptr();
+ VALUE * installed_action_value_ptr();
+ VALUE * pretend_fetch_action_value_ptr();
+
#ifdef ENABLE_RUBY_QA
QACheckProperties value_to_qa_check_properties(VALUE);
#endif
diff --git a/ruby/paludis_ruby_TEST.rb b/ruby/paludis_ruby_TEST.rb
index 128c99a..4d6f7c9 100644
--- a/ruby/paludis_ruby_TEST.rb
+++ b/ruby/paludis_ruby_TEST.rb
@@ -2,7 +2,7 @@
# vim: set sw=4 sts=4 et tw=80 :
#
-# Copyright (c) 2006, 2007 Ciaran McCreesh
+# Copyright (c) 2006, 2007, 2008 Ciaran McCreesh
# Copyright (c) 2008 Richard Brown
#
# This file is part of the Paludis package manager. Paludis is free software;
@@ -41,8 +41,8 @@ module Paludis
env = EnvironmentMaker.instance.make_from_spec("")
spec_good = Paludis::parse_user_package_dep_spec('>=foo/bar-1', [])
spec_bad = Paludis::parse_user_package_dep_spec('>=foo/bar-2', [])
- pid = env.package_database.query(Query::Matches.new(
- Paludis::parse_user_package_dep_spec('=foo/bar-1.0::testrepo', [])), QueryOrder::RequireExactlyOne).first
+ pid = env[Selection::RequireExactlyOne.new(Generator::Matches.new(
+ Paludis::parse_user_package_dep_spec('=foo/bar-1.0::testrepo', [])))].first
assert Paludis::match_package(env, spec_good, pid)
assert !Paludis::match_package(env, spec_bad, pid)
@@ -52,8 +52,8 @@ module Paludis
def test_match_package_in_set
env = EnvironmentMaker.instance.make_from_spec("")
world = env.set('world')
- pid = env.package_database.query(Query::Matches.new(
- Paludis::parse_user_package_dep_spec('=foo/bar-1.0::testrepo', [])), QueryOrder::RequireExactlyOne).first
+ pid = env[Selection::RequireExactlyOne.new(Generator::Matches.new(
+ Paludis::parse_user_package_dep_spec('=foo/bar-1.0::testrepo', [])))].first
assert Paludis::match_package_in_set(env, world, pid)
end
@@ -61,8 +61,8 @@ module Paludis
def test_type_errors
env = EnvironmentMaker.instance.make_from_spec("")
spec = Paludis::parse_user_package_dep_spec('>=foo/bar-1', [])
- pid = env.package_database.query(Query::Matches.new(
- Paludis::parse_user_package_dep_spec('=foo/bar-1.0::testrepo', [])), QueryOrder::RequireExactlyOne).first
+ pid = env[Selection::RequireExactlyOne.new(Generator::Matches.new(
+ Paludis::parse_user_package_dep_spec('=foo/bar-1.0::testrepo', [])))].first
assert_raise TypeError do
Paludis::match_package(spec,spec,pid)
diff --git a/ruby/query.cc b/ruby/query.cc
deleted file mode 100644
index 0326c94..0000000
--- a/ruby/query.cc
+++ /dev/null
@@ -1,394 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2007 Richard Brown
- * Copyright (c) 2007 Alexander Færøy
- * Copyright (c) 2007 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_ruby.hh>
-#include <paludis/util/log.hh>
-#include <paludis/query.hh>
-#include <ruby.h>
-
-using namespace paludis;
-using namespace paludis::ruby;
-
-#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
-
-namespace
-{
- static VALUE c_query_module;
- static VALUE c_query;
- static VALUE c_matches;
- static VALUE c_package;
- static VALUE c_repository;
- static VALUE c_category;
- static VALUE c_not_masked;
- static VALUE c_installed_at_root;
- static VALUE c_all;
- static VALUE c_supports_install_action;
- static VALUE c_supports_uninstall_action;
- static VALUE c_supports_installed_action;
- static VALUE c_supports_pretend_action;
- static VALUE c_supports_config_action;
-
- VALUE
- query_to_value(const Query & v)
- {
- Query * vv(new Query(v));
- return Data_Wrap_Struct(c_query, 0, &Common<Query>::free, vv);
- }
-
- VALUE
- query_init(int, VALUE *, VALUE self)
- {
- return self;
- }
-
- /*
- * Document-method: &
- *
- * call-seq:
- * &(other_query) -> Query
- *
- * Combine Queries
- */
- VALUE
- query_and(VALUE self, VALUE other)
- {
- Query * ptr;
- Data_Get_Struct(self, Query, ptr);
- try
- {
- return query_to_value((*ptr) & value_to_query(other));
- }
- catch (const std::exception & e)
- {
- exception_to_ruby_exception(e);
- }
- }
-
- /*
- * call-seq:
- * Matches.new(pda)
- *
- * Create a new Matches Query object from the given PackageDepSpec.
- */
- VALUE
- matches_new(VALUE self, VALUE pda)
- {
- Query * ptr(0);
- try
- {
- ptr = new query::Matches(*value_to_package_dep_spec(pda));
- VALUE tdata(Data_Wrap_Struct(self, 0, &Common<Query>::free, ptr));
- rb_obj_call_init(tdata, 1, &pda);
- return tdata;
-
- }
- catch (const std::exception & e)
- {
- delete ptr;
- exception_to_ruby_exception(e);
- }
- }
-
- /*
- * call-seq:
- * Package.new(qpn)
- *
- * Create a new Package Query object from the given QualifiedPackageName.
- */
- VALUE
- package_new(VALUE self, VALUE qpn)
- {
- Query * ptr(0);
- try
- {
- ptr = new query::Package(value_to_qualified_package_name(qpn));
- VALUE tdata(Data_Wrap_Struct(self, 0, &Common<Query>::free, ptr));
- rb_obj_call_init(tdata, 1, &qpn);
- return tdata;
-
- }
- catch (const std::exception & e)
- {
- delete ptr;
- exception_to_ruby_exception(e);
- }
- }
-
- template <typename A_>
- struct QueryNew
- {
- static VALUE
- query_new(VALUE self)
- {
- Query * ptr = new A_();
- VALUE tdata(Data_Wrap_Struct(self, 0, &Common<Query>::free, ptr));
- rb_obj_call_init(tdata, 0, 0);
- return tdata;
- }
- };
-
- /*
- * call-seq:
- * InstalledAtRoot.new(root)
- *
- *
- */
- VALUE
- installed_at_root_new(VALUE self, VALUE root)
- {
- Query * ptr(0);
- try
- {
- ptr = new query::InstalledAtRoot(FSEntry(StringValuePtr(root)));
- VALUE tdata(Data_Wrap_Struct(self, 0, &Common<Query>::free, ptr));
- rb_obj_call_init(tdata, 1, &root);
- return tdata;
-
- }
- catch (const std::exception & e)
- {
- delete ptr;
- exception_to_ruby_exception(e);
- }
- }
-
- /*
- * call-seq:
- * Repository.new(repository_name)
- *
- *
- */
- VALUE
- repository_new(VALUE self, VALUE repository_name)
- {
- Query * ptr(0);
- try
- {
- ptr = new query::Repository(RepositoryName(StringValuePtr(repository_name)));
- VALUE tdata(Data_Wrap_Struct(self, 0, &Common<Query>::free, ptr));
- rb_obj_call_init(tdata, 1, &repository_name);
- return tdata;
- }
- catch (const std::exception & e)
- {
- delete ptr;
- exception_to_ruby_exception(e);
- }
- }
-
- /*
- * call-seq:
- * All.new()
- *
- *
- */
- VALUE
- all_new(VALUE self)
- {
- Query * ptr(0);
- try
- {
- ptr = new query::All();
- VALUE tdata(Data_Wrap_Struct(self, 0, &Common<Query>::free, ptr));
- rb_obj_call_init(tdata, 0, 0);
- return tdata;
- }
- catch (const std::exception & e)
- {
- delete ptr;
- exception_to_ruby_exception(e);
- }
- }
-
- /*
- * call-seq
- * Category.new(category_name)
- *
- *
- */
- VALUE
- category_new(VALUE self, VALUE category_name)
- {
- Query * ptr(0);
- try
- {
- ptr = new query::Category(CategoryNamePart(StringValuePtr(category_name)));
- VALUE tdata(Data_Wrap_Struct(self, 0, &Common<Query>::free, ptr));
- rb_obj_call_init(tdata, 1, &category_name);
- return tdata;
- }
- catch (const std::exception & e)
- {
- delete ptr;
- exception_to_ruby_exception(e);
- }
- }
-
- void do_register_query()
- {
- /*
- * Document-module: Paludis::Query
- *
- * Collection of classes for use in querying package databases
- */
- c_query_module = rb_define_module_under(paludis_module(), "Query");
-
- /*
- * Document-class: Paludis::Query::Query
- *
- * Base query class.
- */
- c_query = rb_define_class_under(c_query_module, "Query", rb_cObject);
- rb_funcall(c_query, rb_intern("private_class_method"), 1, rb_str_new2("new"));
- rb_define_method(c_query, "initialize", RUBY_FUNC_CAST(&query_init), -1);
- rb_define_method(c_query, "&", RUBY_FUNC_CAST(&query_and), 1);
- rb_define_method(c_query, "to_s", RUBY_FUNC_CAST(&Common<Query>::to_s), 0);
-
- /*
- * Document-class: Paludis::Query::Matches
- *
- * Fetch packages matching a given PackageDepSpec.
- */
- c_matches = rb_define_class_under(c_query_module, "Matches", c_query);
- rb_define_singleton_method(c_matches, "new", RUBY_FUNC_CAST(&matches_new), 1);
-
- /*
- * Document-class: Paludis::Query::Package
- *
- * Fetch packages with a given package name.
- */
- c_package = rb_define_class_under(c_query_module, "Package", c_query);
- rb_define_singleton_method(c_package, "new", RUBY_FUNC_CAST(&package_new), 1);
-
- /*
- * Document-class: Paludis::Query::NotMasked
- *
- * Fetch packages that are not masked.
- */
- c_not_masked = rb_define_class_under(c_query_module, "NotMasked", c_query);
- rb_define_singleton_method(c_not_masked, "new",
- RUBY_FUNC_CAST(&QueryNew<query::NotMasked>::query_new), 0);
-
- /*
- * Document-class: Paludis::Query::InstalledAtRoot
- *
- * Fetch packages that are installed at a particular root.
- */
- c_installed_at_root = rb_define_class_under(c_query_module,
- "InstalledAtRoot", c_query);
- rb_define_singleton_method(c_installed_at_root, "new", RUBY_FUNC_CAST(&installed_at_root_new), 1);
-
- /*
- * Document-class: Paludis::Query::Repository
- *
- * Fetch packages that are installed at a particular repository.
- */
- c_repository = rb_define_class_under(c_query_module, "Repository", c_query);
- rb_define_singleton_method(c_repository, "new", RUBY_FUNC_CAST(&repository_new), 1);
-
- /*
- * Document-class: Paludis::Query::All
- *
- * Fetch all packages.
- */
- c_all = rb_define_class_under(c_query_module, "All", c_query);
- rb_define_singleton_method(c_all, "new", RUBY_FUNC_CAST(&all_new), 0);
-
- /*
- * Document-class: Paludis::Query::Category
- *
- * Fetch all packages from a particular category.
- */
- c_category = rb_define_class_under(c_query_module, "Category", c_query);
- rb_define_singleton_method(c_category, "new", RUBY_FUNC_CAST(&category_new), 1);
-
- /*
- * Document-class: Paludis::Query::SupportsInstallAction
- *
- * Fetch packages that support InstallAction
- */
- c_supports_install_action = rb_define_class_under(c_query_module, "SupportsInstallAction", c_query);
- rb_define_singleton_method(c_supports_install_action, "new",
- RUBY_FUNC_CAST(&QueryNew<query::SupportsAction<InstallAction> >::query_new), 0);
-
- /*
- * Document-class: Paludis::Query::SupportsUninstallAction
- *
- * Fetch packages that support UninstallAction
- */
- c_supports_uninstall_action = rb_define_class_under(c_query_module, "SupportsUninstallAction", c_query);
- rb_define_singleton_method(c_supports_uninstall_action, "new",
- RUBY_FUNC_CAST(&QueryNew<query::SupportsAction<UninstallAction> >::query_new), 0);
-
- /*
- * Document-class: Paludis::Query::SupportsInstalledAction
- *
- * Fetch packages that support InstalledAction
- */
- c_supports_installed_action = rb_define_class_under(c_query_module, "SupportsInstalledAction", c_query);
- rb_define_singleton_method(c_supports_installed_action, "new",
- RUBY_FUNC_CAST(&QueryNew<query::SupportsAction<InstalledAction> >::query_new), 0);
-
- /*
- * Document-class: Paludis::Query::SupportsPretendAction
- *
- * Fetch packages that support PretendAction
- */
- c_supports_pretend_action = rb_define_class_under(c_query_module, "SupportsPretendAction", c_query);
- rb_define_singleton_method(c_supports_pretend_action, "new",
- RUBY_FUNC_CAST(&QueryNew<query::SupportsAction<PretendAction> >::query_new), 0);
-
- /*
- * Document-class: Paludis::Query::SupportsConfigAction
- *
- * Fetch packages that support ConfigAction
- */
- c_supports_config_action = rb_define_class_under(c_query_module, "SupportsConfigAction", c_query);
- rb_define_singleton_method(c_supports_config_action, "new",
- RUBY_FUNC_CAST(&QueryNew<query::SupportsAction<ConfigAction> >::query_new), 0);
- }
-}
-
-Query
-paludis::ruby::value_to_query(VALUE v)
-{
- if (rb_obj_is_kind_of(v, c_query))
- {
- Query * v_ptr;
- Data_Get_Struct(v, Query, v_ptr);
- return *v_ptr;
- }
- else
- {
- rb_raise(rb_eTypeError, "Can't convert %s into Query", rb_obj_classname(v));
- }
-}
-
-bool
-paludis::ruby::is_kind_of_query(VALUE v)
-{
- return rb_obj_is_kind_of(v, c_query);
-}
-
-
-RegisterRubyClass::Register paludis_ruby_register_query PALUDIS_ATTRIBUTE((used)) (&do_register_query);
-
-
diff --git a/ruby/query_TEST.rb b/ruby/query_TEST.rb
deleted file mode 100644
index b4f516b..0000000
--- a/ruby/query_TEST.rb
+++ /dev/null
@@ -1,244 +0,0 @@
-#!/usr/bin/env ruby
-# vim: set sw=4 sts=4 et tw=80 :
-
-#
-# Copyright (c) 2007 Richard Brown
-# Copyright (c) 2007 Alexander Færøy
-#
-# 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
-#
-
-require 'test/unit'
-require 'Paludis'
-
-module Paludis
- class TestCase_Query < Test::Unit::TestCase
- def test_no_create
- assert_raise NoMethodError do
- Query::Query.new;
- end
- end
- end
-
- class TestCase_NotMasked < Test::Unit::TestCase
- def get_query
- Query::NotMasked.new
- end
-
- def test_create
- assert_nothing_raised do
- get_query
- end
- end
-
- def test_and
- q = get_query
- assert_respond_to q, :&
- assert_kind_of Query::Query, q & q
- end
-
- def test_kind_of
- assert_kind_of Query::Query, get_query
- end
- end
-
- class TestCase_Matches < Test::Unit::TestCase
- def get_query
- Query::Matches.new(Paludis::parse_user_package_dep_spec('>=foo-bar/baz-1', []))
- end
-
- def test_create
- assert_nothing_raised do
- get_query
- end
- end
-
- def test_and
- q = get_query
- assert_respond_to q, :&
- assert_kind_of Query::Query, q & q
- end
-
- def test_kind_of
- assert_kind_of Query::Query, get_query
- end
- end
-
- class TestCase_Package < Test::Unit::TestCase
- def get_query
- Query::Package.new(QualifiedPackageName.new('foo-bar/baz'))
- end
-
- def test_create
- assert_nothing_raised do
- get_query
- end
- end
-
- def test_and
- q = get_query
- assert_respond_to q, :&
- assert_kind_of Query::Query, q & q
- end
-
- def test_kind_of
- assert_kind_of Query::Query, get_query
- end
- end
-
- class TestCase_Repository < Test::Unit::TestCase
- def get_query
- Query::Repository.new("gentoo")
- end
-
- def test_create
- assert_nothing_raised do
- get_query
- end
- end
-
- def test_and
- q = get_query
- assert_respond_to q, :&
- assert_kind_of Query::Query, get_query
- end
- end
-
- class TestCase_All < Test::Unit::TestCase
- def get_query
- Query::All.new
- end
-
- def test_create
- assert_nothing_raised do
- get_query
- end
- end
-
- def test_and
- q = get_query
- assert_respond_to q, :&
- assert_kind_of Query::Query, get_query
- end
- end
-
- class TestCase_Category < Test::Unit::TestCase
- def get_query
- Query::Category.new("foo-bar")
- end
-
- def test_create
- assert_nothing_raised do
- get_query
- end
- end
-
- def test_and
- q = get_query
- assert_respond_to q, :&
- assert_kind_of Query::Query, get_query
- end
- end
-
- class TestCase_SupportsInstallAction < Test::Unit::TestCase
- def get_query
- Query::SupportsInstallAction.new
- end
-
- def test_create
- assert_nothing_raised do
- get_query
- end
- end
-
- def test_and
- q = get_query
- assert_respond_to q, :&
- assert_kind_of Query::Query, get_query
- end
- end
-
- class TestCase_SupportsUninstallAction < Test::Unit::TestCase
- def get_query
- Query::SupportsUninstallAction.new
- end
-
- def test_create
- assert_nothing_raised do
- get_query
- end
- end
-
- def test_and
- q = get_query
- assert_respond_to q, :&
- assert_kind_of Query::Query, get_query
- end
- end
-
- class TestCase_SupportsInstalledAction < Test::Unit::TestCase
- def get_query
- Query::SupportsInstalledAction.new
- end
-
- def test_create
- assert_nothing_raised do
- get_query
- end
- end
-
- def test_and
- q = get_query
- assert_respond_to q, :&
- assert_kind_of Query::Query, get_query
- end
- end
-
- class TestCase_SupportsPretendAction < Test::Unit::TestCase
- def get_query
- Query::SupportsPretendAction.new
- end
-
- def test_create
- assert_nothing_raised do
- get_query
- end
- end
-
- def test_and
- q = get_query
- assert_respond_to q, :&
- assert_kind_of Query::Query, get_query
- end
- end
-
- class TestCase_SupportsConfigAction < Test::Unit::TestCase
- def get_query
- Query::SupportsConfigAction.new
- end
-
- def test_create
- assert_nothing_raised do
- get_query
- end
- end
-
- def test_and
- q = get_query
- assert_respond_to q, :&
- assert_kind_of Query::Query, get_query
- end
- end
-end
-
diff --git a/ruby/repository_TEST.rb b/ruby/repository_TEST.rb
index 69e938b..92d07c1 100644
--- a/ruby/repository_TEST.rb
+++ b/ruby/repository_TEST.rb
@@ -38,28 +38,24 @@ module Paludis
module RepositoryTestCase
def installed_repo
- db.fetch_repository "installed"
+ env.package_database.fetch_repository "installed"
end
def repo
- db.fetch_repository "testrepo"
+ env.package_database.fetch_repository "testrepo"
end
def env
@env or @env = EnvironmentMaker.instance.make_from_spec("")
end
- def db
- env.package_database
- end
-
def no_config_testrepo
NoConfigEnvironment.new Dir.getwd().to_s + "/repository_TEST_dir/testrepo"
end
def p
- db.query(Query::Matches.new(
- Paludis::parse_user_package_dep_spec('=foo/bar-2.0::testrepo', [])), QueryOrder::RequireExactlyOne).first
+ env[Selection::RequireExactlyOne.new(Generator::Matches.new(
+ Paludis::parse_user_package_dep_spec('=foo/bar-2.0::testrepo', [])))].first
end
def installed_pid
@@ -188,7 +184,7 @@ module Paludis
end
def test_get_environment_variable
- pid = db.query(Query::Matches.new(Paludis::parse_user_package_dep_spec('=foo/bar-1.0', [])), QueryOrder::BestVersionOnly).first;
+ pid = env[Selection::BestVersionOnly.new(Generator::Matches.new(Paludis::parse_user_package_dep_spec('=foo/bar-1.0', [])))].first;
assert_equal "hello", repo.get_environment_variable(pid, "TEST_ENV_VAR")
assert_equal "", repo.get_environment_variable(pid, "TEST_UNSET_ENV_VAR")
end
diff --git a/ruby/selection.cc b/ruby/selection.cc
new file mode 100644
index 0000000..2bcba71
--- /dev/null
+++ b/ruby/selection.cc
@@ -0,0 +1,122 @@
+/* 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_ruby.hh>
+
+using namespace paludis;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_selection_module;
+ static VALUE c_selection;
+ static VALUE c_selection_some_arbitrary_version;
+ static VALUE c_selection_best_version_only;
+ static VALUE c_selection_best_version_in_each_slot;
+ static VALUE c_selection_all_versions_sorted;
+ static VALUE c_selection_all_versions_grouped_by_slot;
+ static VALUE c_selection_all_versions_unsorted;
+ static VALUE c_selection_require_exactly_one;
+
+ VALUE
+ selection_init(int, VALUE *, VALUE self)
+ {
+ return self;
+ }
+
+ template <typename T_>
+ struct SelectionNew
+ {
+ static VALUE
+ selection_new(VALUE self, VALUE fg_v)
+ {
+ Selection * ptr(0);
+ try
+ {
+ FilteredGenerator fg(value_to_filtered_generator(fg_v));
+ ptr = new T_(fg);
+ VALUE data(Data_Wrap_Struct(self, 0, &Common<Selection>::free, ptr));
+ rb_obj_call_init(data, 0, &self);
+ return data;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+ };
+
+ void do_register_selection()
+ {
+ c_selection_module = rb_define_module_under(paludis_module(), "Selection");
+
+ c_selection = rb_define_class_under(c_selection_module, "Selection", rb_cObject);
+ rb_funcall(c_selection, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_selection, "initialize", RUBY_FUNC_CAST(&selection_init), -1);
+ rb_define_method(c_selection, "to_s", RUBY_FUNC_CAST(&Common<Selection>::to_s), 0);
+
+ c_selection_some_arbitrary_version = rb_define_class_under(c_selection_module, "SomeArbitraryVersion", c_selection);
+ rb_define_singleton_method(c_selection_some_arbitrary_version, "new",
+ RUBY_FUNC_CAST(&SelectionNew<selection::SomeArbitraryVersion>::selection_new), 1);
+
+ c_selection_best_version_only = rb_define_class_under(c_selection_module, "BestVersionOnly", c_selection);
+ rb_define_singleton_method(c_selection_best_version_only, "new",
+ RUBY_FUNC_CAST(&SelectionNew<selection::BestVersionOnly>::selection_new), 1);
+
+ c_selection_best_version_in_each_slot = rb_define_class_under(c_selection_module, "BestVersionInEachSlot", c_selection);
+ rb_define_singleton_method(c_selection_best_version_in_each_slot, "new",
+ RUBY_FUNC_CAST(&SelectionNew<selection::BestVersionInEachSlot>::selection_new), 1);
+
+ c_selection_all_versions_sorted = rb_define_class_under(c_selection_module, "AllVersionsSorted", c_selection);
+ rb_define_singleton_method(c_selection_all_versions_sorted, "new",
+ RUBY_FUNC_CAST(&SelectionNew<selection::AllVersionsSorted>::selection_new), 1);
+
+ c_selection_all_versions_grouped_by_slot = rb_define_class_under(c_selection_module, "AllVersionsGroupedBySlot", c_selection);
+ rb_define_singleton_method(c_selection_all_versions_grouped_by_slot, "new",
+ RUBY_FUNC_CAST(&SelectionNew<selection::AllVersionsGroupedBySlot>::selection_new), 1);
+
+ c_selection_all_versions_unsorted = rb_define_class_under(c_selection_module, "AllVersionsUnsorted", c_selection);
+ rb_define_singleton_method(c_selection_all_versions_unsorted, "new",
+ RUBY_FUNC_CAST(&SelectionNew<selection::AllVersionsUnsorted>::selection_new), 1);
+
+ c_selection_require_exactly_one = rb_define_class_under(c_selection_module, "RequireExactlyOne", c_selection);
+ rb_define_singleton_method(c_selection_require_exactly_one, "new",
+ RUBY_FUNC_CAST(&SelectionNew<selection::RequireExactlyOne>::selection_new), 1);
+ }
+}
+
+Selection
+paludis::ruby::value_to_selection(VALUE v)
+{
+ if (rb_obj_is_kind_of(v, c_selection))
+ {
+ Selection * f_ptr;
+ Data_Get_Struct(v, Selection, f_ptr);
+ return *f_ptr;
+ }
+ else
+ rb_raise(rb_eTypeError, "Can't convert %s into Selection", rb_obj_classname(v));
+}
+
+RegisterRubyClass::Register paludis_ruby_register_selection PALUDIS_ATTRIBUTE((used))
+ (&do_register_selection);
+
diff --git a/ruby/selection_TEST.rb b/ruby/selection_TEST.rb
new file mode 100644
index 0000000..4e16bfe
--- /dev/null
+++ b/ruby/selection_TEST.rb
@@ -0,0 +1,136 @@
+#!/usr/bin/ruby
+# vim: set sw=4 sts=4 et tw=80 :
+
+#
+# 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
+#
+
+require 'test/unit'
+require 'Paludis'
+
+module Paludis
+ class TestCase_Selection < Test::Unit::TestCase
+ def test_no_create
+ assert_raise NoMethodError do
+ Selection::new
+ end
+ end
+ end
+
+ class TestCase_SelectionSomeArbitraryVersion < Test::Unit::TestCase
+ def test_create
+ assert_nothing_raised do
+ Selection::SomeArbitraryVersion.new(Generator::All.new())
+ end
+
+ assert_nothing_raised do
+ Selection::SomeArbitraryVersion.new(Generator::All.new() | Filter::All.new())
+ end
+ end
+
+ def test_to_s
+ assert_equal Selection::SomeArbitraryVersion.new(Generator::All.new()).to_s,
+ "some arbitrary version from all packages with filter all matches"
+ end
+ end
+
+ class TestCase_SelectionBestVersionOnly < Test::Unit::TestCase
+ def test_create
+ assert_nothing_raised do
+ Selection::BestVersionOnly.new(Generator::All.new())
+ end
+
+ assert_nothing_raised do
+ Selection::BestVersionOnly.new(Generator::All.new() | Filter::All.new())
+ end
+ end
+
+ def test_to_s
+ assert_equal Selection::BestVersionOnly.new(Generator::All.new()).to_s,
+ "best version of each package from all packages with filter all matches"
+ end
+ end
+
+ class TestCase_SelectionBestVersionInEachSlot < Test::Unit::TestCase
+ def test_create
+ assert_nothing_raised do
+ Selection::BestVersionInEachSlot.new(Generator::All.new())
+ end
+
+ assert_nothing_raised do
+ Selection::BestVersionInEachSlot.new(Generator::All.new() | Filter::All.new())
+ end
+ end
+
+ def test_to_s
+ assert_equal Selection::BestVersionInEachSlot.new(Generator::All.new()).to_s,
+ "best version in each slot from all packages with filter all matches"
+ end
+ end
+
+ class TestCase_SelectionAllVersionsGroupedBySlot < Test::Unit::TestCase
+ def test_create
+ assert_nothing_raised do
+ Selection::AllVersionsGroupedBySlot.new(Generator::All.new())
+ end
+
+ assert_nothing_raised do
+ Selection::AllVersionsGroupedBySlot.new(Generator::All.new() | Filter::All.new())
+ end
+ end
+
+ def test_to_s
+ assert_equal Selection::AllVersionsGroupedBySlot.new(Generator::All.new()).to_s,
+ "all versions grouped by slot from all packages with filter all matches"
+ end
+ end
+
+ class TestCase_SelectionAllVersionsUnsorted < Test::Unit::TestCase
+ def test_create
+ assert_nothing_raised do
+ Selection::AllVersionsUnsorted.new(Generator::All.new())
+ end
+
+ assert_nothing_raised do
+ Selection::AllVersionsUnsorted.new(Generator::All.new() | Filter::All.new())
+ end
+ end
+
+ def test_to_s
+ assert_equal Selection::AllVersionsUnsorted.new(Generator::All.new()).to_s,
+ "all versions in some arbitrary order from all packages with filter all matches"
+ end
+ end
+
+ class TestCase_SelectionRequireExactlyOne < Test::Unit::TestCase
+ def test_create
+ assert_nothing_raised do
+ Selection::RequireExactlyOne.new(Generator::All.new())
+ end
+
+ assert_nothing_raised do
+ Selection::RequireExactlyOne.new(Generator::All.new() | Filter::All.new())
+ end
+ end
+
+ def test_to_s
+ assert_equal Selection::RequireExactlyOne.new(Generator::All.new()).to_s,
+ "the single version from all packages with filter all matches"
+ end
+ end
+
+end
+
diff --git a/src/clients/accerso/accerso.cc b/src/clients/accerso/accerso.cc
index 3d2c910..1869612 100644
--- a/src/clients/accerso/accerso.cc
+++ b/src/clients/accerso/accerso.cc
@@ -32,8 +32,11 @@
#include <paludis/util/visitor-impl.hh>
#include <paludis/util/kc.hh>
#include <paludis/environments/no_config/no_config_environment.hh>
+#include <paludis/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
#include <paludis/package_database.hh>
-#include <paludis/query.hh>
#include <tr1/functional>
#include <iostream>
#include <fstream>
@@ -110,10 +113,10 @@ main(int argc, char *argv[])
.extra_params(keys)
.master_repository_dir(FSEntry(CommandLine::get_instance()->a_master_repository_dir.argument())));
- std::tr1::shared_ptr<const PackageIDSequence> ids(
- env.package_database()->query(query::Repository(env.main_repository()->name()), qo_order_by_version));
- std::multimap<std::tr1::shared_ptr<const PackageID>, std::string, PackageIDComparator> results(PackageIDComparator(
- env.package_database().get()));
+ std::tr1::shared_ptr<const PackageIDSequence> ids(env[selection::AllVersionsSorted(
+ generator::Repository(env.main_repository()->name()))]);
+ std::multimap<std::tr1::shared_ptr<const PackageID>, std::string, PackageIDComparator> results(
+ PackageIDComparator(env.package_database().get()));
unsigned success(0), total(0);
for (PackageIDSequence::ConstIterator i(ids->begin()), i_end(ids->end()) ;
diff --git a/src/clients/adjutrix/downgrade_check.cc b/src/clients/adjutrix/downgrade_check.cc
index b9e47a1..8a7d6a3 100644
--- a/src/clients/adjutrix/downgrade_check.cc
+++ b/src/clients/adjutrix/downgrade_check.cc
@@ -19,7 +19,6 @@
#include "downgrade_check.hh"
#include "command_line.hh"
-#include <paludis/query.hh>
#include <paludis/package_database.hh>
#include <paludis/util/sr.hh>
#include <paludis/util/tokeniser.hh>
@@ -29,6 +28,10 @@
#include <paludis/util/make_shared_ptr.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 <fstream>
#include <iostream>
#include <vector>
@@ -48,8 +51,7 @@ namespace
int
build_one_list(NoConfigEnvironment & env, std::ostream & f)
{
- std::tr1::shared_ptr<const PackageIDSequence> matches(
- env.package_database()->query(query::NotMasked(), qo_group_by_slot));
+ std::tr1::shared_ptr<const PackageIDSequence> matches(env[selection::AllVersionsGroupedBySlot(generator::All() | filter::NotMasked())]);
QualifiedPackageName old_package("dummy/dummy");
SlotName old_slot("dummy");
@@ -138,10 +140,9 @@ namespace
std::map<QPNS, VersionSpec>::const_iterator a(after.find(b->first));
if (after.end() == a)
{
- if (! env.package_database()->query(query::Matches(make_package_dep_spec()
+ if (! env[selection::SomeArbitraryVersion(generator::Matches(make_package_dep_spec()
.package(b->first.name)
- .slot_requirement(make_shared_ptr(new UserSlotExactRequirement(b->first.slot)))),
- qo_whatever)->empty())
+ .slot_requirement(make_shared_ptr(new UserSlotExactRequirement(b->first.slot)))))]->empty())
{
results.insert(std::make_pair(b->first, stringify(b->second) + " -> nothing on " + desc));
exit_status |= 2;
diff --git a/src/clients/adjutrix/find_insecure_packages.cc b/src/clients/adjutrix/find_insecure_packages.cc
index 22e60ad..e116e97 100644
--- a/src/clients/adjutrix/find_insecure_packages.cc
+++ b/src/clients/adjutrix/find_insecure_packages.cc
@@ -21,13 +21,16 @@
#include "command_line.hh"
#include <paludis/util/tokeniser.hh>
-#include <paludis/query.hh>
#include <paludis/dep_spec.hh>
#include <paludis/dep_tag.hh>
#include <paludis/package_id.hh>
#include <paludis/package_database.hh>
#include <paludis/util/visitor-impl.hh>
#include <paludis/util/iterator_funcs.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/selection.hh>
#include <set>
#include <map>
@@ -84,8 +87,7 @@ namespace
void 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())
diff --git a/src/clients/adjutrix/find_reverse_deps.cc b/src/clients/adjutrix/find_reverse_deps.cc
index 2569617..86befb1 100644
--- a/src/clients/adjutrix/find_reverse_deps.cc
+++ b/src/clients/adjutrix/find_reverse_deps.cc
@@ -27,13 +27,16 @@
#include <paludis/util/set.hh>
#include <paludis/util/sequence.hh>
#include <paludis/util/options.hh>
-#include <paludis/query.hh>
#include <paludis/dep_spec.hh>
#include <paludis/user_dep_spec.hh>
#include <paludis/package_id.hh>
#include <paludis/package_database.hh>
#include <paludis/metadata_key.hh>
#include <paludis/fuzzy_finder.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/selection.hh>
#include <set>
#include <map>
@@ -164,8 +167,7 @@ namespace
void
ReverseDepChecker::visit_leaf(const PackageDepSpec & a)
{
- std::tr1::shared_ptr<const PackageIDSequence> dep_entries(_env->package_database()->query(
- query::Matches(a), qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> dep_entries((*_env)[selection::AllVersionsSorted(generator::Matches(a))]);
std::tr1::shared_ptr<PackageIDSequence> matches(new PackageIDSequence);
bool header_written = false;
@@ -215,8 +217,7 @@ namespace
{
Context context("When checking package '" + stringify(p) + "':");
- std::tr1::shared_ptr<const PackageIDSequence> p_entries(env.package_database()->query(
- query::Package(p), qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> p_entries(env[selection::AllVersionsSorted(generator::Package(p))]);
bool found_matches(false);
@@ -297,7 +298,7 @@ int do_find_reverse_deps(NoConfigEnvironment & env)
{
cerr << " Looking for suggestions:" << endl;
- FuzzyCandidatesFinder f(env, e.name(), query::All());
+ FuzzyCandidatesFinder f(env, e.name(), filter::All());
if (f.begin() == f.end())
cerr << "No suggestions found." << endl;
@@ -313,8 +314,7 @@ int do_find_reverse_deps(NoConfigEnvironment & env)
return 5;
}
- std::tr1::shared_ptr<const PackageIDSequence> entries(env.package_database()->query(
- query::Matches(*spec), qo_order_by_version));
+ std::tr1::shared_ptr<const PackageIDSequence> entries(env[selection::AllVersionsSorted(generator::Matches(*spec))]);
int ret(0);
if (entries->empty())
diff --git a/src/clients/adjutrix/keywords_graph.cc b/src/clients/adjutrix/keywords_graph.cc
index bcdf9f4..77c8f1b 100644
--- a/src/clients/adjutrix/keywords_graph.cc
+++ b/src/clients/adjutrix/keywords_graph.cc
@@ -26,11 +26,14 @@
#include <paludis/util/sequence.hh>
#include <paludis/util/set.hh>
#include <paludis/util/indirect_iterator-impl.hh>
-#include <paludis/query.hh>
#include <paludis/repository.hh>
#include <paludis/package_database.hh>
#include <paludis/metadata_key.hh>
#include <paludis/package_id.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/selection.hh>
#include <tr1/functional>
#include <set>
#include <map>
@@ -69,11 +72,10 @@ namespace
cout << endl;
FindUnusedPackagesTask task(&e, &repo);
- std::tr1::shared_ptr<const PackageIDSequence> packages(e.package_database()->query(
- query::Matches(make_package_dep_spec()
+ std::tr1::shared_ptr<const PackageIDSequence> packages(e[selection::AllVersionsGroupedBySlot(
+ generator::Matches(make_package_dep_spec()
.package(package)
- .repository(repo.name())),
- qo_group_by_slot));
+ .repository(repo.name())))]);
std::tr1::shared_ptr<const PackageIDSequence> unused(task.execute(package));
if (packages->empty())
diff --git a/src/clients/adjutrix/what_needs_keywording.cc b/src/clients/adjutrix/what_needs_keywording.cc
index fc0cc3c..6467c5e 100644
--- a/src/clients/adjutrix/what_needs_keywording.cc
+++ b/src/clients/adjutrix/what_needs_keywording.cc
@@ -35,8 +35,8 @@
#include <paludis/metadata_key.hh>
#include <paludis/mask.hh>
#include <paludis/fuzzy_finder.hh>
-#include <paludis/query.hh>
#include <paludis/user_dep_spec.hh>
+#include <paludis/filter.hh>
#include <tr1/functional>
#include <set>
#include <map>
@@ -105,7 +105,7 @@ int do_what_needs_keywording(NoConfigEnvironment & env)
{
cerr << " Looking for suggestions:" << endl;
- FuzzyCandidatesFinder f(env, e.name(), query::All());
+ FuzzyCandidatesFinder f(env, e.name(), filter::All());
if (f.begin() == f.end())
cerr << "No suggestions found." << endl;
diff --git a/src/clients/contrarius/stage.cc b/src/clients/contrarius/stage.cc
index 913dda7..86ade0a 100644
--- a/src/clients/contrarius/stage.cc
+++ b/src/clients/contrarius/stage.cc
@@ -22,9 +22,12 @@
#include <paludis/util/sequence.hh>
#include <paludis/util/config_file.hh>
#include <paludis/util/options.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/selection.hh>
#include <paludis/package_database.hh>
#include <paludis/environments/adapted/adapted_environment.hh>
-#include <paludis/query.hh>
#include <paludis/user_dep_spec.hh>
#include <string>
#include <tr1/memory>
@@ -51,10 +54,9 @@ AuxiliaryStage::is_rebuild() const
for (std::list<std::string>::const_iterator p(packages.begin()), p_end(packages.end()) ;
p != p_end ; ++p)
- if ( _env->package_database()->query(
- query::Matches(parse_user_package_dep_spec(*p, UserPackageDepSpecOptions())) &
- query::InstalledAtRoot(_env->root()),
- qo_whatever)->empty())
+ if ((*_env)[selection::SomeArbitraryVersion(
+ generator::Matches(parse_user_package_dep_spec(*p, UserPackageDepSpecOptions())) |
+ filter::InstalledAtRoot(_env->root()))]->empty())
return false;
return true;
@@ -76,10 +78,9 @@ BinutilsStage::build(const StageOptions &) const
bool
BinutilsStage::is_rebuild() const
{
- return (! _env->package_database()->query(
- query::Matches(parse_user_package_dep_spec(TargetConfig::get_instance()->binutils(), UserPackageDepSpecOptions())) &
- query::InstalledAtRoot(_env->root()),
- qo_whatever)->empty());
+ return (! (*_env)[selection::SomeArbitraryVersion(
+ generator::Matches(parse_user_package_dep_spec(TargetConfig::get_instance()->binutils(), UserPackageDepSpecOptions())) |
+ filter::InstalledAtRoot(_env->root()))]->empty());
}
int
@@ -100,10 +101,9 @@ KernelHeadersStage::build(const StageOptions &) const
bool
KernelHeadersStage::is_rebuild() const
{
- return (! _env->package_database()->query(
- query::Matches(parse_user_package_dep_spec(TargetConfig::get_instance()->headers(), UserPackageDepSpecOptions())) &
- query::InstalledAtRoot(_env->root()),
- qo_whatever)->empty());
+ return (! (*_env)[selection::SomeArbitraryVersion(
+ generator::Matches(parse_user_package_dep_spec(TargetConfig::get_instance()->headers(), UserPackageDepSpecOptions())) |
+ filter::InstalledAtRoot(_env->root()))]->empty());
}
int
@@ -132,10 +132,9 @@ MinimalStage::build(const StageOptions &) const
bool
MinimalStage::is_rebuild() const
{
- return (! _env->package_database()->query(
- query::Matches(parse_user_package_dep_spec(TargetConfig::get_instance()->gcc(), UserPackageDepSpecOptions())) &
- query::InstalledAtRoot(_env->root()),
- qo_whatever)->empty());
+ return (! (*_env)[selection::SomeArbitraryVersion(
+ generator::Matches(parse_user_package_dep_spec(TargetConfig::get_instance()->gcc(), UserPackageDepSpecOptions())) |
+ filter::InstalledAtRoot(_env->root()))]->empty());