mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
enforce constness in map(), do only one const_cast, and improve API
This commit is contained in:
parent
8bb98a80b4
commit
59be5c3124
@ -36,7 +36,7 @@ template<typename MatrixType> class Map
|
|||||||
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
|
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
|
||||||
ColsAtCompileTime = MatrixType::ColsAtCompileTime;
|
ColsAtCompileTime = MatrixType::ColsAtCompileTime;
|
||||||
|
|
||||||
Map(Scalar* data, int rows, int cols) : m_data(data), m_rows(rows), m_cols(cols)
|
Map(const Scalar* data, int rows, int cols) : m_data(data), m_rows(rows), m_cols(cols)
|
||||||
{
|
{
|
||||||
assert(rows > 0 && cols > 0);
|
assert(rows > 0 && cols > 0);
|
||||||
}
|
}
|
||||||
@ -55,22 +55,22 @@ template<typename MatrixType> class Map
|
|||||||
|
|
||||||
Scalar& _coeffRef(int row, int col)
|
Scalar& _coeffRef(int row, int col)
|
||||||
{
|
{
|
||||||
return m_data[row + col * m_rows];
|
return const_cast<Scalar*>(m_data)[row + col * m_rows];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Scalar* m_data;
|
const Scalar* m_data;
|
||||||
int m_rows, m_cols;
|
int m_rows, m_cols;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Scalar, typename Derived>
|
template<typename Scalar, typename Derived>
|
||||||
Map<Derived> MatrixBase<Scalar, Derived>::map(const Scalar* data, int rows, int cols)
|
const Map<Derived> MatrixBase<Scalar, Derived>::map(const Scalar* data, int rows, int cols)
|
||||||
{
|
{
|
||||||
return Map<Derived>(const_cast<Scalar*>(data), rows, cols);
|
return Map<Derived>(const_cast<Scalar*>(data), rows, cols);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Scalar, typename Derived>
|
template<typename Scalar, typename Derived>
|
||||||
Map<Derived> MatrixBase<Scalar, Derived>::map(const Scalar* data, int size)
|
const Map<Derived> MatrixBase<Scalar, Derived>::map(const Scalar* data, int size)
|
||||||
{
|
{
|
||||||
assert(IsVector);
|
assert(IsVector);
|
||||||
if(ColsAtCompileTime == 1)
|
if(ColsAtCompileTime == 1)
|
||||||
@ -80,11 +80,33 @@ Map<Derived> MatrixBase<Scalar, Derived>::map(const Scalar* data, int size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename Scalar, typename Derived>
|
template<typename Scalar, typename Derived>
|
||||||
Map<Derived> MatrixBase<Scalar, Derived>::map(const Scalar* data)
|
const Map<Derived> MatrixBase<Scalar, Derived>::map(const Scalar* data)
|
||||||
{
|
{
|
||||||
return Map<Derived>(const_cast<Scalar*>(data), RowsAtCompileTime, ColsAtCompileTime);
|
return Map<Derived>(const_cast<Scalar*>(data), RowsAtCompileTime, ColsAtCompileTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Scalar, typename Derived>
|
||||||
|
Map<Derived> MatrixBase<Scalar, Derived>::map(Scalar* data, int rows, int cols)
|
||||||
|
{
|
||||||
|
return Map<Derived>(data, rows, cols);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Scalar, typename Derived>
|
||||||
|
Map<Derived> MatrixBase<Scalar, Derived>::map(Scalar* data, int size)
|
||||||
|
{
|
||||||
|
assert(IsVector);
|
||||||
|
if(ColsAtCompileTime == 1)
|
||||||
|
return Map<Derived>(data, size, 1);
|
||||||
|
else
|
||||||
|
return Map<Derived>(data, 1, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Scalar, typename Derived>
|
||||||
|
Map<Derived> MatrixBase<Scalar, Derived>::map(Scalar* data)
|
||||||
|
{
|
||||||
|
return Map<Derived>(data, RowsAtCompileTime, ColsAtCompileTime);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename _Scalar, int _Rows, int _Cols>
|
template<typename _Scalar, int _Rows, int _Cols>
|
||||||
Matrix<_Scalar, _Rows, _Cols>
|
Matrix<_Scalar, _Rows, _Cols>
|
||||||
::Matrix(const Scalar *data, int rows, int cols)
|
::Matrix(const Scalar *data, int rows, int cols)
|
||||||
|
@ -95,9 +95,12 @@ template<typename Scalar, typename Derived> class MatrixBase
|
|||||||
diagonal(const OtherDerived& coeffs);
|
diagonal(const OtherDerived& coeffs);
|
||||||
DiagonalCoeffs<Derived> diagonal() const;
|
DiagonalCoeffs<Derived> diagonal() const;
|
||||||
|
|
||||||
static Map<Derived> map(const Scalar* array, int rows, int cols);
|
static const Map<Derived> map(const Scalar* array, int rows, int cols);
|
||||||
static Map<Derived> map(const Scalar* array, int size);
|
static const Map<Derived> map(const Scalar* array, int size);
|
||||||
static Map<Derived> map(const Scalar* array);
|
static const Map<Derived> map(const Scalar* array);
|
||||||
|
static Map<Derived> map(Scalar* array, int rows, int cols);
|
||||||
|
static Map<Derived> map(Scalar* array, int size);
|
||||||
|
static Map<Derived> map(Scalar* array);
|
||||||
|
|
||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
bool isApprox(
|
bool isApprox(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user