Map.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) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
5 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_MAP_H
12 #define EIGEN_MAP_H
13 
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 namespace internal {
19 template<typename PlainObjectType, int MapOptions, typename StrideType>
20 struct traits<Map<PlainObjectType, MapOptions, StrideType> >
21  : public traits<PlainObjectType>
22 {
23  typedef traits<PlainObjectType> TraitsBase;
24  enum {
25  PlainObjectTypeInnerSize = ((traits<PlainObjectType>::Flags&RowMajorBit)==RowMajorBit)
26  ? PlainObjectType::ColsAtCompileTime
27  : PlainObjectType::RowsAtCompileTime,
28 
29  InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0
30  ? int(PlainObjectType::InnerStrideAtCompileTime)
31  : int(StrideType::InnerStrideAtCompileTime),
32  OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0
33  ? (InnerStrideAtCompileTime==Dynamic || PlainObjectTypeInnerSize==Dynamic
34  ? Dynamic
35  : int(InnerStrideAtCompileTime) * int(PlainObjectTypeInnerSize))
36  : int(StrideType::OuterStrideAtCompileTime),
37  Alignment = int(MapOptions)&int(AlignedMask),
38  Flags0 = TraitsBase::Flags & (~NestByRefBit),
39  Flags = is_lvalue<PlainObjectType>::value ? int(Flags0) : (int(Flags0) & ~LvalueBit)
40  };
41 private:
42  enum { Options }; // Expressions don't have Options
43 };
44 }
45 
96 template<typename PlainObjectType, int MapOptions, typename StrideType> class Map
97  : public MapBase<Map<PlainObjectType, MapOptions, StrideType> >
98 {
99  public:
100 
103 
104  typedef typename Base::PointerType PointerType;
107  inline PointerType cast_to_pointer_type(PointerArgType ptr) { return ptr; }
108 
110  inline Index innerStride() const
111  {
112  return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
113  }
114 
116  inline Index outerStride() const
117  {
118  return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
119  : internal::traits<Map>::OuterStrideAtCompileTime != Dynamic ? Index(internal::traits<Map>::OuterStrideAtCompileTime)
120  : IsVectorAtCompileTime ? (this->size() * innerStride())
121  : int(Flags)&RowMajorBit ? (this->cols() * innerStride())
122  : (this->rows() * innerStride());
123  }
124 
131  explicit inline Map(PointerArgType dataPtr, const StrideType& stride = StrideType())
132  : Base(cast_to_pointer_type(dataPtr)), m_stride(stride)
133  {
134  }
135 
143  inline Map(PointerArgType dataPtr, Index size, const StrideType& stride = StrideType())
144  : Base(cast_to_pointer_type(dataPtr), size), m_stride(stride)
145  {
146  }
147 
156  inline Map(PointerArgType dataPtr, Index rows, Index cols, const StrideType& stride = StrideType())
157  : Base(cast_to_pointer_type(dataPtr), rows, cols), m_stride(stride)
158  {
159  }
160 
162 
163  protected:
164  StrideType m_stride;
165 };
166 
167 
168 } // end namespace Eigen
169 
170 #endif // EIGEN_MAP_H
#define EIGEN_CONSTEXPR
Definition: Macros.h:747
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1168
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)
Definition: Macros.h:1122
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:98
Base::PointerType PointerType
Definition: Map.h:104
Map(PointerArgType dataPtr, Index rows, Index cols, const StrideType &stride=StrideType())
Definition: Map.h:156
Map(PointerArgType dataPtr, const StrideType &stride=StrideType())
Definition: Map.h:131
Map(PointerArgType dataPtr, Index size, const StrideType &stride=StrideType())
Definition: Map.h:143
EIGEN_CONSTEXPR Index innerStride() const
Definition: Map.h:110
StrideType m_stride
Definition: Map.h:164
EIGEN_CONSTEXPR Index outerStride() const
Definition: Map.h:116
MapBase< Map > Base
Definition: Map.h:101
PointerType PointerArgType
Definition: Map.h:105
@ AlignedMask
Definition: Constants.h:241
const unsigned int LvalueBit
Definition: Constants.h:146
const unsigned int RowMajorBit
Definition: Constants.h:68
: InteropHeaders
Definition: Core:139
const unsigned int NestByRefBit
Definition: Constants.h:171
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
const int Dynamic
Definition: Constants.h:24