00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef EIGEN_MAP_H
00012 #define EIGEN_MAP_H
00013
00014 namespace Eigen {
00015
00067 namespace internal {
00068 template<typename PlainObjectType, int MapOptions, typename StrideType>
00069 struct traits<Map<PlainObjectType, MapOptions, StrideType> >
00070 : public traits<PlainObjectType>
00071 {
00072 typedef traits<PlainObjectType> TraitsBase;
00073 typedef typename PlainObjectType::Index Index;
00074 typedef typename PlainObjectType::Scalar Scalar;
00075 enum {
00076 InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0
00077 ? int(PlainObjectType::InnerStrideAtCompileTime)
00078 : int(StrideType::InnerStrideAtCompileTime),
00079 OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0
00080 ? int(PlainObjectType::OuterStrideAtCompileTime)
00081 : int(StrideType::OuterStrideAtCompileTime),
00082 HasNoInnerStride = InnerStrideAtCompileTime == 1,
00083 HasNoOuterStride = StrideType::OuterStrideAtCompileTime == 0,
00084 HasNoStride = HasNoInnerStride && HasNoOuterStride,
00085 IsAligned = bool(EIGEN_ALIGN) && ((int(MapOptions)&Aligned)==Aligned),
00086 IsDynamicSize = PlainObjectType::SizeAtCompileTime==Dynamic,
00087 KeepsPacketAccess = bool(HasNoInnerStride)
00088 && ( bool(IsDynamicSize)
00089 || HasNoOuterStride
00090 || ( OuterStrideAtCompileTime!=Dynamic
00091 && ((static_cast<int>(sizeof(Scalar))*OuterStrideAtCompileTime)%16)==0 ) ),
00092 Flags0 = TraitsBase::Flags & (~NestByRefBit),
00093 Flags1 = IsAligned ? (int(Flags0) | AlignedBit) : (int(Flags0) & ~AlignedBit),
00094 Flags2 = (bool(HasNoStride) || bool(PlainObjectType::IsVectorAtCompileTime))
00095 ? int(Flags1) : int(Flags1 & ~LinearAccessBit),
00096 Flags3 = is_lvalue<PlainObjectType>::value ? int(Flags2) : (int(Flags2) & ~LvalueBit),
00097 Flags = KeepsPacketAccess ? int(Flags3) : (int(Flags3) & ~PacketAccessBit)
00098 };
00099 private:
00100 enum { Options };
00101 };
00102 }
00103
00104 template<typename PlainObjectType, int MapOptions, typename StrideType> class Map
00105 : public MapBase<Map<PlainObjectType, MapOptions, StrideType> >
00106 {
00107 public:
00108
00109 typedef MapBase<Map> Base;
00110 EIGEN_DENSE_PUBLIC_INTERFACE(Map)
00111
00112 typedef typename Base::PointerType PointerType;
00113 #if EIGEN2_SUPPORT_STAGE <= STAGE30_FULL_EIGEN3_API
00114 typedef const Scalar* PointerArgType;
00115 inline PointerType cast_to_pointer_type(PointerArgType ptr) { return const_cast<PointerType>(ptr); }
00116 #else
00117 typedef PointerType PointerArgType;
00118 inline PointerType cast_to_pointer_type(PointerArgType ptr) { return ptr; }
00119 #endif
00120
00121 inline Index innerStride() const
00122 {
00123 return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
00124 }
00125
00126 inline Index outerStride() const
00127 {
00128 return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
00129 : IsVectorAtCompileTime ? this->size()
00130 : int(Flags)&RowMajorBit ? this->cols()
00131 : this->rows();
00132 }
00133
00139 inline Map(PointerArgType dataPtr, const StrideType& a_stride = StrideType())
00140 : Base(cast_to_pointer_type(dataPtr)), m_stride(a_stride)
00141 {
00142 PlainObjectType::Base::_check_template_params();
00143 }
00144
00151 inline Map(PointerArgType dataPtr, Index a_size, const StrideType& a_stride = StrideType())
00152 : Base(cast_to_pointer_type(dataPtr), a_size), m_stride(a_stride)
00153 {
00154 PlainObjectType::Base::_check_template_params();
00155 }
00156
00164 inline Map(PointerArgType dataPtr, Index nbRows, Index nbCols, const StrideType& a_stride = StrideType())
00165 : Base(cast_to_pointer_type(dataPtr), nbRows, nbCols), m_stride(a_stride)
00166 {
00167 PlainObjectType::Base::_check_template_params();
00168 }
00169
00170 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map)
00171
00172 protected:
00173 StrideType m_stride;
00174 };
00175
00176 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
00177 inline Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>
00178 ::Array(const Scalar *data)
00179 {
00180 this->_set_noalias(Eigen::Map<const Array>(data));
00181 }
00182
00183 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
00184 inline Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>
00185 ::Matrix(const Scalar *data)
00186 {
00187 this->_set_noalias(Eigen::Map<const Matrix>(data));
00188 }
00189
00190 }
00191
00192 #endif // EIGEN_MAP_H