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