aboutsummaryrefslogtreecommitdiff
path: root/paludis/package_id.cc
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-07-05 00:50:29 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-07-05 00:50:29 +0000
commit624bfdfc96b37df2316f6dd5241f763671259959 (patch)
tree4227b78311bce68aec20a89080a936e21c8013f9 /paludis/package_id.cc
parente931fb60ebe5fec2effef02435aad25f9d054845 (diff)
downloadpaludis-624bfdfc96b37df2316f6dd5241f763671259959.tar.gz
paludis-624bfdfc96b37df2316f6dd5241f763671259959.tar.xz
r3770@snowflake: ciaranm | 2007-07-05 01:48:14 +0100
Collection -> Sequence, Set, Map. Fixes: ticket:241
Diffstat (limited to 'paludis/package_id.cc')
-rw-r--r--paludis/package_id.cc62
1 files changed, 62 insertions, 0 deletions
diff --git a/paludis/package_id.cc b/paludis/package_id.cc
index cb330e9a1..259907916 100644
--- a/paludis/package_id.cc
+++ b/paludis/package_id.cc
@@ -22,10 +22,16 @@
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/iterator.hh>
#include <paludis/util/tr1_functional.hh>
+#include <paludis/util/sequence.hh>
+#include <paludis/util/sequence-impl.hh>
+#include <paludis/util/set.hh>
+#include <paludis/util/set-impl.hh>
#include <paludis/util/stringify.hh>
#include <paludis/name.hh>
#include <paludis/version_spec.hh>
#include <paludis/repository.hh>
+#include <paludis/package_database.hh>
+#include <paludis/hashed_containers.hh>
#include <list>
#include <algorithm>
@@ -36,6 +42,9 @@ using namespace paludis;
#include <paludis/package_id-se.cc>
+template class Sequence<tr1::shared_ptr<const PackageID> >;
+template class Set<tr1::shared_ptr<const PackageID>, PackageIDSetComparator>;
+
namespace paludis
{
template <>
@@ -131,3 +140,56 @@ paludis::operator== (const PackageID & a, const PackageID & b)
&& (! b.arbitrary_less_than_comparison(a));
}
+namespace paludis
+{
+ template <>
+ struct Implementation<PackageIDComparator>
+ {
+ MakeHashedMap<RepositoryName, unsigned>::Type m;
+ };
+}
+
+PackageIDComparator::PackageIDComparator(const PackageDatabase * const db) :
+ PrivateImplementationPattern<PackageIDComparator>(new Implementation<PackageIDComparator>)
+{
+ unsigned c(0);
+ for (PackageDatabase::RepositoryIterator r(db->begin_repositories()),
+ r_end(db->end_repositories()) ; r != r_end ; ++r)
+ _imp->m.insert(std::make_pair((*r)->name(), ++c));
+}
+
+PackageIDComparator::~PackageIDComparator()
+{
+}
+
+bool
+PackageIDComparator::operator() (const tr1::shared_ptr<const PackageID> & a,
+ const tr1::shared_ptr<const PackageID> & b) const
+{
+ if (a->name() < b->name())
+ return true;
+
+ if (a->name() > b->name())
+ return false;
+
+ if (a->version() < b->version())
+ return true;
+
+ if (a->version() > b->version())
+ return false;
+
+ MakeHashedMap<RepositoryName, unsigned>::Type::const_iterator
+ ma(_imp->m.find(a->repository()->name())),
+ mb(_imp->m.find(b->repository()->name()));
+
+ if (ma == _imp->m.end() || mb == _imp->m.end())
+ throw InternalError(PALUDIS_HERE, "Repository not in database");
+
+ if (ma->second < mb->second)
+ return true;
+ if (ma->second > mb->second)
+ return false;
+
+ return a->arbitrary_less_than_comparison(*b);
+}
+