NestByValue.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) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
00006 //
00007 // Eigen is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 3 of the License, or (at your option) any later version.
00011 //
00012 // Alternatively, you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as
00014 // published by the Free Software Foundation; either version 2 of
00015 // the License, or (at your option) any later version.
00016 //
00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License and a copy of the GNU General Public License along with
00024 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00025 
00026 #ifndef EIGEN_NESTBYVALUE_H
00027 #define EIGEN_NESTBYVALUE_H
00028 
00029 namespace Eigen {
00030 
00044 namespace internal {
00045 template<typename ExpressionType>
00046 struct traits<NestByValue<ExpressionType> > : public traits<ExpressionType>
00047 {};
00048 }
00049 
00050 template<typename ExpressionType> class NestByValue
00051   : public internal::dense_xpr_base< NestByValue<ExpressionType> >::type
00052 {
00053   public:
00054 
00055     typedef typename internal::dense_xpr_base<NestByValue>::type Base;
00056     EIGEN_DENSE_PUBLIC_INTERFACE(NestByValue)
00057 
00058     inline NestByValue(const ExpressionType& matrix) : m_expression(matrix) {}
00059 
00060     inline Index rows() const { return m_expression.rows(); }
00061     inline Index cols() const { return m_expression.cols(); }
00062     inline Index outerStride() const { return m_expression.outerStride(); }
00063     inline Index innerStride() const { return m_expression.innerStride(); }
00064 
00065     inline const CoeffReturnType coeff(Index row, Index col) const
00066     {
00067       return m_expression.coeff(row, col);
00068     }
00069 
00070     inline Scalar& coeffRef(Index row, Index col)
00071     {
00072       return m_expression.const_cast_derived().coeffRef(row, col);
00073     }
00074 
00075     inline const CoeffReturnType coeff(Index index) const
00076     {
00077       return m_expression.coeff(index);
00078     }
00079 
00080     inline Scalar& coeffRef(Index index)
00081     {
00082       return m_expression.const_cast_derived().coeffRef(index);
00083     }
00084 
00085     template<int LoadMode>
00086     inline const PacketScalar packet(Index row, Index col) const
00087     {
00088       return m_expression.template packet<LoadMode>(row, col);
00089     }
00090 
00091     template<int LoadMode>
00092     inline void writePacket(Index row, Index col, const PacketScalar& x)
00093     {
00094       m_expression.const_cast_derived().template writePacket<LoadMode>(row, col, x);
00095     }
00096 
00097     template<int LoadMode>
00098     inline const PacketScalar packet(Index index) const
00099     {
00100       return m_expression.template packet<LoadMode>(index);
00101     }
00102 
00103     template<int LoadMode>
00104     inline void writePacket(Index index, const PacketScalar& x)
00105     {
00106       m_expression.const_cast_derived().template writePacket<LoadMode>(index, x);
00107     }
00108 
00109     operator const ExpressionType&() const { return m_expression; }
00110 
00111   protected:
00112     const ExpressionType m_expression;
00113 };
00114 
00117 template<typename Derived>
00118 inline const NestByValue<Derived>
00119 DenseBase<Derived>::nestByValue() const
00120 {
00121   return NestByValue<Derived>(derived());
00122 }
00123 
00124 } // end namespace Eigen
00125 
00126 #endif // EIGEN_NESTBYVALUE_H