Chemical Data Processing Library C++ API - Version 1.2.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 
42  template <typename E>
44  {
45 
46  typedef E VectorType;
47  typedef typename E::SizeType SizeType;
48  typedef typename E::Reference Reference;
49 
50  public:
51  VectorElementAccessor(VectorType& e):
52  vec(e) {}
53 
54  Reference operator()(SizeType i) const
55  {
56  return vec.get()(i);
57  }
58 
59  bool operator==(const VectorElementAccessor& accessor) const
60  {
61  return (&vec.get() == &accessor.vec.get());
62  }
63 
64  private:
65  std::reference_wrapper<VectorType> vec;
66  };
67 
68  template <typename E>
69  class VectorElementAccessor<const E>
70  {
71 
72  typedef E VectorType;
73  typedef typename E::SizeType SizeType;
74  typedef typename E::ConstReference Reference;
75 
76  public:
78  vec(accessor.vec) {}
79 
80  VectorElementAccessor(const VectorType& e):
81  vec(e) {}
82 
83  Reference operator()(SizeType i) const
84  {
85  return vec.get()(i);
86  }
87 
88  bool operator==(const VectorElementAccessor& accessor) const
89  {
90  return (&vec.get() == &accessor.vec.get());
91  }
92 
94  {
95  vec = std::reference_wrapper<const VectorType>(accessor.vec);
96  return *this;
97  }
98 
99  private:
100  std::reference_wrapper<const VectorType> vec;
101  };
102 
103  template <typename E>
105  {
106 
107  typedef E VectorType;
108  typedef typename E::SizeType SizeType;
109  typedef typename E::ValueType ValueType;
112 
114  {
115  return IteratorType(AccessorType(e), idx);
116  }
117  };
118 
119  template <typename E>
120  struct VectorIteratorTraits<const E>
121  {
122 
123  typedef E VectorType;
124  typedef typename E::SizeType SizeType;
125  typedef typename E::ValueType ValueType;
128 
130  {
131  return IteratorType(AccessorType(e), idx);
132  }
133  };
134 
135  template <typename E>
137  {
139  }
140 
141  template <typename E>
143  {
144  return VectorIteratorTraits<E>::makeIterator(e(), e().getSize());
145  }
146 
147  template <typename E>
149  {
151  }
152 
153  template <typename E>
155  {
156  return VectorIteratorTraits<const E>::makeIterator(e(), e().getSize());
157  }
158  } // namespace Math
159 } // namespace CDPL
160 
161 #endif // CDPL_MATH_VECTORITERATOR_HPP
Definition of basic expression types.
Definition of the class CDPL::Util::IndexedElementIterator.
Definition: VectorIterator.hpp:70
VectorElementAccessor(const VectorElementAccessor< E > &accessor)
Definition: VectorIterator.hpp:77
bool operator==(const VectorElementAccessor &accessor) const
Definition: VectorIterator.hpp:88
VectorElementAccessor(const VectorType &e)
Definition: VectorIterator.hpp:80
VectorElementAccessor & operator=(const VectorElementAccessor< E > &accessor)
Definition: VectorIterator.hpp:93
Reference operator()(SizeType i) const
Definition: VectorIterator.hpp:83
Definition: VectorIterator.hpp:44
bool operator==(const VectorElementAccessor &accessor) const
Definition: VectorIterator.hpp:59
VectorElementAccessor(VectorType &e)
Definition: VectorIterator.hpp:51
Reference operator()(SizeType i) const
Definition: VectorIterator.hpp:54
Definition: Expression.hpp:54
A 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)
Definition: VectorIterator.hpp:136
VectorIteratorTraits< E >::IteratorType vectorEnd(VectorExpression< E > &e)
Definition: VectorIterator.hpp:142
The namespace of the Chemical Data Processing Library.
E VectorType
Definition: VectorIterator.hpp:123
static IteratorType makeIterator(const VectorType &e, SizeType idx)
Definition: VectorIterator.hpp:129
E::SizeType SizeType
Definition: VectorIterator.hpp:124
E::ValueType ValueType
Definition: VectorIterator.hpp:125
VectorElementAccessor< const E > AccessorType
Definition: VectorIterator.hpp:126
Util::IndexedElementIterator< const ValueType, AccessorType, SizeType > IteratorType
Definition: VectorIterator.hpp:127
Definition: VectorIterator.hpp:105
E VectorType
Definition: VectorIterator.hpp:107
E::ValueType ValueType
Definition: VectorIterator.hpp:109
Util::IndexedElementIterator< ValueType, AccessorType, SizeType > IteratorType
Definition: VectorIterator.hpp:111
VectorElementAccessor< E > AccessorType
Definition: VectorIterator.hpp:110
static IteratorType makeIterator(VectorType &e, SizeType idx)
Definition: VectorIterator.hpp:113
E::SizeType SizeType
Definition: VectorIterator.hpp:108