aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-10-08 14:35:14 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-10-08 14:35:14 +0000
commitbd16d0222e4c401ebde224f1fa62eaf24356e173 (patch)
tree983a99c1b5776539de2e57f0be9a308300c2db67
parentcbb5f4f9e3324460a9b7fcbb94941711df24df14 (diff)
downloadpaludis-bd16d0222e4c401ebde224f1fa62eaf24356e173.tar.gz
paludis-bd16d0222e4c401ebde224f1fa62eaf24356e173.tar.xz
Split out QueryDelegate into its own file. More Doxygen work.
-rw-r--r--doc/doc_main.doxygen14
-rw-r--r--doc/examples/Makefile.am23
-rw-r--r--doc/examples/example_match_package.cc98
-rw-r--r--doc/examples/example_query.cc108
-rw-r--r--doc/examples/example_query_delegate.cc165
-rw-r--r--paludis/files.m41
-rw-r--r--paludis/match_package.hh39
-rw-r--r--paludis/query-fwd.hh11
-rw-r--r--paludis/query.cc39
-rw-r--r--paludis/query.hh125
-rw-r--r--paludis/query_delegate-fwd.hh34
-rw-r--r--paludis/query_delegate.cc58
-rw-r--r--paludis/query_delegate.hh112
-rw-r--r--python/query.cc1
14 files changed, 696 insertions, 132 deletions
diff --git a/doc/doc_main.doxygen b/doc/doc_main.doxygen
index 36d1ee7..861933e 100644
--- a/doc/doc_main.doxygen
+++ b/doc/doc_main.doxygen
@@ -147,3 +147,17 @@ using namespace paludis;
* - \ref example_repository.cc "example_repository.cc"
*/
+/** \defgroup g_query "Query"
+ *
+ * \ingroup g_paludis
+ *
+ * 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"
+ */
+
diff --git a/doc/examples/Makefile.am b/doc/examples/Makefile.am
index 0a489a1..ae9abff 100644
--- a/doc/examples/Makefile.am
+++ b/doc/examples/Makefile.am
@@ -24,7 +24,10 @@ noinst_PROGRAMS = \
example_package_id \
example_metadata_key \
example_mask \
- example_repository
+ example_repository \
+ example_match_package \
+ example_query \
+ example_query_delegate
EXTRA_DIST = $(noinst_SCRIPTS)
@@ -125,6 +128,24 @@ example_repository_LDFLAGS = \
$(top_builddir)/paludis/libpaludis.la \
$(top_builddir)/paludis/args/libpaludisargs.la
+example_match_package_SOURCES = example_match_package.cc
+example_match_package_LDFLAGS = \
+ libpaludisexamples.a \
+ $(top_builddir)/paludis/libpaludis.la \
+ $(top_builddir)/paludis/args/libpaludisargs.la
+
+example_query_SOURCES = example_query.cc
+example_query_LDFLAGS = \
+ libpaludisexamples.a \
+ $(top_builddir)/paludis/libpaludis.la \
+ $(top_builddir)/paludis/args/libpaludisargs.la
+
+example_query_delegate_SOURCES = example_query_delegate.cc
+example_query_delegate_LDFLAGS = \
+ libpaludisexamples.a \
+ $(top_builddir)/paludis/libpaludis.la \
+ $(top_builddir)/paludis/args/libpaludisargs.la
+
built-sources : $(BUILT_SOURCES)
for s in `echo $(SUBDIRS) | tr -d .` ; do $(MAKE) -C $$s built-sources || exit 1 ; done
diff --git a/doc/examples/example_match_package.cc b/doc/examples/example_match_package.cc
new file mode 100644
index 0000000..dbe5404
--- /dev/null
+++ b/doc/examples/example_match_package.cc
@@ -0,0 +1,98 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/** \file
+ *
+ * Example \ref example_match_package.cc "example_match_package.cc" .
+ *
+ * \ingroup g_query
+ */
+
+/** \example example_match_package.cc
+ *
+ * This example demonstrates how to use paludis::match_package and
+ * paludis::match_package_in_set.
+ */
+
+#include <paludis/paludis.hh>
+#include "example_command_line.hh"
+#include <iostream>
+#include <iomanip>
+
+using namespace paludis;
+using namespace examples;
+
+using std::cout;
+using std::endl;
+using std::left;
+using std::setw;
+
+int main(int argc, char * argv[])
+{
+ int exit_status(0);
+
+ try
+ {
+ CommandLine::get_instance()->run(argc, argv,
+ "example_match_package", "EXAMPLE_MATCH_PACKAGE_OPTIONS", "EXAMPLE_MATCH_PACKAGE_CMDLINE");
+
+ /* We start with an Environment, respecting the user's '--environment' choice. */
+ tr1::shared_ptr<Environment> env(EnvironmentMaker::get_instance()->make_from_spec(
+ CommandLine::get_instance()->a_environment.argument()));
+
+ /* Fetch all installed packages. */
+ tr1::shared_ptr<const PackageIDSequence> ids(env->package_database()->query(
+ query::SupportsAction<InstalledAction>(),
+ qo_order_by_version));
+
+ /* Fetch the 'system' and 'world' sets. Ordinarily we should check for
+ * zero pointers here, but these two sets will always exist. */
+ tr1::shared_ptr<const SetSpecTree::ConstItem> system(env->set(SetName("system"))),
+ world(env->set(SetName("world")));
+
+ /* For each ID: */
+ for (PackageIDSet::ConstIterator i(ids->begin()), i_end(ids->end()) ;
+ i != i_end ; ++i)
+ {
+ /* Is it paludis? */
+ if (match_package(*env, PackageDepSpec("sys-apps/paludis", pds_pm_permissive), **i))
+ cout << left << setw(50) << (stringify(**i) + ":") << " " << "paludis" << endl;
+
+ /* No. Is it in system or world? */
+ else if (match_package_in_set(*env, *system, **i))
+ cout << left << setw(50) << (stringify(**i) + ":") << " " << "system" << endl;
+ else if (match_package_in_set(*env, *world, **i))
+ cout << left << setw(50) << (stringify(**i) + ":") << " " << "world" << endl;
+ else
+ cout << left << setw(50) << (stringify(**i) + ":") << " " << "nothing" << endl;
+ }
+
+ }
+ 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/examples/example_query.cc b/doc/examples/example_query.cc
new file mode 100644
index 0000000..161e8cc
--- /dev/null
+++ b/doc/examples/example_query.cc
@@ -0,0 +1,108 @@
+/* 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 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. */
+ 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. */
+ 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(PackageDepSpec("sys-apps/paludis", pds_pm_permissive)));
+
+ /* Queries can be combined. The resulting query is optimised internally,
+ * potentially giving better performance than doing things by hand. */
+ show_query(env,
+ query::Matches(PackageDepSpec("sys-apps/paludis", pds_pm_permissive)) &
+ query::SupportsAction<InstalledAction>());
+
+ /* Usually query::NotMasked should be combined with
+ * query::SupportsAction<InstallAction>, since installed packages aren't
+ * masked. */
+ show_query(env,
+ query::Matches(PackageDepSpec("sys-apps/paludis", pds_pm_permissive)) &
+ 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/examples/example_query_delegate.cc b/doc/examples/example_query_delegate.cc
new file mode 100644
index 0000000..3af5020
--- /dev/null
+++ b/doc/examples/example_query_delegate.cc
@@ -0,0 +1,165 @@
+/* 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)
+ {
+ }
+
+ tr1::shared_ptr<PackageIDSequence>
+ ids(const Environment & e,
+ tr1::shared_ptr<const RepositoryNameSequence> repos,
+ tr1::shared_ptr<const QualifiedPackageNameSet> pkgs) const
+ {
+ 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... */
+ 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... */
+ 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(tr1::shared_ptr<QueryDelegate>(new DescriptionContainsDelegate(pattern)))
+ {
+ }
+ };
+
+ /* Run a particular query, and show its results. */
+ void show_query(const 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. */
+ 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. */
+ 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("goat"));
+
+ /* 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/paludis/files.m4 b/paludis/files.m4
index b331b97..bc928f9 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -45,6 +45,7 @@ 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')
diff --git a/paludis/match_package.hh b/paludis/match_package.hh
index f6234bd..4aaa17f 100644
--- a/paludis/match_package.hh
+++ b/paludis/match_package.hh
@@ -1,16 +1,33 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+/*
+ * Copyright (c) 2006, 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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_MATCH_PACKAGE_HH
#define PALUDIS_GUARD_PALUDIS_MATCH_PACKAGE_HH 1
/** \file
- * Declare the match_package function.
+ * Declarations for match_package and match_package_in_set.
+ *
+ * \ingroup g_query
*
- * Do not merge this file into dep_spec. It will cause all sorts of horrible
- * circular dependency issues. Avoid including this file in headers if at all
- * possible.
+ * \section Examples
*
- * \ingroup grpmatchpackage
+ * - \ref example_match_package.cc "example_match_package.cc"
*/
#include <paludis/util/attributes.hh>
@@ -23,9 +40,10 @@
namespace paludis
{
/**
- * Return whether the specified spec matches the specified target.
+ * Return whether the specified PackageID matches the specified
+ * PackageDepSpec.
*
- * \ingroup grpmatchpackage
+ * \ingroup g_query
*/
bool match_package(
const Environment & env,
@@ -34,9 +52,12 @@ namespace paludis
PALUDIS_ATTRIBUTE((warn_unused_result)) PALUDIS_VISIBLE;
/**
- * Return whether the specified spec matches the specified target, for heirarchies.
+ * Return whether the specified PackageID matches any of the items in the
+ * specified set.
+ *
+ * Named sets inside the set are expanded.
*
- * \ingroup grpmatchpackage
+ * \ingroup g_query
*/
bool match_package_in_set(
const Environment & env,
diff --git a/paludis/query-fwd.hh b/paludis/query-fwd.hh
index 71a244b..25eebc9 100644
--- a/paludis/query-fwd.hh
+++ b/paludis/query-fwd.hh
@@ -23,9 +23,14 @@
#include <iosfwd>
#include <paludis/util/attributes.hh>
+/** \file
+ * Forward declarations for paludis/query.hh .
+ *
+ * \ingroup g_query
+ */
+
namespace paludis
{
- class QueryDelegate;
class Query;
namespace query
@@ -47,7 +52,7 @@ namespace paludis
*
* \see Query
* \see PackageDatabase::query
- * \ingroup grpquery
+ * \ingroup g_query
*/
Query operator& (const Query &, const Query &) PALUDIS_VISIBLE;
@@ -55,7 +60,7 @@ namespace paludis
* Output a human-readable description of a Query.
*
* \see Query
- * \ingroup grpquery
+ * \ingroup g_query
*/
std::ostream & operator<< (std::ostream &, const Query &) PALUDIS_VISIBLE;
}
diff --git a/paludis/query.cc b/paludis/query.cc
index 0ff70eb..d0d62a3 100644
--- a/paludis/query.cc
+++ b/paludis/query.cc
@@ -17,7 +17,8 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "query.hh"
+#include <paludis/query.hh>
+#include <paludis/query_delegate.hh>
#include <paludis/util/fs_entry.hh>
#include <paludis/util/tr1_functional.hh>
#include <paludis/util/sequence.hh>
@@ -36,47 +37,41 @@
using namespace paludis;
-QueryDelegate::QueryDelegate()
+Query::Query(tr1::shared_ptr<const QueryDelegate> d) :
+ _d(d)
{
}
-QueryDelegate::~QueryDelegate()
+Query::~Query()
{
}
tr1::shared_ptr<RepositoryNameSequence>
-QueryDelegate::repositories(const Environment &) const
+Query::repositories(const Environment & e) const
{
- return tr1::shared_ptr<RepositoryNameSequence>();
+ return _d->repositories(e);
}
tr1::shared_ptr<CategoryNamePartSet>
-QueryDelegate::categories(const Environment &, tr1::shared_ptr<const RepositoryNameSequence>) const
+Query::categories(const Environment & e, tr1::shared_ptr<const RepositoryNameSequence> r) const
{
- return tr1::shared_ptr<CategoryNamePartSet>();
+ return _d->categories(e, r);
}
tr1::shared_ptr<QualifiedPackageNameSet>
-QueryDelegate::packages(const Environment &, tr1::shared_ptr<const RepositoryNameSequence>,
- tr1::shared_ptr<const CategoryNamePartSet>) const
+Query::packages(const Environment & e,
+ tr1::shared_ptr<const RepositoryNameSequence> r,
+ tr1::shared_ptr<const CategoryNamePartSet> c) const
{
- return tr1::shared_ptr<QualifiedPackageNameSet>();
+ return _d->packages(e, r, c);
}
tr1::shared_ptr<PackageIDSequence>
-QueryDelegate::ids(const Environment &, tr1::shared_ptr<const RepositoryNameSequence>,
- tr1::shared_ptr<const QualifiedPackageNameSet>) const
-{
- return tr1::shared_ptr<PackageIDSequence>();
-}
-
-Query::Query(tr1::shared_ptr<const QueryDelegate> d) :
- _d(d)
-{
-}
-
-Query::~Query()
+Query::ids(const Environment & e,
+ tr1::shared_ptr<const RepositoryNameSequence> r,
+ tr1::shared_ptr<const QualifiedPackageNameSet> q) const
{
+ return _d->ids(e, r, q);
}
namespace
diff --git a/paludis/query.hh b/paludis/query.hh
index f35b825..f5fe1e9 100644
--- a/paludis/query.hh
+++ b/paludis/query.hh
@@ -25,86 +25,25 @@
#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
- * Query and related classes.
+ * Declarations for Query and the various query:: classes.
*
- * \ingroup grpquery
+ * \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
{
/**
- * A QueryDelegate subclass is used by Query to provide the information
- * needed by PackageDatabase::query.
- *
- * \see Query
- * \ingroup grpquery
- */
- 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 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 tr1::shared_ptr<CategoryNamePartSet> categories(const Environment &,
- 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 tr1::shared_ptr<QualifiedPackageNameSet> packages(const Environment &,
- tr1::shared_ptr<const RepositoryNameSequence>,
- 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 tr1::shared_ptr<PackageIDSequence> ids(const Environment &,
- tr1::shared_ptr<const RepositoryNameSequence>,
- tr1::shared_ptr<const QualifiedPackageNameSet>) const;
-
- /**
- * Fetch a string representation of our query.
- */
- virtual std::string as_human_readable_string() const = 0;
- };
-
- /**
* Parameter for a PackageDatabase query.
*
* Holds a QueryDelegate to perform actual operations, so that it can be
@@ -112,7 +51,7 @@ namespace paludis
*
* \see QueryDelegate
* \see PackageDatabase::query
- * \ingroup grpquery
+ * \ingroup g_query
* \nosubgrouping
*/
class PALUDIS_VISIBLE Query
@@ -137,30 +76,18 @@ namespace paludis
///\name Delegate-implemented functions
///\{
- tr1::shared_ptr<RepositoryNameSequence> repositories(const Environment & e) const
- {
- return _d->repositories(e);
- }
+ tr1::shared_ptr<RepositoryNameSequence> repositories(const Environment & e) const;
tr1::shared_ptr<CategoryNamePartSet> categories(const Environment & e,
- tr1::shared_ptr<const RepositoryNameSequence> r) const
- {
- return _d->categories(e, r);
- }
+ tr1::shared_ptr<const RepositoryNameSequence> r) const;
tr1::shared_ptr<QualifiedPackageNameSet> packages(const Environment & e,
tr1::shared_ptr<const RepositoryNameSequence> r,
- tr1::shared_ptr<const CategoryNamePartSet> c) const
- {
- return _d->packages(e, r, c);
- }
+ tr1::shared_ptr<const CategoryNamePartSet> c) const;
tr1::shared_ptr<PackageIDSequence> ids(const Environment & e,
tr1::shared_ptr<const RepositoryNameSequence> r,
- tr1::shared_ptr<const QualifiedPackageNameSet> q) const
- {
- return _d->ids(e, r, q);
- }
+ tr1::shared_ptr<const QualifiedPackageNameSet> q) const;
///\}
};
@@ -169,7 +96,7 @@ namespace paludis
* Various Query classes.
*
* \see Query
- * \ingroup grpquery
+ * \ingroup g_query
*/
namespace query
{
@@ -178,7 +105,7 @@ namespace paludis
*
* \see Query
* \see PackageDatabase::query
- * \ingroup grpquery
+ * \ingroup g_query
* \nosubgrouping
*/
class PALUDIS_VISIBLE Matches :
@@ -197,7 +124,8 @@ namespace paludis
* Fetch packages with a given package name.
*
* \see Query
- * \ingroup grpquerybase::query
+ * \see PackageDatabase::query
+ * \ingroup g_query
* \nosubgrouping
*/
class PALUDIS_VISIBLE Package :
@@ -216,7 +144,8 @@ namespace paludis
* Fetch packages in a given repository.
*
* \see Query
- * \ingroup grpquerybase::query
+ * \see PackageDatabase::query
+ * \ingroup g_query
* \nosubgrouping
*/
class PALUDIS_VISIBLE Repository :
@@ -235,7 +164,8 @@ namespace paludis
* Fetch packages in a given category.
*
* \see Query
- * \ingroup grpquerybase::query
+ * \see PackageDatabase::query
+ * \ingroup g_query
* \nosubgrouping
*/
class PALUDIS_VISIBLE Category :
@@ -254,7 +184,8 @@ namespace paludis
* Fetch packages that are not masked.
*
* \see Query
- * \ingroup grpquery
+ * \see PackageDatabase::query
+ * \ingroup g_query
* \nosubgrouping
*/
class PALUDIS_VISIBLE NotMasked :
@@ -274,7 +205,7 @@ namespace paludis
*
* \see Query
* \see PackageDatabase::query
- * \ingroup grpquery
+ * \ingroup g_query
* \nosubgrouping
*/
template <typename A_>
@@ -300,7 +231,7 @@ namespace paludis
*
* \see Query
* \see PackageDatabase::query
- * \ingroup grpquery
+ * \ingroup g_query
* \nosubgrouping
*/
template <typename A_>
@@ -321,7 +252,7 @@ namespace paludis
*
* \see Query
* \see PackageDatabase::query
- * \ingroup grpquery
+ * \ingroup g_query
* \nosubgrouping
*/
class PALUDIS_VISIBLE InstalledAtRoot :
@@ -341,7 +272,7 @@ namespace paludis
*
* \see Query
* \see PackageDatabase::query
- * \ingroup grpquery
+ * \ingroup g_query
* \nosubgrouping
*/
class PALUDIS_VISIBLE All :
diff --git a/paludis/query_delegate-fwd.hh b/paludis/query_delegate-fwd.hh
new file mode 100644
index 0000000..6473265
--- /dev/null
+++ b/paludis/query_delegate-fwd.hh
@@ -0,0 +1,34 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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_FWD_HH
+#define PALUDIS_GUARD_PALUDIS_QUERY_DELEGATE_FWD_HH 1
+
+/** \file
+ * Forward declarations for paludis/query_delegate.hh .
+ *
+ * \ingroup g_query
+ */
+
+namespace paludis
+{
+ class QueryDelegate;
+}
+
+#endif
diff --git a/paludis/query_delegate.cc b/paludis/query_delegate.cc
new file mode 100644
index 0000000..1c94fa4
--- /dev/null
+++ b/paludis/query_delegate.cc
@@ -0,0 +1,58 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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()
+{
+}
+
+tr1::shared_ptr<RepositoryNameSequence>
+QueryDelegate::repositories(const Environment &) const
+{
+ return tr1::shared_ptr<RepositoryNameSequence>();
+}
+
+tr1::shared_ptr<CategoryNamePartSet>
+QueryDelegate::categories(const Environment &, tr1::shared_ptr<const RepositoryNameSequence>) const
+{
+ return tr1::shared_ptr<CategoryNamePartSet>();
+}
+
+tr1::shared_ptr<QualifiedPackageNameSet>
+QueryDelegate::packages(const Environment &, tr1::shared_ptr<const RepositoryNameSequence>,
+ tr1::shared_ptr<const CategoryNamePartSet>) const
+{
+ return tr1::shared_ptr<QualifiedPackageNameSet>();
+}
+
+tr1::shared_ptr<PackageIDSequence>
+QueryDelegate::ids(const Environment &, tr1::shared_ptr<const RepositoryNameSequence>,
+ tr1::shared_ptr<const QualifiedPackageNameSet>) const
+{
+ return tr1::shared_ptr<PackageIDSequence>();
+}
+
+
diff --git a/paludis/query_delegate.hh b/paludis/query_delegate.hh
new file mode 100644
index 0000000..312b14b
--- /dev/null
+++ b/paludis/query_delegate.hh
@@ -0,0 +1,112 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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 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 tr1::shared_ptr<CategoryNamePartSet> categories(const Environment &,
+ 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 tr1::shared_ptr<QualifiedPackageNameSet> packages(const Environment &,
+ tr1::shared_ptr<const RepositoryNameSequence>,
+ 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 tr1::shared_ptr<PackageIDSequence> ids(const Environment &,
+ tr1::shared_ptr<const RepositoryNameSequence>,
+ 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/python/query.cc b/python/query.cc
index d6d1d51..ecd2e8b 100644
--- a/python/query.cc
+++ b/python/query.cc
@@ -21,6 +21,7 @@
#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>