member_iterator.hh

00001 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
00002 
00003 /*
00004  * Copyright (c) 2007, 2008, 2009 Ciaran McCreesh
00005  * Copyright (c) 2007 David Leverton
00006  *
00007  * This file is part of the Paludis package manager. Paludis is free software;
00008  * you can redistribute it and/or modify it under the terms of the GNU General
00009  * Public License version 2, as published by the Free Software Foundation.
00010  *
00011  * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
00012  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00014  * details.
00015  *
00016  * You should have received a copy of the GNU General Public License along with
00017  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00018  * Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 #ifndef PALUDIS_GUARD_PALUDIS_UTIL_MEMBER_ITERATOR_HH
00022 #define PALUDIS_GUARD_PALUDIS_UTIL_MEMBER_ITERATOR_HH 1
00023 
00024 #include <paludis/util/member_iterator-fwd.hh>
00025 #include <paludis/util/operators.hh>
00026 #include <tr1/type_traits>
00027 
00028 namespace paludis
00029 {
00030     template <typename Iterator_>
00031     struct FirstIteratorTypes
00032     {
00033         typedef MemberIterator<
00034             typename std::tr1::remove_reference<typename std::iterator_traits<Iterator_>::value_type>::type::first_type,
00035             Iterator_,
00036             &std::tr1::remove_reference<typename std::iterator_traits<Iterator_>::value_type>::type::first>
00037                 Type;
00038     };
00039 
00040     template <typename Iterator_>
00041     struct SecondIteratorTypes
00042     {
00043         typedef MemberIterator<
00044             typename std::tr1::remove_reference<typename std::iterator_traits<Iterator_>::value_type>::type::second_type,
00045             Iterator_,
00046             &std::tr1::remove_reference<typename std::iterator_traits<Iterator_>::value_type>::type::second>
00047                 Type;
00048     };
00049 
00050     /**
00051      * A MemberIterator is a wrapper around a forward iterator to a struct,
00052      * selecting one particular member of that struct for the value.
00053      *
00054      * \ingroup g_iterator
00055      * \since 0.26
00056      */
00057     template <typename Value_, typename Iterator_,
00058              Value_ std::tr1::remove_reference<typename std::iterator_traits<Iterator_>::value_type>::type::* member_>
00059     class MemberIterator :
00060         public equality_operators::HasEqualityOperators
00061     {
00062         private:
00063             Iterator_ _iter;
00064 
00065         public:
00066             ///\name Basic operations
00067             ///\{
00068 
00069             MemberIterator();
00070             MemberIterator(const MemberIterator &);
00071             MemberIterator(const Iterator_ &);
00072 
00073             MemberIterator & operator= (const MemberIterator &);
00074 
00075             ///\}
00076 
00077             ///\name Standard library typedefs
00078             ///\{
00079 
00080             typedef typename std::tr1::remove_const<typename std::tr1::remove_reference<Value_>::type>::type value_type;
00081             typedef const typename std::tr1::remove_reference<Value_>::type & reference;
00082             typedef const typename std::tr1::remove_reference<Value_>::type * pointer;
00083             typedef std::ptrdiff_t difference_type;
00084             typedef std::forward_iterator_tag iterator_category;
00085 
00086             ///\}
00087 
00088             ///\name Increment
00089             ///\{
00090 
00091             MemberIterator & operator++ ();
00092             MemberIterator operator++ (int);
00093 
00094             ///\}
00095 
00096             ///\name Dereference
00097             ///\{
00098 
00099             pointer operator-> () const;
00100             reference operator* () const;
00101 
00102             ///\}
00103 
00104             ///\name Equality
00105             ///\{
00106 
00107             bool operator== (const MemberIterator &) const;
00108 
00109             ///\}
00110     };
00111 }
00112 
00113 #endif

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