Merged with changes of MS, some similar bug fixes done in parallel

This commit is contained in:
Klaus Basan
2013-04-30 02:34:15 +02:00
22 changed files with 126 additions and 228 deletions

View File

@@ -48,7 +48,7 @@ template <class UsingClass> class CBaseStreamStringifier
* \param uc
* \return
*/
friend QNoDebug &operator<<(QNoDebug &nodebug, const UsingClass &uc)
friend QNoDebug operator<<(QNoDebug nodebug, const UsingClass &uc)
{
return nodebug;
}
@@ -72,7 +72,7 @@ template <class UsingClass> class CBaseStreamStringifier
* \param uc
* \return
*/
friend CLogMessage &operator<<(CLogMessage &log, const UsingClass &uc)
friend CLogMessage operator<<(CLogMessage log, const UsingClass &uc)
{
const CBaseStreamStringifier &sf = uc; // allows to acces protected method
log << sf.stringForStreaming();

View File

@@ -97,7 +97,7 @@ template<class ImplMatrix, int Rows, int Columns> ImplMatrix &CMatrixBase<ImplMa
this->m_matrix(r, c) = CMath::roundEpsilon(this->m_matrix(r, c), 1E-10);
}
}
return static_cast<ImplMatrix &>(*this);
return *derived();
}
/*

View File

@@ -32,12 +32,21 @@ protected:
QString stringForConverter() const;
/*!
* \brief Clone as conrete implementation
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
ImplMatrix clone() const
ImplMatrix const* derived() const
{
return static_cast<ImplMatrix const &>(*this);
return static_cast<ImplMatrix const *>(this);
}
/*!
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
ImplMatrix* derived()
{
return static_cast<ImplMatrix *>(this);
}
public:
@@ -118,7 +127,7 @@ public:
*/
ImplMatrix operator *(double factor) const
{
ImplMatrix m = this->clone();
ImplMatrix m = *derived();
m *= factor;
return m;
}
@@ -159,7 +168,7 @@ public:
*/
ImplMatrix operator /(double factor) const
{
ImplMatrix m = this->clone();
ImplMatrix m = *derived();
m /= factor;
return m;
}
@@ -182,7 +191,7 @@ public:
*/
ImplMatrix operator +(const ImplMatrix &otherMatrix) const
{
ImplMatrix m = this->clone();
ImplMatrix m = *derived();
m += otherMatrix;
return m;
}
@@ -205,7 +214,7 @@ public:
*/
ImplMatrix operator -(const ImplMatrix &otherMatrix) const
{
ImplMatrix m = this->clone();
ImplMatrix m = *derived();
m -= otherMatrix;
return m;
}
@@ -225,8 +234,8 @@ public:
*/
bool isIdentityEpsilon() const
{
ImplMatrix m = this->clone().round();
return m.isIdentity();
ImplMatrix m = *derived();
return m.round().isIdentity();
}
/*!
@@ -260,8 +269,8 @@ public:
*/
bool isZeroEpsilon() const
{
ImplMatrix m = this->clone().round();
return m.isZero();
ImplMatrix m = *derived();
return m.round().isZero();
}
/*!

View File

@@ -62,14 +62,22 @@ protected:
virtual QString stringForConverter() const;
/*!
* \brief Clone as concrete implementation
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
ImplVector clone() const
ImplVector const* derived() const
{
return static_cast<ImplVector const &>(*this);
return static_cast<ImplVector const *>(this);
}
/*!
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
ImplVector* derived()
{
return static_cast<ImplVector *>(this);
}
public:
@@ -198,7 +206,7 @@ public:
*/
ImplVector operator +(const ImplVector &otherVector) const
{
ImplVector v = this->clone();
ImplVector v = *derived();
v += otherVector;
return v;
}
@@ -223,7 +231,7 @@ public:
*/
ImplVector operator -(const ImplVector &otherVector) const
{
ImplVector v = this->clone();
ImplVector v = *derived();
v -= otherVector;
return v;
}
@@ -248,7 +256,7 @@ public:
*/
ImplVector operator *(const ImplVector &otherVector) const
{
ImplVector v = this->clone();
ImplVector v = *derived();
v *= otherVector;
return v;
}
@@ -273,7 +281,7 @@ public:
*/
ImplVector operator *(double factor) const
{
ImplVector v = this->clone();
ImplVector v = *derived();
v *= factor;
return v;
}
@@ -309,7 +317,7 @@ public:
*/
ImplVector operator /(double divisor) const
{
ImplVector v = this->clone();
ImplVector v = *derived();
v /= divisor;
return v;
}
@@ -334,7 +342,7 @@ public:
*/
ImplVector operator /(const ImplVector &otherVector) const
{
ImplVector v = this->clone();
ImplVector v = *derived();
v /= otherVector;
return v;
}
@@ -413,7 +421,7 @@ public:
this->m_i = BlackMisc::Math::CMath::roundEpsilon(this->m_i, epsilon);
this->m_j = BlackMisc::Math::CMath::roundEpsilon(this->m_j, epsilon);
this->m_k = BlackMisc::Math::CMath::roundEpsilon(this->m_k, epsilon);
return static_cast<ImplVector &>(*this);
return *derived();
}
};

View File

@@ -193,7 +193,7 @@ template <class MU, class PQ> CPhysicalQuantity<MU, PQ> &CPhysicalQuantity<MU, P
*/
template <class MU, class PQ> PQ CPhysicalQuantity<MU, PQ>::operator -(const PQ &otherQuantity) const
{
PQ minus = this->clone();
PQ minus = *derived();
minus -= otherQuantity;
return minus;
}
@@ -212,7 +212,7 @@ template <class MU, class PQ> CPhysicalQuantity<MU, PQ> &CPhysicalQuantity<MU, P
*/
template <class MU, class PQ> PQ CPhysicalQuantity<MU, PQ>::operator *(double multiply) const
{
PQ times = this->clone();
PQ times = *derived();
times *= multiply;
return times;
}
@@ -231,7 +231,7 @@ template <class MU, class PQ> CPhysicalQuantity<MU, PQ> &CPhysicalQuantity<MU, P
*/
template <class MU, class PQ> PQ CPhysicalQuantity<MU, PQ>::operator /(double divide) const
{
PQ div = this->clone();
PQ div = *derived();
div /= divide;
return div;
}
@@ -286,7 +286,7 @@ template <class MU, class PQ> PQ &CPhysicalQuantity<MU, PQ>::switchUnit(const MU
this->m_unit = newUnit;
this->setUnitValue(cf);
}
return static_cast<PQ &>(*this);
return *derived();
}
/*

View File

@@ -60,12 +60,21 @@ protected:
}
/*!
* \brief Polymorphic clone as concrete class
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
PQ clone() const
PQ const* derived() const
{
return static_cast<PQ const &>(*this);
return static_cast<PQ const *>(this);
}
/*!
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
PQ* derived()
{
return static_cast<PQ *>(this);
}
/*!

View File

@@ -5,8 +5,9 @@
#ifndef BLACKMISC_PQUNITS_H
#define BLACKMISC_PQUNITS_H
#include "blackmisc/pqbase.h"
#include <math.h>
#include <QtCore/qmath.h>
//
// Used with the template for quantities. This is the reason for