1 /* iterator_to_const and const_iterator_to_const class declarations.
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_iterator_to_const_hh
25 #define PPL_iterator_to_const_hh 1
26 
27 #include "iterator_to_const_types.hh"
28 #include "Powerset_types.hh"
29 #include <iterator>
30 
31 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
32 //! An iterator on a sequence of read-only objects.
33 /*! \ingroup PPL_CXX_interface
34   This template class implements a bidirectional <EM>read-only</EM>
35   iterator on the sequence of objects <CODE>Container</CODE>.
36   By using this iterator class it is not possible to modify the objects
37   contained in <CODE>Container</CODE>; rather, object modification has
38   to be implemented by object replacement, i.e., by using the methods
39   provided by <CODE>Container</CODE> to remove/insert objects.
40   Such a policy (a modifiable container of read-only objects) allows
41   for a reliable enforcement of invariants (such as sortedness of the
42   objects in the sequence).
43 
44   \note
45   For any developers' need, suitable friend declarations allow for
46   accessing the low-level iterators on the sequence of objects.
47 */
48 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
49 template <typename Container>
50 class Parma_Polyhedra_Library::iterator_to_const {
51 private:
52   //! The type of the underlying mutable iterator.
53   typedef typename Container::iterator Base;
54 
55   //! A shortcut for naming the const_iterator traits.
56   typedef typename
57   std::iterator_traits<typename Container::const_iterator> Traits;
58 
59   //! A (mutable) iterator on the sequence of elements.
60   Base base;
61 
62   //! Constructs from the lower-level iterator.
63   iterator_to_const(const Base& b);
64 
65   friend class const_iterator_to_const<Container>;
66   template <typename T> friend class Powerset;
67 
68 public:
69   // Same traits of the const_iterator, therefore
70   // forbidding the direct modification of sequence elements.
71   typedef typename Traits::iterator_category iterator_category;
72   typedef typename Traits::value_type value_type;
73   typedef typename Traits::difference_type difference_type;
74   typedef typename Traits::pointer pointer;
75   typedef typename Traits::reference reference;
76 
77   //! Default constructor.
78   iterator_to_const();
79 
80   //! Copy constructor.
81   iterator_to_const(const iterator_to_const& y);
82 
83   //! Dereference operator.
84   reference operator*() const;
85 
86   //! Indirect access operator.
87   pointer operator->() const;
88 
89   //! Prefix increment operator.
90   iterator_to_const& operator++();
91 
92   //! Postfix increment operator.
93   iterator_to_const operator++(int);
94 
95   //! Prefix decrement operator.
96   iterator_to_const& operator--();
97 
98   //! Postfix decrement operator.
99   iterator_to_const operator--(int);
100 
101   /*! \brief
102     Returns <CODE>true</CODE> if and only if
103     \p *this and \p y are identical.
104   */
105   bool operator==(const iterator_to_const& y) const;
106 
107   /*! \brief
108     Returns <CODE>true</CODE> if and only if
109     \p *this and \p y are different.
110   */
111   bool operator!=(const iterator_to_const& y) const;
112 };
113 
114 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
115 //! A %const_iterator on a sequence of read-only objects.
116 /*! \ingroup PPL_CXX_interface
117   This class, besides implementing a read-only bidirectional iterator
118   on a read-only sequence of objects, ensures interoperability
119   with template class iterator_to_const.
120 */
121 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
122 template <typename Container>
123 class Parma_Polyhedra_Library::const_iterator_to_const {
124 private:
125   //! The type of the underlying %const_iterator.
126   typedef typename Container::const_iterator Base;
127 
128   //! A shortcut for naming traits.
129   typedef typename std::iterator_traits<Base> Traits;
130 
131   //! A %const_iterator on the sequence of elements.
132   Base base;
133 
134   //! Constructs from the lower-level const_iterator.
135   const_iterator_to_const(const Base& b);
136 
137   friend class iterator_to_const<Container>;
138   template <typename T> friend class Powerset;
139 
140 public:
141   // Same traits of the underlying const_iterator.
142   typedef typename Traits::iterator_category iterator_category;
143   typedef typename Traits::value_type value_type;
144   typedef typename Traits::difference_type difference_type;
145   typedef typename Traits::pointer pointer;
146   typedef typename Traits::reference reference;
147 
148   //! Default constructor.
149   const_iterator_to_const();
150 
151   //! Copy constructor.
152   const_iterator_to_const(const const_iterator_to_const& y);
153 
154   //! Constructs from the corresponding non-const iterator.
155   const_iterator_to_const(const iterator_to_const<Container>& y);
156 
157   //! Dereference operator.
158   reference operator*() const;
159 
160   //! Indirect member selector.
161   pointer operator->() const;
162 
163   //! Prefix increment operator.
164   const_iterator_to_const& operator++();
165 
166   //! Postfix increment operator.
167   const_iterator_to_const operator++(int);
168 
169   //! Prefix decrement operator.
170   const_iterator_to_const& operator--();
171 
172   //! Postfix decrement operator.
173   const_iterator_to_const operator--(int);
174 
175   /*! \brief
176     Returns <CODE>true</CODE> if and only if
177     \p *this and \p y are identical.
178   */
179   bool operator==(const const_iterator_to_const& y) const;
180 
181   /*! \brief
182     Returns <CODE>true</CODE> if and only if
183     \p *this and \p y are different.
184   */
185   bool operator!=(const const_iterator_to_const& y) const;
186 };
187 
188 namespace Parma_Polyhedra_Library {
189 
190 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
191 /*! \brief
192   Mixed comparison operator: returns <CODE>true</CODE> if and only
193   if (the const version of) \p x is identical to \p y.
194 
195   \relates const_iterator_to_const
196 */
197 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
198 template <typename Container>
199 bool
200 operator==(const iterator_to_const<Container>& x,
201            const const_iterator_to_const<Container>& y);
202 
203 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
204 /*! \brief
205   Mixed comparison operator: returns <CODE>true</CODE> if and only
206   if (the const version of) \p x is different from \p y.
207 
208   \relates const_iterator_to_const
209 */
210 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
211 template <typename Container>
212 bool
213 operator!=(const iterator_to_const<Container>& x,
214            const const_iterator_to_const<Container>& y);
215 
216 } // namespace Parma_Polyhedra_Library
217 
218 #include "iterator_to_const_inlines.hh"
219 
220 #endif // !defined(PPL_iterator_to_const_hh)
221