SourcePro C++ 12.0 |
SourcePro® C++ API Reference Guide |
SourcePro C++ Documentation Home |
Represents a specified amount of money in a specified currency. More...
#include <rw/currency/money.h>
Public Member Functions | |
RWMoney () | |
RWMoney (const RWMoney< T > &m) | |
RWMoney (const T &amount, const RWCString ¤cyMnemonic) | |
RWMoney (const RWCString ¤cyMnemonic) | |
RWCString | currency () const |
T | amount () const |
void | setCurrency (const RWCString ¤cyMnemonic) |
void | setAmount (const T &amount) |
RWMoney< T > & | operator- () |
RWMoney< T > & | operator= (const RWMoney< T > &rhs) |
RWMoney< T > & | operator+= (const RWMoney< T > &rhs) |
RWMoney< T > & | operator-= (const RWMoney< T > &rhs) |
RWMoney< T > & | operator*= (const T &rhs) |
RWMoney< T > & | operator/= (const T &rhs) |
void | saveOn (RWvostream &) const |
void | saveOn (RWFile &) const |
void | restoreFrom (RWvistream &) |
void | restoreFrom (RWFile &) |
Related Functions | |
(Note that these are not member functions.) | |
template<class T > | |
bool | operator== (const RWMoney< T > &l, const RWMoney< T > &r) |
template<class T > | |
bool | operator< (const RWMoney< T > &l, const RWMoney< T > &r) |
template<class T > | |
bool | operator> (const RWMoney< T > &lhs, const RWMoney< T > &rhs) |
template<class T > | |
bool | operator!= (const RWMoney< T > &lhs, const RWMoney< T > &rhs) |
template<class T > | |
bool | operator>= (const RWMoney< T > &lhs, const RWMoney< T > &rhs) |
template<class T > | |
bool | operator<= (const RWMoney< T > &lhs, const RWMoney< T > &rhs) |
template<class T > | |
RWMoney< T > | operator- (const RWMoney< T > &lhs, const RWMoney< T > &rhs) |
template<class T > | |
RWMoney< T > | operator+ (const RWMoney< T > &lhs, const RWMoney< T > &rhs) |
template<class T > | |
RWMoney< T > | operator* (const RWMoney< T > &lhs, const T &rhs) |
template<class T > | |
RWMoney< T > | operator* (const T &lhs, const RWMoney< T > &rhs) |
template<class T > | |
RWMoney< T > | operator/ (const RWMoney< T > &lhs, const T &rhs) |
template<class T > | |
RWvostream & | operator<< (RWvostream &strm, const RWMoney< T > &n) |
template<class T > | |
RWvistream & | operator>> (RWvistream &strm, RWMoney< T > &n) |
template<class T > | |
RWFile & | operator<< (RWFile &f, const RWMoney< T > &n) |
template<class T > | |
RWFile & | operator>> (RWFile &f, RWMoney< T > &n) |
template<class T > | |
RWMoney< T > | round (const RWMoney< T > &x, unsigned int places) |
Class RWMoney<T> provides a mapping between an amount and a currency, by encapsulating a decimal value and referencing a currency. In C++, the value is an arbitrary decimal type specified as a template parameter.
When RWMoney objects are used in arithmetic operations, all operands must be the same currency. If the currencies for RWMoney operands used in the same equation differ, the operator will throw an exception. Similarly, all assignments to RWMoney objects must have the same currency as the original object. If not, an exception is thrown.
Operations between monies of different currencies may be performed using class RWMoneyCalculator<T>.
#include <rw/currency/money.h> RWMoney<double> m(1.25, "CAD");
Here is an example assignment and some arithmetic calculations:
. . . RWMoney<RWDecimal64> x("1.23","USD"), y("9.87","USD"), z("7.99","CAD"); RWMoney<RWDecimal64> s("0","USD"); s = x + y; // Okay, same currencies s = y - z; // Error, different currencies. Exception thrown. s = x; // Okay, same currencies s = z; // Error, different currencies. Exception thrown. . . .
Constructs a money object with the given amount and currency.
Constructs a money object with the given currency and amount equal to zero.
T RWMoney< T >::amount | ( | ) | const [inline] |
Returns the amount.
Returns the currency's mnemonic
Sets contents of self to self times rhs.
Sets contents of self to self plus rhs.
Returns negation of self. Returned money object will have the same currency as self, but amount will be the negative of self.
Sets contents of self to self minus rhs.
Sets contents of self to self divided by rhs.
Sets contents of self to rhs.
void RWMoney< T >::restoreFrom | ( | RWvistream & | ) |
Restore from a virtual stream.
void RWMoney< T >::saveOn | ( | RWvostream & | ) | const |
Persist to a virtual stream.
void RWMoney< T >::setAmount | ( | const T & | amount | ) | [inline] |
Sets the amount.
Sets the currency mnemonic
Inequality operator.
Multiplication operator.
Multiplication operator.
RWMoney< T > operator+ | ( | const RWMoney< T > & | lhs, | |
const RWMoney< T > & | rhs | |||
) | [related] |
Addition operator.
RWMoney< T > operator- | ( | const RWMoney< T > & | lhs, | |
const RWMoney< T > & | rhs | |||
) | [related] |
Subtraction operator.
Division operator.
Less than operator.
Saves the object to an RWFile.
RWvostream & operator<< | ( | RWvostream & | strm, | |
const RWMoney< T > & | n | |||
) | [related] |
Saves the object to a virtual stream.
Less than or equal to operator.
Equality operator.
Greater than operator.
Greater than or equal to operator.
Restores a object from an RWFile.
RWvistream & operator>> | ( | RWvistream & | strm, | |
RWMoney< T > & | n | |||
) | [related] |
Restores a object from a virtual stream.
Rounds the amount to the indicated number of decimal places. See the description of class RWMoneyCalculator for a discussion of the available rounding methods.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.