23 template<
typename ExpressionType>
24 struct traits<SwapWrapper<ExpressionType> > : traits<ExpressionType> {};
27 template<
typename ExpressionType>
class SwapWrapper
28 :
public internal::dense_xpr_base<SwapWrapper<ExpressionType> >::type
32 typedef typename internal::dense_xpr_base<SwapWrapper>::type Base;
33 EIGEN_DENSE_PUBLIC_INTERFACE(SwapWrapper)
34 typedef typename internal::packet_traits<Scalar>::type Packet;
36 inline SwapWrapper(ExpressionType& xpr) : m_expression(xpr) {}
38 inline Index rows()
const {
return m_expression.rows(); }
39 inline Index cols()
const {
return m_expression.cols(); }
40 inline Index outerStride()
const {
return m_expression.outerStride(); }
41 inline Index innerStride()
const {
return m_expression.innerStride(); }
43 typedef typename internal::conditional<
44 internal::is_lvalue<ExpressionType>::value,
47 >::type ScalarWithConstIfNotLvalue;
49 inline ScalarWithConstIfNotLvalue* data() {
return m_expression.data(); }
50 inline const Scalar* data()
const {
return m_expression.data(); }
52 inline Scalar& coeffRef(Index rowId, Index colId)
54 return m_expression.const_cast_derived().coeffRef(rowId, colId);
57 inline Scalar& coeffRef(Index index)
59 return m_expression.const_cast_derived().coeffRef(index);
62 inline Scalar& coeffRef(Index rowId, Index colId)
const
64 return m_expression.coeffRef(rowId, colId);
67 inline Scalar& coeffRef(Index index)
const
69 return m_expression.coeffRef(index);
72 template<
typename OtherDerived>
73 void copyCoeff(Index rowId, Index colId,
const DenseBase<OtherDerived>& other)
75 OtherDerived& _other = other.const_cast_derived();
76 eigen_internal_assert(rowId >= 0 && rowId < rows()
77 && colId >= 0 && colId < cols());
78 Scalar tmp = m_expression.coeff(rowId, colId);
79 m_expression.coeffRef(rowId, colId) = _other.coeff(rowId, colId);
80 _other.coeffRef(rowId, colId) = tmp;
83 template<
typename OtherDerived>
84 void copyCoeff(Index index,
const DenseBase<OtherDerived>& other)
86 OtherDerived& _other = other.const_cast_derived();
87 eigen_internal_assert(index >= 0 && index < m_expression.size());
88 Scalar tmp = m_expression.coeff(index);
89 m_expression.coeffRef(index) = _other.coeff(index);
90 _other.coeffRef(index) = tmp;
93 template<
typename OtherDerived,
int StoreMode,
int LoadMode>
94 void copyPacket(Index rowId, Index colId,
const DenseBase<OtherDerived>& other)
96 OtherDerived& _other = other.const_cast_derived();
97 eigen_internal_assert(rowId >= 0 && rowId < rows()
98 && colId >= 0 && colId < cols());
99 Packet tmp = m_expression.template packet<StoreMode>(rowId, colId);
100 m_expression.template writePacket<StoreMode>(rowId, colId,
101 _other.template packet<LoadMode>(rowId, colId)
103 _other.template writePacket<LoadMode>(rowId, colId, tmp);
106 template<
typename OtherDerived,
int StoreMode,
int LoadMode>
107 void copyPacket(Index index,
const DenseBase<OtherDerived>& other)
109 OtherDerived& _other = other.const_cast_derived();
110 eigen_internal_assert(index >= 0 && index < m_expression.size());
111 Packet tmp = m_expression.template packet<StoreMode>(index);
112 m_expression.template writePacket<StoreMode>(index,
113 _other.template packet<LoadMode>(index)
115 _other.template writePacket<LoadMode>(index, tmp);
118 ExpressionType& expression()
const {
return m_expression; }
121 ExpressionType& m_expression;
126 #endif // EIGEN_SWAP_H