style changes and removals of typeid

refs #81
This commit is contained in:
Klaus Basan
2013-12-22 20:28:56 +00:00
committed by Mathew Sutcliffe
parent 229d7c6068
commit 978f3c88e5
73 changed files with 7356 additions and 7130 deletions

View File

@@ -18,327 +18,343 @@
namespace BlackMisc
{
namespace PhysicalQuantities
{
/*!
* \brief A physical quantity such as "5m", "20s", "1500ft/s"
*/
template <class MU, class PQ> class CPhysicalQuantity : public BlackMisc::CStreamable
{
private:
double m_value; //!< numeric part
MU m_unit; //!< unit part
/*!
* Which subclass of CMeasurementUnit does this quantity use?
*/
typedef MU UnitClass;
/*!
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
PQ const* derived() const
namespace PhysicalQuantities
{
return static_cast<PQ const *>(this);
}
/*!
* \brief A physical quantity such as "5m", "20s", "1500ft/s"
*/
template <class MU, class PQ> class CPhysicalQuantity : public BlackMisc::CStreamable
{
/*!
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
PQ* derived()
{
return static_cast<PQ *>(this);
}
private:
double m_value; //!< numeric part
MU m_unit; //!< unit part
protected:
/*!
* \brief Constructor with double
* \param value
* \param unit
*/
CPhysicalQuantity(double value, const MU &unit);
/*!
* Which subclass of CMeasurementUnit does this quantity use?
*/
typedef MU UnitClass;
/*!
* \brief Name as string
* \param i18n
* \return
*/
virtual QString convertToQString(bool i18n = false) const
{
return this->valueRoundedWithUnit(this->getUnit(), -1, i18n);
}
/*!
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
PQ const *derived() const
{
return static_cast<PQ const *>(this);
}
public:
/*!
* \brief Virtual destructor
*/
virtual ~CPhysicalQuantity() {}
/*!
* \brief Easy access to derived class (CRTP template parameter)
* \return
*/
PQ *derived()
{
return static_cast<PQ *>(this);
}
/*!
* \brief Unit of the distance
* \return
*/
MU getUnit() const
{
return this->m_unit;
}
protected:
/*!
* \brief Constructor with double
* \param value
* \param unit
*/
CPhysicalQuantity(double value, const MU &unit);
/*!
* \brief Change unit, and convert value to maintain the same quantity
* \param newUnit
* \return
*/
PQ &switchUnit(const MU &newUnit);
/*!
* \brief Rounded value as string
* \param i18n
* \return
*/
virtual QString convertToQString(bool i18n = false) const;
/*!
* \brief Value in given unit
* \param unit
* \return
*/
double value(const MU &unit) const;
public:
/*!
* \brief Virtual destructor
*/
virtual ~CPhysicalQuantity() {}
/*!
* \brief Value in current unit
* \return
*/
double value() const
{
return this->m_value;
}
/*!
* \brief Unit
* \return
*/
MU getUnit() const
{
return this->m_unit;
}
/*!
* \brief Rounded value in given unit
* \param unit
* \param digits
* \return
*/
double valueRounded(const MU &unit, int digits = -1) const;
/*!
* \brief Simply set unit, do no calclulate conversion
* \param unit
* \sa switchUnit
*/
void setUnit(const MU &unit)
{
this->m_unit = unit;
}
/*!
* \brief Rounded value in current unit
* \param digits
* \return
*/
double valueRounded(int digits = -1) const
{
return this->valueRounded(this->m_unit, digits);
}
/*!
* \brief Set unit by string
* \param unitName
*/
void setUnitByString(const QString &unitName)
{
this->m_unit = CMeasurementUnit::unitFromSymbol<MU>(unitName);
}
/*!
* \brief Value to QString with the given unit, e.g. "5.00m"
* \param unit
* \param digits
* \param i18n
* \return
*/
QString valueRoundedWithUnit(const MU &unit, int digits = -1, bool i18n = false) const;
/*!
* \brief Unit
* \return
*/
QString getUnitSymbol() const
{
return this->m_unit.getSymbol(true);
}
/*!
* \brief Value to QString with the current unit, e.g. "5.00m"
* \param digits
* \param i18n
* \return
*/
QString valueRoundedWithUnit(int digits = -1, bool i18n = false) const
{
return this->valueRoundedWithUnit(this->m_unit, digits, i18n);
}
/*!
* \brief Change unit, and convert value to maintain the same quantity
* \param newUnit
* \return
*/
PQ &switchUnit(const MU &newUnit);
/*!
* \brief Change value without changing unit
* \param value
*/
void setValueSameUnit(double value);
/*!
* \brief Value in given unit
* \param unit
* \return
*/
double value(const MU &unit) const;
/*!
* \brief Add to the value in the current unit.
* \param value
*/
void addValueSameUnit(double value);
/*!
* \brief Value in current unit
* \return
*/
double value() const
{
return this->m_value;
}
/*!
* \brief Substract from the value in the current unit.
* \param value
*/
void substractValueSameUnit(double value);
/*!
* \brief Set value in current unit
* \param value
*/
void setCurrentUnitValue(double value)
{
this->m_value = value;
}
/*!
* \brief Multiply operator *=
* \param multiply
* \return
*/
CPhysicalQuantity &operator *=(double multiply);
/*!
* \brief Rounded value in given unit
* \param unit
* \param digits
* \return
*/
double valueRounded(const MU &unit, int digits = -1) const;
/*!
* \brief Divide operator /=
* \param divide
* \return
*/
CPhysicalQuantity &operator /=(double divide);
/*!
* \brief Rounded value in current unit
* \param digits
* \return
*/
double valueRounded(int digits = -1) const
{
return this->valueRounded(this->m_unit, digits);
}
/*!
* \brief Operator *
* \param multiply
* \return
*/
PQ operator *(double multiply) const;
/*!
* \brief Value to QString with the given unit, e.g. "5.00m"
* \param unit
* \param digits
* \param i18n
* \return
*/
QString valueRoundedWithUnit(const MU &unit, int digits = -1, bool i18n = false) const;
/*!
* \brief Operator to support commutative multiplication
* \param factor
* \param other
* \return
*/
friend PQ operator *(double factor, const PQ &other)
{
return other * factor;
}
/*!
* \brief Value to QString with the current unit, e.g. "5.00m"
* \param digits
* \param i18n
* \return
*/
QString valueRoundedWithUnit(int digits = -1, bool i18n = false) const
{
return this->valueRoundedWithUnit(this->m_unit, digits, i18n);
}
/*!
* \brief Operator /
* \param divide
* \return
*/
PQ operator /(double divide) const;
/*!
* \brief Change value without changing unit
* \param value
*/
void setValueSameUnit(double value);
/*!
* \brief Equal operator ==
* \param other
* \return
*/
bool operator==(const CPhysicalQuantity &other) const;
/*!
* \brief Add to the value in the current unit.
* \param value
*/
void addValueSameUnit(double value);
/*!
* \brief Not equal operator !=
* \param other
* \return
*/
bool operator!=(const CPhysicalQuantity &other) const;
/*!
* \brief Substract from the value in the current unit.
* \param value
*/
void substractValueSameUnit(double value);
/*!
* \brief Plus operator +=
* \param other
* \return
*/
CPhysicalQuantity &operator +=(const CPhysicalQuantity &other);
/*!
* \brief Multiply operator *=
* \param multiply
* \return
*/
CPhysicalQuantity &operator *=(double multiply);
/*!
* \brief Minus operator-=
* \param other
* \return
*/
CPhysicalQuantity &operator -=(const CPhysicalQuantity &other);
/*!
* \brief Divide operator /=
* \param divide
* \return
*/
CPhysicalQuantity &operator /=(double divide);
/*!
* \brief Greater operator >
* \param other
* \return
*/
bool operator >(const CPhysicalQuantity &other) const;
/*!
* \brief Operator *
* \param multiply
* \return
*/
PQ operator *(double multiply) const;
/*!
* \brief Less operator <
* \param other
* \return
*/
bool operator <(const CPhysicalQuantity &other) const;
/*!
* \brief Operator to support commutative multiplication
* \param factor
* \param other
* \return
*/
friend PQ operator *(double factor, const PQ &other)
{
return other * factor;
}
/*!
* \brief Less equal operator <=
* \param other
* \return
*/
bool operator <=(const CPhysicalQuantity &other) const;
/*!
* \brief Operator /
* \param divide
* \return
*/
PQ operator /(double divide) const;
/*!
* \brief Greater equal operator >=
* \param other
* \return
*/
bool operator >=(const CPhysicalQuantity &other) const;
/*!
* \brief Equal operator ==
* \param other
* \return
*/
bool operator==(const CPhysicalQuantity &other) const;
/*!
* \brief Plus operator +
* \param other
* \return
*/
PQ operator +(const PQ &other) const;
/*!
* \brief Not equal operator !=
* \param other
* \return
*/
bool operator!=(const CPhysicalQuantity &other) const;
/*!
* \brief Minus operator -
* \param other
* \return
*/
PQ operator -(const PQ &other) const;
/*!
* \brief Plus operator +=
* \param other
* \return
*/
CPhysicalQuantity &operator +=(const CPhysicalQuantity &other);
/*!
* \brief Quantity value <= epsilon
* \return
*/
bool isZeroEpsilon() const
{
return this->m_unit.isEpsilon(this->m_value);
}
/*!
* \brief Minus operator-=
* \param other
* \return
*/
CPhysicalQuantity &operator -=(const CPhysicalQuantity &other);
/*!
* \brief Value >= 0 epsilon considered
* \return
*/
bool isNonNegativeEpsilon() const
{
return this->isZeroEpsilon() || this->m_value > 0;
}
/*!
* \brief Greater operator >
* \param other
* \return
*/
bool operator >(const CPhysicalQuantity &other) const;
/*!
* \brief Value <= 0 epsilon considered
* \return
*/
bool isNonPositiveEpsilon() const
{
return this->isZeroEpsilon() || this->m_value < 0;
}
/*!
* \brief Less operator <
* \param other
* \return
*/
bool operator <(const CPhysicalQuantity &other) const;
/*!
* \brief Stream to DBus <<
* \param argument
*/
virtual void marshallToDbus(QDBusArgument &argument) const
{
argument << this->value(UnitClass::defaultUnit());
argument << this->m_value;
argument << this->m_unit;
}
/*!
* \brief Less equal operator <=
* \param other
* \return
*/
bool operator <=(const CPhysicalQuantity &other) const;
/*!
* \brief Stream from DBus >>
* \param argument
*/
virtual void unmarshallFromDbus(const QDBusArgument &argument)
{
double ignore;
argument >> ignore;
argument >> this->m_value;
argument >> this->m_unit;
}
/*!
* \brief Greater equal operator >=
* \param other
* \return
*/
bool operator >=(const CPhysicalQuantity &other) const;
/*!
* \brief Register metadata of unit and quantity
*/
static void registerMetadata()
{
qRegisterMetaType<MU>(typeid(MU).name());
qDBusRegisterMetaType<MU>();
qDBusRegisterMetaType<QList<MU> >();
qRegisterMetaType<PQ>(typeid(PQ).name());
qDBusRegisterMetaType<PQ>();
qDBusRegisterMetaType<QList<PQ> >();
}
};
/*!
* \brief Plus operator +
* \param other
* \return
*/
PQ operator +(const PQ &other) const;
} // namespace
/*!
* \brief Minus operator -
* \param other
* \return
*/
PQ operator -(const PQ &other) const;
/*!
* \brief Quantity value <= epsilon
* \return
*/
bool isZeroEpsilonConsidered() const
{
return this->m_unit.isEpsilon(this->m_value);
}
/*!
* \brief Value >= 0 epsilon considered
* \return
*/
bool isPositiveWithEpsilonConsidered() const
{
return !this->isZeroEpsilonConsidered() && this->m_value > 0;
}
/*!
* \brief Value <= 0 epsilon considered
* \return
*/
bool isNegativeWithEpsilonConsidered() const
{
return !this->isZeroEpsilonConsidered() && this->m_value < 0;
}
/*!
* \brief Stream to DBus <<
* \param argument
*/
virtual void marshallToDbus(QDBusArgument &argument) const;
/*!
* \brief Stream from DBus >>
* \param argument
*/
virtual void unmarshallFromDbus(const QDBusArgument &argument);
/*!
* \brief Register metadata of unit and quantity
*/
static void registerMetadata();
};
} // namespace
} // namespace
#endif // guard