Chemical Data Processing Library C++ API - Version 1.4.0
VectorIterator.hpp
Go to the documentation of this file.
1 /*
2  * VectorIterator.hpp
3  *
4  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
27 #ifndef CDPL_MATH_VECTORITERATOR_HPP
28 #define CDPL_MATH_VECTORITERATOR_HPP
29 
30 #include <functional>
31 
32 #include "CDPL/Math/Expression.hpp"
34 
35 
36 namespace CDPL
37 {
38 
39  namespace Math
40  {
41 
46  template <typename E>
48  {
49 
50  typedef E VectorType;
51  typedef typename E::SizeType SizeType;
52  typedef typename E::Reference Reference;
53 
54  public:
59  VectorElementAccessor(VectorType& e):
60  vec(e) {}
61 
67  Reference operator()(SizeType i) const
68  {
69  return vec.get()(i);
70  }
71 
77  bool operator==(const VectorElementAccessor& accessor) const
78  {
79  return (&vec.get() == &accessor.vec.get());
80  }
81 
82  private:
83  std::reference_wrapper<VectorType> vec;
84  };
85 
90  template <typename E>
91  class VectorElementAccessor<const E>
92  {
93 
94  typedef E VectorType;
95  typedef typename E::SizeType SizeType;
96  typedef typename E::ConstReference Reference;
97 
98  public:
104  vec(accessor.vec) {}
105 
110  VectorElementAccessor(const VectorType& e):
111  vec(e) {}
112 
118  Reference operator()(SizeType i) const
119  {
120  return vec.get()(i);
121  }
122 
128  bool operator==(const VectorElementAccessor& accessor) const
129  {
130  return (&vec.get() == &accessor.vec.get());
131  }
132 
139  {
140  vec = std::reference_wrapper<const VectorType>(accessor.vec);
141  return *this;
142  }
143 
144  private:
145  std::reference_wrapper<const VectorType> vec;
146  };
147 
152  template <typename E>
154  {
155 
159  typedef E VectorType;
160 
164  typedef typename E::SizeType SizeType;
165 
169  typedef typename E::ValueType ValueType;
170 
175 
180 
188  {
189  return IteratorType(AccessorType(e), idx);
190  }
191  };
192 
197  template <typename E>
198  struct VectorIteratorTraits<const E>
199  {
200 
204  typedef E VectorType;
205 
209  typedef typename E::SizeType SizeType;
210 
214  typedef typename E::ValueType ValueType;
215 
220 
225 
233  {
234  return IteratorType(AccessorType(e), idx);
235  }
236  };
237 
244  template <typename E>
246  {
248  }
249 
256  template <typename E>
258  {
259  return VectorIteratorTraits<E>::makeIterator(e(), e().getSize());
260  }
261 
268  template <typename E>
270  {
272  }
273 
280  template <typename E>
282  {
283  return VectorIteratorTraits<const E>::makeIterator(e(), e().getSize());
284  }
285  } // namespace Math
286 } // namespace CDPL
287 
288 #endif // CDPL_MATH_VECTORITERATOR_HPP
Definition of basic expression types.
Definition of class CDPL::Util::IndexedElementIterator.
Specialization of Math::VectorElementAccessor for const vector references (read-only iteration).
Definition: VectorIterator.hpp:92
VectorElementAccessor(const VectorElementAccessor< E > &accessor)
Constructs the accessor from a mutable vector accessor (relaxing it to read-only access).
Definition: VectorIterator.hpp:103
bool operator==(const VectorElementAccessor &accessor) const
Tells whether this accessor references the same vector as accessor.
Definition: VectorIterator.hpp:128
VectorElementAccessor(const VectorType &e)
Constructs the accessor referencing the constant vector e.
Definition: VectorIterator.hpp:110
VectorElementAccessor & operator=(const VectorElementAccessor< E > &accessor)
Rebinds this accessor to the vector referenced by accessor.
Definition: VectorIterator.hpp:138
Reference operator()(SizeType i) const
Returns a const reference to the element at index i of the referenced vector.
Definition: VectorIterator.hpp:118
Access functor used by Math::VectorIteratorTraits to read mutable vector elements via Util::IndexedEl...
Definition: VectorIterator.hpp:48
bool operator==(const VectorElementAccessor &accessor) const
Tells whether this accessor references the same vector as accessor.
Definition: VectorIterator.hpp:77
VectorElementAccessor(VectorType &e)
Constructs the accessor referencing the (mutable) vector e.
Definition: VectorIterator.hpp:59
Reference operator()(SizeType i) const
Returns a mutable reference to the element at index i of the referenced vector.
Definition: VectorIterator.hpp:67
CRTP base class of all vector expression types.
Definition: Expression.hpp:68
STL compatible random access iterator for container elements accessible by index.
Definition: IndexedElementIterator.hpp:125
constexpr unsigned int E
Specifies that the stereocenter has E configuration.
Definition: CIPDescriptor.hpp:96
VectorIteratorTraits< E >::IteratorType vectorBegin(VectorExpression< E > &e)
Returns a mutable iterator pointing to the first element of the vector expression e.
Definition: VectorIterator.hpp:245
VectorIteratorTraits< E >::IteratorType vectorEnd(VectorExpression< E > &e)
Returns a mutable iterator pointing one past the last element of the vector expression e.
Definition: VectorIterator.hpp:257
The namespace of the Chemical Data Processing Library.
E VectorType
The constant vector expression type being iterated.
Definition: VectorIterator.hpp:204
static IteratorType makeIterator(const VectorType &e, SizeType idx)
Creates a constant iterator pointing to the element at index idx of e.
Definition: VectorIterator.hpp:232
E::SizeType SizeType
The size type used by the iterated vector.
Definition: VectorIterator.hpp:209
E::ValueType ValueType
The element value type of the iterated vector.
Definition: VectorIterator.hpp:214
VectorElementAccessor< const E > AccessorType
The element-access functor type used to materialize iterator references (const-qualified).
Definition: VectorIterator.hpp:219
Util::IndexedElementIterator< const ValueType, AccessorType, SizeType > IteratorType
The constructed constant iterator type (a Util::IndexedElementIterator specialization).
Definition: VectorIterator.hpp:224
Traits selecting the element accessor and Util::IndexedElementIterator specialization for mutable ite...
Definition: VectorIterator.hpp:154
E VectorType
The (mutable) vector expression type being iterated.
Definition: VectorIterator.hpp:159
E::ValueType ValueType
The element value type of the iterated vector.
Definition: VectorIterator.hpp:169
Util::IndexedElementIterator< ValueType, AccessorType, SizeType > IteratorType
The constructed iterator type (a Util::IndexedElementIterator specialization).
Definition: VectorIterator.hpp:179
VectorElementAccessor< E > AccessorType
The element-access functor type used to materialize iterator references.
Definition: VectorIterator.hpp:174
static IteratorType makeIterator(VectorType &e, SizeType idx)
Creates an iterator pointing to the element at index idx of e.
Definition: VectorIterator.hpp:187
E::SizeType SizeType
The size type used by the iterated vector.
Definition: VectorIterator.hpp:164