diff options
author | Benoit Jacob <jacob.benoit.1@gmail.com> | 2010-12-22 17:45:37 -0500 |
---|---|---|
committer | Benoit Jacob <jacob.benoit.1@gmail.com> | 2010-12-22 17:45:37 -0500 |
commit | 75b7d98665dd144c44d7a113c6613f5f998be626 (patch) | |
tree | bc75d316e2ed8e679e744bc34f159dcb0f285243 /Eigen/src/Core/PlainObjectBase.h | |
parent | 3b6d97b51a7e7a4b0c69ae6be44b1c16d72c2e80 (diff) |
bug #54 - really fix const correctness except in Sparse
Diffstat (limited to 'Eigen/src/Core/PlainObjectBase.h')
-rw-r--r-- | Eigen/src/Core/PlainObjectBase.h | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/Eigen/src/Core/PlainObjectBase.h b/Eigen/src/Core/PlainObjectBase.h index 4df262d16..5b0169f72 100644 --- a/Eigen/src/Core/PlainObjectBase.h +++ b/Eigen/src/Core/PlainObjectBase.h @@ -66,15 +66,14 @@ class PlainObjectBase : public internal::dense_xpr_base<Derived>::type using Base::IsVectorAtCompileTime; using Base::Flags; - typedef typename internal::add_const<Derived>::type ConstDerived; friend class Eigen::Map<Derived, Unaligned>; - typedef class Eigen::Map<Derived, Unaligned> MapType; - friend class Eigen::Map<ConstDerived, Unaligned>; - typedef class Eigen::Map<ConstDerived, Unaligned> ConstMapType; + typedef Eigen::Map<Derived, Unaligned> MapType; + friend class Eigen::Map<const Derived, Unaligned>; + typedef const Eigen::Map<const Derived, Unaligned> ConstMapType; friend class Eigen::Map<Derived, Aligned>; - typedef class Eigen::Map<Derived, Aligned> AlignedMapType; - friend class Eigen::Map<ConstDerived, Aligned>; - typedef class Eigen::Map<ConstDerived, Aligned> ConstAlignedMapType; + typedef Eigen::Map<Derived, Aligned> AlignedMapType; + friend class Eigen::Map<const Derived, Aligned>; + typedef const Eigen::Map<const Derived, Aligned> ConstAlignedMapType; protected: DenseStorage<Scalar, Base::MaxSizeAtCompileTime, Base::RowsAtCompileTime, Base::ColsAtCompileTime, Options> m_storage; @@ -116,6 +115,19 @@ class PlainObjectBase : public internal::dense_xpr_base<Derived>::type return m_storage.data()[index]; } + EIGEN_STRONG_INLINE const Scalar& coeffRef(Index row, Index col) const + { + if(Flags & RowMajorBit) + return m_storage.data()[col + row * m_storage.cols()]; + else // column-major + return m_storage.data()[row + col * m_storage.rows()]; + } + + EIGEN_STRONG_INLINE const Scalar& coeffRef(Index index) const + { + return m_storage.data()[index]; + } + template<int LoadMode> EIGEN_STRONG_INLINE PacketScalar packet(Index row, Index col) const { @@ -381,28 +393,28 @@ class PlainObjectBase : public internal::dense_xpr_base<Derived>::type * \see class Map */ //@{ - inline static const ConstMapType Map(const Scalar* data) + inline static ConstMapType Map(const Scalar* data) { return ConstMapType(data); } inline static MapType Map(Scalar* data) { return MapType(data); } - inline static const ConstMapType Map(const Scalar* data, Index size) + inline static ConstMapType Map(const Scalar* data, Index size) { return ConstMapType(data, size); } inline static MapType Map(Scalar* data, Index size) { return MapType(data, size); } - inline static const ConstMapType Map(const Scalar* data, Index rows, Index cols) + inline static ConstMapType Map(const Scalar* data, Index rows, Index cols) { return ConstMapType(data, rows, cols); } inline static MapType Map(Scalar* data, Index rows, Index cols) { return MapType(data, rows, cols); } - inline static const ConstAlignedMapType MapAligned(const Scalar* data) + inline static ConstAlignedMapType MapAligned(const Scalar* data) { return ConstAlignedMapType(data); } inline static AlignedMapType MapAligned(Scalar* data) { return AlignedMapType(data); } - inline static const ConstAlignedMapType MapAligned(const Scalar* data, Index size) + inline static ConstAlignedMapType MapAligned(const Scalar* data, Index size) { return ConstAlignedMapType(data, size); } inline static AlignedMapType MapAligned(Scalar* data, Index size) { return AlignedMapType(data, size); } - inline static const ConstAlignedMapType MapAligned(const Scalar* data, Index rows, Index cols) + inline static ConstAlignedMapType MapAligned(const Scalar* data, Index rows, Index cols) { return ConstAlignedMapType(data, rows, cols); } inline static AlignedMapType MapAligned(Scalar* data, Index rows, Index cols) { return AlignedMapType(data, rows, cols); } @@ -536,6 +548,9 @@ class PlainObjectBase : public internal::dense_xpr_base<Derived>::type INVALID_MATRIX_TEMPLATE_PARAMETERS) } #endif + +private: + enum { ThisConstantIsPrivateInPlainObjectBase }; }; template <typename Derived, typename OtherDerived, bool IsVector> |