00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. Eigen itself is part of the KDE project. 00003 // 00004 // Copyright (C) 2008 Gael Guennebaud <g.gael@free.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 /* This file contains the respective InnerIterator definition of the expressions defined in Eigen/Core 00029 */ 00030 00037 // generic version for dense matrix and expressions 00038 template<typename Derived> class MatrixBase<Derived>::InnerIterator 00039 { 00040 typedef typename Derived::Scalar Scalar; 00041 enum { IsRowMajor = (Derived::Flags&RowMajorBit)==RowMajorBit }; 00042 public: 00043 EIGEN_STRONG_INLINE InnerIterator(const Derived& expr, int outer) 00044 : m_expression(expr), m_inner(0), m_outer(outer), m_end(expr.rows()) 00045 {} 00046 00047 EIGEN_STRONG_INLINE Scalar value() const 00048 { 00049 return (IsRowMajor) ? m_expression.coeff(m_outer, m_inner) 00050 : m_expression.coeff(m_inner, m_outer); 00051 } 00052 00053 EIGEN_STRONG_INLINE InnerIterator& operator++() { m_inner++; return *this; } 00054 00055 EIGEN_STRONG_INLINE int index() const { return m_inner; } 00056 inline int row() const { return IsRowMajor ? m_outer : index(); } 00057 inline int col() const { return IsRowMajor ? index() : m_outer; } 00058 00059 EIGEN_STRONG_INLINE operator bool() const { return m_inner < m_end && m_inner>=0; } 00060 00061 protected: 00062 const Derived& m_expression; 00063 int m_inner; 00064 const int m_outer; 00065 const int m_end; 00066 }; 00067 00068 #endif // EIGEN_COREITERATORS_H