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 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
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


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:33:08