MapBase.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
00005 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00006 //
00007 // This Source Code Form is subject to the terms of the Mozilla
00008 // Public License v. 2.0. If a copy of the MPL was not distributed
00009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00010 
00011 #ifndef EIGEN_MAPBASE_H
00012 #define EIGEN_MAPBASE_H
00013 
00014 #define EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) \
00015       EIGEN_STATIC_ASSERT((int(internal::traits<Derived>::Flags) & LinearAccessBit) || Derived::IsVectorAtCompileTime, \
00016                           YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT)
00017 
00018 namespace Eigen { 
00019 
00027 template<typename Derived> class MapBase<Derived, ReadOnlyAccessors>
00028   : public internal::dense_xpr_base<Derived>::type
00029 {
00030   public:
00031 
00032     typedef typename internal::dense_xpr_base<Derived>::type Base;
00033     enum {
00034       RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
00035       ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
00036       SizeAtCompileTime = Base::SizeAtCompileTime
00037     };
00038 
00039     typedef typename internal::traits<Derived>::StorageKind StorageKind;
00040     typedef typename internal::traits<Derived>::Index Index;
00041     typedef typename internal::traits<Derived>::Scalar Scalar;
00042     typedef typename internal::packet_traits<Scalar>::type PacketScalar;
00043     typedef typename NumTraits<Scalar>::Real RealScalar;
00044     typedef typename internal::conditional<
00045                          bool(internal::is_lvalue<Derived>::value),
00046                          Scalar *,
00047                          const Scalar *>::type
00048                      PointerType;
00049 
00050     using Base::derived;
00051 //    using Base::RowsAtCompileTime;
00052 //    using Base::ColsAtCompileTime;
00053 //    using Base::SizeAtCompileTime;
00054     using Base::MaxRowsAtCompileTime;
00055     using Base::MaxColsAtCompileTime;
00056     using Base::MaxSizeAtCompileTime;
00057     using Base::IsVectorAtCompileTime;
00058     using Base::Flags;
00059     using Base::IsRowMajor;
00060 
00061     using Base::rows;
00062     using Base::cols;
00063     using Base::size;
00064     using Base::coeff;
00065     using Base::coeffRef;
00066     using Base::lazyAssign;
00067     using Base::eval;
00068 
00069     using Base::innerStride;
00070     using Base::outerStride;
00071     using Base::rowStride;
00072     using Base::colStride;
00073 
00074     // bug 217 - compile error on ICC 11.1
00075     using Base::operator=;
00076 
00077     typedef typename Base::CoeffReturnType CoeffReturnType;
00078 
00079     inline Index rows() const { return m_rows.value(); }
00080     inline Index cols() const { return m_cols.value(); }
00081 
00088     inline const Scalar* data() const { return m_data; }
00089 
00090     inline const Scalar& coeff(Index rowId, Index colId) const
00091     {
00092       return m_data[colId * colStride() + rowId * rowStride()];
00093     }
00094 
00095     inline const Scalar& coeff(Index index) const
00096     {
00097       EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
00098       return m_data[index * innerStride()];
00099     }
00100 
00101     inline const Scalar& coeffRef(Index rowId, Index colId) const
00102     {
00103       return this->m_data[colId * colStride() + rowId * rowStride()];
00104     }
00105 
00106     inline const Scalar& coeffRef(Index index) const
00107     {
00108       EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
00109       return this->m_data[index * innerStride()];
00110     }
00111 
00112     template<int LoadMode>
00113     inline PacketScalar packet(Index rowId, Index colId) const
00114     {
00115       return internal::ploadt<PacketScalar, LoadMode>
00116                (m_data + (colId * colStride() + rowId * rowStride()));
00117     }
00118 
00119     template<int LoadMode>
00120     inline PacketScalar packet(Index index) const
00121     {
00122       EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
00123       return internal::ploadt<PacketScalar, LoadMode>(m_data + index * innerStride());
00124     }
00125 
00126     inline MapBase(PointerType dataPtr) : m_data(dataPtr), m_rows(RowsAtCompileTime), m_cols(ColsAtCompileTime)
00127     {
00128       EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
00129       checkSanity();
00130     }
00131 
00132     inline MapBase(PointerType dataPtr, Index vecSize)
00133             : m_data(dataPtr),
00134               m_rows(RowsAtCompileTime == Dynamic ? vecSize : Index(RowsAtCompileTime)),
00135               m_cols(ColsAtCompileTime == Dynamic ? vecSize : Index(ColsAtCompileTime))
00136     {
00137       EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
00138       eigen_assert(vecSize >= 0);
00139       eigen_assert(dataPtr == 0 || SizeAtCompileTime == Dynamic || SizeAtCompileTime == vecSize);
00140       checkSanity();
00141     }
00142 
00143     inline MapBase(PointerType dataPtr, Index nbRows, Index nbCols)
00144             : m_data(dataPtr), m_rows(nbRows), m_cols(nbCols)
00145     {
00146       eigen_assert( (dataPtr == 0)
00147               || (   nbRows >= 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == nbRows)
00148                   && nbCols >= 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == nbCols)));
00149       checkSanity();
00150     }
00151 
00152   protected:
00153 
00154     void checkSanity() const
00155     {
00156       EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(internal::traits<Derived>::Flags&PacketAccessBit,
00157                                         internal::inner_stride_at_compile_time<Derived>::ret==1),
00158                           PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1);
00159       eigen_assert(EIGEN_IMPLIES(internal::traits<Derived>::Flags&AlignedBit, (size_t(m_data) % 16) == 0)
00160                    && "input pointer is not aligned on a 16 byte boundary");
00161     }
00162 
00163     PointerType m_data;
00164     const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
00165     const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
00166 };
00167 
00168 template<typename Derived> class MapBase<Derived, WriteAccessors>
00169   : public MapBase<Derived, ReadOnlyAccessors>
00170 {
00171     typedef MapBase<Derived, ReadOnlyAccessors> ReadOnlyMapBase;
00172   public:
00173 
00174     typedef MapBase<Derived, ReadOnlyAccessors> Base;
00175 
00176     typedef typename Base::Scalar Scalar;
00177     typedef typename Base::PacketScalar PacketScalar;
00178     typedef typename Base::Index Index;
00179     typedef typename Base::PointerType PointerType;
00180 
00181     using Base::derived;
00182     using Base::rows;
00183     using Base::cols;
00184     using Base::size;
00185     using Base::coeff;
00186     using Base::coeffRef;
00187 
00188     using Base::innerStride;
00189     using Base::outerStride;
00190     using Base::rowStride;
00191     using Base::colStride;
00192 
00193     typedef typename internal::conditional<
00194                     internal::is_lvalue<Derived>::value,
00195                     Scalar,
00196                     const Scalar
00197                   >::type ScalarWithConstIfNotLvalue;
00198 
00199     inline const Scalar* data() const { return this->m_data; }
00200     inline ScalarWithConstIfNotLvalue* data() { return this->m_data; } // no const-cast here so non-const-correct code will give a compile error
00201 
00202     inline ScalarWithConstIfNotLvalue& coeffRef(Index row, Index col)
00203     {
00204       return this->m_data[col * colStride() + row * rowStride()];
00205     }
00206 
00207     inline ScalarWithConstIfNotLvalue& coeffRef(Index index)
00208     {
00209       EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
00210       return this->m_data[index * innerStride()];
00211     }
00212 
00213     template<int StoreMode>
00214     inline void writePacket(Index row, Index col, const PacketScalar& val)
00215     {
00216       internal::pstoret<Scalar, PacketScalar, StoreMode>
00217                (this->m_data + (col * colStride() + row * rowStride()), val);
00218     }
00219 
00220     template<int StoreMode>
00221     inline void writePacket(Index index, const PacketScalar& val)
00222     {
00223       EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
00224       internal::pstoret<Scalar, PacketScalar, StoreMode>
00225                 (this->m_data + index * innerStride(), val);
00226     }
00227 
00228     explicit inline MapBase(PointerType dataPtr) : Base(dataPtr) {}
00229     inline MapBase(PointerType dataPtr, Index vecSize) : Base(dataPtr, vecSize) {}
00230     inline MapBase(PointerType dataPtr, Index nbRows, Index nbCols) : Base(dataPtr, nbRows, nbCols) {}
00231 
00232     Derived& operator=(const MapBase& other)
00233     {
00234       ReadOnlyMapBase::Base::operator=(other);
00235       return derived();
00236     }
00237 
00238     // In theory we could simply refer to Base:Base::operator=, but MSVC does not like Base::Base,
00239     // see bugs 821 and 920.
00240     using ReadOnlyMapBase::Base::operator=;
00241 };
00242 
00243 #undef EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS
00244 
00245 } // end namespace Eigen
00246 
00247 #endif // EIGEN_MAPBASE_H


turtlebot_exploration_3d
Author(s): Bona , Shawn
autogenerated on Thu Jun 6 2019 20:59:04