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_MAPBASE_H
00027 #define EIGEN_MAPBASE_H
00028
00029 #define EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) \
00030 EIGEN_STATIC_ASSERT((int(internal::traits<Derived>::Flags) & LinearAccessBit) || Derived::IsVectorAtCompileTime, \
00031 YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT)
00032
00033
00041 template<typename Derived> class MapBase<Derived, ReadOnlyAccessors>
00042 : public internal::dense_xpr_base<Derived>::type
00043 {
00044 public:
00045
00046 typedef typename internal::dense_xpr_base<Derived>::type Base;
00047 enum {
00048 RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
00049 ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
00050 SizeAtCompileTime = Base::SizeAtCompileTime
00051 };
00052
00053 typedef typename internal::traits<Derived>::StorageKind StorageKind;
00054 typedef typename internal::traits<Derived>::Index Index;
00055 typedef typename internal::traits<Derived>::Scalar Scalar;
00056 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
00057 typedef typename NumTraits<Scalar>::Real RealScalar;
00058 typedef typename internal::conditional<
00059 bool(internal::is_lvalue<Derived>::value),
00060 Scalar *,
00061 const Scalar *>::type
00062 PointerType;
00063
00064 using Base::derived;
00065
00066
00067
00068 using Base::MaxRowsAtCompileTime;
00069 using Base::MaxColsAtCompileTime;
00070 using Base::MaxSizeAtCompileTime;
00071 using Base::IsVectorAtCompileTime;
00072 using Base::Flags;
00073 using Base::IsRowMajor;
00074
00075 using Base::rows;
00076 using Base::cols;
00077 using Base::size;
00078 using Base::coeff;
00079 using Base::coeffRef;
00080 using Base::lazyAssign;
00081 using Base::eval;
00082
00083 using Base::innerStride;
00084 using Base::outerStride;
00085 using Base::rowStride;
00086 using Base::colStride;
00087
00088
00089 typedef typename Base::CoeffReturnType CoeffReturnType;
00090
00091 inline Index rows() const { return m_rows.value(); }
00092 inline Index cols() const { return m_cols.value(); }
00093
00100 inline const Scalar* data() const { return m_data; }
00101
00102 inline const Scalar& coeff(Index row, Index col) const
00103 {
00104 return m_data[col * colStride() + row * rowStride()];
00105 }
00106
00107 inline const Scalar& coeff(Index index) const
00108 {
00109 EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
00110 return m_data[index * innerStride()];
00111 }
00112
00113 inline const Scalar& coeffRef(Index row, Index col) const
00114 {
00115 return this->m_data[col * colStride() + row * rowStride()];
00116 }
00117
00118 inline const Scalar& coeffRef(Index index) const
00119 {
00120 EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
00121 return this->m_data[index * innerStride()];
00122 }
00123
00124 template<int LoadMode>
00125 inline PacketScalar packet(Index row, Index col) const
00126 {
00127 return internal::ploadt<PacketScalar, LoadMode>
00128 (m_data + (col * colStride() + row * rowStride()));
00129 }
00130
00131 template<int LoadMode>
00132 inline PacketScalar packet(Index index) const
00133 {
00134 EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
00135 return internal::ploadt<PacketScalar, LoadMode>(m_data + index * innerStride());
00136 }
00137
00138 inline MapBase(PointerType data) : m_data(data), m_rows(RowsAtCompileTime), m_cols(ColsAtCompileTime)
00139 {
00140 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
00141 checkSanity();
00142 }
00143
00144 inline MapBase(PointerType data, Index size)
00145 : m_data(data),
00146 m_rows(RowsAtCompileTime == Dynamic ? size : Index(RowsAtCompileTime)),
00147 m_cols(ColsAtCompileTime == Dynamic ? size : Index(ColsAtCompileTime))
00148 {
00149 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
00150 eigen_assert(size >= 0);
00151 eigen_assert(data == 0 || SizeAtCompileTime == Dynamic || SizeAtCompileTime == size);
00152 checkSanity();
00153 }
00154
00155 inline MapBase(PointerType data, Index rows, Index cols)
00156 : m_data(data), m_rows(rows), m_cols(cols)
00157 {
00158 eigen_assert( (data == 0)
00159 || ( rows >= 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
00160 && cols >= 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)));
00161 checkSanity();
00162 }
00163
00164 protected:
00165
00166 void checkSanity() const
00167 {
00168 EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(internal::traits<Derived>::Flags&PacketAccessBit,
00169 internal::inner_stride_at_compile_time<Derived>::ret==1),
00170 PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1);
00171 eigen_assert(EIGEN_IMPLIES(internal::traits<Derived>::Flags&AlignedBit, (size_t(m_data) % (sizeof(Scalar)*internal::packet_traits<Scalar>::size)) == 0)
00172 && "data is not aligned");
00173 }
00174
00175 PointerType m_data;
00176 const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
00177 const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
00178 };
00179
00180 template<typename Derived> class MapBase<Derived, WriteAccessors>
00181 : public MapBase<Derived, ReadOnlyAccessors>
00182 {
00183 public:
00184
00185 typedef MapBase<Derived, ReadOnlyAccessors> Base;
00186
00187 typedef typename Base::Scalar Scalar;
00188 typedef typename Base::PacketScalar PacketScalar;
00189 typedef typename Base::Index Index;
00190 typedef typename Base::PointerType PointerType;
00191
00192 using Base::derived;
00193 using Base::rows;
00194 using Base::cols;
00195 using Base::size;
00196 using Base::coeff;
00197 using Base::coeffRef;
00198
00199 using Base::innerStride;
00200 using Base::outerStride;
00201 using Base::rowStride;
00202 using Base::colStride;
00203
00204 typedef typename internal::conditional<
00205 internal::is_lvalue<Derived>::value,
00206 Scalar,
00207 const Scalar
00208 >::type ScalarWithConstIfNotLvalue;
00209
00210 inline const Scalar* data() const { return this->m_data; }
00211 inline ScalarWithConstIfNotLvalue* data() { return this->m_data; }
00212
00213 inline ScalarWithConstIfNotLvalue& coeffRef(Index row, Index col)
00214 {
00215 return this->m_data[col * colStride() + row * rowStride()];
00216 }
00217
00218 inline ScalarWithConstIfNotLvalue& coeffRef(Index index)
00219 {
00220 EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
00221 return this->m_data[index * innerStride()];
00222 }
00223
00224 template<int StoreMode>
00225 inline void writePacket(Index row, Index col, const PacketScalar& x)
00226 {
00227 internal::pstoret<Scalar, PacketScalar, StoreMode>
00228 (this->m_data + (col * colStride() + row * rowStride()), x);
00229 }
00230
00231 template<int StoreMode>
00232 inline void writePacket(Index index, const PacketScalar& x)
00233 {
00234 EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
00235 internal::pstoret<Scalar, PacketScalar, StoreMode>
00236 (this->m_data + index * innerStride(), x);
00237 }
00238
00239 inline MapBase(PointerType data) : Base(data) {}
00240 inline MapBase(PointerType data, Index size) : Base(data, size) {}
00241 inline MapBase(PointerType data, Index rows, Index cols) : Base(data, rows, cols) {}
00242
00243 Derived& operator=(const MapBase& other)
00244 {
00245 Base::Base::operator=(other);
00246 return derived();
00247 }
00248
00249 using Base::Base::operator=;
00250 };
00251
00252
00253 #endif // EIGEN_MAPBASE_H