MamaPrice is a special data type for representing floating point numbers that often require special formatting for display purposes, such as prices. More...
#include <MamaPrice.h>
Public Member Functions | |
MamaPrice () | |
MamaPrice (double value, mamaPricePrecision precision=MAMA_PRICE_PREC_100) | |
MamaPrice (const MamaPrice ©) | |
~MamaPrice () | |
MamaPrice & | operator= (const MamaPrice &rhs) |
MamaPrice & | operator+= (const MamaPrice &rhs) |
MamaPrice & | operator-= (const MamaPrice &rhs) |
bool | operator== (const MamaPrice &rhs) const |
bool | operator== (double rhs) const |
bool | operator!= (const MamaPrice &rhs) const |
bool | operator!= (double rhs) const |
bool | operator< (const MamaPrice &rhs) const |
bool | operator< (double rhs) const |
bool | operator> (const MamaPrice &rhs) const |
bool | operator> (double rhs) const |
MamaPrice | operator- (const MamaPrice &rhs) const |
Subtraction operator. | |
MamaPrice | operator- (double rhs) const |
Subtraction operator for double. | |
MamaPrice | operator- () const |
Negation operator. | |
MamaPrice | operator+ (const MamaPrice &rhs) const |
Addition operator. | |
MamaPrice | operator+ (double rhs) const |
Addition operator for double. | |
double | compare (const MamaPrice &rhs) const |
void | clear () |
void | set (double priceValue, mamaPriceHints hints=0) |
void | setValue (double value) |
void | setPrecision (mamaPricePrecision precision) |
void | setHints (mamaPriceHints hints) |
void | setIsValidPrice (bool valid) |
double | getValue () const |
mamaPricePrecision | getPrecision () const |
mamaPriceHints | getHints () const |
bool | getIsValidPrice () const |
void | setFromString (const char *str) |
void | getAsString (char *result, mama_size_t maxLen) const |
const char * | getAsString () const |
Return a string representation of the price. | |
void | negate () |
Negate the price value. | |
bool | isZero () const |
Return whether the price has a value equivalent to zero. | |
mamaPrice | getCValue () |
const mamaPrice | getCValue () const |
Static Public Member Functions | |
static mamaPricePrecision | decimals2Precision (mama_i32_t places) |
Return the appropriate precision code for a given number of decimal places. | |
static mamaPricePrecision | denom2Precision (mama_i32_t denominator) |
Return the appropriate precision code for a given fractional denominator. | |
static mama_i32_t | precision2Decimals (mamaPricePrecision precision) |
Return the number of decimal places for a given precision code. | |
static mama_i32_t | precision2Denom (mamaPricePrecision precision) |
Return the fractional denominator for a given precision code. |
MamaPrice is a special data type for representing floating point numbers that often require special formatting for display purposes, such as prices.
MamaPrice contains the 64-bit (double precision) floating point value and an optional display hint. The set of display hints includes hints for:
Wombat::MamaPrice::MamaPrice | ( | ) |
Wombat::MamaPrice::MamaPrice | ( | double | value, |
mamaPricePrecision | precision = MAMA_PRICE_PREC_100 |
||
) |
Wombat::MamaPrice::MamaPrice | ( | const MamaPrice & | copy | ) |
Wombat::MamaPrice::~MamaPrice | ( | ) |
bool Wombat::MamaPrice::operator== | ( | const MamaPrice & | rhs | ) | const |
bool Wombat::MamaPrice::operator== | ( | double | rhs | ) | const |
bool Wombat::MamaPrice::operator!= | ( | const MamaPrice & | rhs | ) | const |
bool Wombat::MamaPrice::operator!= | ( | double | rhs | ) | const |
bool Wombat::MamaPrice::operator< | ( | const MamaPrice & | rhs | ) | const |
bool Wombat::MamaPrice::operator< | ( | double | rhs | ) | const |
bool Wombat::MamaPrice::operator> | ( | const MamaPrice & | rhs | ) | const |
bool Wombat::MamaPrice::operator> | ( | double | rhs | ) | const |
Subtraction operator.
Note: this operator creates a temporary object.
References getPrecision(), and getValue().
MamaPrice Wombat::MamaPrice::operator- | ( | double | rhs | ) | const |
Subtraction operator for double.
Note: this operator creates a temporary object.
MamaPrice Wombat::MamaPrice::operator- | ( | ) | const |
Negation operator.
Note: this operator creates a temporary object.
Addition operator.
Note: this operator creates a temporary object.
References getPrecision(), and getValue().
MamaPrice Wombat::MamaPrice::operator+ | ( | double | rhs | ) | const |
Addition operator for double.
Note: this operator creates a temporary object.
double Wombat::MamaPrice::compare | ( | const MamaPrice & | rhs | ) | const |
void Wombat::MamaPrice::clear | ( | ) |
void Wombat::MamaPrice::set | ( | double | priceValue, |
mamaPriceHints | hints = 0 |
||
) |
void Wombat::MamaPrice::setValue | ( | double | value | ) |
void Wombat::MamaPrice::setPrecision | ( | mamaPricePrecision | precision | ) |
void Wombat::MamaPrice::setHints | ( | mamaPriceHints | hints | ) |
void Wombat::MamaPrice::setIsValidPrice | ( | bool | valid | ) |
double Wombat::MamaPrice::getValue | ( | ) | const |
Referenced by operator+(), and operator-().
mamaPricePrecision Wombat::MamaPrice::getPrecision | ( | ) | const |
Referenced by operator+(), and operator-().
mamaPriceHints Wombat::MamaPrice::getHints | ( | ) | const |
bool Wombat::MamaPrice::getIsValidPrice | ( | ) | const |
void Wombat::MamaPrice::setFromString | ( | const char * | str | ) |
void Wombat::MamaPrice::getAsString | ( | char * | result, |
mama_size_t | maxLen | ||
) | const |
const char* Wombat::MamaPrice::getAsString | ( | ) | const |
Return a string representation of the price.
Note that the alternative getAsString() method is more efficient because this method must allocate a temporary buffer (automatically destroyed upon object destruction).
void Wombat::MamaPrice::negate | ( | ) |
Negate the price value.
Hints and precisions are not affected.
bool Wombat::MamaPrice::isZero | ( | ) | const |
Return whether the price has a value equivalent to zero.
It may not be exactly 0.0, but we check against +/- epsilon.
|
static |
Return the appropriate precision code for a given number of decimal places.
|
static |
Return the appropriate precision code for a given fractional denominator.
|
static |
Return the number of decimal places for a given precision code.
|
static |
Return the fractional denominator for a given precision code.
mamaPrice Wombat::MamaPrice::getCValue | ( | ) |
const mamaPrice Wombat::MamaPrice::getCValue | ( | ) | const |