27 #ifndef CDPL_MATH_VECTORADAPTER_HPP
28 #define CDPL_MATH_VECTORADAPTER_HPP
30 #include <type_traits>
67 typedef typename std::conditional<std::is_const<V>::value,
68 typename V::ConstReference,
71 typedef typename std::conditional<std::is_const<V>::value,
72 typename V::ConstClosureType,
84 data(v), extElem(1) {}
97 if (i == data.getSize())
110 if (i == data.getSize())
123 if (i == data.getSize())
136 if (i == data.getSize())
148 return (data.getSize() +
SizeType(1));
195 template <
typename E>
208 template <
typename E>
221 template <
typename E>
234 template <
typename T>
237 vectorAssignScalar<ScalarMultiplicationAssignment>(*
this, t);
247 template <
typename T>
250 vectorAssignScalar<ScalarDivisionAssignment>(*
this, t);
260 template <
typename E>
263 vectorAssignVector<ScalarAssignment>(*
this, e);
273 template <
typename E>
276 vectorAssignVector<ScalarAdditionAssignment>(*
this, e);
286 template <
typename E>
289 vectorAssignVector<ScalarSubtractionAssignment>(*
this, e);
322 template <
typename V>
336 typedef typename std::conditional<std::is_const<V>::value,
337 typename V::ConstReference,
340 typedef typename std::conditional<std::is_const<V>::value,
341 typename V::ConstClosureType,
462 template <
typename E>
475 template <
typename T>
492 template <
typename E>
505 template <
typename T>
519 template <
typename E>
532 template <
typename T>
546 template <
typename E>
559 template <
typename T>
563 quaternionAssignScalar<ScalarMultiplicationAssignment>(*
this, t);
573 template <
typename E>
586 template <
typename T>
590 quaternionAssignScalar<ScalarDivisionAssignment>(*
this, t);
601 template <
typename E>
604 quaternionAssignQuaternion<ScalarAssignment>(*
this, e);
614 template <
typename E>
617 quaternionAssignQuaternion<ScalarAdditionAssignment>(*
this, e);
627 template <
typename E>
630 quaternionAssignQuaternion<ScalarSubtractionAssignment>(*
this, e);
674 template <
typename T>
681 template <
typename V>
693 template <
typename V>
705 template <
typename V>
713 template <
typename V>
723 template <
typename E>
736 template <
typename E>
737 VectorQuaternionAdapter<const E>
749 template <
typename E>
750 HomogenousCoordsAdapter<E>
762 template <
typename E>
763 HomogenousCoordsAdapter<const E>
Definition of basic expression types.
Definition of various functors.
Implementation of quaternion assignment routines.
Definition of type traits.
Implementation of vector assignment routines.
Vector expression that exposes a vector V as its homogeneous-coordinate extension by appending an imp...
Definition: VectorAdapter.hpp:51
const SelfType ConstClosureType
Constant closure type used when this adapter appears inside another expression.
Definition: VectorAdapter.hpp:75
std::enable_if< IsScalar< T >::value, HomogenousCoordsAdapter >::type & operator*=(const T &t)
Multiplies every element of this view by the scalar t.
Definition: VectorAdapter.hpp:235
ConstReference operator[](SizeType i) const
Returns a const reference to the element at index i of the view (alias for operator()).
Definition: VectorAdapter.hpp:134
HomogenousCoordsAdapter & minusAssign(const VectorExpression< E > &e)
Subtracts the vector expression e from this view without intermediate temporary.
Definition: VectorAdapter.hpp:287
V VectorType
The wrapped vector type.
Definition: VectorAdapter.hpp:57
SelfType ClosureType
Closure type used when this adapter appears inside another expression.
Definition: VectorAdapter.hpp:77
std::conditional< std::is_const< V >::value, typename V::ConstReference, typename V::Reference >::type Reference
Mutable reference type (degrades to ConstReference when the wrapped vector is const).
Definition: VectorAdapter.hpp:69
Reference operator()(SizeType i)
Returns a mutable reference to the element at index i of the view.
Definition: VectorAdapter.hpp:95
Reference operator[](SizeType i)
Returns a mutable reference to the element at index i of the view (alias for operator()).
Definition: VectorAdapter.hpp:121
const VectorClosureType & getData() const
Returns a const reference to the wrapped vector (via its stored closure).
Definition: VectorAdapter.hpp:173
HomogenousCoordsAdapter & operator=(const HomogenousCoordsAdapter &va)
Copies the elements of va into this view (writing through to the wrapped vector and to the extension ...
Definition: VectorAdapter.hpp:183
bool isEmpty() const
Tells whether the view is empty (always false; the view always has at least the extension element).
Definition: VectorAdapter.hpp:155
std::conditional< std::is_const< V >::value, typename V::ConstClosureType, typename V::ClosureType >::type VectorClosureType
Closure type used to store the wrapped vector internally (mutable or const flavor).
Definition: VectorAdapter.hpp:73
HomogenousCoordsAdapter & operator+=(const VectorExpression< E > &e)
Adds the vector expression e componentwise to this view.
Definition: VectorAdapter.hpp:209
HomogenousCoordsAdapter & operator-=(const VectorExpression< E > &e)
Subtracts the vector expression e componentwise from this view.
Definition: VectorAdapter.hpp:222
SizeType getSize() const
Returns the dimensionality of the view (wrapped vector size + 1).
Definition: VectorAdapter.hpp:146
HomogenousCoordsAdapter(VectorType &v)
Constructs the adapter wrapping v.
Definition: VectorAdapter.hpp:83
HomogenousCoordsAdapter & operator=(const VectorExpression< E > &e)
Assigns the vector expression e to this view (writing through to the wrapped vector).
Definition: VectorAdapter.hpp:196
void swap(HomogenousCoordsAdapter &va)
Swaps the contents of this view with those of va.
Definition: VectorAdapter.hpp:297
V::ValueType ValueType
The element value type of the wrapped vector.
Definition: VectorAdapter.hpp:63
std::enable_if< IsScalar< T >::value, HomogenousCoordsAdapter >::type & operator/=(const T &t)
Divides every element of this view by the scalar t.
Definition: VectorAdapter.hpp:248
V::ConstReference ConstReference
Constant reference type to an element.
Definition: VectorAdapter.hpp:65
ConstReference operator()(SizeType i) const
Returns a const reference to the element at index i of the view.
Definition: VectorAdapter.hpp:108
V::DifferenceType DifferenceType
The signed difference type used by the wrapped vector.
Definition: VectorAdapter.hpp:61
HomogenousCoordsAdapter & plusAssign(const VectorExpression< E > &e)
Adds the vector expression e to this view without intermediate temporary.
Definition: VectorAdapter.hpp:274
VectorClosureType & getData()
Returns a reference to the wrapped vector (via its stored closure).
Definition: VectorAdapter.hpp:164
friend void swap(HomogenousCoordsAdapter &va1, HomogenousCoordsAdapter &va2)
ADL-enabled free-function form of swap().
Definition: VectorAdapter.hpp:308
V::SizeType SizeType
The size type used by the wrapped vector.
Definition: VectorAdapter.hpp:59
HomogenousCoordsAdapter & assign(const VectorExpression< E > &e)
Assigns the vector expression e to this view without intermediate temporary.
Definition: VectorAdapter.hpp:261
CRTP base class for all quaternion expression types.
Definition: Expression.hpp:142
General 4-component quaternion .
Definition: Quaternion.hpp:396
CRTP base class for all vector expression types.
Definition: Expression.hpp:66
Quaternion expression that exposes a 4-element vector as a quaternion (component indices 0-3 map to C...
Definition: VectorAdapter.hpp:324
VectorQuaternionAdapter & assign(const QuaternionExpression< E > &e)
Assigns the quaternion expression e to this view without intermediate temporary (use only when e does...
Definition: VectorAdapter.hpp:602
Reference getC4()
Returns a mutable reference to component C4 (mapped to element 3 of the wrapped vector).
Definition: VectorAdapter.hpp:386
Reference getC3()
Returns a mutable reference to component C3 (mapped to element 2 of the wrapped vector).
Definition: VectorAdapter.hpp:377
VectorClosureType & getData()
Returns a reference to the wrapped vector (via its stored closure).
Definition: VectorAdapter.hpp:431
V VectorType
The wrapped 4-element vector type.
Definition: VectorAdapter.hpp:330
ConstReference getC4() const
Returns a const reference to component C4.
Definition: VectorAdapter.hpp:422
ConstReference getC1() const
Returns a const reference to component C1.
Definition: VectorAdapter.hpp:395
std::enable_if< IsScalar< T >::value, VectorQuaternionAdapter >::type & operator-=(const T &t)
Subtracts the scalar t from component C1 of this view.
Definition: VectorAdapter.hpp:534
std::conditional< std::is_const< V >::value, typename V::ConstClosureType, typename V::ClosureType >::type VectorClosureType
Closure type used to store the wrapped vector internally.
Definition: VectorAdapter.hpp:342
V::ValueType ValueType
The element value type.
Definition: VectorAdapter.hpp:332
ConstReference getC2() const
Returns a const reference to component C2.
Definition: VectorAdapter.hpp:404
VectorQuaternionAdapter & plusAssign(const QuaternionExpression< E > &e)
Adds the quaternion expression e to this view without intermediate temporary.
Definition: VectorAdapter.hpp:615
std::enable_if< IsScalar< T >::value, VectorQuaternionAdapter >::type & operator+=(const T &t)
Adds the scalar t to component C1 of this view.
Definition: VectorAdapter.hpp:507
void set(const ValueType &c1=ValueType(), const ValueType &c2=ValueType(), const ValueType &c3=ValueType(), const ValueType &c4=ValueType())
Assigns the four supplied component values to this view (writing through to the wrapped vector).
Definition: VectorAdapter.hpp:661
ConstReference getC3() const
Returns a const reference to component C3.
Definition: VectorAdapter.hpp:413
VectorQuaternionAdapter & operator+=(const QuaternionExpression< E > &e)
Adds the quaternion expression e componentwise to this view.
Definition: VectorAdapter.hpp:493
const VectorClosureType & getData() const
Returns a const reference to the wrapped vector (via its stored closure).
Definition: VectorAdapter.hpp:440
Reference getC1()
Returns a mutable reference to component C1 (mapped to element 0 of the wrapped vector).
Definition: VectorAdapter.hpp:359
SelfType ClosureType
Closure type used when this adapter appears inside another expression.
Definition: VectorAdapter.hpp:346
VectorQuaternionAdapter & operator*=(const QuaternionExpression< E > &e)
Multiplies this view by the quaternion expression e (Hamilton-product semantics).
Definition: VectorAdapter.hpp:547
std::conditional< std::is_const< V >::value, typename V::ConstReference, typename V::Reference >::type Reference
Mutable reference type (degrades to ConstReference when the wrapped vector is const).
Definition: VectorAdapter.hpp:338
VectorQuaternionAdapter & operator=(const VectorQuaternionAdapter &a)
Copies the components of a into this view (writing through to the wrapped vector).
Definition: VectorAdapter.hpp:450
std::enable_if< IsScalar< T >::value, VectorQuaternionAdapter >::type & operator=(const T &t)
Assigns the scalar t to this view (sets C1 to t and the remaining components to the default value).
Definition: VectorAdapter.hpp:477
std::enable_if< IsScalar< T >::value, VectorQuaternionAdapter >::type & operator/=(const T &t)
Divides every component of this view by the scalar t.
Definition: VectorAdapter.hpp:588
VectorQuaternionAdapter(VectorType &v)
Constructs the adapter wrapping the 4-element vector v.
Definition: VectorAdapter.hpp:352
V::ConstReference ConstReference
Constant reference type to a component.
Definition: VectorAdapter.hpp:334
Reference getC2()
Returns a mutable reference to component C2 (mapped to element 1 of the wrapped vector).
Definition: VectorAdapter.hpp:368
std::enable_if< IsScalar< T >::value, VectorQuaternionAdapter >::type & operator*=(const T &t)
Multiplies every component of this view by the scalar t.
Definition: VectorAdapter.hpp:561
const SelfType ConstClosureType
Constant closure type used when this adapter appears inside another expression.
Definition: VectorAdapter.hpp:344
void swap(VectorQuaternionAdapter &a)
Swaps the components of this view with those of a.
Definition: VectorAdapter.hpp:638
VectorQuaternionAdapter & minusAssign(const QuaternionExpression< E > &e)
Subtracts the quaternion expression e from this view without intermediate temporary.
Definition: VectorAdapter.hpp:628
VectorQuaternionAdapter & operator=(const QuaternionExpression< E > &e)
Assigns the quaternion expression e to this view (writing through to the wrapped vector).
Definition: VectorAdapter.hpp:463
VectorQuaternionAdapter & operator-=(const QuaternionExpression< E > &e)
Subtracts the quaternion expression e componentwise from this view.
Definition: VectorAdapter.hpp:520
friend void swap(VectorQuaternionAdapter &a1, VectorQuaternionAdapter &a2)
ADL-enabled free-function form of swap().
Definition: VectorAdapter.hpp:649
VectorQuaternionAdapter & operator/=(const QuaternionExpression< E > &e)
Divides this view by the quaternion expression e (Hamilton-quotient semantics).
Definition: VectorAdapter.hpp:574
constexpr unsigned int V
Specifies Vanadium.
Definition: AtomType.hpp:177
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
HomogenousCoordsAdapter< E > homog(VectorExpression< E > &e)
Creates a mutable Math::HomogenousCoordsAdapter view of the vector expression e (extends e by an impl...
Definition: VectorAdapter.hpp:751
void quaternionSwap(Q &q, QuaternionExpression< E > &e)
Swaps the components of two quaternion expressions component by component.
Definition: QuaternionAssignment.hpp:93
void vectorSwap(V &v, VectorExpression< E > &e)
Swaps the elements of two equally sized vector expressions element by element.
Definition: VectorAssignment.hpp:97
std::enable_if< IsScalar< T >::value, RealQuaternion< T > >::type quat(const T &t)
Constructs a Math::RealQuaternion from the scalar t (its real component).
Definition: Quaternion.hpp:1152
The namespace of the Chemical Data Processing Library.
Quaternion< typename V::ValueType > Type
The Math::Quaternion specialization used as the temporary quaternion type.
Definition: VectorAdapter.hpp:686
Quaternion< typename V::ValueType > Type
The Math::Quaternion specialization used as the temporary quaternion type.
Definition: VectorAdapter.hpp:698
Selects a concrete temporary quaternion type compatible with the quaternion expression Q.
Definition: TypeTraits.hpp:325
Q::QuaternionTemporaryType Type
The concrete temporary quaternion type compatible with the quaternion expression Q.
Definition: TypeTraits.hpp:328
Selects a concrete temporary vector type compatible with the vector expression V.
Definition: TypeTraits.hpp:301
V::VectorTemporaryType Type
The concrete temporary vector type compatible with the vector expression V.
Definition: TypeTraits.hpp:304