aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-07-17 17:32:51 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-07-17 17:32:51 +0000
commit09849ab2e660ce87faf80055e86ea29e123dd948 (patch)
tree5df2cb9c662698f47dc6d0576e91be6e7547104f
parentf69b88e0b6e6d7b836cf921445f7242b52b52d8d (diff)
downloadpaludis-09849ab2e660ce87faf80055e86ea29e123dd948.tar.gz
paludis-09849ab2e660ce87faf80055e86ea29e123dd948.tar.xz
More libwrapiter conversions
-rw-r--r--paludis/dep_atom_flattener.cc1
-rw-r--r--paludis/environment.cc1
-rw-r--r--paludis/package_database.cc56
-rw-r--r--paludis/package_database.hh88
4 files changed, 86 insertions, 60 deletions
diff --git a/paludis/dep_atom_flattener.cc b/paludis/dep_atom_flattener.cc
index 71f38f7..8aa5ae7 100644
--- a/paludis/dep_atom_flattener.cc
+++ b/paludis/dep_atom_flattener.cc
@@ -19,6 +19,7 @@
#include <paludis/dep_atom.hh>
#include <paludis/dep_atom_flattener.hh>
+#include <list>
/** \file
* Implementation of dep_atom_flattener.hh.
diff --git a/paludis/environment.cc b/paludis/environment.cc
index 03859ac..8f46327 100644
--- a/paludis/environment.cc
+++ b/paludis/environment.cc
@@ -25,6 +25,7 @@
#include <paludis/util/tokeniser.hh>
#include <set>
+#include <list>
/** \file
* Implementation of Environment.
diff --git a/paludis/package_database.cc b/paludis/package_database.cc
index bbaa8b7..1f40f77 100644
--- a/paludis/package_database.cc
+++ b/paludis/package_database.cc
@@ -73,6 +73,56 @@ NoSuchVersionError::NoSuchVersionError(const std::string & name,
{
}
+struct AmbiguousPackageNameError::NameData
+{
+ std::string name;
+ std::list<std::string> names;
+};
+
+
+template <typename I_>
+AmbiguousPackageNameError::AmbiguousPackageNameError(const std::string & name,
+ I_ begin, const I_ end) throw () :
+ PackageDatabaseLookupError("Ambiguous package name '" + name + "' (candidates are " +
+ join(begin, end, ", ") + ")"),
+ _name_data(new NameData)
+{
+ _name_data->name = name;
+ std::transform(begin, end, std::back_inserter(_name_data->names),
+ &stringify<typename std::iterator_traits<I_>::value_type>);
+}
+
+AmbiguousPackageNameError::AmbiguousPackageNameError(const AmbiguousPackageNameError & other) :
+ PackageDatabaseLookupError(other),
+ _name_data(new NameData)
+{
+ _name_data->name = other._name_data->name;
+ _name_data->names = other._name_data->names;
+}
+
+AmbiguousPackageNameError::~AmbiguousPackageNameError() throw ()
+{
+ delete _name_data;
+}
+
+AmbiguousPackageNameError::OptionsIterator
+AmbiguousPackageNameError::begin_options() const
+{
+ return OptionsIterator(_name_data->names.begin());
+}
+
+AmbiguousPackageNameError::OptionsIterator
+AmbiguousPackageNameError::end_options() const
+{
+ return OptionsIterator(_name_data->names.end());
+}
+
+const std::string &
+AmbiguousPackageNameError::name() const
+{
+ return _name_data->name;
+}
+
namespace paludis
{
/**
@@ -93,6 +143,7 @@ namespace paludis
const Environment * environment;
};
}
+
PackageDatabase::PackageDatabase(const Environment * const e) :
PrivateImplementationPattern<PackageDatabase>(new Implementation<PackageDatabase>)
{
@@ -236,11 +287,12 @@ PackageDatabase::query(PackageDepAtom::ConstPointer a, const InstallState s) con
PackageDatabase::RepositoryIterator
PackageDatabase::begin_repositories() const
{
- return _imp->repositories.begin();
+ return RepositoryIterator(_imp->repositories.begin());
}
PackageDatabase::RepositoryIterator
PackageDatabase::end_repositories() const
{
- return _imp->repositories.end();
+ return RepositoryIterator(_imp->repositories.end());
}
+
diff --git a/paludis/package_database.hh b/paludis/package_database.hh
index 76d269d..dbac74b 100644
--- a/paludis/package_database.hh
+++ b/paludis/package_database.hh
@@ -38,10 +38,7 @@
#include <paludis/contents.hh>
#include <iosfwd>
-#include <algorithm>
-#include <functional>
-#include <iterator>
-#include <list>
+#include <libwrapiter/libwrapiter_forward_iterator.hh>
/** \file
* Declarations for the PackageDatabase class and related utilities.
@@ -93,67 +90,45 @@ namespace paludis
* \ingroup grpexceptions
* \ingroup grppackagedatabase
*/
- class AmbiguousPackageNameError : public PackageDatabaseLookupError
+ class AmbiguousPackageNameError :
+ public PackageDatabaseLookupError
{
private:
+ struct NameData;
+ NameData * const _name_data;
+
std::string _name;
- std::list<std::string> _names;
public:
- /**
- * Constructor.
- */
+ ///\name Basic operations
+ ///\{
+
template <typename I_>
AmbiguousPackageNameError(const std::string & name,
I_ begin, const I_ end) throw ();
- /**
- * Destructor.
- */
- virtual ~AmbiguousPackageNameError() throw ()
- {
- }
+ AmbiguousPackageNameError(const AmbiguousPackageNameError &);
+
+ virtual ~AmbiguousPackageNameError() throw ();
+
+ ///\}
/**
* The name of the package.
*/
- const std::string & name() const
- {
- return _name;
- }
+ const std::string & name() const;
- /**
- * Iterator over possible matches.
- */
- typedef std::list<std::string>::const_iterator OptionsIterator;
+ ///\name Iterate over possible matches
+ ///\{
- /**
- * Start of our options.
- */
- OptionsIterator begin_options() const
- {
- return _names.begin();
- }
+ typedef libwrapiter::ForwardIterator<AmbiguousPackageNameError,
+ const std::string> OptionsIterator;
- /**
- * Past the end of our options.
- */
- OptionsIterator end_options() const
- {
- return _names.end();
- }
- };
+ OptionsIterator begin_options() const;
+ OptionsIterator end_options() const;
- template <typename I_>
- AmbiguousPackageNameError::AmbiguousPackageNameError(const std::string & name,
- I_ begin, const I_ end) throw () :
- PackageDatabaseLookupError("Ambiguous package name '" + name + "' (candidates are " +
- join(begin, end, ", ") + ")"),
- _name(name)
- {
- std::transform(begin, end, std::back_inserter(_names),
- &stringify<typename std::iterator_traits<I_>::value_type>);
- }
+ ///\}
+ };
/**
* Thrown if a Repository with the same name as an existing member is added
@@ -322,20 +297,17 @@ namespace paludis
const RepositoryName & better_repository(const RepositoryName &,
const RepositoryName &) const;
- /**
- * Iterate over all of our repositories.
- */
- typedef std::list<Repository::ConstPointer>::const_iterator RepositoryIterator;
+ ///\name Iterate over our repositories
+ ///\{
+
+ typedef libwrapiter::ForwardIterator<PackageDatabase,
+ const Repository::ConstPointer> RepositoryIterator;
- /**
- * Iterator to the start of our repositories.
- */
RepositoryIterator begin_repositories() const;
- /**
- * Iterator to past the end of our repositories.
- */
RepositoryIterator end_repositories() const;
+
+ ///\}
};
}