Swap.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
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 rowId, Index colId)
00053     {
00054       return m_expression.const_cast_derived().coeffRef(rowId, colId);
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 rowId, Index colId) const
00063     {
00064       return m_expression.coeffRef(rowId, colId);
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 rowId, Index colId, const DenseBase<OtherDerived>& other)
00074     {
00075       OtherDerived& _other = other.const_cast_derived();
00076       eigen_internal_assert(rowId >= 0 && rowId < rows()
00077                          && colId >= 0 && colId < cols());
00078       Scalar tmp = m_expression.coeff(rowId, colId);
00079       m_expression.coeffRef(rowId, colId) = _other.coeff(rowId, colId);
00080       _other.coeffRef(rowId, colId) = 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 rowId, Index colId, const DenseBase<OtherDerived>& other)
00095     {
00096       OtherDerived& _other = other.const_cast_derived();
00097       eigen_internal_assert(rowId >= 0 && rowId < rows()
00098                         && colId >= 0 && colId < cols());
00099       Packet tmp = m_expression.template packet<StoreMode>(rowId, colId);
00100       m_expression.template writePacket<StoreMode>(rowId, colId,
00101         _other.template packet<LoadMode>(rowId, colId)
00102       );
00103       _other.template writePacket<LoadMode>(rowId, colId, 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 } // end namespace Eigen
00125 
00126 #endif // EIGEN_SWAP_H


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Sat Jun 8 2019 19:39:55