Chemical Data Processing Library C++ API - Version 1.2.0
QuaternionAdapter.hpp
Go to the documentation of this file.
1 /*
2  * QuaternionAdapter.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_QUATERNIONADAPTER_HPP
28 #define CDPL_MATH_QUATERNIONADAPTER_HPP
29 
30 #include <cstddef>
31 #include <type_traits>
32 
33 #include "CDPL/Math/Expression.hpp"
35 #include "CDPL/Math/TypeTraits.hpp"
36 #include "CDPL/Math/Functional.hpp"
37 #include "CDPL/Base/Exceptions.hpp"
38 
39 
40 namespace CDPL
41 {
42 
43  namespace Math
44  {
45 
46  template <typename Q>
47  class QuaternionVectorAdapter : public VectorExpression<QuaternionVectorAdapter<Q> >
48  {
49 
51 
52  public:
53  typedef Q QuaternionType;
54  typedef typename std::size_t SizeType;
55  typedef typename std::ptrdiff_t DifferenceType;
56  typedef typename Q::ValueType ValueType;
57  typedef typename Q::ConstReference ConstReference;
58  typedef typename std::conditional<std::is_const<Q>::value,
59  typename Q::ConstReference,
60  typename Q::Reference>::type Reference;
61  typedef typename std::conditional<std::is_const<Q>::value,
62  typename Q::ConstClosureType,
63  typename Q::ClosureType>::type QuaternionClosureType;
64  typedef const SelfType ConstClosureType;
66 
68  data(q) {}
69 
71  {
72  switch (i) {
73 
74  case 0:
75  return data.getC1();
76 
77  case 1:
78  return data.getC2();
79 
80  case 2:
81  return data.getC3();
82 
83  case 3:
84  return data.getC4();
85 
86  default:
87  throw Base::IndexError("QuaternionVectorAdapter: Index out of range");
88  }
89  }
90 
92  {
93  switch (i) {
94 
95  case 0:
96  return data.getC1();
97 
98  case 1:
99  return data.getC2();
100 
101  case 2:
102  return data.getC3();
103 
104  case 3:
105  return data.getC4();
106 
107  default:
108  throw Base::IndexError("QuaternionVectorAdapter: Index out of range");
109  }
110  }
111 
113  {
114  return this->operator()(i);
115  }
116 
118  {
119  return this->operator()(i);
120  }
121 
123  {
124  return 4;
125  }
126 
127  bool isEmpty() const
128  {
129  return false;
130  }
131 
133  {
134  return data;
135  }
136 
138  {
139  return data;
140  }
141 
143  {
144  vectorAssignVector<ScalarAssignment>(*this, typename VectorTemporaryTraits<SelfType>::Type(a));
145  return *this;
146  }
147 
148  template <typename E>
150  {
151  vectorAssignVector<ScalarAssignment>(*this, typename VectorTemporaryTraits<SelfType>::Type(e));
152  return *this;
153  }
154 
155  template <typename E>
157  {
158  vectorAssignVector<ScalarAssignment>(*this, typename VectorTemporaryTraits<SelfType>::Type(*this + e));
159  return *this;
160  }
161 
162  template <typename E>
164  {
165  vectorAssignVector<ScalarAssignment>(*this, typename VectorTemporaryTraits<SelfType>::Type(*this - e));
166  return *this;
167  }
168 
169  template <typename T>
170  typename std::enable_if<IsScalar<T>::value, QuaternionVectorAdapter>::type& operator*=(const T& t)
171  {
172  vectorAssignScalar<ScalarMultiplicationAssignment>(*this, t);
173  return *this;
174  }
175 
176  template <typename T>
177  typename std::enable_if<IsScalar<T>::value, QuaternionVectorAdapter>::type& operator/=(const T& t)
178  {
179  vectorAssignScalar<ScalarDivisionAssignment>(*this, t);
180  return *this;
181  }
182 
183  template <typename E>
185  {
186  vectorAssignVector<ScalarAssignment>(*this, e);
187  return *this;
188  }
189 
190  template <typename E>
192  {
193  vectorAssignVector<ScalarAdditionAssignment>(*this, e);
194  return *this;
195  }
196 
197  template <typename E>
199  {
200  vectorAssignVector<ScalarSubtractionAssignment>(*this, e);
201  return *this;
202  }
203 
205  {
206  if (this != &a)
207  vectorSwap(*this, a);
208  }
209 
211  {
212  a1.swap(a2);
213  }
214 
215  private:
217  };
218 
219  template <typename T, std::size_t N>
220  class CVector;
221  template <typename Q>
223  {
224 
226  };
227 
228  template <typename Q>
230  {
231 
233  };
234 
235  template <typename E>
238  {
239  return QuaternionVectorAdapter<E>(e());
240  }
241 
242  template <typename E>
243  QuaternionVectorAdapter<const E>
245  {
247  }
248  } // namespace Math
249 } // namespace CDPL
250 
251 #endif // CDPL_MATH_QUATERNIONADAPTER_HPP
Definition of exception classes.
Definition of basic expression types.
Definition of various functors.
Definition of type traits.
Implementation of vector assignment routines.
Thrown to indicate that an index is out of range.
Definition: Base/Exceptions.hpp:152
Definition: Vector.hpp:1053
Definition: Expression.hpp:98
Definition: QuaternionAdapter.hpp:48
QuaternionVectorAdapter(QuaternionType &q)
Definition: QuaternionAdapter.hpp:67
const SelfType ConstClosureType
Definition: QuaternionAdapter.hpp:64
QuaternionVectorAdapter & assign(const VectorExpression< E > &e)
Definition: QuaternionAdapter.hpp:184
QuaternionClosureType & getData()
Definition: QuaternionAdapter.hpp:132
SizeType getSize() const
Definition: QuaternionAdapter.hpp:122
Q::ConstReference ConstReference
Definition: QuaternionAdapter.hpp:57
friend void swap(QuaternionVectorAdapter &a1, QuaternionVectorAdapter &a2)
Definition: QuaternionAdapter.hpp:210
Reference operator()(SizeType i)
Definition: QuaternionAdapter.hpp:70
ConstReference operator[](SizeType i) const
Definition: QuaternionAdapter.hpp:117
QuaternionVectorAdapter & minusAssign(const VectorExpression< E > &e)
Definition: QuaternionAdapter.hpp:198
std::conditional< std::is_const< Q >::value, typename Q::ConstClosureType, typename Q::ClosureType >::type QuaternionClosureType
Definition: QuaternionAdapter.hpp:63
QuaternionVectorAdapter & operator+=(const VectorExpression< E > &e)
Definition: QuaternionAdapter.hpp:156
bool isEmpty() const
Definition: QuaternionAdapter.hpp:127
std::enable_if< IsScalar< T >::value, QuaternionVectorAdapter >::type & operator/=(const T &t)
Definition: QuaternionAdapter.hpp:177
std::conditional< std::is_const< Q >::value, typename Q::ConstReference, typename Q::Reference >::type Reference
Definition: QuaternionAdapter.hpp:60
QuaternionVectorAdapter & operator-=(const VectorExpression< E > &e)
Definition: QuaternionAdapter.hpp:163
std::size_t SizeType
Definition: QuaternionAdapter.hpp:54
void swap(QuaternionVectorAdapter &a)
Definition: QuaternionAdapter.hpp:204
QuaternionVectorAdapter & plusAssign(const VectorExpression< E > &e)
Definition: QuaternionAdapter.hpp:191
SelfType ClosureType
Definition: QuaternionAdapter.hpp:65
std::ptrdiff_t DifferenceType
Definition: QuaternionAdapter.hpp:55
Reference operator[](SizeType i)
Definition: QuaternionAdapter.hpp:112
ConstReference operator()(SizeType i) const
Definition: QuaternionAdapter.hpp:91
QuaternionVectorAdapter & operator=(const QuaternionVectorAdapter &a)
Definition: QuaternionAdapter.hpp:142
Q::ValueType ValueType
Definition: QuaternionAdapter.hpp:56
const QuaternionClosureType & getData() const
Definition: QuaternionAdapter.hpp:137
std::enable_if< IsScalar< T >::value, QuaternionVectorAdapter >::type & operator*=(const T &t)
Definition: QuaternionAdapter.hpp:170
Q QuaternionType
Definition: QuaternionAdapter.hpp:53
QuaternionVectorAdapter & operator=(const VectorExpression< E > &e)
Definition: QuaternionAdapter.hpp:149
Definition: Expression.hpp:54
const ExpressionType & operator()() const
Definition: Expression.hpp:59
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
constexpr unsigned int Q
A generic type that covers any element except hydrogen and carbon.
Definition: AtomType.hpp:647
QuaternionVectorAdapter< E > vec(QuaternionExpression< E > &e)
Definition: QuaternionAdapter.hpp:237
void vectorSwap(V &v, VectorExpression< E > &e)
Definition: VectorAssignment.hpp:72
The namespace of the Chemical Data Processing Library.
CVector< typename Q::ValueType, 4 > Type
Definition: QuaternionAdapter.hpp:225
CVector< typename Q::ValueType, 4 > Type
Definition: QuaternionAdapter.hpp:232
Definition: TypeTraits.hpp:179
V::VectorTemporaryType Type
Definition: TypeTraits.hpp:181