aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-13 17:43:51 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-13 17:43:51 +0000
commit8a0e1084e86cabd6ca1fa7f0975e63ec62cbe124 (patch)
treea74959ec65c3c1dbed853ab0780263d383fc6d9e
parent463f56aa30492fb2723fb91be70bf9d3d17c36fb (diff)
downloadpaludis-8a0e1084e86cabd6ca1fa7f0975e63ec62cbe124.tar.gz
paludis-8a0e1084e86cabd6ca1fa7f0975e63ec62cbe124.tar.xz
Provide a way of knowing about all our registered constructors
-rw-r--r--paludis/virtual_constructor.hh16
-rw-r--r--paludis/virtual_constructor_TEST.cc24
2 files changed, 40 insertions, 0 deletions
diff --git a/paludis/virtual_constructor.hh b/paludis/virtual_constructor.hh
index 8ebb9f9..ce7dd00 100644
--- a/paludis/virtual_constructor.hh
+++ b/paludis/virtual_constructor.hh
@@ -23,6 +23,7 @@
#include <paludis/exception.hh>
#include <paludis/instantiation_policy.hh>
#include <paludis/stringify.hh>
+#include <paludis/transform_insert_iterator.hh>
#include <algorithm>
#include <vector>
@@ -189,6 +190,12 @@ namespace paludis
void register_maker(const KeyType_ & k, const ValueType_ & v);
/**
+ * Copy out our keys.
+ */
+ template <typename T_>
+ void copy_keys(T_ out_iter) const;
+
+ /**
* An instance of this class registers a new maker with the
* specified key.
*
@@ -233,6 +240,15 @@ namespace paludis
std::make_pair(k, v))->second)
throw VirtualConstructorRegisterFailure(k);
}
+
+ template <typename KeyType_, typename ValueType_, typename NotFoundBehaviour_>
+ template <typename T_>
+ void
+ VirtualConstructor<KeyType_, ValueType_, NotFoundBehaviour_>::copy_keys(T_ out_iter) const
+ {
+ std::copy(entries.begin(), entries.end(), TransformInsertIterator<
+ T_, SelectFirst<KeyType_, ValueType_> >(out_iter));
+ }
}
#endif
diff --git a/paludis/virtual_constructor_TEST.cc b/paludis/virtual_constructor_TEST.cc
index 86c116b..81cb02a 100644
--- a/paludis/virtual_constructor_TEST.cc
+++ b/paludis/virtual_constructor_TEST.cc
@@ -4,6 +4,7 @@
#include "counted_ptr.hh"
#include <test/test_runner.hh>
#include <test/test_framework.hh>
+#include <set>
using namespace test;
using namespace paludis;
@@ -139,5 +140,28 @@ namespace test_cases
"gerbil")(cs_large)->flavour(), NoCookie);
}
} test_virtual_constructor;
+
+ /**
+ * \test Test VirtualConstructor keys
+ *
+ * \ingroup Test
+ */
+ struct VirtualConstructorKeysTest : TestCase
+ {
+ VirtualConstructorKeysTest() : TestCase("virtual constructor keys") { }
+
+ void run()
+ {
+ std::set<std::string> keys;
+
+ TEST_CHECK(keys.empty());
+ CookieMaker::get_instance()->copy_keys(std::inserter(keys, keys.begin()));
+ TEST_CHECK(! keys.empty());
+ TEST_CHECK(keys.end() != keys.find("crunchy ginger"));
+ TEST_CHECK(keys.end() != keys.find("ginger"));
+ TEST_CHECK(keys.end() != keys.find("chocolate chip"));
+ TEST_CHECK(keys.end() == keys.find("gerbil"));
+ }
+ } test_virtual_constructor_keys;
}