Enhancements to QxtCurrency and patches for more current compilers

This commit is contained in:
Dee Holtsclaw 2012-02-29 23:03:33 -05:00
parent 010875460f
commit b039ef746b
2 changed files with 36 additions and 25 deletions

View File

@ -33,7 +33,8 @@
#ifndef QT_NO_DEBUG
#include <QDebug>
#endif
#include <stdlib.h>
#include <stdint.h>
/*!
* \class QxtCurrency
* \inmodule QxtCore
@ -445,6 +446,10 @@ QList<QxtCurrency::Pair> QxtCurrency::amortize(QxtCurrency P, double r, int n,
Constructs a currency object from a pre-adjusted integer value \a v. The
value is expected to already assume 4 decimal places so you should first
multiply by 10000LL if this is not the case.
\warning This constructor is probably ill-advised. At least as documented.
Propose a static method for this conversion which takes a CY and enabled
for Windows. A corresponding operator CY() should also be considered.
*/
/*! \fn QxtCurrency QxtCurrency::abs() const
@ -511,14 +516,11 @@ QList<QxtCurrency::Pair> QxtCurrency::amortize(QxtCurrency P, double r, int n,
/*! \fn QxtCurrency QxtCurrency::operator+(const QxtCurrency &rhs) const
Returns the result of adding the value \a rhs to the current value.
*/
/*! \fn QxtCurrency QxtCurrency::operator+(int rhs) const
\overload
Various overrides are also provided for integral and floating point values.
*/
/*! \fn QxtCurrency QxtCurrency::operator+(double rhs) const
\overload
\internal
*/
/*! \fn QxtCurrency& QxtCurrency::operator+=(const QxtCurrency &rhs)
@ -530,14 +532,11 @@ QList<QxtCurrency::Pair> QxtCurrency::amortize(QxtCurrency P, double r, int n,
Returns the result of subtracting the value \a rhs from the current
value.
*/
/*! \fn QxtCurrency QxtCurrency::operator-(int rhs) const
\overload
Various overrides are also provided for integral and floating point values.
*/
/*! \fn QxtCurrency QxtCurrency::operator-(double rhs) const
\overload
\internal
*/
/*! \fn QxtCurrency& QxtCurrency::operator-=(const QxtCurrency &rhs)
@ -549,14 +548,11 @@ QList<QxtCurrency::Pair> QxtCurrency::amortize(QxtCurrency P, double r, int n,
/*! \fn QxtCurrency QxtCurrency::operator*(const QxtCurrency &rhs) const
Returns the result of multiplying the current value by \a rhs.
*/
/*! \fn QxtCurrency& QxtCurrency::operator*(int rhs) const
\overload
Various overrides are also provided for integral and floating point values.
*/
/*! \fn QxtCurrency& QxtCurrency::operator*(double rhs) const
\overload
\internal
*/
/*! \fn QxtCurrency& QxtCurrency::operator*=(const QxtCurrency &rhs)
@ -567,14 +563,11 @@ QList<QxtCurrency::Pair> QxtCurrency::amortize(QxtCurrency P, double r, int n,
/*! \fn QxtCurrency QxtCurrency::operator/(const QxtCurrency &rhs) const
Returns the result of dividing the current value by \a rhs.
*/
/*! \fn QxtCurrency QxtCurrency::operator/(int rhs) const
\overload
Various overrides are also provided for integral and floating point values.
*/
/*! \fn QxtCurrency QxtCurrency::operator/(double rhs) const
\overload
\internal
*/
/*! \fn QxtCurrency& QxtCurrency::operator/=(const QxtCurrency &rhs)

View File

@ -39,6 +39,8 @@
#include <limits>
#include <QVariant>
#include <QTextStream>
#include <boost/utility.hpp>
#include <boost/type_traits.hpp>
//////////////////////////////////////////////////////////////////////////////
// Supporting functions
@ -104,12 +106,16 @@ public:
return result;
}
// Add an integer to a currency value
QxtCurrency operator+(int rhs) const
#ifndef qdoc
template<typename T>
typename boost::enable_if<boost::is_integral<T>, QxtCurrency>::type
operator+(T &rhs) const
{
QxtCurrency result;
result.value = value + static_cast<qlonglong>(rhs) * 10000;
return result;
}
#endif
// Add a double to a currency value
QxtCurrency operator+(double rhs) const
{
@ -131,12 +137,16 @@ public:
return result;
}
// Subtract an integer from a currency value
QxtCurrency operator-(int rhs) const
#ifndef qdoc
template<typename T>
typename boost::enable_if<boost::is_integral<T>, QxtCurrency>::type
operator-(T &rhs) const
{
QxtCurrency result;
result.value = value - static_cast<qlonglong>(rhs) * 10000LL;
return result;
}
#endif
// Subtract a double from a currency value
QxtCurrency operator-(double rhs) const
{
@ -158,12 +168,16 @@ public:
return result;
}
// Multiply a currency value by an integer
QxtCurrency operator*(int rhs) const
#ifndef qdoc
template<typename T>
typename boost::enable_if<boost::is_integral<T>, QxtCurrency>::type
operator*(T &rhs) const
{
QxtCurrency result;
result.value = value * static_cast<qlonglong>(rhs);
return result;
}
#endif
// Multiply a currency value by a double
QxtCurrency operator*(double rhs) const
{
@ -185,12 +199,16 @@ public:
return result;
}
// Divide a currency value by an integer
QxtCurrency operator/(int rhs) const
#ifndef qdoc
template<typename T>
typename boost::enable_if<boost::is_integral<T>, QxtCurrency>::type
operator/(T &rhs) const
{
QxtCurrency result;
result.value = value / static_cast<qlonglong>(rhs);
return result;
}
#endif
// Divide a currency value by a double
QxtCurrency operator/(double rhs) const
{