1 /* Ptr_Iterator class declaration. 2 Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it> 3 Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com) 4 5 This file is part of the Parma Polyhedra Library (PPL). 6 7 The PPL is free software; you can redistribute it and/or modify it 8 under the terms of the GNU General Public License as published by the 9 Free Software Foundation; either version 3 of the License, or (at your 10 option) any later version. 11 12 The PPL is distributed in the hope that it will be useful, but WITHOUT 13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software Foundation, 19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. 20 21 For the most up-to-date information see the Parma Polyhedra Library 22 site: http://bugseng.com/products/ppl/ . */ 23 24 #ifndef PPL_Ptr_Iterator_defs_hh 25 #define PPL_Ptr_Iterator_defs_hh 1 26 27 #include "Ptr_Iterator_types.hh" 28 #include <iterator> 29 30 namespace Parma_Polyhedra_Library { 31 32 namespace Implementation { 33 34 template<typename P, typename Q> 35 bool operator==(const Ptr_Iterator<P>& x, const Ptr_Iterator<Q>& y); 36 37 template<typename P, typename Q> 38 bool operator!=(const Ptr_Iterator<P>& x, const Ptr_Iterator<Q>& y); 39 40 template<typename P, typename Q> 41 bool operator<(const Ptr_Iterator<P>& x, const Ptr_Iterator<Q>& y); 42 43 template<typename P, typename Q> 44 bool operator<=(const Ptr_Iterator<P>& x, const Ptr_Iterator<Q>& y); 45 46 template<typename P, typename Q> 47 bool operator>(const Ptr_Iterator<P>& x, const Ptr_Iterator<Q>& y); 48 49 template<typename P, typename Q> 50 bool operator>=(const Ptr_Iterator<P>& x, const Ptr_Iterator<Q>& y); 51 52 template<typename P, typename Q> 53 typename Ptr_Iterator<P>::difference_type 54 operator-(const Ptr_Iterator<P>& x, const Ptr_Iterator<Q>& y); 55 56 template<typename P> 57 Ptr_Iterator<P> operator+(typename Ptr_Iterator<P>::difference_type m, 58 const Ptr_Iterator<P>& y); 59 60 } // namespace Implementation 61 62 } // namespace Parma_Polyhedra_Library 63 64 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS 65 //! A class to define STL const and non-const iterators from pointer types. 66 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS) 67 template <typename P> 68 class Parma_Polyhedra_Library::Implementation::Ptr_Iterator 69 : public std::iterator<typename std::iterator_traits<P>::iterator_category, 70 typename std::iterator_traits<P>::value_type, 71 typename std::iterator_traits<P>::difference_type, 72 typename std::iterator_traits<P>::pointer, 73 typename std::iterator_traits<P>::reference> { 74 public: 75 typedef typename std::iterator_traits<P>::difference_type difference_type; 76 typedef typename std::iterator_traits<P>::reference reference; 77 typedef typename std::iterator_traits<P>::pointer pointer; 78 79 //! Default constructor: no guarantees. 80 Ptr_Iterator(); 81 82 //! Construct an iterator pointing at \p q. 83 explicit Ptr_Iterator(const P& q); 84 85 /*! \brief 86 Copy constructor allowing the construction of a const_iterator 87 from a non-const iterator. 88 */ 89 template<typename Q> 90 Ptr_Iterator(const Ptr_Iterator<Q>& q); 91 92 //! Dereference operator. 93 reference operator*() const; 94 95 //! Indirect member selector. 96 pointer operator->() const; 97 98 //! Subscript operator. 99 reference operator[](const difference_type m) const; 100 101 //! Prefix increment operator. 102 Ptr_Iterator& operator++(); 103 104 //! Postfix increment operator. 105 Ptr_Iterator operator++(int); 106 107 //! Prefix decrement operator 108 Ptr_Iterator& operator--(); 109 110 //! Postfix decrement operator. 111 Ptr_Iterator operator--(int); 112 113 //! Assignment-increment operator. 114 Ptr_Iterator& operator+=(const difference_type m); 115 116 //! Assignment-decrement operator. 117 Ptr_Iterator& operator-=(const difference_type m); 118 119 //! Returns the difference between \p *this and \p y. 120 difference_type operator-(const Ptr_Iterator& y) const; 121 122 //! Returns the sum of \p *this and \p m. 123 Ptr_Iterator operator+(const difference_type m) const; 124 125 //! Returns the difference of \p *this and \p m. 126 Ptr_Iterator operator-(const difference_type m) const; 127 128 private: 129 //! The base pointer implementing the iterator. 130 P p; 131 132 //! Returns the hidden pointer. 133 const P& base() const; 134 135 template <typename Q, typename R> 136 friend bool Parma_Polyhedra_Library::Implementation:: 137 operator==(const Ptr_Iterator<Q>& x, const Ptr_Iterator<R>& y); 138 139 template <typename Q, typename R> 140 friend bool Parma_Polyhedra_Library::Implementation:: 141 operator!=(const Ptr_Iterator<Q>& x, const Ptr_Iterator<R>& y); 142 143 template<typename Q, typename R> 144 friend bool Parma_Polyhedra_Library::Implementation:: 145 operator<(const Ptr_Iterator<Q>& x, const Ptr_Iterator<R>& y); 146 147 template<typename Q, typename R> 148 friend bool Parma_Polyhedra_Library::Implementation:: 149 operator<=(const Ptr_Iterator<Q>& x, const Ptr_Iterator<R>& y); 150 151 template<typename Q, typename R> 152 friend bool Parma_Polyhedra_Library::Implementation:: 153 operator>(const Ptr_Iterator<Q>& x, const Ptr_Iterator<R>& y); 154 155 template<typename Q, typename R> 156 friend bool Parma_Polyhedra_Library::Implementation:: 157 operator>=(const Ptr_Iterator<Q>& x, const Ptr_Iterator<R>& y); 158 159 template<typename Q, typename R> 160 friend typename Ptr_Iterator<Q>::difference_type 161 Parma_Polyhedra_Library::Implementation:: 162 operator-(const Ptr_Iterator<Q>& x, const Ptr_Iterator<R>& y); 163 164 friend Ptr_Iterator<P> 165 Parma_Polyhedra_Library::Implementation:: 166 operator+<>(typename Ptr_Iterator<P>::difference_type m, 167 const Ptr_Iterator<P>& y); 168 }; 169 170 #include "Ptr_Iterator_inlines.hh" 171 172 #endif // !defined(PPL_Ptr_Iterator_defs_hh) 173