From 75b7d98665dd144c44d7a113c6613f5f998be626 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Wed, 22 Dec 2010 17:45:37 -0500 Subject: bug #54 - really fix const correctness except in Sparse --- Eigen/src/Core/PlainObjectBase.h | 41 +++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'Eigen/src/Core/PlainObjectBase.h') 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::type using Base::IsVectorAtCompileTime; using Base::Flags; - typedef typename internal::add_const::type ConstDerived; friend class Eigen::Map; - typedef class Eigen::Map MapType; - friend class Eigen::Map; - typedef class Eigen::Map ConstMapType; + typedef Eigen::Map MapType; + friend class Eigen::Map; + typedef const Eigen::Map ConstMapType; friend class Eigen::Map; - typedef class Eigen::Map AlignedMapType; - friend class Eigen::Map; - typedef class Eigen::Map ConstAlignedMapType; + typedef Eigen::Map AlignedMapType; + friend class Eigen::Map; + typedef const Eigen::Map ConstAlignedMapType; protected: DenseStorage m_storage; @@ -116,6 +115,19 @@ class PlainObjectBase : public internal::dense_xpr_base::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 EIGEN_STRONG_INLINE PacketScalar packet(Index row, Index col) const { @@ -381,28 +393,28 @@ class PlainObjectBase : public internal::dense_xpr_base::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::type INVALID_MATRIX_TEMPLATE_PARAMETERS) } #endif + +private: + enum { ThisConstantIsPrivateInPlainObjectBase }; }; template -- cgit v1.2.3