From 366971bea41c6af940b87d79122727bfc793cdac Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 2 Jun 2008 22:58:36 +0000 Subject: * start of the Geometry module with a cross product and quaternion expressions (haven't tried them yet) * applied the meta selector rule to MatrixBase::swap() --- Eigen/src/Core/Swap.h | 61 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 22 deletions(-) (limited to 'Eigen/src/Core/Swap.h') diff --git a/Eigen/src/Core/Swap.h b/Eigen/src/Core/Swap.h index cffdb1cc6..5e3187071 100644 --- a/Eigen/src/Core/Swap.h +++ b/Eigen/src/Core/Swap.h @@ -5,12 +5,12 @@ // // Eigen is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either +// License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. // // Alternatively, 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 of +// published by the Free Software Foundation; either version 2 of // the License, or (at your option) any later version. // // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY @@ -18,13 +18,16 @@ // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the // GNU General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public +// You should have received a copy of the GNU Lesser General Public // License and a copy of the GNU General Public License along with // Eigen. If not, see . #ifndef EIGEN_SWAP_H #define EIGEN_SWAP_H +template +struct ei_swap_selector; + /** swaps *this with the expression \a other. * * \note \a other is only marked const because I couln't find another way @@ -41,25 +44,7 @@ void MatrixBase::swap(const MatrixBase& other) MatrixBase *_other = const_cast*>(&other); if(SizeAtCompileTime == Dynamic) { - Scalar tmp; - if(IsVectorAtCompileTime) - { - ei_assert(OtherDerived::IsVectorAtCompileTime && size() == _other->size()); - for(int i = 0; i < size(); i++) - { - tmp = coeff(i); - coeffRef(i) = _other->coeff(i); - _other->coeffRef(i) = tmp; - } - } - else - for(int j = 0; j < cols(); j++) - for(int i = 0; i < rows(); i++) - { - tmp = coeff(i, j); - coeffRef(i, j) = _other->coeff(i, j); - _other->coeffRef(i, j) = tmp; - } + ei_swap_selector::run(derived(),other.const_cast_derived()); } else // SizeAtCompileTime != Dynamic { @@ -69,4 +54,36 @@ void MatrixBase::swap(const MatrixBase& other) } } +template +struct ei_swap_selector +{ + inline static void run(Derived& src, OtherDerived& other) + { + typename Derived::Scalar tmp; + ei_assert(OtherDerived::IsVectorAtCompileTime && src.size() == other.size()); + for(int i = 0; i < src.size(); i++) + { + tmp = src.coeff(i); + src.coeffRef(i) = other.coeff(i); + other.coeffRef(i) = tmp; + } + } +}; + +template +struct ei_swap_selector +{ + inline void run(Derived& src, OtherDerived& other) + { + typename Derived::Scalar tmp; + for(int j = 0; j < src.cols(); j++) + for(int i = 0; i < src.rows(); i++) + { + tmp = src.coeff(i, j); + src.coeffRef(i, j) = other.coeff(i, j); + other.coeffRef(i, j) = tmp; + } + } +}; + #endif // EIGEN_SWAP_H -- cgit v1.2.3