ForceAlignedAccess.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) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // Eigen is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // Alternatively, you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of
14 // the License, or (at your option) any later version.
15 //
16 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License and a copy of the GNU General Public License along with
23 // Eigen. If not, see <http://www.gnu.org/licenses/>.
24 
25 #ifndef EIGEN_FORCEALIGNEDACCESS_H
26 #define EIGEN_FORCEALIGNEDACCESS_H
27 
28 namespace Eigen {
29 
43 namespace internal {
44 template<typename ExpressionType>
45 struct traits<ForceAlignedAccess<ExpressionType> > : public traits<ExpressionType>
46 {};
47 }
48 
49 template<typename ExpressionType> class ForceAlignedAccess
50  : public internal::dense_xpr_base< ForceAlignedAccess<ExpressionType> >::type
51 {
52  public:
53 
54  typedef typename internal::dense_xpr_base<ForceAlignedAccess>::type Base;
56 
57  inline ForceAlignedAccess(const ExpressionType& matrix) : m_expression(matrix) {}
58 
59  inline Index rows() const { return m_expression.rows(); }
60  inline Index cols() const { return m_expression.cols(); }
61  inline Index outerStride() const { return m_expression.outerStride(); }
62  inline Index innerStride() const { return m_expression.innerStride(); }
63 
64  inline const CoeffReturnType coeff(Index row, Index col) const
65  {
66  return m_expression.coeff(row, col);
67  }
68 
69  inline Scalar& coeffRef(Index row, Index col)
70  {
71  return m_expression.const_cast_derived().coeffRef(row, col);
72  }
73 
74  inline const CoeffReturnType coeff(Index index) const
75  {
76  return m_expression.coeff(index);
77  }
78 
79  inline Scalar& coeffRef(Index index)
80  {
81  return m_expression.const_cast_derived().coeffRef(index);
82  }
83 
84  template<int LoadMode>
85  inline const PacketScalar packet(Index row, Index col) const
86  {
87  return m_expression.template packet<Aligned>(row, col);
88  }
89 
90  template<int LoadMode>
91  inline void writePacket(Index row, Index col, const PacketScalar& x)
92  {
93  m_expression.const_cast_derived().template writePacket<Aligned>(row, col, x);
94  }
95 
96  template<int LoadMode>
97  inline const PacketScalar packet(Index index) const
98  {
99  return m_expression.template packet<Aligned>(index);
100  }
101 
102  template<int LoadMode>
103  inline void writePacket(Index index, const PacketScalar& x)
104  {
105  m_expression.const_cast_derived().template writePacket<Aligned>(index, x);
106  }
107 
108  operator const ExpressionType&() const { return m_expression; }
109 
110  protected:
111  const ExpressionType& m_expression;
112 
113  private:
114  ForceAlignedAccess& operator=(const ForceAlignedAccess&);
115 };
116 
120 template<typename Derived>
121 inline const ForceAlignedAccess<Derived>
123 {
124  return ForceAlignedAccess<Derived>(derived());
125 }
126 
130 template<typename Derived>
133 {
134  return ForceAlignedAccess<Derived>(derived());
135 }
136 
140 template<typename Derived>
141 template<bool Enable>
142 inline typename internal::add_const_on_value_type<typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type>::type
144 {
145  return derived();
146 }
147 
151 template<typename Derived>
152 template<bool Enable>
153 inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type
155 {
156  return derived();
157 }
158 
159 } // end namespace Eigen
160 
161 #endif // EIGEN_FORCEALIGNEDACCESS_H