OpenMAMA C++ API
Wombat::MamaPrice Class Reference

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 &copy)
 
 ~MamaPrice ()
 
MamaPriceoperator= (const MamaPrice &rhs)
 
MamaPriceoperator+= (const MamaPrice &rhs)
 
MamaPriceoperator-= (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. More...
 
MamaPrice operator- (double rhs) const
 Subtraction operator for double. More...
 
MamaPrice operator- () const
 Negation operator. More...
 
MamaPrice operator+ (const MamaPrice &rhs) const
 Addition operator. More...
 
MamaPrice operator+ (double rhs) const
 Addition operator for double. More...
 
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. More...
 
void negate ()
 Negate the price value. More...
 
bool isZero () const
 Return whether the price has a value equivalent to zero. More...
 
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. More...
 
static mamaPricePrecision denom2Precision (mama_i32_t denominator)
 Return the appropriate precision code for a given fractional denominator. More...
 
static mama_i32_t precision2Decimals (mamaPricePrecision precision)
 Return the number of decimal places for a given precision code. More...
 
static mama_i32_t precision2Denom (mamaPricePrecision precision)
 Return the fractional denominator for a given precision code. More...
 

Detailed Description

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:

  • a number of decimal places,
  • a fractional denominator that are powers of two, and
  • hints for special denominators used in the finance industry (e.g., halves of 32nds).

Constructor & Destructor Documentation

§ MamaPrice() [1/3]

Wombat::MamaPrice::MamaPrice ( )

§ MamaPrice() [2/3]

Wombat::MamaPrice::MamaPrice ( double  value,
mamaPricePrecision  precision = MAMA_PRICE_PREC_100 
)

§ MamaPrice() [3/3]

Wombat::MamaPrice::MamaPrice ( const MamaPrice copy)

§ ~MamaPrice()

Wombat::MamaPrice::~MamaPrice ( )

Member Function Documentation

§ operator=()

MamaPrice& Wombat::MamaPrice::operator= ( const MamaPrice rhs)

§ operator+=()

MamaPrice& Wombat::MamaPrice::operator+= ( const MamaPrice rhs)

§ operator-=()

MamaPrice& Wombat::MamaPrice::operator-= ( const MamaPrice rhs)

§ operator==() [1/2]

bool Wombat::MamaPrice::operator== ( const MamaPrice rhs) const

§ operator==() [2/2]

bool Wombat::MamaPrice::operator== ( double  rhs) const

§ operator!=() [1/2]

bool Wombat::MamaPrice::operator!= ( const MamaPrice rhs) const
inline

§ operator!=() [2/2]

bool Wombat::MamaPrice::operator!= ( double  rhs) const
inline

§ operator<() [1/2]

bool Wombat::MamaPrice::operator< ( const MamaPrice rhs) const

§ operator<() [2/2]

bool Wombat::MamaPrice::operator< ( double  rhs) const

§ operator>() [1/2]

bool Wombat::MamaPrice::operator> ( const MamaPrice rhs) const

§ operator>() [2/2]

bool Wombat::MamaPrice::operator> ( double  rhs) const

§ operator-() [1/3]

MamaPrice Wombat::MamaPrice::operator- ( const MamaPrice rhs) const
inline

Subtraction operator.

Note: this operator creates a temporary object.

References getPrecision(), and getValue().

§ operator-() [2/3]

MamaPrice Wombat::MamaPrice::operator- ( double  rhs) const
inline

Subtraction operator for double.

Note: this operator creates a temporary object.

§ operator-() [3/3]

MamaPrice Wombat::MamaPrice::operator- ( ) const
inline

Negation operator.

Note: this operator creates a temporary object.

§ operator+() [1/2]

MamaPrice Wombat::MamaPrice::operator+ ( const MamaPrice rhs) const
inline

Addition operator.

Note: this operator creates a temporary object.

References getPrecision(), and getValue().

§ operator+() [2/2]

MamaPrice Wombat::MamaPrice::operator+ ( double  rhs) const
inline

Addition operator for double.

Note: this operator creates a temporary object.

§ compare()

double Wombat::MamaPrice::compare ( const MamaPrice rhs) const

§ clear()

void Wombat::MamaPrice::clear ( )

§ set()

void Wombat::MamaPrice::set ( double  priceValue,
mamaPriceHints  hints = 0 
)

§ setValue()

void Wombat::MamaPrice::setValue ( double  value)

§ setPrecision()

void Wombat::MamaPrice::setPrecision ( mamaPricePrecision  precision)

§ setHints()

void Wombat::MamaPrice::setHints ( mamaPriceHints  hints)

§ setIsValidPrice()

void Wombat::MamaPrice::setIsValidPrice ( bool  valid)

§ getValue()

double Wombat::MamaPrice::getValue ( ) const

Referenced by operator+(), and operator-().

§ getPrecision()

mamaPricePrecision Wombat::MamaPrice::getPrecision ( ) const

Referenced by operator+(), and operator-().

§ getHints()

mamaPriceHints Wombat::MamaPrice::getHints ( ) const

§ getIsValidPrice()

bool Wombat::MamaPrice::getIsValidPrice ( ) const

§ setFromString()

void Wombat::MamaPrice::setFromString ( const char *  str)

§ getAsString() [1/2]

void Wombat::MamaPrice::getAsString ( char *  result,
mama_size_t  maxLen 
) const

§ getAsString() [2/2]

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).

§ negate()

void Wombat::MamaPrice::negate ( )

Negate the price value.

Hints and precisions are not affected.

§ isZero()

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.

§ decimals2Precision()

static mamaPricePrecision Wombat::MamaPrice::decimals2Precision ( mama_i32_t  places)
static

Return the appropriate precision code for a given number of decimal places.

§ denom2Precision()

static mamaPricePrecision Wombat::MamaPrice::denom2Precision ( mama_i32_t  denominator)
static

Return the appropriate precision code for a given fractional denominator.

§ precision2Decimals()

static mama_i32_t Wombat::MamaPrice::precision2Decimals ( mamaPricePrecision  precision)
static

Return the number of decimal places for a given precision code.

§ precision2Denom()

static mama_i32_t Wombat::MamaPrice::precision2Denom ( mamaPricePrecision  precision)
static

Return the fractional denominator for a given precision code.

§ getCValue() [1/2]

mamaPrice Wombat::MamaPrice::getCValue ( )

§ getCValue() [2/2]

const mamaPrice Wombat::MamaPrice::getCValue ( ) const