Chemical Data Processing Library C++ API - Version 1.1.1
VectorAdapter.hpp
Go to the documentation of this file.
1 /*
2  * VectorAdapter.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_VECTORADAPTER_HPP
28 #define CDPL_MATH_VECTORADAPTER_HPP
29 
30 #include <type_traits>
31 
32 #include "CDPL/Math/Expression.hpp"
35 #include "CDPL/Math/TypeTraits.hpp"
36 #include "CDPL/Math/Functional.hpp"
37 
38 
39 namespace CDPL
40 {
41 
42  namespace Math
43  {
44 
45  template <typename V>
46  class HomogenousCoordsAdapter : public VectorExpression<HomogenousCoordsAdapter<V> >
47  {
48 
50 
51  public:
52  typedef V VectorType;
53  typedef typename V::SizeType SizeType;
54  typedef typename V::DifferenceType DifferenceType;
55  typedef typename V::ValueType ValueType;
56  typedef typename V::ConstReference ConstReference;
57  typedef typename std::conditional<std::is_const<V>::value,
58  typename V::ConstReference,
59  typename V::Reference>::type Reference;
60  typedef typename std::conditional<std::is_const<V>::value,
61  typename V::ConstClosureType,
62  typename V::ClosureType>::type VectorClosureType;
63  typedef const SelfType ConstClosureType;
65 
67  data(v), extElem(1) {}
68 
70  {
71  if (i == data.getSize())
72  return extElem;
73 
74  return data(i);
75  }
76 
78  {
79  if (i == data.getSize())
80  return extElem;
81 
82  return data(i);
83  }
84 
86  {
87  if (i == data.getSize())
88  return extElem;
89 
90  return data[i];
91  }
92 
94  {
95  if (i == data.getSize())
96  return extElem;
97 
98  return data[i];
99  }
100 
102  {
103  return (data.getSize() + SizeType(1));
104  }
105 
106  bool isEmpty() const
107  {
108  return false;
109  }
110 
112  {
113  return data;
114  }
115 
116  const VectorClosureType& getData() const
117  {
118  return data;
119  }
120 
122  {
123  vectorAssignVector<ScalarAssignment>(*this, typename VectorTemporaryTraits<V>::Type(va));
124  return *this;
125  }
126 
127  template <typename E>
129  {
130  vectorAssignVector<ScalarAssignment>(*this, typename VectorTemporaryTraits<V>::Type(e));
131  return *this;
132  }
133 
134  template <typename E>
136  {
137  vectorAssignVector<ScalarAssignment>(*this, typename VectorTemporaryTraits<V>::Type(*this + e));
138  return *this;
139  }
140 
141  template <typename E>
143  {
144  vectorAssignVector<ScalarAssignment>(*this, typename VectorTemporaryTraits<V>::Type(*this - e));
145  return *this;
146  }
147 
148  template <typename T>
149  typename std::enable_if<IsScalar<T>::value, HomogenousCoordsAdapter>::type& operator*=(const T& t)
150  {
151  vectorAssignScalar<ScalarMultiplicationAssignment>(*this, t);
152  return *this;
153  }
154 
155  template <typename T>
156  typename std::enable_if<IsScalar<T>::value, HomogenousCoordsAdapter>::type& operator/=(const T& t)
157  {
158  vectorAssignScalar<ScalarDivisionAssignment>(*this, t);
159  return *this;
160  }
161 
162  template <typename E>
164  {
165  vectorAssignVector<ScalarAssignment>(*this, e);
166  return *this;
167  }
168 
169  template <typename E>
171  {
172  vectorAssignVector<ScalarAdditionAssignment>(*this, e);
173  return *this;
174  }
175 
176  template <typename E>
178  {
179  vectorAssignVector<ScalarSubtractionAssignment>(*this, e);
180  return *this;
181  }
182 
184  {
185  if (this != &va)
186  vectorSwap(*this, va);
187  }
188 
190  {
191  va1.swap(va2);
192  }
193 
194  private:
195  VectorClosureType data;
196  ValueType extElem;
197  };
198 
199  template <typename V>
200  class VectorQuaternionAdapter : public QuaternionExpression<VectorQuaternionAdapter<V> >
201  {
202 
204 
205  public:
206  typedef V VectorType;
207  typedef typename V::ValueType ValueType;
208  typedef typename V::ConstReference ConstReference;
209  typedef typename std::conditional<std::is_const<V>::value,
210  typename V::ConstReference,
211  typename V::Reference>::type Reference;
212  typedef typename std::conditional<std::is_const<V>::value,
213  typename V::ConstClosureType,
214  typename V::ClosureType>::type VectorClosureType;
215  typedef const SelfType ConstClosureType;
217 
219  data(v) {}
220 
222  {
223  return data(0);
224  }
225 
227  {
228  return data(1);
229  }
230 
232  {
233  return data(2);
234  }
235 
237  {
238  return data(3);
239  }
240 
242  {
243  return data(0);
244  }
245 
247  {
248  return data(1);
249  }
250 
252  {
253  return data(2);
254  }
255 
257  {
258  return data(3);
259  }
260 
262  {
263  return data;
264  }
265 
266  const VectorClosureType& getData() const
267  {
268  return data;
269  }
270 
272  {
273  quaternionAssignQuaternion<ScalarAssignment>(*this, typename QuaternionTemporaryTraits<SelfType>::Type(a));
274  return *this;
275  }
276 
277  template <typename E>
279  {
280  quaternionAssignQuaternion<ScalarAssignment>(*this, typename QuaternionTemporaryTraits<SelfType>::Type(e));
281  return *this;
282  }
283 
284  template <typename T>
285  typename std::enable_if<IsScalar<T>::value, VectorQuaternionAdapter>::type&
286  operator=(const T& t)
287  {
288  data(0) = t;
289  data(1) = ValueType();
290  data(2) = ValueType();
291  data(3) = ValueType();
292  return *this;
293  }
294 
295  template <typename E>
297  {
298  quaternionAssignQuaternion<ScalarAssignment>(*this, typename QuaternionTemporaryTraits<SelfType>::Type(*this + e));
299  return *this;
300  }
301 
302  template <typename T>
303  typename std::enable_if<IsScalar<T>::value, VectorQuaternionAdapter>::type&
304  operator+=(const T& t)
305  {
306  data(0) += t;
307  return *this;
308  }
309 
310  template <typename E>
312  {
313  quaternionAssignQuaternion<ScalarAssignment>(*this, typename QuaternionTemporaryTraits<SelfType>::Type(*this - e));
314  return *this;
315  }
316 
317  template <typename T>
318  typename std::enable_if<IsScalar<T>::value, VectorQuaternionAdapter>::type&
319  operator-=(const T& t)
320  {
321  data(0) -= t;
322  return *this;
323  }
324 
325  template <typename E>
327  {
328  quaternionAssignQuaternion<ScalarAssignment>(*this, typename QuaternionTemporaryTraits<SelfType>::Type(*this * e));
329  return *this;
330  }
331 
332  template <typename T>
333  typename std::enable_if<IsScalar<T>::value, VectorQuaternionAdapter>::type&
334  operator*=(const T& t)
335  {
336  quaternionAssignScalar<ScalarMultiplicationAssignment>(*this, t);
337  return *this;
338  }
339 
340  template <typename E>
342  {
343  quaternionAssignQuaternion<ScalarAssignment>(*this, typename QuaternionTemporaryTraits<SelfType>::Type(*this / e));
344  return *this;
345  }
346 
347  template <typename T>
348  typename std::enable_if<IsScalar<T>::value, VectorQuaternionAdapter>::type&
349  operator/=(const T& t)
350  {
351  quaternionAssignScalar<ScalarDivisionAssignment>(*this, t);
352  return *this;
353  }
354 
355  template <typename E>
357  {
358  quaternionAssignQuaternion<ScalarAssignment>(*this, e);
359  return *this;
360  }
361 
362  template <typename E>
364  {
365  quaternionAssignQuaternion<ScalarAdditionAssignment>(*this, e);
366  return *this;
367  }
368 
369  template <typename E>
371  {
372  quaternionAssignQuaternion<ScalarSubtractionAssignment>(*this, e);
373  return *this;
374  }
375 
377  {
378  if (this != &a)
379  quaternionSwap(*this, a);
380  }
381 
383  {
384  a1.swap(a2);
385  }
386 
387  void set(const ValueType& c1 = ValueType(), const ValueType& c2 = ValueType(),
388  const ValueType& c3 = ValueType(), const ValueType& c4 = ValueType())
389  {
390  data(0) = c1;
391  data(1) = c2;
392  data(2) = c3;
393  data(3) = c4;
394  }
395 
396  private:
397  VectorClosureType data;
398  };
399 
400  template <typename T>
401  class Quaternion;
402  template <typename V>
404  {
405 
407  };
408 
409  template <typename V>
411  {
412 
414  };
415 
416  template <typename V>
418  {};
419 
420  template <typename V>
422  {};
423 
424  template <typename E>
427  {
428  return VectorQuaternionAdapter<E>(e());
429  }
430 
431  template <typename E>
432  VectorQuaternionAdapter<const E>
434  {
436  }
437 
438  template <typename E>
439  HomogenousCoordsAdapter<E>
441  {
442  return HomogenousCoordsAdapter<E>(e());
443  }
444 
445  template <typename E>
446  HomogenousCoordsAdapter<const E>
448  {
450  }
451  } // namespace Math
452 } // namespace CDPL
453 
454 #endif // CDPL_MATH_VECTORADAPTER_HPP
CDPL::Math::VectorQuaternionAdapter::swap
void swap(VectorQuaternionAdapter &a)
Definition: VectorAdapter.hpp:376
CDPL::Math::QuaternionTemporaryTraits< VectorQuaternionAdapter< V > >::Type
Quaternion< typename V::ValueType > Type
Definition: VectorAdapter.hpp:406
CDPL::Math::HomogenousCoordsAdapter::operator+=
HomogenousCoordsAdapter & operator+=(const VectorExpression< E > &e)
Definition: VectorAdapter.hpp:135
CDPL::Math::HomogenousCoordsAdapter::minusAssign
HomogenousCoordsAdapter & minusAssign(const VectorExpression< E > &e)
Definition: VectorAdapter.hpp:177
CDPL::Math::VectorTemporaryTraits
Definition: TypeTraits.hpp:179
CDPL::Math::VectorQuaternionAdapter::ConstClosureType
const SelfType ConstClosureType
Definition: VectorAdapter.hpp:215
CDPL::Math::vectorSwap
void vectorSwap(V &v, VectorExpression< E > &e)
Definition: VectorAssignment.hpp:72
VectorAssignment.hpp
Implementation of vector assignment routines.
CDPL::Math::HomogenousCoordsAdapter::operator=
HomogenousCoordsAdapter & operator=(const HomogenousCoordsAdapter &va)
Definition: VectorAdapter.hpp:121
CDPL::Math::VectorQuaternionAdapter::operator*=
std::enable_if< IsScalar< T >::value, VectorQuaternionAdapter >::type & operator*=(const T &t)
Definition: VectorAdapter.hpp:334
CDPL::Math::HomogenousCoordsAdapter::getData
VectorClosureType & getData()
Definition: VectorAdapter.hpp:111
CDPL::Math::HomogenousCoordsAdapter::operator()
Reference operator()(SizeType i)
Definition: VectorAdapter.hpp:69
CDPL::Math::QuaternionTemporaryTraits::Type
Q::QuaternionTemporaryType Type
Definition: TypeTraits.hpp:195
CDPL::Math::VectorQuaternionAdapter::operator=
std::enable_if< IsScalar< T >::value, VectorQuaternionAdapter >::type & operator=(const T &t)
Definition: VectorAdapter.hpp:286
CDPL::Math::VectorQuaternionAdapter::getC3
Reference getC3()
Definition: VectorAdapter.hpp:231
CDPL::Math::VectorExpression
Definition: Expression.hpp:54
CDPL::Math::VectorQuaternionAdapter::Reference
std::conditional< std::is_const< V >::value, typename V::ConstReference, typename V::Reference >::type Reference
Definition: VectorAdapter.hpp:211
CDPL::Math::VectorQuaternionAdapter::ClosureType
SelfType ClosureType
Definition: VectorAdapter.hpp:216
CDPL::Math::HomogenousCoordsAdapter
Definition: VectorAdapter.hpp:47
CDPL::Math::HomogenousCoordsAdapter::swap
void swap(HomogenousCoordsAdapter &va)
Definition: VectorAdapter.hpp:183
CDPL::Math::quat
std::enable_if< IsScalar< T >::value, RealQuaternion< T > >::type quat(const T &t)
Definition: Quaternion.hpp:662
CDPL::Math::VectorQuaternionAdapter
Definition: VectorAdapter.hpp:201
CDPL::Math::VectorQuaternionAdapter::VectorType
V VectorType
Definition: VectorAdapter.hpp:206
CDPL::Math::HomogenousCoordsAdapter::swap
friend void swap(HomogenousCoordsAdapter &va1, HomogenousCoordsAdapter &va2)
Definition: VectorAdapter.hpp:189
CDPL::Math::Quaternion
Definition: Quaternion.hpp:239
CDPL::Math::HomogenousCoordsAdapter::getData
const VectorClosureType & getData() const
Definition: VectorAdapter.hpp:116
CDPL::Math::VectorQuaternionAdapter::operator+=
VectorQuaternionAdapter & operator+=(const QuaternionExpression< E > &e)
Definition: VectorAdapter.hpp:296
CDPL::Math::HomogenousCoordsAdapter::ConstReference
V::ConstReference ConstReference
Definition: VectorAdapter.hpp:56
CDPL::Math::HomogenousCoordsAdapter::operator=
HomogenousCoordsAdapter & operator=(const VectorExpression< E > &e)
Definition: VectorAdapter.hpp:128
CDPL::Math::VectorQuaternionAdapter::assign
VectorQuaternionAdapter & assign(const QuaternionExpression< E > &e)
Definition: VectorAdapter.hpp:356
CDPL::Math::VectorQuaternionAdapter::ConstReference
V::ConstReference ConstReference
Definition: VectorAdapter.hpp:208
CDPL::Math::HomogenousCoordsAdapter::plusAssign
HomogenousCoordsAdapter & plusAssign(const VectorExpression< E > &e)
Definition: VectorAdapter.hpp:170
CDPL::Math::VectorQuaternionAdapter::operator+=
std::enable_if< IsScalar< T >::value, VectorQuaternionAdapter >::type & operator+=(const T &t)
Definition: VectorAdapter.hpp:304
CDPL::Math::HomogenousCoordsAdapter::DifferenceType
V::DifferenceType DifferenceType
Definition: VectorAdapter.hpp:54
CDPL::Math::QuaternionExpression
Definition: Expression.hpp:98
CDPL::Math::VectorQuaternionAdapter::getC2
ConstReference getC2() const
Definition: VectorAdapter.hpp:246
CDPL::Math::VectorQuaternionAdapter::plusAssign
VectorQuaternionAdapter & plusAssign(const QuaternionExpression< E > &e)
Definition: VectorAdapter.hpp:363
CDPL::Math::VectorQuaternionAdapter::operator-=
VectorQuaternionAdapter & operator-=(const QuaternionExpression< E > &e)
Definition: VectorAdapter.hpp:311
CDPL::Math::HomogenousCoordsAdapter::operator/=
std::enable_if< IsScalar< T >::value, HomogenousCoordsAdapter >::type & operator/=(const T &t)
Definition: VectorAdapter.hpp:156
CDPL::Math::HomogenousCoordsAdapter::getSize
SizeType getSize() const
Definition: VectorAdapter.hpp:101
CDPL::Math::HomogenousCoordsAdapter::operator*=
std::enable_if< IsScalar< T >::value, HomogenousCoordsAdapter >::type & operator*=(const T &t)
Definition: VectorAdapter.hpp:149
CDPL::Math::HomogenousCoordsAdapter::ClosureType
SelfType ClosureType
Definition: VectorAdapter.hpp:64
CDPL::Math::HomogenousCoordsAdapter::SizeType
V::SizeType SizeType
Definition: VectorAdapter.hpp:53
CDPL::Math::HomogenousCoordsAdapter::Reference
std::conditional< std::is_const< V >::value, typename V::ConstReference, typename V::Reference >::type Reference
Definition: VectorAdapter.hpp:59
CDPL::Math::VectorQuaternionAdapter::getData
const VectorClosureType & getData() const
Definition: VectorAdapter.hpp:266
TypeTraits.hpp
Definition of type traits.
CDPL::Math::VectorQuaternionAdapter::getC3
ConstReference getC3() const
Definition: VectorAdapter.hpp:251
CDPL::Math::homog
HomogenousCoordsAdapter< E > homog(VectorExpression< E > &e)
Definition: VectorAdapter.hpp:440
CDPL::Math::HomogenousCoordsAdapter::operator()
ConstReference operator()(SizeType i) const
Definition: VectorAdapter.hpp:77
V
CDPL::Math::VectorQuaternionAdapter::getData
VectorClosureType & getData()
Definition: VectorAdapter.hpp:261
CDPL::Math::quaternionSwap
void quaternionSwap(Q &q, QuaternionExpression< E > &e)
Definition: QuaternionAssignment.hpp:65
CDPL::Math::VectorQuaternionAdapter::operator/=
std::enable_if< IsScalar< T >::value, VectorQuaternionAdapter >::type & operator/=(const T &t)
Definition: VectorAdapter.hpp:349
Functional.hpp
Definition of various functors.
CDPL::Math::QuaternionTemporaryTraits
Definition: TypeTraits.hpp:193
CDPL::Math::VectorQuaternionAdapter::getC4
Reference getC4()
Definition: VectorAdapter.hpp:236
CDPL::Math::VectorQuaternionAdapter::operator=
VectorQuaternionAdapter & operator=(const VectorQuaternionAdapter &a)
Definition: VectorAdapter.hpp:271
QuaternionAssignment.hpp
Implementation of quaternion assignment routines.
CDPL::Chem::AtomType::T
const unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
CDPL::Math::VectorQuaternionAdapter::VectorQuaternionAdapter
VectorQuaternionAdapter(VectorType &v)
Definition: VectorAdapter.hpp:218
CDPL::Math::VectorQuaternionAdapter::getC1
Reference getC1()
Definition: VectorAdapter.hpp:221
CDPL::Math::HomogenousCoordsAdapter::ConstClosureType
const SelfType ConstClosureType
Definition: VectorAdapter.hpp:63
CDPL::Math::HomogenousCoordsAdapter::ValueType
V::ValueType ValueType
Definition: VectorAdapter.hpp:55
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Math::VectorQuaternionAdapter::operator=
VectorQuaternionAdapter & operator=(const QuaternionExpression< E > &e)
Definition: VectorAdapter.hpp:278
CDPL::Math::VectorQuaternionAdapter::set
void set(const ValueType &c1=ValueType(), const ValueType &c2=ValueType(), const ValueType &c3=ValueType(), const ValueType &c4=ValueType())
Definition: VectorAdapter.hpp:387
CDPL::Math::HomogenousCoordsAdapter::isEmpty
bool isEmpty() const
Definition: VectorAdapter.hpp:106
CDPL::Math::VectorQuaternionAdapter::ValueType
V::ValueType ValueType
Definition: VectorAdapter.hpp:207
CDPL::Math::VectorQuaternionAdapter::operator*=
VectorQuaternionAdapter & operator*=(const QuaternionExpression< E > &e)
Definition: VectorAdapter.hpp:326
CDPL::Math::VectorQuaternionAdapter::swap
friend void swap(VectorQuaternionAdapter &a1, VectorQuaternionAdapter &a2)
Definition: VectorAdapter.hpp:382
CDPL::Math::HomogenousCoordsAdapter::operator[]
Reference operator[](SizeType i)
Definition: VectorAdapter.hpp:85
CDPL::Math::HomogenousCoordsAdapter::VectorClosureType
std::conditional< std::is_const< V >::value, typename V::ConstClosureType, typename V::ClosureType >::type VectorClosureType
Definition: VectorAdapter.hpp:62
CDPL::Math::HomogenousCoordsAdapter::operator[]
ConstReference operator[](SizeType i) const
Definition: VectorAdapter.hpp:93
CDPL::Math::VectorQuaternionAdapter::getC2
Reference getC2()
Definition: VectorAdapter.hpp:226
CDPL::Math::VectorQuaternionAdapter::minusAssign
VectorQuaternionAdapter & minusAssign(const QuaternionExpression< E > &e)
Definition: VectorAdapter.hpp:370
CDPL::Math::HomogenousCoordsAdapter::assign
HomogenousCoordsAdapter & assign(const VectorExpression< E > &e)
Definition: VectorAdapter.hpp:163
CDPL::Math::QuaternionTemporaryTraits< const VectorQuaternionAdapter< V > >::Type
Quaternion< typename V::ValueType > Type
Definition: VectorAdapter.hpp:413
Expression.hpp
Definition of basic expression types.
CDPL::Math::VectorQuaternionAdapter::VectorClosureType
std::conditional< std::is_const< V >::value, typename V::ConstClosureType, typename V::ClosureType >::type VectorClosureType
Definition: VectorAdapter.hpp:214
CDPL::Math::VectorQuaternionAdapter::getC4
ConstReference getC4() const
Definition: VectorAdapter.hpp:256
CDPL::Math::VectorQuaternionAdapter::getC1
ConstReference getC1() const
Definition: VectorAdapter.hpp:241
CDPL::Math::HomogenousCoordsAdapter::VectorType
V VectorType
Definition: VectorAdapter.hpp:52
CDPL::Math::VectorQuaternionAdapter::operator/=
VectorQuaternionAdapter & operator/=(const QuaternionExpression< E > &e)
Definition: VectorAdapter.hpp:341
CDPL::Math::VectorTemporaryTraits::Type
V::VectorTemporaryType Type
Definition: TypeTraits.hpp:181
CDPL::Math::HomogenousCoordsAdapter::operator-=
HomogenousCoordsAdapter & operator-=(const VectorExpression< E > &e)
Definition: VectorAdapter.hpp:142
CDPL::Math::HomogenousCoordsAdapter::HomogenousCoordsAdapter
HomogenousCoordsAdapter(VectorType &v)
Definition: VectorAdapter.hpp:66
CDPL::Math::VectorQuaternionAdapter::operator-=
std::enable_if< IsScalar< T >::value, VectorQuaternionAdapter >::type & operator-=(const T &t)
Definition: VectorAdapter.hpp:319