CoreIterators.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) 2008-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_COREITERATORS_H
26 #define EIGEN_COREITERATORS_H
27 
28 namespace Eigen {
29 
30 /* This file contains the respective InnerIterator definition of the expressions defined in Eigen/Core
31  */
32 
40 // generic version for dense matrix and expressions
41 template<typename Derived> class DenseBase<Derived>::InnerIterator
42 {
43  protected:
44  typedef typename Derived::Scalar Scalar;
45  typedef typename Derived::Index Index;
46 
47  enum { IsRowMajor = (Derived::Flags&RowMajorBit)==RowMajorBit };
48  public:
49  EIGEN_STRONG_INLINE InnerIterator(const Derived& expr, Index outer)
50  : m_expression(expr), m_inner(0), m_outer(outer), m_end(expr.innerSize())
51  {}
52 
54  {
55  return (IsRowMajor) ? m_expression.coeff(m_outer, m_inner)
56  : m_expression.coeff(m_inner, m_outer);
57  }
58 
59  EIGEN_STRONG_INLINE InnerIterator& operator++() { m_inner++; return *this; }
60 
61  EIGEN_STRONG_INLINE Index index() const { return m_inner; }
62  inline Index row() const { return IsRowMajor ? m_outer : index(); }
63  inline Index col() const { return IsRowMajor ? index() : m_outer; }
64 
65  EIGEN_STRONG_INLINE operator bool() const { return m_inner < m_end && m_inner>=0; }
66 
67  protected:
68  const Derived& m_expression;
69  Index m_inner;
70  const Index m_outer;
71  const Index m_end;
72 };
73 
74 } // end namespace Eigen
75 
76 #endif // EIGEN_COREITERATORS_H