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
00034 template<typename ExpressionType>
00035 struct ei_traits<SwapWrapper<ExpressionType> >
00036 {
00037 typedef typename ExpressionType::Scalar Scalar;
00038 enum {
00039 RowsAtCompileTime = ExpressionType::RowsAtCompileTime,
00040 ColsAtCompileTime = ExpressionType::ColsAtCompileTime,
00041 MaxRowsAtCompileTime = ExpressionType::MaxRowsAtCompileTime,
00042 MaxColsAtCompileTime = ExpressionType::MaxColsAtCompileTime,
00043 Flags = ExpressionType::Flags,
00044 CoeffReadCost = ExpressionType::CoeffReadCost
00045 };
00046 };
00047
00048 template<typename ExpressionType> class SwapWrapper
00049 : public MatrixBase<SwapWrapper<ExpressionType> >
00050 {
00051 public:
00052
00053 EIGEN_GENERIC_PUBLIC_INTERFACE(SwapWrapper)
00054 typedef typename ei_packet_traits<Scalar>::type Packet;
00055
00056 inline SwapWrapper(ExpressionType& xpr) : m_expression(xpr) {}
00057
00058 inline int rows() const { return m_expression.rows(); }
00059 inline int cols() const { return m_expression.cols(); }
00060 inline int stride() const { return m_expression.stride(); }
00061
00062 inline Scalar& coeffRef(int row, int col)
00063 {
00064 return m_expression.const_cast_derived().coeffRef(row, col);
00065 }
00066
00067 inline Scalar& coeffRef(int index)
00068 {
00069 return m_expression.const_cast_derived().coeffRef(index);
00070 }
00071
00072 template<typename OtherDerived>
00073 void copyCoeff(int row, int col, const MatrixBase<OtherDerived>& other)
00074 {
00075 OtherDerived& _other = other.const_cast_derived();
00076 ei_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(int index, const MatrixBase<OtherDerived>& other)
00085 {
00086 OtherDerived& _other = other.const_cast_derived();
00087 ei_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(int row, int col, const MatrixBase<OtherDerived>& other)
00095 {
00096 OtherDerived& _other = other.const_cast_derived();
00097 ei_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(int index, const MatrixBase<OtherDerived>& other)
00108 {
00109 OtherDerived& _other = other.const_cast_derived();
00110 ei_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 protected:
00119 ExpressionType& m_expression;
00120
00121 private:
00122 SwapWrapper& operator=(const SwapWrapper&);
00123 };
00124
00132 template<typename Derived>
00133 template<typename OtherDerived>
00134 void MatrixBase<Derived>::swap(const MatrixBase<OtherDerived>& other)
00135 {
00136 (SwapWrapper<Derived>(derived())).lazyAssign(other);
00137 }
00138
00139 #endif // EIGEN_SWAP_H
00140
00141
00142
00143
00144
00145