aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-10-15 17:17:05 +0000
committerAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-10-15 17:17:05 +0000
commit54e98e25ee31ab62b68cca717e1c6de668497f33 (patch)
treefe5108074b47e76fe0cdd0e0310505c17f1ba4a1
parent962cd6add043d0aa6d0339888a2dd0e501dc375a (diff)
downloadpaludis-54e98e25ee31ab62b68cca717e1c6de668497f33.tar.gz
paludis-54e98e25ee31ab62b68cca717e1c6de668497f33.tar.xz
Move nifty iterator stuff from reconcilio/util to paludis/util.
-rw-r--r--paludis/util/iterator.hh70
-rw-r--r--paludis/util/iterator_TEST.cc104
-rw-r--r--src/clients/reconcilio/broken_linkage_finder/broken_linkage_finder.cc1
-rw-r--r--src/clients/reconcilio/broken_linkage_finder/elf_linkage_checker.cc1
-rw-r--r--src/clients/reconcilio/util/Makefile.am12
-rw-r--r--src/clients/reconcilio/util/iterator.hh97
-rw-r--r--src/clients/reconcilio/util/iterator_TEST.cc126
7 files changed, 176 insertions, 235 deletions
diff --git a/paludis/util/iterator.hh b/paludis/util/iterator.hh
index 332d7b0..e9c2d1a 100644
--- a/paludis/util/iterator.hh
+++ b/paludis/util/iterator.hh
@@ -2,6 +2,7 @@
/*
* Copyright (c) 2005, 2006, 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
+ * Copyright (c) 2007 David Leverton <levertond@googlemail.com>
*
* 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
@@ -498,6 +499,75 @@ namespace paludis
{
return CreateInsertIterator<Iter_, Type_>(i);
}
+
+ template <typename Value_, typename Iterator_, Value_ std::iterator_traits<Iterator_>::value_type::* member_>
+ class MemberIterator :
+ public std::iterator<std::forward_iterator_tag, const Value_>,
+ public paludis::equality_operators::HasEqualityOperators
+ {
+ private:
+ Iterator_ _it;
+
+ public:
+ MemberIterator(Iterator_ it) :
+ _it(it)
+ {
+ }
+
+ bool operator== (const MemberIterator & other) const
+ {
+ return _it == other._it;
+ }
+
+ MemberIterator & operator++ ()
+ {
+ ++_it;
+ return *this;
+ }
+
+ MemberIterator operator++ (int)
+ {
+ return MemberIterator(_it++);
+ }
+
+ typename std::iterator_traits<MemberIterator>::reference operator* () const
+ {
+ return (*_it).*member_;
+ }
+
+ typename std::iterator_traits<MemberIterator>::pointer operator-> () const
+ {
+ return &((*_it).*member_);
+ }
+ };
+
+ template <typename Iterator_>
+ struct FirstIterator
+ {
+ typedef MemberIterator<typename std::iterator_traits<Iterator_>::value_type::first_type,
+ Iterator_, &std::iterator_traits<Iterator_>::value_type::first> Type;
+ };
+
+ template <typename Iterator_>
+ inline typename FirstIterator<Iterator_>::Type
+ first_iterator(Iterator_ it)
+ {
+ return typename FirstIterator<Iterator_>::Type(it);
+ }
+
+ template <typename Iterator_>
+ struct SecondIterator
+ {
+ typedef MemberIterator<typename std::iterator_traits<Iterator_>::value_type::second_type,
+ Iterator_, &std::iterator_traits<Iterator_>::value_type::second> Type;
+ };
+
+ template <typename Iterator_>
+ inline typename SecondIterator<Iterator_>::Type
+ second_iterator(Iterator_ it)
+ {
+ return typename SecondIterator<Iterator_>::Type(it);
+ }
}
#endif
diff --git a/paludis/util/iterator_TEST.cc b/paludis/util/iterator_TEST.cc
index bd6e06a..0ceb348 100644
--- a/paludis/util/iterator_TEST.cc
+++ b/paludis/util/iterator_TEST.cc
@@ -2,6 +2,7 @@
/*
* Copyright (c) 2005, 2006, 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
+ * Copyright (c) 2007 David Leverton <levertond@googlemail.com>
*
* 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,11 +21,13 @@
#include <algorithm>
#include <list>
#include <paludis/util/iterator.hh>
+#include <paludis/util/join.hh>
#include <test/test_framework.hh>
#include <test/test_runner.hh>
#include <vector>
#include <set>
#include <map>
+#include <string>
#include <paludis/util/tr1_memory.hh>
using namespace test;
@@ -333,3 +336,104 @@ namespace test_cases
}
} test_create_insert_iterator;
}
+
+namespace test_cases
+{
+ /**
+ * \test Test first_iterator.
+ *
+ */
+ struct FirstIteratorTest : TestCase
+ {
+ FirstIteratorTest() : TestCase("first_iterator") {}
+
+ void run()
+ {
+ typedef std::vector<std::pair<std::string, std::string> > V;
+
+ V v;
+ v.push_back(std::pair<std::string, std::string>("one", "I"));
+ v.push_back(std::pair<std::string, std::string>("two", "II"));
+ v.push_back(std::pair<std::string, std::string>("three", "III"));
+ v.push_back(std::pair<std::string, std::string>("four", "IV"));
+ v.push_back(std::pair<std::string, std::string>("five", "V"));
+
+ FirstIterator<V::iterator>::Type it = first_iterator(v.begin());
+ TEST_CHECK(it == it);
+ TEST_CHECK(! (it != it));
+ TEST_CHECK_EQUAL(*it, "one");
+ TEST_CHECK_EQUAL(it->length(), 3U);
+
+ FirstIterator<V::iterator>::Type it2(it);
+ TEST_CHECK(it == it2);
+ TEST_CHECK(! (it != it2));
+ TEST_CHECK_EQUAL(*++it2, "two");
+ TEST_CHECK_EQUAL(*it2, "two");
+ TEST_CHECK_EQUAL(it2->length(), 3U);
+ TEST_CHECK(it != it2);
+ TEST_CHECK(! (it == it2));
+
+ FirstIterator<V::iterator>::Type it3(it2);
+ TEST_CHECK(it2 == it3++);
+ TEST_CHECK(it2 != it3);
+ TEST_CHECK_EQUAL(*it3, "three");
+ TEST_CHECK_EQUAL(it3->length(), 5U);
+
+ it3 = it2;
+ TEST_CHECK(it2 == it3);
+ TEST_CHECK_EQUAL(*it3, "two");
+ TEST_CHECK_EQUAL(*it3++, "two");
+
+ TEST_CHECK_EQUAL(join(first_iterator(v.begin()), first_iterator(v.end()), " "), "one two three four five");
+ }
+ } first_iterator_test;
+
+ /**
+ * \test Test second_iterator.
+ *
+ */
+ struct SecondIteratorTest : TestCase
+ {
+ SecondIteratorTest() : TestCase("second_iterator") {}
+
+ void run()
+ {
+ typedef std::map<std::string, std::string> M;
+
+ M m;
+ m["I"] = "one";
+ m["II"] = "two";
+ m["III"] = "three";
+ m["IV"] = "four";
+ m["V"] = "five";
+
+ SecondIterator<M::iterator>::Type it = second_iterator(m.begin());
+ TEST_CHECK(it == it);
+ TEST_CHECK(! (it != it));
+ TEST_CHECK_EQUAL(*it, "one");
+ TEST_CHECK_EQUAL(it->length(), 3U);
+
+ SecondIterator<M::iterator>::Type it2(it);
+ TEST_CHECK(it == it2);
+ TEST_CHECK(! (it != it2));
+ TEST_CHECK_EQUAL(*++it2, "two");
+ TEST_CHECK_EQUAL(*it2, "two");
+ TEST_CHECK_EQUAL(it2->length(), 3U);
+ TEST_CHECK(it != it2);
+ TEST_CHECK(! (it == it2));
+
+ SecondIterator<M::iterator>::Type it3(it2);
+ TEST_CHECK(it2 == it3++);
+ TEST_CHECK(it2 != it3);
+ TEST_CHECK_EQUAL(*it3, "three");
+ TEST_CHECK_EQUAL(it3->length(), 5U);
+
+ it3 = it2;
+ TEST_CHECK(it2 == it3);
+ TEST_CHECK_EQUAL(*it3, "two");
+ TEST_CHECK_EQUAL(*it3++, "two");
+
+ TEST_CHECK_EQUAL(join(second_iterator(m.begin()), second_iterator(m.end()), " "), "one two three four five");
+ }
+ } second_iterator_test;
+}
diff --git a/src/clients/reconcilio/broken_linkage_finder/broken_linkage_finder.cc b/src/clients/reconcilio/broken_linkage_finder/broken_linkage_finder.cc
index 232ff8f..216c7bf 100644
--- a/src/clients/reconcilio/broken_linkage_finder/broken_linkage_finder.cc
+++ b/src/clients/reconcilio/broken_linkage_finder/broken_linkage_finder.cc
@@ -23,7 +23,6 @@
#include "libtool_linkage_checker.hh"
#include "linkage_checker.hh"
-#include <src/clients/reconcilio/util/iterator.hh>
#include <src/clients/reconcilio/util/realpath.hh>
#include <paludis/util/fs_entry.hh>
diff --git a/src/clients/reconcilio/broken_linkage_finder/elf_linkage_checker.cc b/src/clients/reconcilio/broken_linkage_finder/elf_linkage_checker.cc
index f13a9f4..eedc684 100644
--- a/src/clients/reconcilio/broken_linkage_finder/elf_linkage_checker.cc
+++ b/src/clients/reconcilio/broken_linkage_finder/elf_linkage_checker.cc
@@ -19,7 +19,6 @@
#include "elf_linkage_checker.hh"
-#include <src/clients/reconcilio/util/iterator.hh>
#include <src/clients/reconcilio/util/realpath.hh>
#include <src/clients/reconcilio/littlelf/elf.hh>
diff --git a/src/clients/reconcilio/util/Makefile.am b/src/clients/reconcilio/util/Makefile.am
index d57f4ce..82e5ed4 100644
--- a/src/clients/reconcilio/util/Makefile.am
+++ b/src/clients/reconcilio/util/Makefile.am
@@ -6,28 +6,20 @@ noinst_LIBRARIES = libreconcilioutil.a
libreconcilioutil_a_SOURCES = \
realpath.cc realpath.hh \
- wildcard_expander.cc wildcard_expander.hh \
- iterator.hh
+ wildcard_expander.cc wildcard_expander.hh
TESTS_ENVIRONMENT = env \
TEST_SCRIPT_DIR="$(srcdir)/" \
TEST_OUTPUT_WRAPPER="`$(top_srcdir)/paludis/repositories/e/ebuild/utils/canonicalise $(top_builddir)/paludis/util/outputwrapper`" \
bash $(top_srcdir)/test/run_test.sh bash
-TESTS = iterator_TEST realpath_TEST wildcard_expander_TEST
+TESTS = realpath_TEST wildcard_expander_TEST
check_PROGRAMS = $(TESTS)
EXTRA_DIST = \
realpath_TEST_setup.sh realpath_TEST_cleanup.sh \
wildcard_expander_TEST_setup.sh wildcard_expander_TEST_cleanup.sh
-iterator_TEST_SOURCES = iterator_TEST.cc
-iterator_TEST_LDADD = \
- libreconcilioutil.a \
- $(top_builddir)/paludis/util/libpaludisutil.la \
- $(top_builddir)/paludis/util/test_extras.o \
- $(top_builddir)/test/libtest.a
-
realpath_TEST_SOURCES = realpath_TEST.cc
realpath_TEST_LDADD = \
libreconcilioutil.a \
diff --git a/src/clients/reconcilio/util/iterator.hh b/src/clients/reconcilio/util/iterator.hh
deleted file mode 100644
index 25ccbd6..0000000
--- a/src/clients/reconcilio/util/iterator.hh
+++ /dev/null
@@ -1,97 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2007 David Leverton <levertond@googlemail.com>
- *
- * 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_RECONCILIO_UTIL_ITERATOR_HH
-#define PALUDIS_GUARD_RECONCILIO_UTIL_ITERATOR_HH
-
-#include <paludis/util/operators.hh>
-
-#include <iterator>
-
-template <typename Value_, typename Iterator_, Value_ std::iterator_traits<Iterator_>::value_type::* member_>
-class MemberIterator :
- public std::iterator<std::forward_iterator_tag, const Value_>,
- public paludis::equality_operators::HasEqualityOperators
-{
- private:
- Iterator_ _it;
-
- public:
- MemberIterator(Iterator_ it) :
- _it(it)
- {
- }
-
- bool operator== (const MemberIterator & other) const
- {
- return _it == other._it;
- }
-
- MemberIterator & operator++ ()
- {
- ++_it;
- return *this;
- }
-
- MemberIterator operator++ (int)
- {
- return MemberIterator(_it++);
- }
-
- typename std::iterator_traits<MemberIterator>::reference operator* () const
- {
- return (*_it).*member_;
- }
-
- typename std::iterator_traits<MemberIterator>::pointer operator-> () const
- {
- return &((*_it).*member_);
- }
-};
-
-template <typename Iterator_>
-struct FirstIterator
-{
- typedef MemberIterator<typename std::iterator_traits<Iterator_>::value_type::first_type,
- Iterator_, &std::iterator_traits<Iterator_>::value_type::first> Type;
-};
-
-template <typename Iterator_>
-inline typename FirstIterator<Iterator_>::Type
-first_iterator(Iterator_ it)
-{
- return typename FirstIterator<Iterator_>::Type(it);
-}
-
-template <typename Iterator_>
-struct SecondIterator
-{
- typedef MemberIterator<typename std::iterator_traits<Iterator_>::value_type::second_type,
- Iterator_, &std::iterator_traits<Iterator_>::value_type::second> Type;
-};
-
-template <typename Iterator_>
-inline typename SecondIterator<Iterator_>::Type
-second_iterator(Iterator_ it)
-{
- return typename SecondIterator<Iterator_>::Type(it);
-}
-
-#endif
-
diff --git a/src/clients/reconcilio/util/iterator_TEST.cc b/src/clients/reconcilio/util/iterator_TEST.cc
deleted file mode 100644
index b11deb1..0000000
--- a/src/clients/reconcilio/util/iterator_TEST.cc
+++ /dev/null
@@ -1,126 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2007 David Leverton <levertond@googlemail.com>
- *
- * 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 "iterator.hh"
-
-#include <paludis/util/join.hh>
-
-#include <test/test_runner.hh>
-#include <test/test_framework.hh>
-
-#include <map>
-#include <string>
-#include <vector>
-
-using namespace test;
-using namespace paludis;
-
-namespace test_cases
-{
- struct FirstIteratorTest : TestCase
- {
- FirstIteratorTest() : TestCase("first_iterator") {}
-
- void run()
- {
- typedef std::vector<std::pair<std::string, std::string> > V;
-
- V v;
- v.push_back(std::pair<std::string, std::string>("one", "I"));
- v.push_back(std::pair<std::string, std::string>("two", "II"));
- v.push_back(std::pair<std::string, std::string>("three", "III"));
- v.push_back(std::pair<std::string, std::string>("four", "IV"));
- v.push_back(std::pair<std::string, std::string>("five", "V"));
-
- FirstIterator<V::iterator>::Type it = first_iterator(v.begin());
- TEST_CHECK(it == it);
- TEST_CHECK(! (it != it));
- TEST_CHECK_EQUAL(*it, "one");
- TEST_CHECK_EQUAL(it->length(), 3U);
-
- FirstIterator<V::iterator>::Type it2(it);
- TEST_CHECK(it == it2);
- TEST_CHECK(! (it != it2));
- TEST_CHECK_EQUAL(*++it2, "two");
- TEST_CHECK_EQUAL(*it2, "two");
- TEST_CHECK_EQUAL(it2->length(), 3U);
- TEST_CHECK(it != it2);
- TEST_CHECK(! (it == it2));
-
- FirstIterator<V::iterator>::Type it3(it2);
- TEST_CHECK(it2 == it3++);
- TEST_CHECK(it2 != it3);
- TEST_CHECK_EQUAL(*it3, "three");
- TEST_CHECK_EQUAL(it3->length(), 5U);
-
- it3 = it2;
- TEST_CHECK(it2 == it3);
- TEST_CHECK_EQUAL(*it3, "two");
- TEST_CHECK_EQUAL(*it3++, "two");
-
- TEST_CHECK_EQUAL(join(first_iterator(v.begin()), first_iterator(v.end()), " "), "one two three four five");
- }
- } first_iterator_test;
-
- struct SecondIteratorTest : TestCase
- {
- SecondIteratorTest() : TestCase("second_iterator") {}
-
- void run()
- {
- typedef std::map<std::string, std::string> M;
-
- M m;
- m["I"] = "one";
- m["II"] = "two";
- m["III"] = "three";
- m["IV"] = "four";
- m["V"] = "five";
-
- SecondIterator<M::iterator>::Type it = second_iterator(m.begin());
- TEST_CHECK(it == it);
- TEST_CHECK(! (it != it));
- TEST_CHECK_EQUAL(*it, "one");
- TEST_CHECK_EQUAL(it->length(), 3U);
-
- SecondIterator<M::iterator>::Type it2(it);
- TEST_CHECK(it == it2);
- TEST_CHECK(! (it != it2));
- TEST_CHECK_EQUAL(*++it2, "two");
- TEST_CHECK_EQUAL(*it2, "two");
- TEST_CHECK_EQUAL(it2->length(), 3U);
- TEST_CHECK(it != it2);
- TEST_CHECK(! (it == it2));
-
- SecondIterator<M::iterator>::Type it3(it2);
- TEST_CHECK(it2 == it3++);
- TEST_CHECK(it2 != it3);
- TEST_CHECK_EQUAL(*it3, "three");
- TEST_CHECK_EQUAL(it3->length(), 5U);
-
- it3 = it2;
- TEST_CHECK(it2 == it3);
- TEST_CHECK_EQUAL(*it3, "two");
- TEST_CHECK_EQUAL(*it3++, "two");
-
- TEST_CHECK_EQUAL(join(second_iterator(m.begin()), second_iterator(m.end()), " "), "one two three four five");
- }
- } second_iterator_test;
-}
-