aboutsummaryrefslogtreecommitdiff
path: root/paludis/util/indirect_iterator.hh
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-11-02 08:39:11 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-11-02 08:39:11 +0000
commit7dd876b56e1bce94b46ffd665377a449f2500eea (patch)
tree913675cab2f917dc3443233692a409318289e329 /paludis/util/indirect_iterator.hh
parentd832a1dd9e9718619bfb7bb7d0e3b48e26e65a33 (diff)
downloadpaludis-7dd876b56e1bce94b46ffd665377a449f2500eea.tar.gz
paludis-7dd876b56e1bce94b46ffd665377a449f2500eea.tar.xz
Fix first lot of breakage
Diffstat (limited to 'paludis/util/indirect_iterator.hh')
-rw-r--r--paludis/util/indirect_iterator.hh128
1 files changed, 128 insertions, 0 deletions
diff --git a/paludis/util/indirect_iterator.hh b/paludis/util/indirect_iterator.hh
new file mode 100644
index 000000000..6bf5ce0b2
--- /dev/null
+++ b/paludis/util/indirect_iterator.hh
@@ -0,0 +1,128 @@
+/* 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
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_UTIL_INDIRECT_ITERATOR_HH
+#define PALUDIS_GUARD_PALUDIS_UTIL_INDIRECT_ITERATOR_HH 1
+
+#include <paludis/util/indirect_iterator-fwd.hh>
+#include <paludis/util/operators.hh>
+#include <paludis/util/tr1_memory.hh>
+#include <paludis/util/tr1_functional.hh>
+#include <paludis/util/tr1_type_traits.hh>
+
+namespace paludis
+{
+ template <typename T_>
+ struct IndirectIteratorValueType<T_ *>
+ {
+ typedef T_ Type;
+ };
+
+ template <typename T_>
+ struct IndirectIteratorValueType<tr1::shared_ptr<T_> >
+ {
+ typedef T_ Type;
+ };
+
+ template <typename T_>
+ struct IndirectIteratorValueType<tr1::shared_ptr<const T_> >
+ {
+ typedef const T_ Type;
+ };
+
+ template <typename T_>
+ struct IndirectIteratorValueType<const T_>
+ {
+ typedef typename IndirectIteratorValueType<T_>::Type Type;
+ };
+
+ template <typename T_>
+ struct IndirectIteratorValueType<T_ &>
+ {
+ typedef typename IndirectIteratorValueType<T_>::Type Type;
+ };
+
+ /**
+ * An IndirectIterator turns an iterator over T_ * or tr1::shared_ptr<T_> into an iterator
+ * over T_.
+ *
+ * \ingroup g_iterator
+ * \see indirect_iterator
+ */
+ template <typename Iter_, typename Value_>
+ class IndirectIterator :
+ public relational_operators::HasRelationalOperators
+ {
+ friend bool operator== <> (const IndirectIterator &, const IndirectIterator &);
+ friend bool operator< <> (const IndirectIterator &, const IndirectIterator &);
+
+ private:
+ Iter_ _iter;
+
+ public:
+ ///\name Basic operations
+ ///\{
+
+ IndirectIterator();
+ IndirectIterator(const IndirectIterator &);
+ IndirectIterator(const Iter_ &);
+
+ IndirectIterator & operator= (const IndirectIterator &);
+
+ ///\}
+
+ ///\name Standard library typedefs
+ ///\{
+
+ typedef typename tr1::remove_reference<Value_>::type & value_type;
+ typedef typename tr1::remove_reference<Value_>::type & reference;
+ typedef typename tr1::remove_reference<Value_>::type * pointer;
+ typedef std::ptrdiff_t difference_type;
+ typedef typename std::iterator_traits<Iter_>::iterator_category iterator_category;
+
+ ///\}
+
+ ///\name Increment
+ ///\{
+
+ IndirectIterator & operator++ ();
+ IndirectIterator operator++ (int);
+
+ ///\}
+
+ ///\name Dereference
+ ///\{
+
+ pointer operator-> () const;
+ reference operator* () const;
+
+ ///\}
+ };
+
+ /**
+ * Construct an IndirectIterator from another iterator.
+ *
+ * \see IndirectIterator
+ * \ingroup g_iterator
+ */
+ template <typename Iter_>
+ IndirectIterator<Iter_> indirect_iterator(const Iter_ & t);
+}
+
+#endif