ArrayWrapper.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-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
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_ARRAYWRAPPER_H
00011 #define EIGEN_ARRAYWRAPPER_H
00012 
00013 namespace Eigen { 
00014 
00026 namespace internal {
00027 template<typename ExpressionType>
00028 struct traits<ArrayWrapper<ExpressionType> >
00029   : public traits<typename remove_all<typename ExpressionType::Nested>::type >
00030 {
00031   typedef ArrayXpr XprKind;
00032 };
00033 }
00034 
00035 template<typename ExpressionType>
00036 class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> >
00037 {
00038   public:
00039     typedef ArrayBase<ArrayWrapper> Base;
00040     EIGEN_DENSE_PUBLIC_INTERFACE(ArrayWrapper)
00041     EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ArrayWrapper)
00042 
00043     typedef typename internal::conditional<
00044                        internal::is_lvalue<ExpressionType>::value,
00045                        Scalar,
00046                        const Scalar
00047                      >::type ScalarWithConstIfNotLvalue;
00048 
00049     typedef typename internal::nested<ExpressionType>::type NestedExpressionType;
00050 
00051     inline ArrayWrapper(ExpressionType& matrix) : m_expression(matrix) {}
00052 
00053     inline Index rows() const { return m_expression.rows(); }
00054     inline Index cols() const { return m_expression.cols(); }
00055     inline Index outerStride() const { return m_expression.outerStride(); }
00056     inline Index innerStride() const { return m_expression.innerStride(); }
00057 
00058     inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
00059     inline const Scalar* data() const { return m_expression.data(); }
00060 
00061     inline CoeffReturnType coeff(Index row, Index col) const
00062     {
00063       return m_expression.coeff(row, col);
00064     }
00065 
00066     inline Scalar& coeffRef(Index row, Index col)
00067     {
00068       return m_expression.const_cast_derived().coeffRef(row, col);
00069     }
00070 
00071     inline const Scalar& coeffRef(Index row, Index col) const
00072     {
00073       return m_expression.const_cast_derived().coeffRef(row, col);
00074     }
00075 
00076     inline CoeffReturnType coeff(Index index) const
00077     {
00078       return m_expression.coeff(index);
00079     }
00080 
00081     inline Scalar& coeffRef(Index index)
00082     {
00083       return m_expression.const_cast_derived().coeffRef(index);
00084     }
00085 
00086     inline const Scalar& coeffRef(Index index) const
00087     {
00088       return m_expression.const_cast_derived().coeffRef(index);
00089     }
00090 
00091     template<int LoadMode>
00092     inline const PacketScalar packet(Index row, Index col) const
00093     {
00094       return m_expression.template packet<LoadMode>(row, col);
00095     }
00096 
00097     template<int LoadMode>
00098     inline void writePacket(Index row, Index col, const PacketScalar& x)
00099     {
00100       m_expression.const_cast_derived().template writePacket<LoadMode>(row, col, x);
00101     }
00102 
00103     template<int LoadMode>
00104     inline const PacketScalar packet(Index index) const
00105     {
00106       return m_expression.template packet<LoadMode>(index);
00107     }
00108 
00109     template<int LoadMode>
00110     inline void writePacket(Index index, const PacketScalar& x)
00111     {
00112       m_expression.const_cast_derived().template writePacket<LoadMode>(index, x);
00113     }
00114 
00115     template<typename Dest>
00116     inline void evalTo(Dest& dst) const { dst = m_expression; }
00117 
00118     const typename internal::remove_all<NestedExpressionType>::type& 
00119     nestedExpression() const 
00120     {
00121       return m_expression;
00122     }
00123 
00126     void resize(Index newSize) { m_expression.const_cast_derived().resize(newSize); }
00129     void resize(Index nbRows, Index nbCols) { m_expression.const_cast_derived().resize(nbRows,nbCols); }
00130 
00131   protected:
00132     NestedExpressionType m_expression;
00133 };
00134 
00146 namespace internal {
00147 template<typename ExpressionType>
00148 struct traits<MatrixWrapper<ExpressionType> >
00149  : public traits<typename remove_all<typename ExpressionType::Nested>::type >
00150 {
00151   typedef MatrixXpr XprKind;
00152 };
00153 }
00154 
00155 template<typename ExpressionType>
00156 class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> >
00157 {
00158   public:
00159     typedef MatrixBase<MatrixWrapper<ExpressionType> > Base;
00160     EIGEN_DENSE_PUBLIC_INTERFACE(MatrixWrapper)
00161     EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixWrapper)
00162 
00163     typedef typename internal::conditional<
00164                        internal::is_lvalue<ExpressionType>::value,
00165                        Scalar,
00166                        const Scalar
00167                      >::type ScalarWithConstIfNotLvalue;
00168 
00169     typedef typename internal::nested<ExpressionType>::type NestedExpressionType;
00170 
00171     inline MatrixWrapper(ExpressionType& matrix) : m_expression(matrix) {}
00172 
00173     inline Index rows() const { return m_expression.rows(); }
00174     inline Index cols() const { return m_expression.cols(); }
00175     inline Index outerStride() const { return m_expression.outerStride(); }
00176     inline Index innerStride() const { return m_expression.innerStride(); }
00177 
00178     inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
00179     inline const Scalar* data() const { return m_expression.data(); }
00180 
00181     inline CoeffReturnType coeff(Index row, Index col) const
00182     {
00183       return m_expression.coeff(row, col);
00184     }
00185 
00186     inline Scalar& coeffRef(Index row, Index col)
00187     {
00188       return m_expression.const_cast_derived().coeffRef(row, col);
00189     }
00190 
00191     inline const Scalar& coeffRef(Index row, Index col) const
00192     {
00193       return m_expression.derived().coeffRef(row, col);
00194     }
00195 
00196     inline CoeffReturnType coeff(Index index) const
00197     {
00198       return m_expression.coeff(index);
00199     }
00200 
00201     inline Scalar& coeffRef(Index index)
00202     {
00203       return m_expression.const_cast_derived().coeffRef(index);
00204     }
00205 
00206     inline const Scalar& coeffRef(Index index) const
00207     {
00208       return m_expression.const_cast_derived().coeffRef(index);
00209     }
00210 
00211     template<int LoadMode>
00212     inline const PacketScalar packet(Index row, Index col) const
00213     {
00214       return m_expression.template packet<LoadMode>(row, col);
00215     }
00216 
00217     template<int LoadMode>
00218     inline void writePacket(Index row, Index col, const PacketScalar& x)
00219     {
00220       m_expression.const_cast_derived().template writePacket<LoadMode>(row, col, x);
00221     }
00222 
00223     template<int LoadMode>
00224     inline const PacketScalar packet(Index index) const
00225     {
00226       return m_expression.template packet<LoadMode>(index);
00227     }
00228 
00229     template<int LoadMode>
00230     inline void writePacket(Index index, const PacketScalar& x)
00231     {
00232       m_expression.const_cast_derived().template writePacket<LoadMode>(index, x);
00233     }
00234 
00235     const typename internal::remove_all<NestedExpressionType>::type& 
00236     nestedExpression() const 
00237     {
00238       return m_expression;
00239     }
00240 
00243     void resize(Index newSize) { m_expression.const_cast_derived().resize(newSize); }
00246     void resize(Index nbRows, Index nbCols) { m_expression.const_cast_derived().resize(nbRows,nbCols); }
00247 
00248   protected:
00249     NestedExpressionType m_expression;
00250 };
00251 
00252 } // end namespace Eigen
00253 
00254 #endif // EIGEN_ARRAYWRAPPER_H


win_eigen
Author(s): Daniel Stonier
autogenerated on Mon Oct 6 2014 12:24:08