NoAlias.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) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
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_NOALIAS_H
00026 #define EIGEN_NOALIAS_H
00027 
00028 namespace Eigen {
00029 
00045 template<typename ExpressionType, template <typename> class StorageBase>
00046 class NoAlias
00047 {
00048     typedef typename ExpressionType::Scalar Scalar;
00049   public:
00050     NoAlias(ExpressionType& expression) : m_expression(expression) {}
00051 
00054     template<typename OtherDerived>
00055     EIGEN_STRONG_INLINE ExpressionType& operator=(const StorageBase<OtherDerived>& other)
00056     { return internal::assign_selector<ExpressionType,OtherDerived,false>::run(m_expression,other.derived()); }
00057 
00059     template<typename OtherDerived>
00060     EIGEN_STRONG_INLINE ExpressionType& operator+=(const StorageBase<OtherDerived>& other)
00061     {
00062       typedef SelfCwiseBinaryOp<internal::scalar_sum_op<Scalar>, ExpressionType, OtherDerived> SelfAdder;
00063       SelfAdder tmp(m_expression);
00064       typedef typename internal::nested<OtherDerived>::type OtherDerivedNested;
00065       typedef typename internal::remove_all<OtherDerivedNested>::type _OtherDerivedNested;
00066       internal::assign_selector<SelfAdder,_OtherDerivedNested,false>::run(tmp,OtherDerivedNested(other.derived()));
00067       return m_expression;
00068     }
00069 
00071     template<typename OtherDerived>
00072     EIGEN_STRONG_INLINE ExpressionType& operator-=(const StorageBase<OtherDerived>& other)
00073     {
00074       typedef SelfCwiseBinaryOp<internal::scalar_difference_op<Scalar>, ExpressionType, OtherDerived> SelfAdder;
00075       SelfAdder tmp(m_expression);
00076       typedef typename internal::nested<OtherDerived>::type OtherDerivedNested;
00077       typedef typename internal::remove_all<OtherDerivedNested>::type _OtherDerivedNested;
00078       internal::assign_selector<SelfAdder,_OtherDerivedNested,false>::run(tmp,OtherDerivedNested(other.derived()));
00079       return m_expression;
00080     }
00081 
00082 #ifndef EIGEN_PARSED_BY_DOXYGEN
00083     template<typename ProductDerived, typename Lhs, typename Rhs>
00084     EIGEN_STRONG_INLINE ExpressionType& operator+=(const ProductBase<ProductDerived, Lhs,Rhs>& other)
00085     { other.derived().addTo(m_expression); return m_expression; }
00086 
00087     template<typename ProductDerived, typename Lhs, typename Rhs>
00088     EIGEN_STRONG_INLINE ExpressionType& operator-=(const ProductBase<ProductDerived, Lhs,Rhs>& other)
00089     { other.derived().subTo(m_expression); return m_expression; }
00090 
00091     template<typename Lhs, typename Rhs, int NestingFlags>
00092     EIGEN_STRONG_INLINE ExpressionType& operator+=(const CoeffBasedProduct<Lhs,Rhs,NestingFlags>& other)
00093     { return m_expression.derived() += CoeffBasedProduct<Lhs,Rhs,NestByRefBit>(other.lhs(), other.rhs()); }
00094 
00095     template<typename Lhs, typename Rhs, int NestingFlags>
00096     EIGEN_STRONG_INLINE ExpressionType& operator-=(const CoeffBasedProduct<Lhs,Rhs,NestingFlags>& other)
00097     { return m_expression.derived() -= CoeffBasedProduct<Lhs,Rhs,NestByRefBit>(other.lhs(), other.rhs()); }
00098 #endif
00099 
00100   protected:
00101     ExpressionType& m_expression;
00102 };
00103 
00132 template<typename Derived>
00133 NoAlias<Derived,MatrixBase> MatrixBase<Derived>::noalias()
00134 {
00135   return derived();
00136 }
00137 
00138 } // end namespace Eigen
00139 
00140 #endif // EIGEN_NOALIAS_H