Chemical Data Processing Library C++ API - Version 1.1.1
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
CDPL::Chem::CIPDescriptor::E
const unsigned int E
Specifies that the stereocenter has E configuration.
Definition: CIPDescriptor.hpp:96
CDPL::Math::VectorElementAccessor::operator==
bool operator==(const VectorElementAccessor &accessor) const
Definition: VectorIterator.hpp:59
IndexedElementIterator.hpp
Definition of the class CDPL::Util::IndexedElementIterator.
CDPL::Math::VectorExpression
Definition: Expression.hpp:54
CDPL::Math::VectorElementAccessor::operator()
Reference operator()(SizeType i) const
Definition: VectorIterator.hpp:54
CDPL::Math::VectorIteratorTraits::SizeType
E::SizeType SizeType
Definition: VectorIterator.hpp:108
CDPL::Math::VectorElementAccessor< const E >::operator=
VectorElementAccessor & operator=(const VectorElementAccessor< E > &accessor)
Definition: VectorIterator.hpp:93
CDPL::Math::VectorElementAccessor< const E >::VectorElementAccessor
VectorElementAccessor(const VectorElementAccessor< E > &accessor)
Definition: VectorIterator.hpp:77
CDPL::Math::VectorIteratorTraits
Definition: VectorIterator.hpp:105
CDPL::Util::IndexedElementIterator
A STL compatible random access iterator for container elements accessible by index.
Definition: IndexedElementIterator.hpp:125
CDPL::Math::VectorElementAccessor< const E >::VectorElementAccessor
VectorElementAccessor(const VectorType &e)
Definition: VectorIterator.hpp:80
CDPL::Math::VectorElementAccessor::VectorElementAccessor
VectorElementAccessor(VectorType &e)
Definition: VectorIterator.hpp:51
CDPL::Math::VectorIteratorTraits< const E >::SizeType
E::SizeType SizeType
Definition: VectorIterator.hpp:124
CDPL::Math::VectorElementAccessor
Definition: VectorIterator.hpp:44
CDPL::Math::VectorIteratorTraits< const E >::ValueType
E::ValueType ValueType
Definition: VectorIterator.hpp:125
CDPL::Math::VectorElementAccessor< const E >::operator==
bool operator==(const VectorElementAccessor &accessor) const
Definition: VectorIterator.hpp:88
CDPL::Math::VectorIteratorTraits::IteratorType
Util::IndexedElementIterator< ValueType, AccessorType, SizeType > IteratorType
Definition: VectorIterator.hpp:111
CDPL::Math::VectorIteratorTraits::ValueType
E::ValueType ValueType
Definition: VectorIterator.hpp:109
CDPL::Math::VectorElementAccessor< const E >::operator()
Reference operator()(SizeType i) const
Definition: VectorIterator.hpp:83
CDPL::Math::VectorIteratorTraits::makeIterator
static IteratorType makeIterator(VectorType &e, SizeType idx)
Definition: VectorIterator.hpp:113
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Math::VectorElementAccessor< const E >
Definition: VectorIterator.hpp:70
CDPL::Math::VectorIteratorTraits< const E >::IteratorType
Util::IndexedElementIterator< const ValueType, AccessorType, SizeType > IteratorType
Definition: VectorIterator.hpp:127
CDPL::Math::VectorIteratorTraits< const E >::makeIterator
static IteratorType makeIterator(const VectorType &e, SizeType idx)
Definition: VectorIterator.hpp:129
CDPL::Math::VectorIteratorTraits::VectorType
E VectorType
Definition: VectorIterator.hpp:107
CDPL::Math::vectorBegin
VectorIteratorTraits< E >::IteratorType vectorBegin(VectorExpression< E > &e)
Definition: VectorIterator.hpp:136
CDPL::Math::VectorIteratorTraits< const E >::VectorType
E VectorType
Definition: VectorIterator.hpp:123
Expression.hpp
Definition of basic expression types.
CDPL::Math::VectorIteratorTraits::AccessorType
VectorElementAccessor< E > AccessorType
Definition: VectorIterator.hpp:110
CDPL::Math::vectorEnd
VectorIteratorTraits< E >::IteratorType vectorEnd(VectorExpression< E > &e)
Definition: VectorIterator.hpp:142
CDPL::Math::VectorIteratorTraits< const E >::AccessorType
VectorElementAccessor< const E > AccessorType
Definition: VectorIterator.hpp:126