NestByValue.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // Eigen is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 3 of the License, or (at your option) any later version.
11 //
12 // Alternatively, you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License as
14 // published by the Free Software Foundation; either version 2 of
15 // the License, or (at your option) any later version.
16 //
17 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License and a copy of the GNU General Public License along with
24 // Eigen. If not, see <http://www.gnu.org/licenses/>.
25 
26 #ifndef EIGEN_NESTBYVALUE_H
27 #define EIGEN_NESTBYVALUE_H
28 
29 namespace Eigen {
30 
44 namespace internal {
45 template<typename ExpressionType>
46 struct traits<NestByValue<ExpressionType> > : public traits<ExpressionType>
47 {};
48 }
49 
50 template<typename ExpressionType> class NestByValue
51  : public internal::dense_xpr_base< NestByValue<ExpressionType> >::type
52 {
53  public:
54 
55  typedef typename internal::dense_xpr_base<NestByValue>::type Base;
57 
58  inline NestByValue(const ExpressionType& matrix) : m_expression(matrix) {}
59 
60  inline Index rows() const { return m_expression.rows(); }
61  inline Index cols() const { return m_expression.cols(); }
62  inline Index outerStride() const { return m_expression.outerStride(); }
63  inline Index innerStride() const { return m_expression.innerStride(); }
64 
65  inline const CoeffReturnType coeff(Index row, Index col) const
66  {
67  return m_expression.coeff(row, col);
68  }
69 
70  inline Scalar& coeffRef(Index row, Index col)
71  {
72  return m_expression.const_cast_derived().coeffRef(row, col);
73  }
74 
75  inline const CoeffReturnType coeff(Index index) const
76  {
77  return m_expression.coeff(index);
78  }
79 
80  inline Scalar& coeffRef(Index index)
81  {
82  return m_expression.const_cast_derived().coeffRef(index);
83  }
84 
85  template<int LoadMode>
86  inline const PacketScalar packet(Index row, Index col) const
87  {
88  return m_expression.template packet<LoadMode>(row, col);
89  }
90 
91  template<int LoadMode>
92  inline void writePacket(Index row, Index col, const PacketScalar& x)
93  {
94  m_expression.const_cast_derived().template writePacket<LoadMode>(row, col, x);
95  }
96 
97  template<int LoadMode>
98  inline const PacketScalar packet(Index index) const
99  {
100  return m_expression.template packet<LoadMode>(index);
101  }
102 
103  template<int LoadMode>
104  inline void writePacket(Index index, const PacketScalar& x)
105  {
106  m_expression.const_cast_derived().template writePacket<LoadMode>(index, x);
107  }
108 
109  operator const ExpressionType&() const { return m_expression; }
110 
111  protected:
112  const ExpressionType m_expression;
113 };
114 
117 template<typename Derived>
118 inline const NestByValue<Derived>
120 {
121  return NestByValue<Derived>(derived());
122 }
123 
124 } // end namespace Eigen
125 
126 #endif // EIGEN_NESTBYVALUE_H