aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-08-14 19:10:06 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-08-14 19:10:06 +0100
commit1942ce8358ed3c2e11471bf4c780fc23e37edca5 (patch)
treeea8e2daeb4e3b3ba0ddddf54ce005cb8090cd2ce
parent02c0429d9a58c9c577adf24c9c816bbfca5ddec8 (diff)
downloadpaludis-1942ce8358ed3c2e11471bf4c780fc23e37edca5.tar.gz
paludis-1942ce8358ed3c2e11471bf4c780fc23e37edca5.tar.xz
Kill VirtualConstructor
-rw-r--r--paludis/util/files.m41
-rw-r--r--paludis/util/virtual_constructor-impl.hh155
-rw-r--r--paludis/util/virtual_constructor.hh136
-rw-r--r--paludis/util/virtual_constructor_TEST.cc191
4 files changed, 0 insertions, 483 deletions
diff --git a/paludis/util/files.m4 b/paludis/util/files.m4
index 6a731b9..99af6d6 100644
--- a/paludis/util/files.m4
+++ b/paludis/util/files.m4
@@ -66,7 +66,6 @@ add(`thread_pool', `hh', `cc', `test')
add(`tokeniser', `hh', `cc', `test')
add(`util', `hh')
add(`validated', `hh', `fwd', `test')
-add(`virtual_constructor', `hh', `impl', `test')
add(`visitor', `hh', `impl', `fwd', `test')
add(`visitor_cast', `hh', `test')
add(`wrapped_forward_iterator', `hh', `fwd', `impl', `test')
diff --git a/paludis/util/virtual_constructor-impl.hh b/paludis/util/virtual_constructor-impl.hh
deleted file mode 100644
index 0e4b018..0000000
--- a/paludis/util/virtual_constructor-impl.hh
+++ /dev/null
@@ -1,155 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 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_VIRTUAL_CONSTRUCTOR_IMPL_HH
-#define PALUDIS_GUARD_PALUDIS_VIRTUAL_CONSTRUCTOR_IMPL_HH 1
-
-#include <paludis/util/virtual_constructor.hh>
-#include <paludis/util/stringify.hh>
-#include <tr1/functional>
-#include <algorithm>
-#include <vector>
-
-/** \file
- * Implementation for paludis/util/virtual_constructor.hh .
- *
- * \ingroup g_oo
- */
-
-namespace paludis
-{
- namespace virtual_constructor_not_found
- {
- template <typename ExceptionType_>
- template <typename KeyType_, typename ValueType_>
- ValueType_
- ThrowException<ExceptionType_>::Parent<KeyType_, ValueType_>::handle_not_found(
- const KeyType_ & k) const
- {
- throw ExceptionType_(k);
- }
- }
-
- /**
- * For internal use by VirtualConstructor.
- *
- * \ingroup g_oo
- */
- namespace virtual_constructor_internals
- {
- /**
- * Comparator class for our entries.
- *
- * \ingroup g_oo
- */
- template <typename First_, typename Second_>
- struct ComparePairByFirst
- {
- /**
- * Compare, with the entry on the LHS.
- */
- bool operator() (const std::pair<First_, Second_> & a, const First_ & b) const
- {
- return a.first < b;
- }
-
- /**
- * Compare, with the entry on the RHS.
- */
- bool operator() (const First_ & a, const std::pair<First_, Second_> & b) const
- {
- return a < b.first;
- }
- };
- }
-
- /**
- * Holds the entries for a VirtualConstructor.
- *
- * \see VirtualConstructor
- * \ingroup g_oo
- * \nosubgrouping
- */
- template <typename KeyType_, typename ValueType_, typename NotFoundBehaviour_>
- struct VirtualConstructor<KeyType_, ValueType_, NotFoundBehaviour_>::EntriesHolder
- {
- /// The entries.
- std::vector<std::pair<KeyType_, ValueType_> > entries;
- };
-
- template <typename KeyType_, typename ValueType_, typename NotFoundBehaviour_>
- VirtualConstructor<KeyType_, ValueType_, NotFoundBehaviour_>::VirtualConstructor() :
- _entries_holder(new EntriesHolder)
- {
- }
-
- template <typename KeyType_, typename ValueType_, typename NotFoundBehaviour_>
- VirtualConstructor<KeyType_, ValueType_, NotFoundBehaviour_>::~VirtualConstructor()
- {
- delete _entries_holder;
- }
-
- template <typename KeyType_, typename ValueType_, typename NotFoundBehaviour_>
- ValueType_
- VirtualConstructor<KeyType_, ValueType_, NotFoundBehaviour_>::operator[] (const KeyType_ & k) const
- {
- return find_maker(k);
- }
-
- template <typename KeyType_, typename ValueType_, typename NotFoundBehaviour_>
- ValueType_
- VirtualConstructor<KeyType_, ValueType_, NotFoundBehaviour_>::find_maker(
- const KeyType_ & k) const
- {
- std::pair<
- typename std::vector<std::pair<KeyType_, ValueType_> >::const_iterator,
- typename std::vector<std::pair<KeyType_, ValueType_> >::const_iterator > m(
- std::equal_range(_entries_holder->entries.begin(), _entries_holder->entries.end(), k,
- virtual_constructor_internals::ComparePairByFirst<KeyType_, ValueType_>()));
- if (m.first == m.second)
- return this->handle_not_found(k);
- else
- return m.first->second;
- }
-
- template <typename KeyType_, typename ValueType_, typename NotFoundBehaviour_>
- void
- VirtualConstructor<KeyType_, ValueType_, NotFoundBehaviour_>::register_maker(
- const KeyType_ & k, const ValueType_ & v)
- {
- std::pair<
- typename std::vector<std::pair<KeyType_, ValueType_> >::iterator,
- typename std::vector<std::pair<KeyType_, ValueType_> >::iterator > m(
- std::equal_range(_entries_holder->entries.begin(), _entries_holder->entries.end(), k,
- virtual_constructor_internals::ComparePairByFirst<KeyType_, ValueType_>()));
- if (m.first == m.second)
- _entries_holder->entries.insert(m.first, std::make_pair(k, v));
- }
-
- template <typename KeyType_, typename ValueType_, typename NotFoundBehaviour_>
- template <typename T_>
- void
- VirtualConstructor<KeyType_, ValueType_, NotFoundBehaviour_>::copy_keys(T_ out_iter) const
- {
- std::transform(_entries_holder->entries.begin(), _entries_holder->entries.end(), out_iter,
- std::tr1::mem_fn(&std::pair<KeyType_, ValueType_>::first));
- }
-}
-
-#endif
diff --git a/paludis/util/virtual_constructor.hh b/paludis/util/virtual_constructor.hh
deleted file mode 100644
index 114f600..0000000
--- a/paludis/util/virtual_constructor.hh
+++ /dev/null
@@ -1,136 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006, 2007 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_VIRTUAL_CONSTRUCTOR_HH
-#define PALUDIS_GUARD_PALUDIS_VIRTUAL_CONSTRUCTOR_HH 1
-
-#include <paludis/util/exception.hh>
-#include <paludis/util/private_implementation_pattern.hh>
-#include <paludis/util/instantiation_policy.hh>
-
-/** \file
- * Declarations for VirtualConstructor and related classes.
- *
- * \ingroup g_oo
- *
- * \section Examples
- *
- * - None at this time.
- */
-
-namespace paludis
-{
- /**
- * Behaviour policy classes for what to do if an appropriate constructor
- * cannot be found for a VirtualConstructor::find_maker call.
- *
- * \ingroup g_oo
- */
- namespace virtual_constructor_not_found
- {
- /**
- * Throw an exception of type ExceptionType_, which should have a
- * constructor that takes a single parameter of KeyType_.
- *
- * \ingroup g_oo
- */
- template <typename ExceptionType_>
- struct ThrowException
- {
- /**
- * Internal use: provide handle_not_found.
- *
- * \ingroup g_oo
- */
- template <typename KeyType_, typename ValueType_>
- struct Parent
- {
- /**
- * Internal use: called when we cannot find a key.
- */
- ValueType_ handle_not_found(const KeyType_ & k) const PALUDIS_ATTRIBUTE((noreturn));
- };
- };
- }
-
- /**
- * A VirtualConstructor can be used where a mapping between the value of
- * some key type (often a string) to the construction of some kind of
- * class (possibly via a functor) is required.
- *
- * \ingroup g_oo
- */
- template <typename KeyType_, typename ValueType_, typename NotFoundBehaviour_>
- class PALUDIS_VISIBLE VirtualConstructor :
- public NotFoundBehaviour_::template Parent<KeyType_, ValueType_>,
- private InstantiationPolicy<VirtualConstructor<KeyType_, ValueType_, NotFoundBehaviour_>, instantiation_method::NonCopyableTag>
- {
- private:
- struct EntriesHolder;
- EntriesHolder * _entries_holder;
-
- protected:
- /**
- * Constructor.
- */
- VirtualConstructor();
-
- public:
- ~VirtualConstructor();
-
- /**
- * The type of our key.
- */
- typedef KeyType_ KeyType;
-
- /**
- * The type of our value.
- */
- typedef ValueType_ ValueType;
-
- /**
- * The behaviour policy for when a key is not found.
- */
- typedef NotFoundBehaviour_ NotFoundBehaviour;
-
- /**
- * Find a value for the specified key, or perform the appropriate
- * NotFoundBehaviour.
- */
- ValueType_ find_maker(const KeyType_ & k) const;
-
- /**
- * Convenience alias for find_maker.
- */
- ValueType_ operator[] (const KeyType_ & k) const;
-
- /**
- * Register a new maker.
- */
- void register_maker(const KeyType_ & k, const ValueType_ & v);
-
- /**
- * Copy out our keys.
- */
- template <typename T_>
- void copy_keys(T_ out_iter) const;
- };
-}
-
-#endif
diff --git a/paludis/util/virtual_constructor_TEST.cc b/paludis/util/virtual_constructor_TEST.cc
deleted file mode 100644
index b8b8c17..0000000
--- a/paludis/util/virtual_constructor_TEST.cc
+++ /dev/null
@@ -1,191 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 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
- */
-
-#include <paludis/util/virtual_constructor.hh>
-#include <paludis/util/virtual_constructor-impl.hh>
-#include <paludis/util/instantiation_policy-impl.hh>
-#include <test/test_framework.hh>
-#include <test/test_runner.hh>
-#include <set>
-#include <tr1/memory>
-
-/** \file
- * Test cases for VirtualConstructor.
- *
- */
-
-using namespace test;
-using namespace paludis;
-
-namespace
-{
- enum CookieSize
- {
- cs_small,
- cs_large
- };
-
- class Cookie
- {
- private:
- CookieSize _size;
-
- protected:
- Cookie(CookieSize sz) :
- _size(sz)
- {
- }
-
- public:
- virtual std::string flavour() const = 0;
-
- virtual ~Cookie()
- {
- }
-
- CookieSize size() const
- {
- return _size;
- }
- };
-
- struct NoCookie
- {
- NoCookie(const std::string &)
- {
- }
- };
-
- class ChocolateChipCookie : public Cookie
- {
- public:
- ChocolateChipCookie(CookieSize sz) :
- Cookie(sz)
- {
- }
-
- std::string flavour() const
- {
- return "Chocolate Chip";
- }
-
- static std::tr1::shared_ptr<Cookie> make(CookieSize size)
- {
- return std::tr1::shared_ptr<Cookie>(new ChocolateChipCookie(size));
- }
- };
-
- class GingerCookie : public Cookie
- {
- private:
- bool _with_crunchy_bits;
-
- public:
- GingerCookie(CookieSize sz, bool with_crunchy_bits) :
- Cookie(sz),
- _with_crunchy_bits(with_crunchy_bits)
- {
- }
-
- std::string flavour() const
- {
- return _with_crunchy_bits ? "Crunchy Ginger" : "Ginger";
- }
-
- static std::tr1::shared_ptr<Cookie> make(CookieSize size)
- {
- return std::tr1::shared_ptr<Cookie>(new GingerCookie(size, false));
- }
-
- static std::tr1::shared_ptr<Cookie> make_crunchy(CookieSize size)
- {
- return std::tr1::shared_ptr<Cookie>(new GingerCookie(size, true));
- }
- };
-
- class CookieMaker :
- public VirtualConstructor<std::string,
- std::tr1::shared_ptr<Cookie> (*) (CookieSize),
- virtual_constructor_not_found::ThrowException<NoCookie> >,
- public InstantiationPolicy<CookieMaker, instantiation_method::SingletonTag>
- {
- friend class InstantiationPolicy<CookieMaker, instantiation_method::SingletonTag>;
-
- private:
- CookieMaker()
- {
- register_maker("chocolate chip", &ChocolateChipCookie::make);
- register_maker("ginger", &GingerCookie::make);
- register_maker("crunchy ginger", &GingerCookie::make_crunchy);
- }
- };
-}
-
-namespace test_cases
-{
- /**
- * \test Test VirtualConstructor.
- *
- */
- struct VirtualConstructorTest : TestCase
- {
- VirtualConstructorTest() : TestCase("virtual constructor") { }
-
- void run()
- {
- TEST_CHECK_EQUAL(CookieMaker::get_instance()->find_maker(
- "chocolate chip")(cs_large)->flavour(), "Chocolate Chip");
- TEST_CHECK_EQUAL(CookieMaker::get_instance()->find_maker(
- "chocolate chip")(cs_large)->size(), cs_large);
- TEST_CHECK_EQUAL(CookieMaker::get_instance()->find_maker(
- "chocolate chip")(cs_small)->size(), cs_small);
-
- TEST_CHECK_EQUAL((*CookieMaker::get_instance())["ginger"](cs_small)->flavour(),
- "Ginger");
- TEST_CHECK_EQUAL((*CookieMaker::get_instance())["crunchy ginger"](cs_small)->flavour(),
- "Crunchy Ginger");
-
- TEST_CHECK_THROWS(CookieMaker::get_instance()->find_maker(
- "gerbil")(cs_large)->flavour(), NoCookie);
- }
- } test_virtual_constructor;
-
- /**
- * \test Test VirtualConstructor keys
- *
- */
- 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;
-}
-