Wiselib
wiselib.stable/util/pstl/iterator.h
Go to the documentation of this file.
00001 /***************************************************************************
00002  ** This file is part of the generic algorithm library Wiselib.           **
00003  ** Copyright (C) 2008,2009 by the Wisebed (www.wisebed.eu) project.      **
00004  **                                                                       **
00005  ** The Wiselib is free software: you can redistribute it and/or modify   **
00006  ** it under the terms of the GNU Lesser General Public License as        **
00007  ** published by the Free Software Foundation, either version 3 of the    **
00008  ** License, or (at your option) any later version.                       **
00009  **                                                                       **
00010  ** The Wiselib is distributed in the hope that it will be useful,        **
00011  ** but WITHOUT ANY WARRANTY; without even the implied warranty of        **
00012  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         **
00013  ** GNU Lesser General Public License for more details.                   **
00014  **                                                                       **
00015  ** You should have received a copy of the GNU Lesser General Public      **
00016  ** License along with the Wiselib.                                       **
00017  ** If not, see <http://www.gnu.org/licenses/>.                           **
00018  ***************************************************************************/
00019 #ifndef __WISELIB_INTERNAL_INTERFACE_STL_ITERATOR_H
00020 #define __WISELIB_INTERNAL_INTERFACE_STL_ITERATOR_H
00021 
00022 #include "util/pstl/iterator_base_types.h"
00023 
00024 namespace wiselib
00025 {
00026 
00027    template<typename OsModel_P,
00028             typename Iterator_P,
00029             typename Container_P>
00030    class normal_iterator
00031    {
00032    public:
00033       typedef OsModel_P OsModel;
00034 
00035       typedef Iterator_P iterator_type;
00036       typedef typename iterator_traits<Iterator_P>::iterator_category iterator_category;
00037       typedef typename iterator_traits<Iterator_P>::value_type value_type;
00038       typedef typename iterator_traits<Iterator_P>::difference_type difference_type;
00039       typedef typename iterator_traits<Iterator_P>::reference reference;
00040       typedef typename iterator_traits<Iterator_P>::pointer pointer;
00041       // --------------------------------------------------------------------
00044       normal_iterator()
00045          : current_( iterator_type() )
00046       {};
00047       // --------------------------------------------------------------------
00048       explicit
00049       normal_iterator( const iterator_type& it )
00050          : current_( it )
00051       {}
00053       // --------------------------------------------------------------------
00056       reference operator*() const
00057       { return *current_; }
00058       // --------------------------------------------------------------------
00059       pointer operator->() const
00060       { return current_; }
00061       // --------------------------------------------------------------------
00062       const iterator_type& base() const
00063       { return current_; }
00065       // --------------------------------------------------------------------
00068       normal_iterator&
00069       operator++()
00070       {
00071          ++current_;
00072          return *this;
00073       }
00074       // --------------------------------------------------------------------
00075       normal_iterator
00076       operator++(int)
00077       { return normal_iterator( current_++ ); }
00078       // --------------------------------------------------------------------
00079       normal_iterator&
00080       operator--()
00081       {
00082          --current_;
00083          return *this;
00084       }
00085       // --------------------------------------------------------------------
00086       normal_iterator
00087       operator--(int)
00088       { return normal_iterator( current_-- ); }
00089       // --------------------------------------------------------------------
00090       // Random access iterator requirements
00091       reference
00092       operator[](const difference_type& n) const
00093       { return current_[n]; }
00094       // --------------------------------------------------------------------
00095       normal_iterator&
00096       operator+=(const difference_type& n)
00097       { current_ += n; return *this; }
00098       // --------------------------------------------------------------------
00099       normal_iterator
00100       operator+(const difference_type& n) const
00101       { return normal_iterator(current_ + n); }
00102       // --------------------------------------------------------------------
00103       normal_iterator&
00104       operator-=(const difference_type& n)
00105       { current_ -= n; return *this; }
00106       // --------------------------------------------------------------------
00107       normal_iterator
00108       operator-(const difference_type& n) const
00109       { return normal_iterator(current_ - n); }
00111 
00112    private:
00113       iterator_type current_;
00114    };
00115 
00118    template<typename _OsModel, typename _Iterator_L, typename _Iterator_R, typename _Container>
00119    inline bool
00120    operator==( const normal_iterator<_OsModel, _Iterator_L, _Container>& lhs,
00121                const normal_iterator<_OsModel, _Iterator_R, _Container>& rhs)
00122    { return lhs.base() == rhs.base(); }
00123    // --------------------------------------------------------------------
00124    template<typename _OsModel, typename _Iterator, typename _Container>
00125    inline bool
00126    operator==( const normal_iterator<_OsModel, _Iterator, _Container>& lhs,
00127                const normal_iterator<_OsModel, _Iterator, _Container>& rhs)
00128    { return lhs.base() == rhs.base(); }
00129    // --------------------------------------------------------------------
00130    template<typename _OsModel, typename _Iterator_L, typename _Iterator_R, typename _Container>
00131    inline bool
00132    operator!=( const normal_iterator<_OsModel, _Iterator_L, _Container>& lhs,
00133                const normal_iterator<_OsModel, _Iterator_R, _Container>& rhs)
00134    { return lhs.base() != rhs.base(); }
00135    // --------------------------------------------------------------------
00136    template<typename _OsModel, typename _Iterator, typename _Container>
00137    inline bool
00138    operator!=( const normal_iterator<_OsModel, _Iterator, _Container>& lhs,
00139                const normal_iterator<_OsModel, _Iterator, _Container>& rhs)
00140    { return lhs.base() != rhs.base(); }
00141    // --------------------------------------------------------------------
00142    template<typename _OsModel, typename _Iterator_L, typename _Iterator_R, typename _Container>
00143    inline typename normal_iterator<_OsModel, _Iterator_L, _Container>::difference_type
00144    operator-( const normal_iterator<_OsModel, _Iterator_L, _Container>& lhs,
00145               const normal_iterator<_OsModel, _Iterator_R, _Container>& rhs)
00146    { return lhs.base() - rhs.base(); }
00147    // --------------------------------------------------------------------
00148    template<typename _OsModel, typename _Iterator, typename _Container>
00149    inline typename normal_iterator<_OsModel, _Iterator, _Container>::difference_type
00150    operator-( const normal_iterator<_OsModel, _Iterator, _Container>& lhs,
00151               const normal_iterator<_OsModel, _Iterator, _Container>& rhs)
00152    { return lhs.base() - rhs.base(); }
00153    // --------------------------------------------------------------------
00154    template<typename _OsModel, typename _Iterator_L, typename _Iterator_R, typename _Container>
00155    inline typename normal_iterator<_OsModel, _Iterator_L, _Container>::difference_type
00156    operator+( const normal_iterator<_OsModel, _Iterator_L, _Container>& lhs,
00157               const normal_iterator<_OsModel, _Iterator_R, _Container>& rhs)
00158    { return lhs.base() + rhs.base(); }
00159    // --------------------------------------------------------------------
00160    template<typename _OsModel, typename _Iterator, typename _Container>
00161    inline typename normal_iterator<_OsModel, _Iterator, _Container>::difference_type
00162    operator+( const normal_iterator<_OsModel, _Iterator, _Container>& lhs,
00163               const normal_iterator<_OsModel, _Iterator, _Container>& rhs)
00164    { return lhs.base() + rhs.base(); }
00165    // --------------------------------------------------------------------
00166    template<typename _OsModel, typename _Iterator_L, typename _Iterator_R, typename _Container>
00167    inline bool
00168    operator<( const normal_iterator<_OsModel, _Iterator_L, _Container>& lhs,
00169               const normal_iterator<_OsModel, _Iterator_R, _Container>& rhs)
00170    { return rhs.base() < lhs.base(); }
00171    // --------------------------------------------------------------------
00172    template<typename _OsModel, typename _Iterator, typename _Container>
00173    inline bool
00174    operator<( const normal_iterator<_OsModel, _Iterator, _Container>& lhs,
00175               const normal_iterator<_OsModel, _Iterator, _Container>& rhs)
00176    { return rhs.base() < lhs.base(); }
00177    // --------------------------------------------------------------------
00178    template<typename _OsModel, typename _Iterator_L, typename _Iterator_R, typename _Container>
00179    inline bool
00180    operator>( const normal_iterator<_OsModel, _Iterator_L, _Container>& lhs,
00181               const normal_iterator<_OsModel, _Iterator_R, _Container>& rhs)
00182    { return rhs < lhs; }
00183    // --------------------------------------------------------------------
00184    template<typename _OsModel, typename _Iterator, typename _Container>
00185    inline bool
00186    operator>( const normal_iterator<_OsModel, _Iterator, _Container>& lhs,
00187               const normal_iterator<_OsModel, _Iterator, _Container>& rhs)
00188    { return rhs < lhs; }
00189    // --------------------------------------------------------------------
00190    template<typename _OsModel, typename _Iterator_L, typename _Iterator_R, typename _Container>
00191    inline bool
00192    operator<=( const normal_iterator<_OsModel, _Iterator_L, _Container>& lhs,
00193               const normal_iterator<_OsModel, _Iterator_R, _Container>& rhs)
00194    { return !(rhs < lhs); }
00195    // --------------------------------------------------------------------
00196    template<typename _OsModel, typename _Iterator, typename _Container>
00197    inline bool
00198    operator<=( const normal_iterator<_OsModel, _Iterator, _Container>& lhs,
00199               const normal_iterator<_OsModel, _Iterator, _Container>& rhs)
00200    { return !(rhs < lhs); }
00201    // --------------------------------------------------------------------
00202    template<typename _OsModel, typename _Iterator_L, typename _Iterator_R, typename _Container>
00203    inline bool
00204    operator>=( const normal_iterator<_OsModel, _Iterator_L, _Container>& lhs,
00205               const normal_iterator<_OsModel, _Iterator_R, _Container>& rhs)
00206    { return !(lhs < rhs); }
00207    // --------------------------------------------------------------------
00208    template<typename _OsModel, typename _Iterator, typename _Container>
00209    inline bool
00210    operator>=( const normal_iterator<_OsModel, _Iterator, _Container>& lhs,
00211               const normal_iterator<_OsModel, _Iterator, _Container>& rhs)
00212    { return !(lhs < rhs); }
00214 
00215 }
00216 
00217 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines