ForceAlignedAccess.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 // 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_FORCEALIGNEDACCESS_H
00026 #define EIGEN_FORCEALIGNEDACCESS_H
00027 
00028 namespace Eigen {
00029 
00043 namespace internal {
00044 template<typename ExpressionType>
00045 struct traits<ForceAlignedAccess<ExpressionType> > : public traits<ExpressionType>
00046 {};
00047 }
00048 
00049 template<typename ExpressionType> class ForceAlignedAccess
00050   : public internal::dense_xpr_base< ForceAlignedAccess<ExpressionType> >::type
00051 {
00052   public:
00053 
00054     typedef typename internal::dense_xpr_base<ForceAlignedAccess>::type Base;
00055     EIGEN_DENSE_PUBLIC_INTERFACE(ForceAlignedAccess)
00056 
00057     inline ForceAlignedAccess(const ExpressionType& matrix) : m_expression(matrix) {}
00058 
00059     inline Index rows() const { return m_expression.rows(); }
00060     inline Index cols() const { return m_expression.cols(); }
00061     inline Index outerStride() const { return m_expression.outerStride(); }
00062     inline Index innerStride() const { return m_expression.innerStride(); }
00063 
00064     inline const CoeffReturnType coeff(Index row, Index col) const
00065     {
00066       return m_expression.coeff(row, col);
00067     }
00068 
00069     inline Scalar& coeffRef(Index row, Index col)
00070     {
00071       return m_expression.const_cast_derived().coeffRef(row, col);
00072     }
00073 
00074     inline const CoeffReturnType coeff(Index index) const
00075     {
00076       return m_expression.coeff(index);
00077     }
00078 
00079     inline Scalar& coeffRef(Index index)
00080     {
00081       return m_expression.const_cast_derived().coeffRef(index);
00082     }
00083 
00084     template<int LoadMode>
00085     inline const PacketScalar packet(Index row, Index col) const
00086     {
00087       return m_expression.template packet<Aligned>(row, col);
00088     }
00089 
00090     template<int LoadMode>
00091     inline void writePacket(Index row, Index col, const PacketScalar& x)
00092     {
00093       m_expression.const_cast_derived().template writePacket<Aligned>(row, col, x);
00094     }
00095 
00096     template<int LoadMode>
00097     inline const PacketScalar packet(Index index) const
00098     {
00099       return m_expression.template packet<Aligned>(index);
00100     }
00101 
00102     template<int LoadMode>
00103     inline void writePacket(Index index, const PacketScalar& x)
00104     {
00105       m_expression.const_cast_derived().template writePacket<Aligned>(index, x);
00106     }
00107 
00108     operator const ExpressionType&() const { return m_expression; }
00109 
00110   protected:
00111     const ExpressionType& m_expression;
00112 
00113   private:
00114     ForceAlignedAccess& operator=(const ForceAlignedAccess&);
00115 };
00116 
00120 template<typename Derived>
00121 inline const ForceAlignedAccess<Derived>
00122 MatrixBase<Derived>::forceAlignedAccess() const
00123 {
00124   return ForceAlignedAccess<Derived>(derived());
00125 }
00126 
00130 template<typename Derived>
00131 inline ForceAlignedAccess<Derived>
00132 MatrixBase<Derived>::forceAlignedAccess()
00133 {
00134   return ForceAlignedAccess<Derived>(derived());
00135 }
00136 
00140 template<typename Derived>
00141 template<bool Enable>
00142 inline typename internal::add_const_on_value_type<typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type>::type
00143 MatrixBase<Derived>::forceAlignedAccessIf() const
00144 {
00145   return derived();
00146 }
00147 
00151 template<typename Derived>
00152 template<bool Enable>
00153 inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type
00154 MatrixBase<Derived>::forceAlignedAccessIf()
00155 {
00156   return derived();
00157 }
00158 
00159 } // end namespace Eigen
00160 
00161 #endif // EIGEN_FORCEALIGNEDACCESS_H