CoreIterators.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-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_COREITERATORS_H
00026 #define EIGEN_COREITERATORS_H
00027 
00028 namespace Eigen { 
00029 
00030 /* This file contains the respective InnerIterator definition of the expressions defined in Eigen/Core
00031  */
00032 
00040 // generic version for dense matrix and expressions
00041 template<typename Derived> class DenseBase<Derived>::InnerIterator
00042 {
00043   protected:
00044     typedef typename Derived::Scalar Scalar;
00045     typedef typename Derived::Index Index;
00046 
00047     enum { IsRowMajor = (Derived::Flags&RowMajorBit)==RowMajorBit };
00048   public:
00049     EIGEN_STRONG_INLINE InnerIterator(const Derived& expr, Index outer)
00050       : m_expression(expr), m_inner(0), m_outer(outer), m_end(expr.innerSize())
00051     {}
00052 
00053     EIGEN_STRONG_INLINE Scalar value() const
00054     {
00055       return (IsRowMajor) ? m_expression.coeff(m_outer, m_inner)
00056                           : m_expression.coeff(m_inner, m_outer);
00057     }
00058 
00059     EIGEN_STRONG_INLINE InnerIterator& operator++() { m_inner++; return *this; }
00060 
00061     EIGEN_STRONG_INLINE Index index() const { return m_inner; }
00062     inline Index row() const { return IsRowMajor ? m_outer : index(); }
00063     inline Index col() const { return IsRowMajor ? index() : m_outer; }
00064 
00065     EIGEN_STRONG_INLINE operator bool() const { return m_inner < m_end && m_inner>=0; }
00066 
00067   protected:
00068     const Derived& m_expression;
00069     Index m_inner;
00070     const Index m_outer;
00071     const Index m_end;
00072 };
00073 
00074 } // end namespace Eigen
00075 
00076 #endif // EIGEN_COREITERATORS_H