BPS C++ API  2.24.4
bpsdecimal.h
Go to the documentation of this file.
1 
4 #ifndef BPSDECIMAL_H
5 #define BPSDECIMAL_H
6 
7 #include "bpscore_global.h"
8 #include <QMetaType>
9 #include <iosfwd>
10 
11 class QTextStream;
12 
87 {
88 public:
89 
93  static int metaType();
94 
98  static BpsDecimal Pi();
99 
106  static BpsDecimal fromString(const char* aString, bool* aOk = 0);
107 
114  static BpsDecimal fromString(const QByteArray& aString, bool* aOk = 0);
115 
122  static BpsDecimal fromString(const QString& aString, bool* aOk = 0);
123 
128 
133  BpsDecimal(const BpsDecimal& aOther);
134 
139  BpsDecimal(qint32 aValue);
140 
145  BpsDecimal(quint32 aValue);
146 
151  BpsDecimal(qlonglong aValue);
152 
157  BpsDecimal(qulonglong aValue);
158 
163  BpsDecimal(double aValue);
164 
170  BpsDecimal(const QString& aString);
171 
177  BpsDecimal(const QByteArray& aString);
178 
184  BpsDecimal(const char* aString);
185 
192  BpsDecimal(const QVariant& aVariant);
193 
194  virtual ~BpsDecimal();
195 
200  operator QVariant() const;
201 
207 
217  QString toString() const;
218 
232  QString toString(int aDecPlaces, int aMaxSize = 36) const;
233 
238  double toDouble() const;
239 
248  qint32 toInt() const;
249 
258  quint32 toUInt() const;
259 
265  qlonglong toLongLong() const;
266 
272  qulonglong toULongLong() const;
273 
279  BpsDecimal& operator=(const BpsDecimal& aOther);
280 
286  BpsDecimal& operator=(qint32 aOther);
287 
293  BpsDecimal& operator=(quint32 aOther);
294 
300  BpsDecimal& operator=(qlonglong aOther);
301 
307  BpsDecimal& operator=(qulonglong aOther);
308 
314  BpsDecimal& operator=(double aOther);
315 
323  BpsDecimal& operator=(const QString& aString);
324 
332  BpsDecimal& operator=(const QByteArray& aString);
333 
341  BpsDecimal& operator=(const char* aString);
342 
350  BpsDecimal& operator=(const QVariant& aVariant);
351 
357 
363 
369 
375 
381  BpsDecimal operator+(const BpsDecimal& aOther) const;
382 
388  BpsDecimal operator-(const BpsDecimal& aOther) const;
389 
395  BpsDecimal operator*(const BpsDecimal& aOther) const;
396 
402  BpsDecimal operator/(const BpsDecimal& aOther) const;
403 
409  BpsDecimal operator%(const BpsDecimal& aOther) const;
410 
417 
424 
431 
438 
445 
451  bool operator==(const BpsDecimal& aOther) const;
452 
458  bool operator!=(const BpsDecimal& aOther) const;
459 
465  bool operator<(const BpsDecimal& aOther) const;
466 
472  bool operator>(const BpsDecimal& aOther) const;
473 
479  bool operator<=(const BpsDecimal& aOther) const;
480 
486  bool operator>=(const BpsDecimal& aOther) const;
487 
493  BpsDecimal div(const BpsDecimal& aOther) const;
494 
500  BpsDecimal min(const BpsDecimal& aOther) const;
501 
507  BpsDecimal max(const BpsDecimal& aOther) const;
508 
514  BpsDecimal power(const BpsDecimal& aOther) const;
515 
521  BpsDecimal rounded(int aDecPlaces) const;
522 
527  BpsDecimal ceil() const;
528 
533  BpsDecimal floor() const;
534 
539  BpsDecimal up() const;
540 
545  BpsDecimal down() const;
546 
550  BpsDecimal abs() const;
551 
556  BpsDecimal exp() const;
557 
562  BpsDecimal ln() const;
563 
568  BpsDecimal log10() const;
569 
574  BpsDecimal sqrt() const;
575 
580  bool isFinite() const;
581 
586  bool isInfinite() const;
587 
592  bool isNegative() const;
593 
598  bool isNaN() const;
599 
604  bool isInteger() const;
605 
607  bool convertTo(QString* aValue, bool* aOk = 0) const;
608  bool convertTo(double* aValue, bool* aOk = 0) const;
609  bool convertTo(qint32* aValue, bool* aOk = 0) const;
610  bool convertTo(quint32* aValue, bool* aOk = 0) const;
611  bool convertTo(qlonglong* aValue, bool* aOk = 0) const;
612  bool convertTo(qulonglong* aValue, bool* aOk = 0) const;
613 
614 private:
615  friend BPSCORE_EXPORT BpsDecimal operator-(const BpsDecimal& aValue);
616  friend BPSCORE_EXPORT QDataStream& operator<<(QDataStream& aStream, const BpsDecimal& aDecimal);
617  friend BPSCORE_EXPORT QDataStream& operator>>(QDataStream& aStream, BpsDecimal& aDecimal);
618  friend BPSCORE_EXPORT uint qHash(const BpsDecimal& aValue, uint aSeed);
619 
620  quint8 mData[16];
622 };
623 
625 Q_DECLARE_METATYPE(BpsDecimal);
626 Q_DECLARE_TYPEINFO(BpsDecimal, Q_MOVABLE_TYPE);
628 
635 
643 
651 
659 
666 BPSCORE_EXPORT std::ostream& operator<<(std::ostream& aStream, const BpsDecimal& aDecimal);
667 
675 
682 BPSCORE_EXPORT uint qHash(const BpsDecimal& aValue, uint aSeed);
683 
684 #endif // BPSDECIMAL_H
Public include file for BPS CORE library macros.
#define BPSCORE_EXPORT
Declare class to be an import from the shared library.
Definition: bpscore_global.h:22
BPSCORE_EXPORT QDataStream & operator<<(QDataStream &aStream, const BpsMargins &aMargins)
Write the margins to a stream.
BPSCORE_EXPORT QDataStream & operator>>(QDataStream &aStream, BpsMargins &aMargins)
Read the margins from a stream.
A class for decimal arithmetics.
Definition: bpsdecimal.h:87
BpsDecimal operator%(const BpsDecimal &aOther) const
Integer divide by other value and return remainder as result.
BpsDecimal & operator=(const QString &aString)
Assign value from a string.
BpsDecimal()
The default constructor initializes the value to NaN.
BpsDecimal operator--(int)
Postfix decrement the value by one.
BPSCORE_EXPORT uint qHash(const BpsDecimal &aValue, uint aSeed)
Returns a hash value, as required by QHash or QSet.
BpsDecimal max(const BpsDecimal &aOther) const
Compare this value with the other and return the larger (nearer towards +Infinity).
QString toString(int aDecPlaces, int aMaxSize=36) const
Converts a decimal value to a string of format [-]9.9.
BpsDecimal & operator=(quint32 aOther)
Assign value from a 32 bit unsigned integer.
BpsDecimal power(const BpsDecimal &aOther) const
Raises this value to the power of the other value and returns the result.
BPSCORE_EXPORT QDebug operator<<(QDebug aDebug, const BpsDecimal &aDecimal)
Write the string representation of a decimal value to a debug stream.
BpsDecimal(const char *aString)
Construct from a decimal string representation.
quint32 toUInt() const
Get the value as unsigned 32 bit integer.
BpsDecimal log10() const
Calculate the logarithm to base ten of this value and return the result.
bool operator==(const BpsDecimal &aOther) const
Compare with other value for equality.
BpsDecimal ceil() const
If the value is not integer, round up to next integer (towards +Infinity).
BpsDecimal & operator%=(const BpsDecimal &aOther)
Integer divide by other value and set remainder as value.
BpsDecimal(double aValue)
Construct from a double value.
bool isInfinite() const
Check if value is infinite.
BpsDecimal & operator++()
Prefix increment the value by one.
BpsDecimal(const QString &aString)
Construct from a decimal string representation.
bool operator<=(const BpsDecimal &aOther) const
Compare if less than or equal to other value.
BpsDecimal(const BpsDecimal &aOther)
The copy constructor.
BpsDecimal operator/(const BpsDecimal &aOther) const
Divide by other value and return result.
BpsDecimal & operator=(const BpsDecimal &aOther)
Assign value from an other decimal.
bool isNegative() const
Check if value is negative.
BPSCORE_EXPORT QDataStream & operator<<(QDataStream &aStream, const BpsDecimal &aDecimal)
Write the binary code of the decimal value to a data stream.
BpsDecimal floor() const
If the value is not integer, round down to next integer (towards -Infinity).
static BpsDecimal fromString(const char *aString, bool *aOk=0)
Convert a string to a decimal value.
BpsDecimal & operator/=(const BpsDecimal &aOther)
Divide by other value.
bool operator>=(const BpsDecimal &aOther) const
Compare if greater than or equal to other value.
static int metaType()
BpsDecimal & operator=(const QByteArray &aString)
Assign value from a string.
BpsDecimal & operator*=(const BpsDecimal &aOther)
Multiply with other value.
BpsDecimal rounded(int aDecPlaces) const
Round to an number of decimal places.
BpsDecimal sqrt() const
Calculate the square root of this value and return the result.
BpsDecimal abs() const
BpsDecimal & operator=(const QVariant &aVariant)
Assign value from a QVariant.
BpsDecimal(qint32 aValue)
Construct from a signed 32 bit integer value.
bool operator>(const BpsDecimal &aOther) const
Compare if greater than other value.
BpsDecimal & operator-=(const BpsDecimal &aOther)
Subtract second value.
BpsDecimal & operator=(qlonglong aOther)
Assign value from a 64 bit signed integer.
static BpsDecimal fromString(const QString &aString, bool *aOk=0)
Convert a string to a decimal value.
BpsDecimal & operator+=(const BpsDecimal &aOther)
Add other value.
BpsDecimal & operator=(qint32 aOther)
Assign value from a 32 bit signed integer.
BpsDecimal & operator=(double aOther)
Assign value from a double.
BpsDecimal operator+(const BpsDecimal &aOther) const
Add two values and return result.
BpsDecimal & operator--()
Prefix decrement the value by one.
static BpsDecimal fromString(const QByteArray &aString, bool *aOk=0)
Convert a string to a decimal value.
qint32 toInt() const
Get the value as signed 32 bit integer.
BPSCORE_EXPORT BpsDecimal operator-(const BpsDecimal &aValue)
Unary prefix minus operator.
BPSCORE_EXPORT QTextStream & operator<<(QTextStream &aStream, const BpsDecimal &aDecimal)
Write the string representation of the decimal value to a text stream.
BpsDecimal(const QByteArray &aString)
Construct from a decimal string representation.
BpsDecimal down() const
If the value is not integer, round down to next integer (towards 0).
QString toString() const
Converts a decimal value to a string.
BPSCORE_EXPORT QDataStream & operator>>(QDataStream &aStream, BpsDecimal &aDecimal)
Read the binary code of the decimal value from a data stream.
BpsDecimal(quint32 aValue)
Construct from a unsigned 32 bit integer value.
bool isNaN() const
Check if value is not a number.
BpsDecimal(qulonglong aValue)
Construct from a 64 bit unsigned integer value.
BpsDecimal(const QVariant &aVariant)
Construct from a QVariant.
qulonglong toULongLong() const
Get the value as 64 bit unsigned integer.
BpsDecimal operator-(const BpsDecimal &aOther) const
Subtract second value and return result.
bool isInteger() const
Check if value is finite and has exponent=0.
BpsDecimal up() const
If the value is not integer, round up to next integer (away from 0).
bool operator<(const BpsDecimal &aOther) const
Compare if less than other value.
bool operator!=(const BpsDecimal &aOther) const
Compare with other value for un-equality.
BpsDecimal & operator=(const char *aString)
Assign value from a string.
BpsDecimal & operator=(qulonglong aOther)
Assign value from a 64 bit unsigned integer.
BpsDecimal operator++(int)
Postfix increment the value by one.
BpsDecimal ln() const
Calculate the natural logarithm (to base e) of this value and return the result.
double toDouble() const
Get the value as double.
BpsDecimal div(const BpsDecimal &aOther) const
Divides this value by the other value and returns the integer part of the result.
BpsDecimal exp() const
Calculate e to the power of this value and return the result.
BpsDecimal min(const BpsDecimal &aOther) const
Compare this value with the other and return the smaller (nearer towards -Infinity).
bool isFinite() const
Check if value is neither infinite nor a NaN.
QVariant toVariant() const
Explicit conversion to QVariant.
BPSCORE_EXPORT std::ostream & operator<<(std::ostream &aStream, const BpsDecimal &aDecimal)
Write the string representation of the decimal value to a std::ostream.
static BpsDecimal Pi()
BpsDecimal(qlonglong aValue)
Construct from a 64 bit signed integer value.
qlonglong toLongLong() const
Get the value as 64 bit signed integer.
BpsDecimal operator*(const BpsDecimal &aOther) const
Multiply with other value and return result.