aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/DenseDirectAccessBase.h
blob: a62debcc6926c96215ea3c86d0ff4e97a5fc1a5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
//
// Eigen is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// Alternatively, you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License and a copy of the GNU General Public License along with
// Eigen. If not, see <http://www.gnu.org/licenses/>.

#ifndef EIGEN_DENSEDIRECTACCESSBASE_H
#define EIGEN_DENSEDIRECTACCESSBASE_H

template<typename Derived> struct ei_has_direct_access
{
  enum { ret = (ei_traits<Derived>::Flags & DirectAccessBit) ? 1 : 0 };
};

template<typename Derived, bool _HasDirectAccess = ei_has_direct_access<Derived>::ret>
struct ei_inner_stride_at_compile_time
{
  enum { ret = ei_traits<Derived>::InnerStrideAtCompileTime };
};

template<typename Derived>
struct ei_inner_stride_at_compile_time<Derived, false>
{
  enum { ret = 0 };
};

template<typename Derived, bool _HasDirectAccess = ei_has_direct_access<Derived>::ret>
struct ei_outer_stride_at_compile_time
{
  enum { ret = ei_traits<Derived>::OuterStrideAtCompileTime };
};

template<typename Derived>
struct ei_outer_stride_at_compile_time<Derived, false>
{
  enum { ret = 0 };
};

template<typename Derived, typename XprKind = typename ei_traits<Derived>::XprKind>
struct ei_dense_xpr_base
{
  /* ei_dense_xpr_base should only ever be used on dense expressions, thus falling either into the MatrixXpr or into the ArrayXpr cases */
};

template<typename Derived>
struct ei_dense_xpr_base<Derived, MatrixXpr>
{
  typedef MatrixBase<Derived> type;
};

template<typename Derived>
struct ei_dense_xpr_base<Derived, ArrayXpr>
{
  typedef ArrayBase<Derived> type;
};

template<typename Derived> class DenseDirectAccessBase
  : public ei_dense_xpr_base<Derived>::type
{
  public:

    typedef typename ei_dense_xpr_base<Derived>::type Base;

    using Base::IsVectorAtCompileTime;
    using Base::IsRowMajor;
    using Base::derived;
    using Base::operator=;

    typedef typename Base::CoeffReturnType CoeffReturnType;

    enum {
      InnerStrideAtCompileTime = ei_traits<Derived>::InnerStrideAtCompileTime,
      OuterStrideAtCompileTime = ei_traits<Derived>::OuterStrideAtCompileTime
    };

    /** \returns the pointer increment between two consecutive elements within a slice in the inner direction.
      *
      * \sa outerStride(), rowStride(), colStride()
      */
    inline int innerStride() const
    {
      return derived().innerStride();
    }

    /** \returns the pointer increment between two consecutive inner slices (for example, between two consecutive columns
      *          in a column-major matrix).
      *
      * \sa innerStride(), rowStride(), colStride()
      */
    inline int outerStride() const
    {
      return derived().outerStride();
    }

    inline int stride() const
    {
      return IsVectorAtCompileTime ? innerStride() : outerStride();
    }

    /** \returns the pointer increment between two consecutive rows.
      *
      * \sa innerStride(), outerStride(), colStride()
      */
    inline int rowStride() const
    {
      return IsRowMajor ? outerStride() : innerStride();
    }

    /** \returns the pointer increment between two consecutive columns.
      *
      * \sa innerStride(), outerStride(), rowStride()
      */
    inline int colStride() const
    {
      return IsRowMajor ? innerStride() : outerStride();
    }

};

#endif // EIGEN_DENSEDIRECTACCESSBASE_H