diff --git a/src/Core.h b/src/Core.h index 2b2e5b388..0a10e2a14 100644 --- a/src/Core.h +++ b/src/Core.h @@ -11,6 +11,7 @@ namespace Eigen { #include "Core/MatrixRef.h" #include "Core/MatrixStorage.h" #include "Core/Matrix.h" +#include "Core/Cast.h" #include "Core/Eval.h" #include "Core/ScalarMultiple.h" #include "Core/Sum.h" diff --git a/src/Core/Cast.h b/src/Core/Cast.h new file mode 100644 index 000000000..cc4e19f23 --- /dev/null +++ b/src/Core/Cast.h @@ -0,0 +1,70 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. Eigen itself is part of the KDE project. +// +// Copyright (C) 2006-2007 Benoit Jacob +// +// Eigen is free software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the Free Software +// Foundation; either version 2 or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +// details. +// +// You should have received a copy of the GNU General Public License along +// with Eigen; if not, write to the Free Software Foundation, Inc., 51 +// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +// +// As a special exception, if other files instantiate templates or use macros +// or functions from this file, or you compile this file and link it +// with other works to produce a work based on this file, this file does not +// by itself cause the resulting work to be covered by the GNU General Public +// License. This exception does not invalidate any other reasons why a work +// based on this file might be covered by the GNU General Public License. + +#ifndef EI_CAST_H +#define EI_CAST_H + +template class Cast + : public Object > +{ + public: + typedef NewScalar Scalar; + typedef typename MatrixType::Ref MatRef; + friend class Object >; + + static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime, + ColsAtCompileTime = MatrixType::ColsAtCompileTime; + + Cast(const MatRef& matrix) : m_matrix(matrix) {} + + Cast(const Cast& other) + : m_matrix(other.m_matrix) {} + + // assignments are illegal but we still want to intercept them and get clean compile errors + EI_INHERIT_ASSIGNMENT_OPERATORS(Cast) + + private: + const Cast& _ref() const { return *this; } + int _rows() const { return m_matrix.rows(); } + int _cols() const { return m_matrix.cols(); } + + Scalar _read(int row, int col) const + { + return static_cast(m_matrix.read(row, col)); + } + + protected: + MatRef m_matrix; +}; + +template +template +Cast +Object::cast() const +{ + return Cast(static_cast(this)->ref()); +} + +#endif // EI_CAST_H diff --git a/src/Core/Conjugate.h b/src/Core/Conjugate.h index 6061fab03..127b0dee9 100644 --- a/src/Core/Conjugate.h +++ b/src/Core/Conjugate.h @@ -42,7 +42,8 @@ template class Conjugate Conjugate(const Conjugate& other) : m_matrix(other.m_matrix) {} - EI_INHERIT_ASSIGNMENT_OPERATORS(Conjugate) + // assignments are illegal but we still want to intercept them and get clean compile errors + EI_INHERIT_ASSIGNMENT_OPERATORS(Conjugate) private: const Conjugate& _ref() const { return *this; } diff --git a/src/Core/Matrix.h b/src/Core/Matrix.h index 0d714faac..10b3dd1d2 100644 --- a/src/Core/Matrix.h +++ b/src/Core/Matrix.h @@ -28,7 +28,7 @@ template class Matrix : public Object<_Scalar, Matrix<_Scalar, _Rows, _Cols> >, - public MatrixStorage<_Scalar, _Rows, _Cols> + public MatrixStorage<_Scalar, _Rows, _Cols> { public: friend class Object<_Scalar, Matrix>; diff --git a/src/Core/Object.h b/src/Core/Object.h index 93871a1d6..ff412e789 100644 --- a/src/Core/Object.h +++ b/src/Core/Object.h @@ -91,6 +91,8 @@ template class Object return *static_cast(this); } + template Cast cast() const; + Row row(int i) const; Column col(int i) const; Minor minor(int row, int col) const; @@ -102,7 +104,6 @@ template class Object template Scalar dot(const OtherDerived& other) const; - RealScalar norm2() const; RealScalar norm() const; ScalarMultiple normalized() const; diff --git a/src/Core/Util.h b/src/Core/Util.h index 5dcc5c4a1..7ad38aa21 100644 --- a/src/Core/Util.h +++ b/src/Core/Util.h @@ -43,6 +43,7 @@ using Eigen::Matrix; //forward declarations template class Matrix; template class MatrixRef; +template class Cast; template class Row; template class Column; template class Minor;