indirect_iterator.hh

00001 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
00002 
00003 /*
00004  * Copyright (c) 2007, 2008 Ciaran McCreesh
00005  *
00006  * This file is part of the Paludis package manager. Paludis is free software;
00007  * you can redistribute it and/or modify it under the terms of the GNU General
00008  * Public License version 2, as published by the Free Software Foundation.
00009  *
00010  * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
00011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00012  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00013  * details.
00014  *
00015  * You should have received a copy of the GNU General Public License along with
00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00017  * Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #ifndef PALUDIS_GUARD_PALUDIS_UTIL_INDIRECT_ITERATOR_HH
00021 #define PALUDIS_GUARD_PALUDIS_UTIL_INDIRECT_ITERATOR_HH 1
00022 
00023 #include <paludis/util/indirect_iterator-fwd.hh>
00024 #include <paludis/util/operators.hh>
00025 #include <tr1/memory>
00026 #include <tr1/functional>
00027 #include <tr1/type_traits>
00028 
00029 namespace paludis
00030 {
00031     template <typename T_>
00032     struct IndirectIteratorValueType
00033     {
00034         typedef typename std::iterator_traits<T_>::value_type Type;
00035     };
00036 
00037     template <typename T_>
00038     struct IndirectIteratorValueType<T_ *>
00039     {
00040         typedef T_ Type;
00041     };
00042 
00043     template <typename T_>
00044     struct IndirectIteratorValueType<std::tr1::shared_ptr<T_> >
00045     {
00046         typedef T_ Type;
00047     };
00048 
00049     template <typename T_>
00050     struct IndirectIteratorValueType<std::tr1::shared_ptr<const T_> >
00051     {
00052         typedef const T_ Type;
00053     };
00054 
00055     template <typename T_>
00056     struct IndirectIteratorValueType<const T_>
00057     {
00058         typedef typename IndirectIteratorValueType<T_>::Type Type;
00059     };
00060 
00061     template <typename T_>
00062     struct IndirectIteratorValueType<T_ &>
00063     {
00064         typedef typename IndirectIteratorValueType<T_>::Type Type;
00065     };
00066 
00067     /**
00068      * An IndirectIterator turns an iterator over T_ * or std::tr1::shared_ptr<T_> into an iterator
00069      * over T_.
00070      *
00071      * \ingroup g_iterator
00072      * \see indirect_iterator
00073      */
00074     template <typename Iter_, typename Value_>
00075     class IndirectIterator :
00076         public relational_operators::HasRelationalOperators
00077     {
00078         friend bool operator== <> (const IndirectIterator &, const IndirectIterator &);
00079         friend bool operator< <> (const IndirectIterator &, const IndirectIterator &);
00080 
00081         private:
00082             Iter_ _iter;
00083 
00084         public:
00085             ///\name Basic operations
00086             ///\{
00087 
00088             IndirectIterator();
00089             IndirectIterator(const IndirectIterator &);
00090             IndirectIterator(const Iter_ &);
00091 
00092             IndirectIterator & operator= (const IndirectIterator &);
00093 
00094             ///\}
00095 
00096             ///\name Standard library typedefs
00097             ///\{
00098 
00099             typedef typename std::tr1::remove_reference<Value_>::type & value_type;
00100             typedef typename std::tr1::remove_reference<Value_>::type & reference;
00101             typedef typename std::tr1::remove_reference<Value_>::type * pointer;
00102             typedef std::ptrdiff_t difference_type;
00103             typedef std::forward_iterator_tag iterator_category;
00104 
00105             ///\}
00106 
00107             ///\name Increment
00108             ///\{
00109 
00110             IndirectIterator & operator++ ();
00111             IndirectIterator operator++ (int);
00112 
00113             ///\}
00114 
00115             ///\name Dereference
00116             ///\{
00117 
00118             pointer operator-> () const;
00119             reference operator* () const;
00120 
00121             ///\}
00122     };
00123 
00124     /**
00125      * Construct an IndirectIterator from another iterator.
00126      *
00127      * \see IndirectIterator
00128      * \ingroup g_iterator
00129      */
00130     template <typename Iter_>
00131     IndirectIterator<Iter_> indirect_iterator(const Iter_ & t);
00132 }
00133 
00134 #endif

Generated on Mon Sep 21 10:36:08 2009 for paludis by  doxygen 1.5.4