diff options
author | 2011-03-26 19:30:45 +0000 | |
---|---|---|
committer | 2011-03-26 19:30:45 +0000 | |
commit | 1b7c77f752e38dd36142f5fb8e07cfa96bebe855 (patch) | |
tree | 35e9cd347ba3bdfb4cf1b199925916126e5ab298 | |
parent | 7586e9b910edf4bfc176417bf971a9d83243b139 (diff) | |
download | paludis-1b7c77f752e38dd36142f5fb8e07cfa96bebe855.tar.gz paludis-1b7c77f752e38dd36142f5fb8e07cfa96bebe855.tar.xz |
Kill PackageDatabase
-rw-r--r-- | paludis/files.m4 | 1 | ||||
-rw-r--r-- | paludis/package_database-fwd.hh | 41 | ||||
-rw-r--r-- | paludis/package_database.cc | 352 | ||||
-rw-r--r-- | paludis/package_database.hh | 147 |
4 files changed, 0 insertions, 541 deletions
diff --git a/paludis/files.m4 b/paludis/files.m4 index 635003c9f..da806a3f4 100644 --- a/paludis/files.m4 +++ b/paludis/files.m4 @@ -75,7 +75,6 @@ add(`notifier_callback', `hh', `cc', `fwd') add(`output_manager', `hh', `fwd', `cc', `se') add(`output_manager_factory', `hh', `fwd', `cc') add(`output_manager_from_environment', `hh', `fwd', `cc') -add(`package_database', `hh', `cc', `fwd') add(`package_dep_spec_collection', `hh', `cc', `fwd') add(`package_dep_spec_properties', `hh', `cc', `fwd') add(`package_id', `hh', `cc', `fwd', `se') diff --git a/paludis/package_database-fwd.hh b/paludis/package_database-fwd.hh deleted file mode 100644 index eea66d8a1..000000000 --- a/paludis/package_database-fwd.hh +++ /dev/null @@ -1,41 +0,0 @@ -/* vim: set sw=4 sts=4 et foldmethod=syntax : */ - -/* - * 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 - * 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_PACKAGE_DATABASE_FWD_HH -#define PALUDIS_GUARD_PALUDIS_PACKAGE_DATABASE_FWD_HH 1 - -/** \file - * Forward declarations for paludis/package_database.hh . - * - * \ingroup g_package_database - */ - -namespace paludis -{ - class PackageDatabaseError; - class PackageDatabaseLookupError; - class AmbiguousPackageNameError; - class DuplicateRepositoryError; - class NoSuchPackageError; - class NoSuchRepositoryError; - - class PackageDatabase; -} - -#endif diff --git a/paludis/package_database.cc b/paludis/package_database.cc deleted file mode 100644 index f0ba5f02b..000000000 --- a/paludis/package_database.cc +++ /dev/null @@ -1,352 +0,0 @@ -/* vim: set sw=4 sts=4 et foldmethod=syntax : */ - -/* - * Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010, 2011 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/dep_spec.hh> -#include <paludis/match_package.hh> -#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/partially_made_package_dep_spec.hh> -#include <paludis/metadata_key.hh> -#include <paludis/util/log.hh> -#include <paludis/util/pimp-impl.hh> -#include <paludis/util/stringify.hh> -#include <paludis/util/join.hh> -#include <paludis/util/indirect_iterator-impl.hh> -#include <paludis/util/iterator_funcs.hh> -#include <paludis/util/member_iterator-impl.hh> -#include <paludis/util/set-impl.hh> -#include <paludis/util/map.hh> -#include <paludis/util/map-impl.hh> -#include <paludis/util/sequence.hh> -#include <paludis/util/sequence-impl.hh> -#include <paludis/util/wrapped_forward_iterator-impl.hh> -#include <paludis/util/member_iterator.hh> -#include <paludis/util/make_null_shared_ptr.hh> -#include <functional> -#include <algorithm> -#include <list> -#include <map> -#include <set> - -using namespace paludis; - -namespace paludis -{ - template <> - struct WrappedForwardIteratorTraits<PackageDatabase::RepositoryConstIteratorTag> - { - typedef std::list<std::shared_ptr<Repository> >::const_iterator UnderlyingIterator; - }; -} - -namespace paludis -{ - template<> - struct Imp<PackageDatabase> - { - std::list<std::shared_ptr<Repository> > repositories; - std::multimap<int, std::list<std::shared_ptr<Repository> >::iterator> repository_importances; - const Environment * environment; - }; -} - -PackageDatabase::PackageDatabase(const Environment * const e) : - _imp() -{ - _imp->environment = e; -} - -PackageDatabase::~PackageDatabase() -{ -} - -void -PackageDatabase::add_repository(int i, const std::shared_ptr<Repository> r) -{ - Context c("When adding a repository named '" + stringify(r->name()) + "':"); - - for (IndirectIterator<RepositoryConstIterator> r_c(begin_repositories()), r_end(end_repositories()) ; - r_c != r_end ; ++r_c) - if (r_c->name() == r->name()) - throw DuplicateRepositoryError(stringify(r->name())); - - std::list<std::shared_ptr<Repository> >::iterator q(_imp->repositories.end()); - for (std::multimap<int, std::list<std::shared_ptr<Repository> >::iterator>::iterator - p(_imp->repository_importances.begin()), p_end(_imp->repository_importances.end()) ; - p != p_end ; ++p) - if (p->first > i) - { - q = p->second; - break; - } - - _imp->repository_importances.insert(std::make_pair(i, _imp->repositories.insert(q, r))); -} - -namespace -{ - typedef std::map<const QualifiedPackageName, std::pair<bool, bool> > QPNIMap; - - struct CategoryRepositoryNamePairComparator - { - bool operator() (const std::pair<CategoryNamePart, RepositoryName> & a, - const std::pair<CategoryNamePart, RepositoryName> & b) const - { - if (a.first != b.first) - return a.first < b.first; - return a.second < b.second; - } - }; - - struct IsInstalled - { - const Environment * const _env; - - IsInstalled(const Environment * e) : - _env(e) - { - } - - typedef QualifiedPackageName argument_type; - typedef bool result_type; - - bool operator() (const QualifiedPackageName & qpn) const - { - return ! (*_env)[selection::SomeArbitraryVersion(generator::Package(qpn) | - filter::InstalledAtRoot(_env->preferred_root_key()->value()))]->empty(); - } - }; - - struct IsImportant - { - typedef QualifiedPackageName argument_type; - typedef bool result_type; - - const std::shared_ptr<QPNIMap> _map; - - IsImportant(const std::shared_ptr<QPNIMap> & m) : - _map(m) - { - } - - bool operator() (const QualifiedPackageName & qpn) const - { - return _map->find(qpn)->second.first; - } - }; - - struct IsInUnimportantRepo - { - typedef QualifiedPackageName argument_type; - typedef bool result_type; - - const std::shared_ptr<QPNIMap> _map; - - IsInUnimportantRepo(const std::shared_ptr<QPNIMap> & m) : - _map(m) - { - } - - bool operator() (const QualifiedPackageName & qpn) const - { - return ! _map->find(qpn)->second.second; - } - }; -} - -QualifiedPackageName -PackageDatabase::fetch_unique_qualified_package_name(const PackageNamePart & p, const Filter & f, const bool disambiguate) const -{ - Context context("When disambiguating package name '" + stringify(p) + "':"); - - // Map matching QualifiedPackageNames with a pair of flags specifying - // respectively that at least one repository containing the package thinks - // the category is important and that the package is in a repository - // that reports it is important itself - std::shared_ptr<QPNIMap> result(new QPNIMap); - std::set<std::pair<CategoryNamePart, RepositoryName>, CategoryRepositoryNamePairComparator> checked; - - std::shared_ptr<const PackageIDSequence> pkgs((*_imp->environment)[selection::AllVersionsUnsorted( - generator::Matches(make_package_dep_spec({ }).package_name_part(p), make_null_shared_ptr(), { }) | 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()) + "':"); - - if (! checked.insert(std::make_pair(it->name().category(), it->repository_name())).second) - continue; - - auto repo(fetch_repository(it->repository_name())); - std::shared_ptr<const CategoryNamePartSet> unimportant_cats(repo->unimportant_category_names({ })); - bool is_important(unimportant_cats->end() == unimportant_cats->find(it->name().category())); - bool is_in_important_repo(! repo->is_unimportant()); - QPNIMap::iterator i(result->insert(std::make_pair(it->name(), std::make_pair(is_important, is_in_important_repo))).first); - i->second.first = i->second.first || is_important; - i->second.second = i->second.second || is_in_important_repo; - } - - if (result->empty()) - throw NoSuchPackageError(stringify(p)); - if (result->size() > 1) - { - using namespace std::placeholders; - - std::list<QualifiedPackageName> qpns; - - do - { - const IsImportant is_important(result); - const IsInstalled is_installed(_imp->environment); - const IsInUnimportantRepo is_in_unimportant_repo(result); - - std::remove_copy_if(first_iterator(result->begin()), first_iterator(result->end()), - std::front_inserter(qpns), - std::bind(std::logical_and<bool>(), - std::bind(std::not1(is_important), _1), - std::bind(std::not1(is_installed), _1))); - - if (! qpns.empty() && next(qpns.begin()) == qpns.end()) - break; - - qpns.remove_if(std::bind(is_in_unimportant_repo, _1)); - - if (! qpns.empty() && next(qpns.begin()) == qpns.end()) - break; - - qpns.remove_if(std::bind(std::logical_and<bool>(), - std::bind(is_important, _1), - std::bind(std::not1(is_installed), _1))); - - if (! qpns.empty() && next(qpns.begin()) == qpns.end()) - break; - - qpns.remove_if(std::bind(std::logical_and<bool>(), - std::bind(std::not1(is_important), _1), - std::bind(is_installed, _1))); - - if (! qpns.empty() && next(qpns.begin()) == qpns.end()) - break; - - auto candidates(std::make_shared<Sequence<std::string> >()); - std::transform(first_iterator(result->begin()), first_iterator(result->end()), candidates->back_inserter(), - &stringify<QualifiedPackageName>); - throw AmbiguousPackageNameError(stringify(p), candidates); - } while (false); - - if (! disambiguate) - { - auto candidates(std::make_shared<Sequence<std::string> >()); - std::transform(first_iterator(result->begin()), first_iterator(result->end()), candidates->back_inserter(), - &stringify<QualifiedPackageName>); - throw AmbiguousPackageNameError(stringify(p), candidates); - } - - Log::get_instance()->message("package_database.ambiguous_name", ll_warning, lc_context) - << "Package name '" << p << "' is ambiguous, assuming you meant '" << *qpns.begin() - << "' (candidates were '" - << join(first_iterator(result->begin()), first_iterator(result->end()), "', '") << "')"; - - return *qpns.begin(); - } - else - return result->begin()->first; -} - -std::shared_ptr<const Repository> -PackageDatabase::fetch_repository(const RepositoryName & n) const -{ - for (RepositoryConstIterator r(begin_repositories()), r_end(end_repositories()) ; - r != r_end ; ++r) - if ((*r)->name() == n) - return *r; - - throw NoSuchRepositoryError(n); -} - -std::shared_ptr<Repository> -PackageDatabase::fetch_repository(const RepositoryName & n) -{ - for (RepositoryConstIterator r(begin_repositories()), r_end(end_repositories()) ; - r != r_end ; ++r) - if ((*r)->name() == n) - return *r; - - throw NoSuchRepositoryError(n); -} - -bool -PackageDatabase::has_repository_named(const RepositoryName & n) const -{ - for (RepositoryConstIterator r(begin_repositories()), r_end(end_repositories()) ; - r != r_end ; ++r) - if ((*r)->name() == n) - return true; - - return false; -} - -bool -PackageDatabase::more_important_than(const RepositoryName & lhs, - const RepositoryName & rhs) const -{ - std::map<std::string, int> rank; - int x(0); - for (PackageDatabase::RepositoryConstIterator r(begin_repositories()), r_end(end_repositories()) ; - r != r_end ; ++r) - rank.insert(std::make_pair(stringify((*r)->name()), ++x)); - - std::map<std::string, int>::const_iterator l(rank.find(stringify(lhs))); - if (l == rank.end()) - throw InternalError(PALUDIS_HERE, "lhs.repository '" + stringify(lhs) + "' not in rank"); - - std::map<std::string, int>::const_iterator r(rank.find(stringify(rhs))); - if (r == rank.end()) - throw InternalError(PALUDIS_HERE, "rhs.repository '" + stringify(rhs) + "' not in rank"); - - return l->second > r->second; -} - -PackageDatabase::RepositoryConstIterator -PackageDatabase::begin_repositories() const -{ - return RepositoryConstIterator(_imp->repositories.begin()); -} - -PackageDatabase::RepositoryConstIterator -PackageDatabase::end_repositories() const -{ - return RepositoryConstIterator(_imp->repositories.end()); -} - -const Filter & -PackageDatabase::all_filter() -{ - static const Filter result((filter::All())); - return result; -} - -template class WrappedForwardIterator<PackageDatabase::RepositoryConstIteratorTag, const std::shared_ptr<Repository> >; - diff --git a/paludis/package_database.hh b/paludis/package_database.hh deleted file mode 100644 index 589b8e62c..000000000 --- a/paludis/package_database.hh +++ /dev/null @@ -1,147 +0,0 @@ -/* vim: set sw=4 sts=4 et foldmethod=syntax : */ - -/* - * Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010, 2011 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_PACKAGE_DATABASE_HH -#define PALUDIS_GUARD_PALUDIS_PACKAGE_DATABASE_HH 1 - -#include <paludis/package_database-fwd.hh> -#include <paludis/dep_spec.hh> -#include <paludis/name.hh> -#include <paludis/repository.hh> -#include <paludis/selection-fwd.hh> -#include <paludis/filter-fwd.hh> -#include <paludis/version_spec.hh> -#include <paludis/contents.hh> -#include <paludis/environment.hh> - -#include <paludis/util/exception.hh> -#include <paludis/util/join.hh> -#include <paludis/util/pimp.hh> -#include <paludis/util/stringify.hh> -#include <paludis/util/wrapped_forward_iterator.hh> - -#include <iosfwd> - -/** \file - * Declarations for PackageDatabase. - * - * \ingroup g_package_database - * - * \section Examples - * - * - \ref example_package_database.cc "example_package_database.cc" - */ - -namespace paludis -{ - /** - * A PackageDatabase, which is owned by an Environment, contains a number of - * Repository instances and supports various querying methods. - * - * \ingroup g_package_database - */ - class PALUDIS_VISIBLE PackageDatabase - { - friend class EnvironmentImplementation; - friend class WrappedForwardIteratorTraits<Environment::RepositoryConstIteratorTag>; - - private: - Pimp<PackageDatabase> _imp; - - static const Filter & all_filter() PALUDIS_ATTRIBUTE((warn_unused_result)); - - public: - ~PackageDatabase(); - - protected: - ///\name Basic operations - ///\{ - - explicit PackageDatabase(const Environment * const); - - PackageDatabase(const PackageDatabase &) = delete; - PackageDatabase & operator= (const PackageDatabase &) = delete; - - ///\} - - /** - * Add a repository. - * - * \exception DuplicateRepositoryError if a Repository with the - * same name as the new Repository already exists in our - * collection. - */ - void add_repository(int importance, const std::shared_ptr<Repository>); - - /** - * Fetch a named repository. - */ - std::shared_ptr<const Repository> fetch_repository(const RepositoryName &) const - PALUDIS_ATTRIBUTE((warn_unused_result)); - - /** - * Fetch a named repository. - */ - std::shared_ptr<Repository> fetch_repository(const RepositoryName &) - PALUDIS_ATTRIBUTE((warn_unused_result)); - - /** - * Do we have a named repository? - */ - bool has_repository_named(const RepositoryName &) const - PALUDIS_ATTRIBUTE((warn_unused_result)); - - /** - * 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. If disambiguate is set to false, the - * exception will be always thrown in presence of ambiguity. - * \since 0.56 takes the disambiguate flag. - */ - QualifiedPackageName fetch_unique_qualified_package_name( - const PackageNamePart &, const Filter & = all_filter(), const bool disambiguate = true) const - PALUDIS_ATTRIBUTE((warn_unused_result)); - - /** - * Return true if the first repository is more important than the second. - */ - bool more_important_than(const RepositoryName &, const RepositoryName &) const - PALUDIS_ATTRIBUTE((warn_unused_result)); - - ///\name Iterate over our repositories - ///\{ - - struct RepositoryConstIteratorTag; - typedef WrappedForwardIterator<RepositoryConstIteratorTag, const std::shared_ptr<Repository> > RepositoryConstIterator; - - RepositoryConstIterator begin_repositories() const - PALUDIS_ATTRIBUTE((warn_unused_result)); - - RepositoryConstIterator end_repositories() const - PALUDIS_ATTRIBUTE((warn_unused_result)); - - ///\} - }; - - extern template class WrappedForwardIterator<PackageDatabase::RepositoryConstIteratorTag, const std::shared_ptr<Repository> >; -} - -#endif |