Chemical Data Processing Library C++ API - Version 1.1.1
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
CDPL::Chem::AtomType::Q
const unsigned int Q
A generic type that covers any element except hydrogen and carbon.
Definition: AtomType.hpp:627
CDPL::Math::VectorTemporaryTraits
Definition: TypeTraits.hpp:179
CDPL::Math::vectorSwap
void vectorSwap(V &v, VectorExpression< E > &e)
Definition: VectorAssignment.hpp:72
VectorAssignment.hpp
Implementation of vector assignment routines.
CDPL::Math::QuaternionVectorAdapter::getSize
SizeType getSize() const
Definition: QuaternionAdapter.hpp:122
CDPL::Math::QuaternionVectorAdapter::ConstClosureType
const SelfType ConstClosureType
Definition: QuaternionAdapter.hpp:64
CDPL::Math::QuaternionVectorAdapter::getData
QuaternionClosureType & getData()
Definition: QuaternionAdapter.hpp:132
CDPL::Math::VectorExpression
Definition: Expression.hpp:54
CDPL::Math::QuaternionVectorAdapter::operator/=
std::enable_if< IsScalar< T >::value, QuaternionVectorAdapter >::type & operator/=(const T &t)
Definition: QuaternionAdapter.hpp:177
CDPL::Math::QuaternionVectorAdapter::operator()
ConstReference operator()(SizeType i) const
Definition: QuaternionAdapter.hpp:91
CDPL::Math::QuaternionVectorAdapter::QuaternionClosureType
std::conditional< std::is_const< Q >::value, typename Q::ConstClosureType, typename Q::ClosureType >::type QuaternionClosureType
Definition: QuaternionAdapter.hpp:63
CDPL::Math::QuaternionVectorAdapter::swap
friend void swap(QuaternionVectorAdapter &a1, QuaternionVectorAdapter &a2)
Definition: QuaternionAdapter.hpp:210
CDPL::Math::QuaternionVectorAdapter::ConstReference
Q::ConstReference ConstReference
Definition: QuaternionAdapter.hpp:57
CDPL::Math::QuaternionVectorAdapter::operator*=
std::enable_if< IsScalar< T >::value, QuaternionVectorAdapter >::type & operator*=(const T &t)
Definition: QuaternionAdapter.hpp:170
CDPL::Math::QuaternionVectorAdapter::assign
QuaternionVectorAdapter & assign(const VectorExpression< E > &e)
Definition: QuaternionAdapter.hpp:184
CDPL::Math::QuaternionVectorAdapter::operator[]
Reference operator[](SizeType i)
Definition: QuaternionAdapter.hpp:112
CDPL::Math::VectorExpression< QuaternionVectorAdapter< Q > >::operator()
const ExpressionType & operator()() const
Definition: Expression.hpp:59
CDPL::Math::QuaternionVectorAdapter::operator-=
QuaternionVectorAdapter & operator-=(const VectorExpression< E > &e)
Definition: QuaternionAdapter.hpp:163
CDPL::Math::QuaternionExpression
Definition: Expression.hpp:98
CDPL::Math::QuaternionVectorAdapter::ClosureType
SelfType ClosureType
Definition: QuaternionAdapter.hpp:65
CDPL::Math::QuaternionVectorAdapter::SizeType
std::size_t SizeType
Definition: QuaternionAdapter.hpp:54
CDPL::Base::IndexError
Thrown to indicate that an index is out of range.
Definition: Base/Exceptions.hpp:152
CDPL::Math::QuaternionVectorAdapter
Definition: QuaternionAdapter.hpp:48
CDPL::Math::QuaternionVectorAdapter::getData
const QuaternionClosureType & getData() const
Definition: QuaternionAdapter.hpp:137
CDPL::Math::QuaternionVectorAdapter::QuaternionVectorAdapter
QuaternionVectorAdapter(QuaternionType &q)
Definition: QuaternionAdapter.hpp:67
CDPL::Math::QuaternionVectorAdapter::isEmpty
bool isEmpty() const
Definition: QuaternionAdapter.hpp:127
CDPL::Math::QuaternionVectorAdapter::operator()
Reference operator()(SizeType i)
Definition: QuaternionAdapter.hpp:70
TypeTraits.hpp
Definition of type traits.
CDPL::Math::CVector
Definition: Vector.hpp:1053
CDPL::Math::vec
QuaternionVectorAdapter< E > vec(QuaternionExpression< E > &e)
Definition: QuaternionAdapter.hpp:237
Functional.hpp
Definition of various functors.
CDPL::Math::QuaternionVectorAdapter::QuaternionType
Q QuaternionType
Definition: QuaternionAdapter.hpp:53
CDPL::Math::QuaternionVectorAdapter::DifferenceType
std::ptrdiff_t DifferenceType
Definition: QuaternionAdapter.hpp:55
CDPL::Math::VectorTemporaryTraits< QuaternionVectorAdapter< Q > >::Type
CVector< typename Q::ValueType, 4 > Type
Definition: QuaternionAdapter.hpp:225
CDPL::Chem::AtomType::T
const unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
Exceptions.hpp
Definition of exception classes.
CDPL::Math::QuaternionVectorAdapter::minusAssign
QuaternionVectorAdapter & minusAssign(const VectorExpression< E > &e)
Definition: QuaternionAdapter.hpp:198
CDPL::Math::VectorTemporaryTraits< const QuaternionVectorAdapter< Q > >::Type
CVector< typename Q::ValueType, 4 > Type
Definition: QuaternionAdapter.hpp:232
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Math::QuaternionVectorAdapter::operator=
QuaternionVectorAdapter & operator=(const QuaternionVectorAdapter &a)
Definition: QuaternionAdapter.hpp:142
CDPL::Math::QuaternionVectorAdapter::operator+=
QuaternionVectorAdapter & operator+=(const VectorExpression< E > &e)
Definition: QuaternionAdapter.hpp:156
CDPL::Math::QuaternionVectorAdapter::ValueType
Q::ValueType ValueType
Definition: QuaternionAdapter.hpp:56
CDPL::Math::QuaternionVectorAdapter::plusAssign
QuaternionVectorAdapter & plusAssign(const VectorExpression< E > &e)
Definition: QuaternionAdapter.hpp:191
CDPL::Math::QuaternionVectorAdapter::swap
void swap(QuaternionVectorAdapter &a)
Definition: QuaternionAdapter.hpp:204
CDPL::Math::QuaternionVectorAdapter::Reference
std::conditional< std::is_const< Q >::value, typename Q::ConstReference, typename Q::Reference >::type Reference
Definition: QuaternionAdapter.hpp:60
Expression.hpp
Definition of basic expression types.
CDPL::Math::VectorTemporaryTraits::Type
V::VectorTemporaryType Type
Definition: TypeTraits.hpp:181
CDPL::Math::QuaternionVectorAdapter::operator=
QuaternionVectorAdapter & operator=(const VectorExpression< E > &e)
Definition: QuaternionAdapter.hpp:149
CDPL::Math::QuaternionVectorAdapter::operator[]
ConstReference operator[](SizeType i) const
Definition: QuaternionAdapter.hpp:117