SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWMoney< T > Class Template Reference

Represents a specified amount of money in a specified currency. More...

#include <rw/currency/money.h>

Public Member Functions

 RWMoney ()
 
 RWMoney (const RWCString &currencyMnemonic)
 
 RWMoney (const RWMoney< T > &m)
 
 RWMoney (const T &amount, const RWCString &currencyMnemonic)
 
amount (void) const
 
RWCString currency (void) const
 
RWMoney< T > & operator*= (const T &rhs)
 
RWMoney< T > & operator+= (const RWMoney< T > &rhs)
 
RWMoney< T > & operator- (void)
 
RWMoney< T > & operator-= (const RWMoney< T > &rhs)
 
RWMoney< T > & operator/= (const T &rhs)
 
RWMoney< T > & operator= (const RWMoney< T > &rhs)
 
void restoreFrom (RWFile &)
 
void restoreFrom (RWvistream &)
 
void saveOn (RWFile &) const
 
void saveOn (RWvostream &) const
 
void setAmount (const T &amount)
 
void setCurrency (const RWCString &currencyMnemonic)
 

Related Symbols

(Note that these are not member symbols.)

template<class T >
bool 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 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 >
bool operator< (const RWMoney< T > &l, const RWMoney< T > &r)
 
template<class T >
RWFileoperator<< (RWFile &f, const RWMoney< T > &n)
 
template<class T >
RWvostreamoperator<< (RWvostream &strm, const RWMoney< T > &n)
 
template<class T >
bool operator<= (const RWMoney< T > &lhs, const RWMoney< T > &rhs)
 
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 >
RWFileoperator>> (RWFile &f, RWMoney< T > &n)
 
template<class T >
RWvistreamoperator>> (RWvistream &strm, RWMoney< T > &n)
 
template<class T >
RWMoney< T > round (const RWMoney< T > &x, unsigned int places)
 

Detailed Description

template<class T>
class RWMoney< T >

Class RWMoney 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.

Synopsis
#include <rw/currency/money.h>
RWMoney<double> m(1.25, "CAD");
Represents a specified amount of money in a specified currency.
Definition money.h:67
Example

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.

Constructor & Destructor Documentation

◆ RWMoney() [1/4]

template<class T >
RWMoney< T >::RWMoney ( )

Default constructor. Behavior is undefined.

◆ RWMoney() [2/4]

template<class T >
RWMoney< T >::RWMoney ( const RWMoney< T > & m)

Copy constructor.

◆ RWMoney() [3/4]

template<class T >
RWMoney< T >::RWMoney ( const T & amount,
const RWCString & currencyMnemonic )

Constructs a money object with the given amount and currency.

◆ RWMoney() [4/4]

template<class T >
RWMoney< T >::RWMoney ( const RWCString & currencyMnemonic)

Constructs a money object with the given currency and amount equal to zero.

Member Function Documentation

◆ amount()

template<class T >
T RWMoney< T >::amount ( void ) const
inline

Returns the amount.

◆ currency()

template<class T >
RWCString RWMoney< T >::currency ( void ) const
inline

Returns the currency's mnemonic

◆ operator*=()

template<class T >
RWMoney< T > & RWMoney< T >::operator*= ( const T & rhs)
inline

Sets contents of self to self times rhs.

◆ operator+=()

template<class T >
RWMoney< T > & RWMoney< T >::operator+= ( const RWMoney< T > & rhs)
inline

Sets contents of self to self plus rhs.

◆ operator-()

template<class T >
RWMoney< T > & RWMoney< T >::operator- ( void )
inline

Returns negation of self. Returned money object will have the same currency as self, but amount will be the negative of self.

◆ operator-=()

template<class T >
RWMoney< T > & RWMoney< T >::operator-= ( const RWMoney< T > & rhs)
inline

Sets contents of self to self minus rhs.

◆ operator/=()

template<class T >
RWMoney< T > & RWMoney< T >::operator/= ( const T & rhs)
inline

Sets contents of self to self divided by rhs.

◆ operator=()

template<class T >
RWMoney< T > & RWMoney< T >::operator= ( const RWMoney< T > & rhs)
inline

Sets contents of self to rhs.

◆ restoreFrom() [1/2]

template<class T >
void RWMoney< T >::restoreFrom ( RWFile & )

Restore from an RWFile.

◆ restoreFrom() [2/2]

template<class T >
void RWMoney< T >::restoreFrom ( RWvistream & )

Restore from a virtual stream.

◆ saveOn() [1/2]

template<class T >
void RWMoney< T >::saveOn ( RWFile & ) const

Persist to an RWFile.

◆ saveOn() [2/2]

template<class T >
void RWMoney< T >::saveOn ( RWvostream & ) const

Persist to a virtual stream.

◆ setAmount()

template<class T >
void RWMoney< T >::setAmount ( const T & amount)
inline

Sets the amount.

◆ setCurrency()

template<class T >
void RWMoney< T >::setCurrency ( const RWCString & currencyMnemonic)
inline

Sets the currency mnemonic

Friends And Related Symbol Documentation

◆ operator!=()

template<class T >
bool operator!= ( const RWMoney< T > & lhs,
const RWMoney< T > & rhs )
related

Inequality operator.

◆ operator*() [1/2]

template<class T >
RWMoney< T > operator* ( const RWMoney< T > & lhs,
const T & rhs )
related

Multiplication operator.

◆ operator*() [2/2]

template<class T >
RWMoney< T > operator* ( const T & lhs,
const RWMoney< T > & rhs )
related

Multiplication operator.

◆ operator+()

template<class T >
RWMoney< T > operator+ ( const RWMoney< T > & lhs,
const RWMoney< T > & rhs )
related

Addition operator.

◆ operator-()

template<class T >
RWMoney< T > operator- ( const RWMoney< T > & lhs,
const RWMoney< T > & rhs )
related

Subtraction operator.

◆ operator/()

template<class T >
RWMoney< T > operator/ ( const RWMoney< T > & lhs,
const T & rhs )
related

Division operator.

◆ operator<()

template<class T >
bool operator< ( const RWMoney< T > & l,
const RWMoney< T > & r )
related

Less than operator.

◆ operator<<() [1/2]

template<class T >
RWFile & operator<< ( RWFile & f,
const RWMoney< T > & n )
related

Saves the object to an RWFile.

◆ operator<<() [2/2]

template<class T >
RWvostream & operator<< ( RWvostream & strm,
const RWMoney< T > & n )
related

Saves the object to a virtual stream.

◆ operator<=()

template<class T >
bool operator<= ( const RWMoney< T > & lhs,
const RWMoney< T > & rhs )
related

Less than or equal to operator.

◆ operator==()

template<class T >
bool operator== ( const RWMoney< T > & l,
const RWMoney< T > & r )
related

Equality operator.

◆ operator>()

template<class T >
bool operator> ( const RWMoney< T > & lhs,
const RWMoney< T > & rhs )
related

Greater than operator.

◆ operator>=()

template<class T >
bool operator>= ( const RWMoney< T > & lhs,
const RWMoney< T > & rhs )
related

Greater than or equal to operator.

◆ operator>>() [1/2]

template<class T >
RWFile & operator>> ( RWFile & f,
RWMoney< T > & n )
related

Restores a object from an RWFile.

◆ operator>>() [2/2]

template<class T >
RWvistream & operator>> ( RWvistream & strm,
RWMoney< T > & n )
related

Restores a object from a virtual stream.

◆ round()

template<class T >
RWMoney< T > round ( const RWMoney< T > & x,
unsigned int places )
related

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 © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.