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/Block.h | |
parent | 3b6d97b51a7e7a4b0c69ae6be44b1c16d72c2e80 (diff) |
bug #54 - really fix const correctness except in Sparse
Diffstat (limited to 'Eigen/src/Core/Block.h')
-rw-r--r-- | Eigen/src/Core/Block.h | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index 3ab242537..00d5d8b4e 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -96,9 +96,13 @@ struct traits<Block<XprType, BlockRows, BlockCols, InnerPanel, HasDirectAccess> ? PacketAccessBit : 0, MaskAlignedBit = (InnerPanel && (OuterStrideAtCompileTime!=Dynamic) && ((OuterStrideAtCompileTime % packet_traits<Scalar>::size) == 0)) ? AlignedBit : 0, FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0, - Flags0 = traits<XprType>::Flags & (HereditaryBits | MaskPacketAccessBit | LvalueBit | DirectAccessBit | MaskAlignedBit), - Flags1 = Flags0 | FlagsLinearAccessBit, - Flags = (Flags1 & ~RowMajorBit) | (IsRowMajor ? RowMajorBit : 0) + FlagsLvalueBit = is_lvalue<XprType>::value ? LvalueBit : 0, + FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0, + Flags0 = traits<XprType>::Flags & ( (HereditaryBits & ~RowMajorBit) | + DirectAccessBit | + MaskPacketAccessBit | + MaskAlignedBit), + Flags = Flags0 | FlagsLinearAccessBit | FlagsLvalueBit | FlagsRowMajorBit }; }; } @@ -163,6 +167,13 @@ template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel, bool H inline Scalar& coeffRef(Index row, Index col) { + EIGEN_STATIC_ASSERT_LVALUE(XprType) + return m_xpr.const_cast_derived() + .coeffRef(row + m_startRow.value(), col + m_startCol.value()); + } + + inline const Scalar& coeffRef(Index row, Index col) const + { return m_xpr.const_cast_derived() .coeffRef(row + m_startRow.value(), col + m_startCol.value()); } @@ -174,6 +185,14 @@ template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel, bool H inline Scalar& coeffRef(Index index) { + EIGEN_STATIC_ASSERT_LVALUE(XprType) + return m_xpr.const_cast_derived() + .coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index), + m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0)); + } + + inline const Scalar& coeffRef(Index index) const + { return m_xpr.const_cast_derived() .coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index), m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0)); @@ -246,8 +265,8 @@ class Block<XprType,BlockRows,BlockCols, InnerPanel,true> /** Column or Row constructor */ - inline Block(const XprType& xpr, Index i) - : Base(&xpr.const_cast_derived().coeffRef( + inline Block(XprType& xpr, Index i) + : Base(&xpr.coeffRef( (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0, (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0), BlockRows==1 ? 1 : xpr.rows(), @@ -262,8 +281,8 @@ class Block<XprType,BlockRows,BlockCols, InnerPanel,true> /** Fixed-size constructor */ - inline Block(const XprType& xpr, Index startRow, Index startCol) - : Base(&xpr.const_cast_derived().coeffRef(startRow,startCol)), m_xpr(xpr) + inline Block(XprType& xpr, Index startRow, Index startCol) + : Base(&xpr.coeffRef(startRow,startCol)), m_xpr(xpr) { eigen_assert(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= xpr.rows() && startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= xpr.cols()); @@ -272,10 +291,10 @@ class Block<XprType,BlockRows,BlockCols, InnerPanel,true> /** Dynamic-size constructor */ - inline Block(const XprType& xpr, + inline Block(XprType& xpr, Index startRow, Index startCol, Index blockRows, Index blockCols) - : Base(&xpr.const_cast_derived().coeffRef(startRow,startCol), blockRows, blockCols), + : Base(&xpr.coeffRef(startRow,startCol), blockRows, blockCols), m_xpr(xpr) { eigen_assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==blockRows) |