aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2012-03-30 19:12:03 +0100
committerAvatar David Leverton <levertond@googlemail.com> 2012-03-30 19:12:03 +0100
commitd5b8921e7a707d74e795b9549d1e07eb4973de9d (patch)
tree4deb792ac5124acd3fd6c77001b00074b742d6f9
parentde6b2ae2f2ec414b30fa953b80a9cc58f2d875df (diff)
downloadpaludis-d5b8921e7a707d74e795b9549d1e07eb4973de9d.tar.gz
paludis-d5b8921e7a707d74e795b9549d1e07eb4973de9d.tar.xz
Add a way to get all the supported algorithms
-rw-r--r--paludis/util/digest_registry.cc22
-rw-r--r--paludis/util/digest_registry.hh10
2 files changed, 30 insertions, 2 deletions
diff --git a/paludis/util/digest_registry.cc b/paludis/util/digest_registry.cc
index ec7ab1e..6994b8f 100644
--- a/paludis/util/digest_registry.cc
+++ b/paludis/util/digest_registry.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2011 David Leverton
+ * Copyright (c) 2011, 2012 David Leverton
*
* 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,6 +20,7 @@
#include <paludis/util/digest_registry.hh>
#include <paludis/util/pimp-impl.hh>
#include <paludis/util/singleton-impl.hh>
+#include <paludis/util/wrapped_forward_iterator-impl.hh>
#include <map>
using namespace paludis;
@@ -32,6 +33,12 @@ namespace
namespace paludis
{
template <>
+ struct WrappedForwardIteratorTraits<DigestRegistry::AlgorithmsConstIteratorTag>
+ {
+ typedef FunctionMap::const_iterator UnderlyingIterator;
+ };
+
+ template <>
struct Imp<DigestRegistry>
{
FunctionMap functions;
@@ -55,6 +62,18 @@ DigestRegistry::get(const std::string & algo) const
return it->second;
}
+DigestRegistry::AlgorithmsConstIterator
+DigestRegistry::begin_algorithms() const
+{
+ return AlgorithmsConstIterator(_imp->functions.begin());
+}
+
+DigestRegistry::AlgorithmsConstIterator
+DigestRegistry::end_algorithms() const
+{
+ return AlgorithmsConstIterator(_imp->functions.end());
+}
+
void
DigestRegistry::register_function(const std::string & algo, const Function & func)
{
@@ -65,6 +84,7 @@ namespace paludis
{
template class Pimp<DigestRegistry>;
template class Singleton<DigestRegistry>;
+ template class WrappedForwardIterator<DigestRegistry::AlgorithmsConstIteratorTag, const std::pair<const std::string, DigestRegistry::Function> >;
}
diff --git a/paludis/util/digest_registry.hh b/paludis/util/digest_registry.hh
index cfa86ce..cf14fcf 100644
--- a/paludis/util/digest_registry.hh
+++ b/paludis/util/digest_registry.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2011 David Leverton
+ * Copyright (c) 2011, 2012 David Leverton
*
* 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
@@ -25,7 +25,9 @@
#include <paludis/util/attributes.hh>
#include <paludis/util/pimp.hh>
#include <paludis/util/singleton.hh>
+#include <paludis/util/wrapped_forward_iterator-fwd.hh>
#include <functional>
+#include <utility>
namespace paludis
{
@@ -39,6 +41,12 @@ namespace paludis
Function get(const std::string & algo) const;
+ struct AlgorithmsConstIteratorTag;
+ typedef WrappedForwardIterator<AlgorithmsConstIteratorTag, const std::pair<const std::string, Function> > AlgorithmsConstIterator;
+
+ AlgorithmsConstIterator begin_algorithms() const PALUDIS_ATTRIBUTE((warn_unused_result));
+ AlgorithmsConstIterator end_algorithms() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
template <typename T_>
class Registration
{