aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Core
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2007-10-15 05:56:21 +0000
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2007-10-15 05:56:21 +0000
commit884a718b0a2faad2e34cd916704cbc6c2a23550e (patch)
treeede4aca3c0ea94364932cfb740cbb7ceb2c2c928 /src/Core
parentf355ef2df0f51fc80565285a907f48925a554505 (diff)
make shameless use of const_cast to reduce code redundancy. This means Eigen2
gives up enforcing constness. I really tried to enforce it, but it really was much hassle because our expression templates can be lvalues (not only rvalues) and so much code had to be written twice.
Diffstat (limited to 'src/Core')
-rw-r--r--src/Core/Block.h3
-rw-r--r--src/Core/Column.h3
-rw-r--r--src/Core/Conjugate.h7
-rw-r--r--src/Core/Difference.h7
-rw-r--r--src/Core/Dot.h1
-rw-r--r--src/Core/FromArray.h2
-rw-r--r--src/Core/Identity.h2
-rw-r--r--src/Core/Matrix.h11
-rw-r--r--src/Core/MatrixRef.h27
-rw-r--r--src/Core/Minor.h2
-rw-r--r--src/Core/Object.h8
-rw-r--r--src/Core/Opposite.h7
-rw-r--r--src/Core/Product.h7
-rw-r--r--src/Core/Random.h3
-rw-r--r--src/Core/Row.h3
-rw-r--r--src/Core/ScalarMultiple.h7
-rw-r--r--src/Core/Sum.h8
-rw-r--r--src/Core/Transpose.h3
-rw-r--r--src/Core/Util.h3
-rw-r--r--src/Core/Zero.h3
20 files changed, 34 insertions, 83 deletions
diff --git a/src/Core/Block.h b/src/Core/Block.h
index d705133b5..d3a00f6c8 100644
--- a/src/Core/Block.h
+++ b/src/Core/Block.h
@@ -54,8 +54,7 @@ template<typename MatrixType> class Block
EI_INHERIT_ASSIGNMENT_OPERATORS(Block)
private:
- Block& _ref() { return *this; }
- const Block& _constRef() const { return *this; }
+ const Block& _ref() const { return *this; }
int _rows() const { return m_endRow - m_startRow + 1; }
int _cols() const { return m_endCol - m_startCol + 1; }
diff --git a/src/Core/Column.h b/src/Core/Column.h
index 5367c39f1..d8ed8e0a7 100644
--- a/src/Core/Column.h
+++ b/src/Core/Column.h
@@ -49,8 +49,7 @@ template<typename MatrixType> class Column
EI_INHERIT_ASSIGNMENT_OPERATORS(Column)
private:
- Column& _ref() { return *this; }
- const Column& _constRef() const { return *this; }
+ const Column& _ref() const { return *this; }
int _rows() const { return m_matrix.rows(); }
int _cols() const { return 1; }
diff --git a/src/Core/Conjugate.h b/src/Core/Conjugate.h
index 541f47da7..dae265953 100644
--- a/src/Core/Conjugate.h
+++ b/src/Core/Conjugate.h
@@ -31,7 +31,7 @@ template<typename MatrixType> class Conjugate
{
public:
typedef typename MatrixType::Scalar Scalar;
- typedef typename MatrixType::ConstRef MatRef;
+ typedef typename MatrixType::Ref MatRef;
friend class Object<Scalar, Conjugate<MatrixType> >;
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
@@ -45,8 +45,7 @@ template<typename MatrixType> class Conjugate
EI_INHERIT_ASSIGNMENT_OPERATORS(Conjugate)
private:
- Conjugate& _ref() { return *this; }
- const Conjugate& _constRef() const { return *this; }
+ const Conjugate& _ref() const { return *this; }
int _rows() const { return m_matrix.rows(); }
int _cols() const { return m_matrix.cols(); }
@@ -63,7 +62,7 @@ template<typename Scalar, typename Derived>
Conjugate<Derived>
Object<Scalar, Derived>::conjugate() const
{
- return Conjugate<Derived>(static_cast<const Derived*>(this)->constRef());
+ return Conjugate<Derived>(static_cast<const Derived*>(this)->ref());
}
#endif // EI_CONJUGATE_H
diff --git a/src/Core/Difference.h b/src/Core/Difference.h
index 182555c83..6184090fc 100644
--- a/src/Core/Difference.h
+++ b/src/Core/Difference.h
@@ -31,8 +31,8 @@ template<typename Lhs, typename Rhs> class Difference
{
public:
typedef typename Lhs::Scalar Scalar;
- typedef typename Lhs::ConstRef LhsRef;
- typedef typename Rhs::ConstRef RhsRef;
+ typedef typename Lhs::Ref LhsRef;
+ typedef typename Rhs::Ref RhsRef;
friend class Object<Scalar, Difference>;
static const int RowsAtCompileTime = Lhs::RowsAtCompileTime,
@@ -51,7 +51,6 @@ template<typename Lhs, typename Rhs> class Difference
private:
const Difference& _ref() const { return *this; }
- const Difference& _constRef() const { return *this; }
int _rows() const { return m_lhs.rows(); }
int _cols() const { return m_lhs.cols(); }
@@ -69,7 +68,7 @@ template<typename Scalar, typename Derived1, typename Derived2>
Difference<Derived1, Derived2>
operator-(const Object<Scalar, Derived1> &mat1, const Object<Scalar, Derived2> &mat2)
{
- return Difference<Derived1, Derived2>(mat1.constRef(), mat2.constRef());
+ return Difference<Derived1, Derived2>(mat1.ref(), mat2.ref());
}
template<typename Scalar, typename Derived>
diff --git a/src/Core/Dot.h b/src/Core/Dot.h
index e630d669c..43df2766e 100644
--- a/src/Core/Dot.h
+++ b/src/Core/Dot.h
@@ -77,7 +77,6 @@ Scalar Object<Scalar, Derived>::dot(const OtherDerived& other) const
template<typename Scalar, typename Derived>
typename NumTraits<Scalar>::Real Object<Scalar, Derived>::norm2() const
{
- assert(IsVector);
return NumTraits<Scalar>::real(dot(*this));
}
diff --git a/src/Core/FromArray.h b/src/Core/FromArray.h
index 30ee567cb..ab144ed13 100644
--- a/src/Core/FromArray.h
+++ b/src/Core/FromArray.h
@@ -45,7 +45,7 @@ template<typename MatrixType> class FromArray
private:
FromArray& _ref() { return *this; }
- const FromArray& _constRef() const { return *this; }
+ const FromArray& _ref() const { return *this; }
int _rows() const { return m_rows; }
int _cols() const { return m_cols; }
diff --git a/src/Core/Identity.h b/src/Core/Identity.h
index 4b437a844..e6f7cdd5e 100644
--- a/src/Core/Identity.h
+++ b/src/Core/Identity.h
@@ -44,7 +44,7 @@ template<typename MatrixType> class Identity
private:
Identity& _ref() { return *this; }
- const Identity& _constRef() const { return *this; }
+ const Identity& _ref() const { return *this; }
int _rows() const { return m_rows; }
int _cols() const { return m_rows; }
diff --git a/src/Core/Matrix.h b/src/Core/Matrix.h
index 518057d9f..0d714faac 100644
--- a/src/Core/Matrix.h
+++ b/src/Core/Matrix.h
@@ -32,13 +32,11 @@ class Matrix : public Object<_Scalar, Matrix<_Scalar, _Rows, _Cols> >,
{
public:
friend class Object<_Scalar, Matrix>;
- typedef Object<_Scalar, Matrix> Base;
- typedef MatrixStorage<_Scalar, _Rows, _Cols> Storage;
+ typedef Object<_Scalar, Matrix> Base;
+ typedef MatrixStorage<_Scalar, _Rows, _Cols> Storage;
typedef _Scalar Scalar;
- typedef MatrixRef<Matrix> Ref;
- typedef MatrixConstRef<Matrix> ConstRef;
+ typedef MatrixRef<Matrix> Ref;
friend class MatrixRef<Matrix>;
- friend class MatrixConstRef<Matrix>;
static const int RowsAtCompileTime = _Rows, ColsAtCompileTime = _Cols;
@@ -49,8 +47,7 @@ class Matrix : public Object<_Scalar, Matrix<_Scalar, _Rows, _Cols> >,
{ return Storage::m_array; }
private:
- Ref _ref() { return Ref(*this); }
- ConstRef _constRef() const { return ConstRef(*this); }
+ Ref _ref() const { return Ref(*this); }
const Scalar& _read(int row, int col) const
{
diff --git a/src/Core/MatrixRef.h b/src/Core/MatrixRef.h
index 7e6aea5e6..8fab9d06a 100644
--- a/src/Core/MatrixRef.h
+++ b/src/Core/MatrixRef.h
@@ -26,31 +26,6 @@
#ifndef EI_MATRIXREF_H
#define EI_MATRIXREF_H
-template<typename MatrixType> class MatrixConstRef
- : public Object<typename MatrixType::Scalar, MatrixConstRef<MatrixType> >
-{
- public:
- typedef typename MatrixType::Scalar Scalar;
- friend class Object<Scalar, MatrixConstRef>;
-
- MatrixConstRef(const MatrixType& matrix) : m_matrix(matrix) {}
- MatrixConstRef(const MatrixConstRef& other) : m_matrix(other.m_matrix) {}
- ~MatrixConstRef() {}
-
- EI_INHERIT_ASSIGNMENT_OPERATORS(MatrixConstRef)
-
- private:
- int _rows() const { return m_matrix.rows(); }
- int _cols() const { return m_matrix.cols(); }
-
- const Scalar& _read(int row, int col) const
- {
- return m_matrix._read(row, col);
- }
-
- const MatrixType& m_matrix;
-};
-
template<typename MatrixType> class MatrixRef
: public Object<typename MatrixType::Scalar, MatrixRef<MatrixType> >
{
@@ -58,7 +33,7 @@ template<typename MatrixType> class MatrixRef
typedef typename MatrixType::Scalar Scalar;
friend class Object<Scalar, MatrixRef>;
- MatrixRef(MatrixType& matrix) : m_matrix(matrix) {}
+ MatrixRef(const MatrixType& matrix) : m_matrix(*const_cast<MatrixType*>(&matrix)) {}
MatrixRef(const MatrixRef& other) : m_matrix(other.m_matrix) {}
~MatrixRef() {}
diff --git a/src/Core/Minor.h b/src/Core/Minor.h
index 95d52f293..bc9025d3a 100644
--- a/src/Core/Minor.h
+++ b/src/Core/Minor.h
@@ -54,7 +54,7 @@ template<typename MatrixType> class Minor
private:
Minor& _ref() { return *this; }
- const Minor& _constRef() const { return *this; }
+ const Minor& _ref() const { return *this; }
int _rows() const { return m_matrix.rows() - 1; }
int _cols() const { return m_matrix.cols() - 1; }
diff --git a/src/Core/Object.h b/src/Core/Object.h
index 96eb83cfd..93871a1d6 100644
--- a/src/Core/Object.h
+++ b/src/Core/Object.h
@@ -55,18 +55,14 @@ template<typename Scalar, typename Derived> class Object
static const bool IsVector = RowsAtCompileTime == 1 || ColsAtCompileTime == 1;
typedef typename ForwardDecl<Derived>::Ref Ref;
- typedef typename ForwardDecl<Derived>::ConstRef ConstRef;
typedef typename NumTraits<Scalar>::Real RealScalar;
int rows() const { return static_cast<const Derived *>(this)->_rows(); }
int cols() const { return static_cast<const Derived *>(this)->_cols(); }
int size() const { return rows() * cols(); }
- Ref ref()
- { return static_cast<Derived *>(this)->_ref(); }
-
- ConstRef constRef() const
- { return static_cast<const Derived *>(this)->_constRef(); }
+ Ref ref() const
+ { return static_cast<const Derived *>(this)->_ref(); }
Scalar& write(int row, int col)
{
diff --git a/src/Core/Opposite.h b/src/Core/Opposite.h
index e99a8f2ee..06d77c767 100644
--- a/src/Core/Opposite.h
+++ b/src/Core/Opposite.h
@@ -31,7 +31,7 @@ template<typename MatrixType> class Opposite
{
public:
typedef typename MatrixType::Scalar Scalar;
- typedef typename MatrixType::ConstRef MatRef;
+ typedef typename MatrixType::Ref MatRef;
friend class Object<Scalar, Opposite<MatrixType> >;
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
@@ -45,8 +45,7 @@ template<typename MatrixType> class Opposite
EI_INHERIT_ASSIGNMENT_OPERATORS(Opposite)
private:
- Opposite& _ref() { return *this; }
- const Opposite& _constRef() const { return *this; }
+ const Opposite& _ref() const { return *this; }
int _rows() const { return m_matrix.rows(); }
int _cols() const { return m_matrix.cols(); }
@@ -63,7 +62,7 @@ template<typename Scalar, typename Derived>
Opposite<Derived>
Object<Scalar, Derived>::operator-() const
{
- return Opposite<Derived>(static_cast<const Derived*>(this)->constRef());
+ return Opposite<Derived>(static_cast<const Derived*>(this)->ref());
}
#endif // EI_OPPOSITE_H
diff --git a/src/Core/Product.h b/src/Core/Product.h
index 29b11b74d..854816a71 100644
--- a/src/Core/Product.h
+++ b/src/Core/Product.h
@@ -66,8 +66,8 @@ template<typename Lhs, typename Rhs> class Product
{
public:
typedef typename Lhs::Scalar Scalar;
- typedef typename Lhs::ConstRef LhsRef;
- typedef typename Rhs::ConstRef RhsRef;
+ typedef typename Lhs::Ref LhsRef;
+ typedef typename Rhs::Ref RhsRef;
friend class Object<Scalar, Product>;
static const int RowsAtCompileTime = Lhs::RowsAtCompileTime,
@@ -86,7 +86,6 @@ template<typename Lhs, typename Rhs> class Product
private:
const Product& _ref() const { return *this; }
- const Product& _constRef() const { return *this; }
int _rows() const { return m_lhs.rows(); }
int _cols() const { return m_rhs.cols(); }
@@ -115,7 +114,7 @@ template<typename OtherDerived>
Product<Derived, OtherDerived>
Object<Scalar, Derived>::lazyProduct(const Object<Scalar, OtherDerived> &other) const
{
- return Product<Derived, OtherDerived>(constRef(), other.constRef());
+ return Product<Derived, OtherDerived>(ref(), other.ref());
}
template<typename Scalar, typename Derived1, typename Derived2>
diff --git a/src/Core/Random.h b/src/Core/Random.h
index 872ed6878..f4e301f4f 100644
--- a/src/Core/Random.h
+++ b/src/Core/Random.h
@@ -42,8 +42,7 @@ template<typename MatrixType> class Random
}
private:
- Random& _ref() { return *this; }
- const Random& _constRef() const { return *this; }
+ const Random& _ref() const { return *this; }
int _rows() const { return m_rows; }
int _cols() const { return m_cols; }
diff --git a/src/Core/Row.h b/src/Core/Row.h
index 7b8a8a9b4..00ec34d9a 100644
--- a/src/Core/Row.h
+++ b/src/Core/Row.h
@@ -55,8 +55,7 @@ template<typename MatrixType> class Row
EI_INHERIT_ASSIGNMENT_OPERATORS(Row)
private:
- Row& _ref() { return *this; }
- const Row& _constRef() const { return *this; }
+ const Row& _ref() const { return *this; }
int _rows() const { return 1; }
int _cols() const { return m_matrix.cols(); }
diff --git a/src/Core/ScalarMultiple.h b/src/Core/ScalarMultiple.h
index 137804c43..060adf185 100644
--- a/src/Core/ScalarMultiple.h
+++ b/src/Core/ScalarMultiple.h
@@ -31,7 +31,7 @@ template<typename MatrixType> class ScalarMultiple
{
public:
typedef typename MatrixType::Scalar Scalar;
- typedef typename MatrixType::ConstRef MatRef;
+ typedef typename MatrixType::Ref MatRef;
friend class Object<typename MatrixType::Scalar, ScalarMultiple<MatrixType> >;
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
@@ -47,7 +47,6 @@ template<typename MatrixType> class ScalarMultiple
private:
const ScalarMultiple& _ref() const { return *this; }
- const ScalarMultiple& _constRef() const { return *this; }
int _rows() const { return m_matrix.rows(); }
int _cols() const { return m_matrix.cols(); }
@@ -67,7 +66,7 @@ ScalarMultiple<Derived> \
operator*(const Object<Scalar, Derived>& matrix, \
OtherScalar scalar) \
{ \
- return ScalarMultiple<Derived>(matrix.constRef(), scalar); \
+ return ScalarMultiple<Derived>(matrix.ref(), scalar); \
} \
\
template<typename Scalar, typename Derived> \
@@ -75,7 +74,7 @@ ScalarMultiple<Derived> \
operator*(OtherScalar scalar, \
const Object<Scalar, Derived>& matrix) \
{ \
- return ScalarMultiple<Derived>(matrix.constRef(), scalar); \
+ return ScalarMultiple<Derived>(matrix.ref(), scalar); \
} \
\
template<typename Scalar, typename Derived> \
diff --git a/src/Core/Sum.h b/src/Core/Sum.h
index 2b3ec5807..49968c238 100644
--- a/src/Core/Sum.h
+++ b/src/Core/Sum.h
@@ -31,8 +31,8 @@ template<typename Lhs, typename Rhs> class Sum
{
public:
typedef typename Lhs::Scalar Scalar;
- typedef typename Lhs::ConstRef LhsRef;
- typedef typename Rhs::ConstRef RhsRef;
+ typedef typename Lhs::Ref LhsRef;
+ typedef typename Rhs::Ref RhsRef;
friend class Object<Scalar, Sum>;
static const int RowsAtCompileTime = Lhs::RowsAtCompileTime,
@@ -50,9 +50,7 @@ template<typename Lhs, typename Rhs> class Sum
EI_INHERIT_ASSIGNMENT_OPERATORS(Sum)
private:
-
const Sum& _ref() const { return *this; }
- const Sum& _constRef() const { return *this; }
int _rows() const { return m_lhs.rows(); }
int _cols() const { return m_lhs.cols(); }
@@ -70,7 +68,7 @@ template<typename Scalar, typename Derived1, typename Derived2>
Sum<Derived1, Derived2>
operator+(const Object<Scalar, Derived1> &mat1, const Object<Scalar, Derived2> &mat2)
{
- return Sum<Derived1, Derived2>(mat1.constRef(), mat2.constRef());
+ return Sum<Derived1, Derived2>(mat1.ref(), mat2.ref());
}
template<typename Scalar, typename Derived>
diff --git a/src/Core/Transpose.h b/src/Core/Transpose.h
index b15ad4691..c9c4f669e 100644
--- a/src/Core/Transpose.h
+++ b/src/Core/Transpose.h
@@ -45,8 +45,7 @@ template<typename MatrixType> class Transpose
EI_INHERIT_ASSIGNMENT_OPERATORS(Transpose)
private:
- Transpose& _ref() { return *this; }
- const Transpose& _constRef() const { return *this; }
+ const Transpose& _ref() const { return *this; }
int _rows() const { return m_matrix.cols(); }
int _cols() const { return m_matrix.rows(); }
diff --git a/src/Core/Util.h b/src/Core/Util.h
index fdc6b27a1..5dcc5c4a1 100644
--- a/src/Core/Util.h
+++ b/src/Core/Util.h
@@ -43,7 +43,6 @@ using Eigen::Matrix;
//forward declarations
template<typename _Scalar, int _Rows, int _Cols> class Matrix;
template<typename MatrixType> class MatrixRef;
-template<typename MatrixType> class MatrixConstRef;
template<typename MatrixType> class Row;
template<typename MatrixType> class Column;
template<typename MatrixType> class Minor;
@@ -64,14 +63,12 @@ template<typename MatrixType> class FromArray;
template<typename T> struct ForwardDecl
{
typedef T Ref;
- typedef T ConstRef;
};
template<typename _Scalar, int _Rows, int _Cols>
struct ForwardDecl<Matrix<_Scalar, _Rows, _Cols> >
{
typedef MatrixRef<Matrix<_Scalar, _Rows, _Cols> > Ref;
- typedef MatrixConstRef<Matrix<_Scalar, _Rows, _Cols> > ConstRef;
};
const int Dynamic = -1;
diff --git a/src/Core/Zero.h b/src/Core/Zero.h
index 16a5747e2..ca599c937 100644
--- a/src/Core/Zero.h
+++ b/src/Core/Zero.h
@@ -42,8 +42,7 @@ template<typename MatrixType> class Zero
}
private:
- Zero& _ref() { return *this; }
- const Zero& _constRef() const { return *this; }
+ const Zero& _ref() const { return *this; }
int _rows() const { return m_rows; }
int _cols() const { return m_cols; }