Flagged.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 Benoit Jacob <jacob.benoit.1@gmail.com>
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_FLAGGED_H
00026 #define EIGEN_FLAGGED_H
00027 
00028 namespace Eigen { 
00029 
00046 namespace internal {
00047 template<typename ExpressionType, unsigned int Added, unsigned int Removed>
00048 struct traits<Flagged<ExpressionType, Added, Removed> > : traits<ExpressionType>
00049 {
00050   enum { Flags = (ExpressionType::Flags | Added) & ~Removed };
00051 };
00052 }
00053 
00054 template<typename ExpressionType, unsigned int Added, unsigned int Removed> class Flagged
00055   : public MatrixBase<Flagged<ExpressionType, Added, Removed> >
00056 {
00057   public:
00058 
00059     typedef MatrixBase<Flagged> Base;
00060     
00061     EIGEN_DENSE_PUBLIC_INTERFACE(Flagged)
00062     typedef typename internal::conditional<internal::must_nest_by_value<ExpressionType>::ret,
00063         ExpressionType, const ExpressionType&>::type ExpressionTypeNested;
00064     typedef typename ExpressionType::InnerIterator InnerIterator;
00065 
00066     inline Flagged(const ExpressionType& matrix) : m_matrix(matrix) {}
00067 
00068     inline Index rows() const { return m_matrix.rows(); }
00069     inline Index cols() const { return m_matrix.cols(); }
00070     inline Index outerStride() const { return m_matrix.outerStride(); }
00071     inline Index innerStride() const { return m_matrix.innerStride(); }
00072 
00073     inline CoeffReturnType coeff(Index row, Index col) const
00074     {
00075       return m_matrix.coeff(row, col);
00076     }
00077 
00078     inline CoeffReturnType coeff(Index index) const
00079     {
00080       return m_matrix.coeff(index);
00081     }
00082     
00083     inline const Scalar& coeffRef(Index row, Index col) const
00084     {
00085       return m_matrix.const_cast_derived().coeffRef(row, col);
00086     }
00087 
00088     inline const Scalar& coeffRef(Index index) const
00089     {
00090       return m_matrix.const_cast_derived().coeffRef(index);
00091     }
00092 
00093     inline Scalar& coeffRef(Index row, Index col)
00094     {
00095       return m_matrix.const_cast_derived().coeffRef(row, col);
00096     }
00097 
00098     inline Scalar& coeffRef(Index index)
00099     {
00100       return m_matrix.const_cast_derived().coeffRef(index);
00101     }
00102 
00103     template<int LoadMode>
00104     inline const PacketScalar packet(Index row, Index col) const
00105     {
00106       return m_matrix.template packet<LoadMode>(row, col);
00107     }
00108 
00109     template<int LoadMode>
00110     inline void writePacket(Index row, Index col, const PacketScalar& x)
00111     {
00112       m_matrix.const_cast_derived().template writePacket<LoadMode>(row, col, x);
00113     }
00114 
00115     template<int LoadMode>
00116     inline const PacketScalar packet(Index index) const
00117     {
00118       return m_matrix.template packet<LoadMode>(index);
00119     }
00120 
00121     template<int LoadMode>
00122     inline void writePacket(Index index, const PacketScalar& x)
00123     {
00124       m_matrix.const_cast_derived().template writePacket<LoadMode>(index, x);
00125     }
00126 
00127     const ExpressionType& _expression() const { return m_matrix; }
00128 
00129     template<typename OtherDerived>
00130     typename ExpressionType::PlainObject solveTriangular(const MatrixBase<OtherDerived>& other) const;
00131 
00132     template<typename OtherDerived>
00133     void solveTriangularInPlace(const MatrixBase<OtherDerived>& other) const;
00134 
00135   protected:
00136     ExpressionTypeNested m_matrix;
00137 };
00138 
00145 template<typename Derived>
00146 template<unsigned int Added,unsigned int Removed>
00147 inline const Flagged<Derived, Added, Removed>
00148 DenseBase<Derived>::flagged() const
00149 {
00150   return derived();
00151 }
00152 
00153 } // end namespace Eigen
00154 
00155 #endif // EIGEN_FLAGGED_H