made derived() private instead of protected in CRTP

This commit is contained in:
Mathew Sutcliffe
2013-04-30 20:12:47 +01:00
parent ad6ac0186b
commit e5afc2c627
3 changed files with 48 additions and 48 deletions

View File

@@ -20,17 +20,7 @@ namespace Math
*/
template<class ImplMatrix, int Rows, int Columns> class CMatrixBase : public BlackMisc::CBaseStreamStringifier<ImplMatrix>
{
protected:
// no bug, Qt expects columns rows
QGenericMatrix<Columns, Rows, double> m_matrix; //!< backing data
/*!
* \brief Conversion to string
* \return
*/
QString stringForConverter() const;
private:
/*!
* \brief Easy access to derived class (CRTP template parameter)
* \return
@@ -49,6 +39,16 @@ protected:
return static_cast<ImplMatrix *>(this);
}
protected:
// no bug, Qt expects columns rows
QGenericMatrix<Columns, Rows, double> m_matrix; //!< backing data
/*!
* \brief Conversion to string
* \return
*/
QString stringForConverter() const;
public:
/*!
* \brief Default constructor

View File

@@ -23,6 +23,25 @@ class CMatrix3x1; // forward declaration
*/
template <class ImplVector> class CVector3DBase : public CBaseStreamStringifier<ImplVector>
{
private:
/*!
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
ImplVector const* derived() const
{
return static_cast<ImplVector const *>(this);
}
/*!
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
ImplVector* derived()
{
return static_cast<ImplVector *>(this);
}
protected:
// using own value since Qt QVector3D stores internally as float
@@ -61,24 +80,6 @@ protected:
*/
virtual QString stringForConverter() const;
/*!
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
ImplVector const* derived() const
{
return static_cast<ImplVector const *>(this);
}
/*!
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
ImplVector* derived()
{
return static_cast<ImplVector *>(this);
}
public:
// getter and setters are implemented in the derived classes

View File

@@ -23,13 +23,30 @@ namespace PhysicalQuantities
*/
template <class MU, class PQ> class CPhysicalQuantity : public BlackMisc::CBaseStreamStringifier<PQ>
{
private:
double m_unitValueD; //!< value backed by double
qint32 m_unitValueI; //!< value backed by integer, allows sole integer arithmetic
double m_convertedSiUnitValueD; //!< SI unit value
bool m_isIntegerBaseValue; //!< flag integer? / double?
/*!
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
PQ const* derived() const
{
return static_cast<PQ const *>(this);
}
/*!
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
PQ* derived()
{
return static_cast<PQ *>(this);
}
protected:
MU m_unit; //!< unit
MU m_conversionSiUnit; //!< corresponding SI base unit
@@ -59,24 +76,6 @@ protected:
return this->unitValueRoundedWithUnit(-1);
}
/*!
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
PQ const* derived() const
{
return static_cast<PQ const *>(this);
}
/*!
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
PQ* derived()
{
return static_cast<PQ *>(this);
}
/*!
* \brief Init by integer
* \param baseValue