aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-12-23 07:56:28 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-12-23 07:56:28 +0000
commitb28273710efa547971a1a629b1e2efacb8a2eab8 (patch)
tree36fbf99aba24176ae24251e12253ee6e0b3c9d15
parentd8becf1b2566fe6649dfc7d4d811b84d974d4665 (diff)
downloadpaludis-b28273710efa547971a1a629b1e2efacb8a2eab8.tar.gz
paludis-b28273710efa547971a1a629b1e2efacb8a2eab8.tar.xz
Extend WrappedForwardIterator
-rw-r--r--paludis/util/files.m42
-rw-r--r--paludis/util/wrapped_forward_iterator-impl.hh28
-rw-r--r--paludis/util/wrapped_forward_iterator.hh8
-rw-r--r--paludis/util/wrapped_forward_iterator_TEST.cc50
4 files changed, 87 insertions, 1 deletions
diff --git a/paludis/util/files.m4 b/paludis/util/files.m4
index 0ef5ed0..2b21b3e 100644
--- a/paludis/util/files.m4
+++ b/paludis/util/files.m4
@@ -63,6 +63,6 @@ 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')
+add(`wrapped_forward_iterator', `hh', `fwd', `impl', `test')
add(`wrapped_output_iterator', `hh', `fwd', `impl')
diff --git a/paludis/util/wrapped_forward_iterator-impl.hh b/paludis/util/wrapped_forward_iterator-impl.hh
index a54f862..7a02ded 100644
--- a/paludis/util/wrapped_forward_iterator-impl.hh
+++ b/paludis/util/wrapped_forward_iterator-impl.hh
@@ -32,6 +32,8 @@ namespace paludis
virtual typename WrappedForwardIterator<Tag_, Value_>::pointer pointer() const = 0;
virtual typename WrappedForwardIterator<Tag_, Value_>::reference reference() const = 0;
virtual bool equal(const Base *) const = 0;
+ virtual void * underlying_iterator_ptr() = 0;
+ virtual const void * underlying_iterator_ptr() const = 0;
virtual ~Base()
{
@@ -74,6 +76,16 @@ namespace paludis
{
return i == static_cast<const BaseImpl *>(other)->i;
}
+
+ void * underlying_iterator_ptr()
+ {
+ return &i;
+ }
+
+ const void * underlying_iterator_ptr() const
+ {
+ return &i;
+ }
};
template <typename Tag_, typename Value_>
@@ -150,6 +162,22 @@ namespace paludis
return _base->equal(other._base);
}
+
+ template <typename Tag_, typename Value_>
+ template <typename Iter_>
+ Iter_ &
+ WrappedForwardIterator<Tag_, Value_>::underlying_iterator()
+ {
+ return *static_cast<Iter_ *>(_base->underlying_iterator_ptr());
+ }
+
+ template <typename Tag_, typename Value_>
+ template <typename Iter_>
+ const Iter_ &
+ WrappedForwardIterator<Tag_, Value_>::underlying_iterator() const
+ {
+ return *static_cast<const Iter_ *>(_base->underlying_iterator_ptr());
+ }
}
#endif
diff --git a/paludis/util/wrapped_forward_iterator.hh b/paludis/util/wrapped_forward_iterator.hh
index f793801..c3d5120 100644
--- a/paludis/util/wrapped_forward_iterator.hh
+++ b/paludis/util/wrapped_forward_iterator.hh
@@ -99,6 +99,14 @@ namespace paludis
bool operator== (const WrappedForwardIterator &) const;
///\}
+
+ ///\name Underlying iterator
+ ///\{
+
+ template <typename T_> T_ & underlying_iterator();
+ template <typename T_> const T_ & underlying_iterator() const;
+
+ ///\}
};
}
diff --git a/paludis/util/wrapped_forward_iterator_TEST.cc b/paludis/util/wrapped_forward_iterator_TEST.cc
new file mode 100644
index 0000000..9a8af56
--- /dev/null
+++ b/paludis/util/wrapped_forward_iterator_TEST.cc
@@ -0,0 +1,50 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 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
+ */
+
+#include <paludis/util/wrapped_forward_iterator-impl.hh>
+#include <paludis/util/join.hh>
+#include <paludis/util/iterator_funcs.hh>
+#include <test/test_runner.hh>
+#include <test/test_framework.hh>
+#include <vector>
+#include <list>
+
+using namespace test;
+using namespace paludis;
+
+namespace test_cases
+{
+ struct WrappedForwardIteratorTest : TestCase
+ {
+ WrappedForwardIteratorTest() : TestCase("wrapped_forward_iterator") { }
+
+ void run()
+ {
+ std::list<int> l;
+ l.push_back(1);
+ l.push_back(2);
+ l.push_back(3);
+
+ typedef WrappedForwardIterator<void, int> I;
+ TEST_CHECK_EQUAL(join(I(l.begin()), I(l.end()), ", "), "1, 2, 3");
+ TEST_CHECK(I(l.begin()).underlying_iterator<std::list<int>::iterator>() == l.begin());
+ }
+ } test_wrapped_forward_iterator;
+}
+