00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef EIGEN_MAP_H
00027 #define EIGEN_MAP_H
00028
00080 namespace internal {
00081 template<typename PlainObjectType, int MapOptions, typename StrideType>
00082 struct traits<Map<PlainObjectType, MapOptions, StrideType> >
00083 : public traits<PlainObjectType>
00084 {
00085 typedef traits<PlainObjectType> TraitsBase;
00086 typedef typename PlainObjectType::Index Index;
00087 typedef typename PlainObjectType::Scalar Scalar;
00088 enum {
00089 InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0
00090 ? int(PlainObjectType::InnerStrideAtCompileTime)
00091 : int(StrideType::InnerStrideAtCompileTime),
00092 OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0
00093 ? int(PlainObjectType::OuterStrideAtCompileTime)
00094 : int(StrideType::OuterStrideAtCompileTime),
00095 HasNoInnerStride = InnerStrideAtCompileTime == 1,
00096 HasNoOuterStride = StrideType::OuterStrideAtCompileTime == 0,
00097 HasNoStride = HasNoInnerStride && HasNoOuterStride,
00098 IsAligned = bool(EIGEN_ALIGN) && ((int(MapOptions)&Aligned)==Aligned),
00099 IsDynamicSize = PlainObjectType::SizeAtCompileTime==Dynamic,
00100 KeepsPacketAccess = bool(HasNoInnerStride)
00101 && ( bool(IsDynamicSize)
00102 || HasNoOuterStride
00103 || ( OuterStrideAtCompileTime!=Dynamic
00104 && ((static_cast<int>(sizeof(Scalar))*OuterStrideAtCompileTime)%16)==0 ) ),
00105 Flags0 = TraitsBase::Flags,
00106 Flags1 = IsAligned ? (int(Flags0) | AlignedBit) : (int(Flags0) & ~AlignedBit),
00107 Flags2 = (bool(HasNoStride) || bool(PlainObjectType::IsVectorAtCompileTime))
00108 ? int(Flags1) : int(Flags1 & ~LinearAccessBit),
00109 Flags3 = is_lvalue<PlainObjectType>::value ? int(Flags2) : (int(Flags2) & ~LvalueBit),
00110 Flags = KeepsPacketAccess ? int(Flags3) : (int(Flags3) & ~PacketAccessBit)
00111 };
00112 private:
00113 enum { Options };
00114 };
00115 }
00116
00117 template<typename PlainObjectType, int MapOptions, typename StrideType> class Map
00118 : public MapBase<Map<PlainObjectType, MapOptions, StrideType> >
00119 {
00120 public:
00121
00122 typedef MapBase<Map> Base;
00123
00124 EIGEN_DENSE_PUBLIC_INTERFACE(Map)
00125
00126 typedef typename Base::PointerType PointerType;
00127 #if EIGEN2_SUPPORT_STAGE <= STAGE30_FULL_EIGEN3_API
00128 typedef const Scalar* PointerArgType;
00129 inline PointerType cast_to_pointer_type(PointerArgType ptr) { return const_cast<PointerType>(ptr); }
00130 #else
00131 typedef PointerType PointerArgType;
00132 inline PointerType cast_to_pointer_type(PointerArgType ptr) { return ptr; }
00133 #endif
00134
00135 inline Index innerStride() const
00136 {
00137 return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
00138 }
00139
00140 inline Index outerStride() const
00141 {
00142 return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
00143 : IsVectorAtCompileTime ? this->size()
00144 : int(Flags)&RowMajorBit ? this->cols()
00145 : this->rows();
00146 }
00147
00153 inline Map(PointerArgType data, const StrideType& stride = StrideType())
00154 : Base(cast_to_pointer_type(data)), m_stride(stride)
00155 {
00156 PlainObjectType::Base::_check_template_params();
00157 }
00158
00165 inline Map(PointerArgType data, Index size, const StrideType& stride = StrideType())
00166 : Base(cast_to_pointer_type(data), size), m_stride(stride)
00167 {
00168 PlainObjectType::Base::_check_template_params();
00169 }
00170
00178 inline Map(PointerArgType data, Index rows, Index cols, const StrideType& stride = StrideType())
00179 : Base(cast_to_pointer_type(data), rows, cols), m_stride(stride)
00180 {
00181 PlainObjectType::Base::_check_template_params();
00182 }
00183
00184
00185 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map)
00186
00187 protected:
00188 StrideType m_stride;
00189 };
00190
00191 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
00192 inline Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>
00193 ::Array(const Scalar *data)
00194 {
00195 this->_set_noalias(Eigen::Map<const Array>(data));
00196 }
00197
00198 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
00199 inline Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>
00200 ::Matrix(const Scalar *data)
00201 {
00202 this->_set_noalias(Eigen::Map<const Matrix>(data));
00203 }
00204
00205 #endif // EIGEN_MAP_H