Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef EIGEN_SWAP_H
00011 #define EIGEN_SWAP_H
00012
00013 namespace Eigen {
00014
00022 namespace internal {
00023 template<typename ExpressionType>
00024 struct traits<SwapWrapper<ExpressionType> > : traits<ExpressionType> {};
00025 }
00026
00027 template<typename ExpressionType> class SwapWrapper
00028 : public internal::dense_xpr_base<SwapWrapper<ExpressionType> >::type
00029 {
00030 public:
00031
00032 typedef typename internal::dense_xpr_base<SwapWrapper>::type Base;
00033 EIGEN_DENSE_PUBLIC_INTERFACE(SwapWrapper)
00034 typedef typename internal::packet_traits<Scalar>::type Packet;
00035
00036 inline SwapWrapper(ExpressionType& xpr) : m_expression(xpr) {}
00037
00038 inline Index rows() const { return m_expression.rows(); }
00039 inline Index cols() const { return m_expression.cols(); }
00040 inline Index outerStride() const { return m_expression.outerStride(); }
00041 inline Index innerStride() const { return m_expression.innerStride(); }
00042
00043 typedef typename internal::conditional<
00044 internal::is_lvalue<ExpressionType>::value,
00045 Scalar,
00046 const Scalar
00047 >::type ScalarWithConstIfNotLvalue;
00048
00049 inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
00050 inline const Scalar* data() const { return m_expression.data(); }
00051
00052 inline Scalar& coeffRef(Index row, Index col)
00053 {
00054 return m_expression.const_cast_derived().coeffRef(row, col);
00055 }
00056
00057 inline Scalar& coeffRef(Index index)
00058 {
00059 return m_expression.const_cast_derived().coeffRef(index);
00060 }
00061
00062 inline Scalar& coeffRef(Index row, Index col) const
00063 {
00064 return m_expression.coeffRef(row, col);
00065 }
00066
00067 inline Scalar& coeffRef(Index index) const
00068 {
00069 return m_expression.coeffRef(index);
00070 }
00071
00072 template<typename OtherDerived>
00073 void copyCoeff(Index row, Index col, const DenseBase<OtherDerived>& other)
00074 {
00075 OtherDerived& _other = other.const_cast_derived();
00076 eigen_internal_assert(row >= 0 && row < rows()
00077 && col >= 0 && col < cols());
00078 Scalar tmp = m_expression.coeff(row, col);
00079 m_expression.coeffRef(row, col) = _other.coeff(row, col);
00080 _other.coeffRef(row, col) = tmp;
00081 }
00082
00083 template<typename OtherDerived>
00084 void copyCoeff(Index index, const DenseBase<OtherDerived>& other)
00085 {
00086 OtherDerived& _other = other.const_cast_derived();
00087 eigen_internal_assert(index >= 0 && index < m_expression.size());
00088 Scalar tmp = m_expression.coeff(index);
00089 m_expression.coeffRef(index) = _other.coeff(index);
00090 _other.coeffRef(index) = tmp;
00091 }
00092
00093 template<typename OtherDerived, int StoreMode, int LoadMode>
00094 void copyPacket(Index row, Index col, const DenseBase<OtherDerived>& other)
00095 {
00096 OtherDerived& _other = other.const_cast_derived();
00097 eigen_internal_assert(row >= 0 && row < rows()
00098 && col >= 0 && col < cols());
00099 Packet tmp = m_expression.template packet<StoreMode>(row, col);
00100 m_expression.template writePacket<StoreMode>(row, col,
00101 _other.template packet<LoadMode>(row, col)
00102 );
00103 _other.template writePacket<LoadMode>(row, col, tmp);
00104 }
00105
00106 template<typename OtherDerived, int StoreMode, int LoadMode>
00107 void copyPacket(Index index, const DenseBase<OtherDerived>& other)
00108 {
00109 OtherDerived& _other = other.const_cast_derived();
00110 eigen_internal_assert(index >= 0 && index < m_expression.size());
00111 Packet tmp = m_expression.template packet<StoreMode>(index);
00112 m_expression.template writePacket<StoreMode>(index,
00113 _other.template packet<LoadMode>(index)
00114 );
00115 _other.template writePacket<LoadMode>(index, tmp);
00116 }
00117
00118 ExpressionType& expression() const { return m_expression; }
00119
00120 protected:
00121 ExpressionType& m_expression;
00122 };
00123
00124 }
00125
00126 #endif // EIGEN_SWAP_H