SourcePro® API Reference Guide

 
List of all members | Public Types | Public Member Functions
RWMoneyCalculator< T > Class Template Reference

Performs algebraic operations when the money operands in an equation are not of the same currency. More...

#include <rw/currency/moneycalc.h>

Public Types

enum  ConversionType { noConversion, base, target, source }
 
enum  RoundMethod {
  noRounding, up, down, plain,
  bankers
}
 

Public Member Functions

 RWMoneyCalculator ()
 
 RWMoneyCalculator (const RWMoneyCalculator< T > &calc)
 
 RWMoneyCalculator (RoundMethod rm, unsigned int accuracy, unsigned int roundDigit=5)
 
 RWMoneyCalculator (const RWExchangeFactory< T > &ef, ConversionType ct, const RWCString &baseCurr="", RoundMethod rm=noRounding, unsigned int accuracy=2, unsigned int roundDigit=5)
 
 RWMoneyCalculator (const RWExchangeRateTable &ert, ConversionType ct, const RWCString &baseCurr="", RoundMethod rm=noRounding, unsigned int accuracy=2, unsigned int roundDigit=5)
 
RWMoney< T > abs (const RWMoney< T > &x) const
 
unsigned int accuracy () const
 
RWMoney< T > add (const RWMoney< T > &lhs, const RWMoney< T > &rhs) const
 
RWCString baseCurrency () const
 
ConversionType conversionType () const
 
RWMoney< T > divide (const RWMoney< T > &lhs, const T &rhs) const
 
bool equal (const RWMoney< T > &lhs, const RWMoney< T > &rhs) const
 
RWExchangeFactory< T > exchangeFactory () const
 
RWExchangeFactory< T > & exchangeFactory ()
 
bool greaterThan (const RWMoney< T > &lhs, const RWMoney< T > &rhs) const
 
bool greaterThanOrEqual (const RWMoney< T > &lhs, const RWMoney< T > &rhs) const
 
bool greaterThanZero (const RWMoney< T > &x) const
 
bool isZero (const RWMoney< T > &x) const
 
bool lessThan (const RWMoney< T > &lhs, const RWMoney< T > &rhs) const
 
bool lessThanOrEqual (const RWMoney< T > &lhs, const RWMoney< T > &rhs) const
 
bool lessThanZero (const RWMoney< T > &x) const
 
RWMoney< T > multiply (const RWMoney< T > &lhs, const T &rhs) const
 
RWMoney< T > multiply (const T &lhs, const RWMoney< T > &rhs) const
 
RWMoneyCalculator< T > & operator= (const RWMoneyCalculator< T > &)
 
RWMoney< T > round (const RWMoney< T > &) const
 
unsigned int roundDigit () const
 
RoundMethod roundMethod () const
 
bool sameCurrency (const RWMoney< T > &lhs, const RWMoney< T > &rhs) const
 
void setAccuracy (unsigned int a)
 
void setConversionType (ConversionType ct)
 
void setExchangeFactory (const RWExchangeFactory< T > &f)
 
void setRoundDigit (unsigned int rd)
 
void setRoundMethod (RoundMethod rm)
 
RWMoney< T > subtract (const RWMoney< T > &lhs, const RWMoney< T > &rhs) const
 

Detailed Description

template<class T>
class RWMoneyCalculator< T >

Class RWMoneyCalculator can perform algebraic operations when the money operands in the equation are not of the same currency. Because some conversion from one currency to another must occur before such an operation can be carried out, RWMoneyCalculator lets you specify a conversion policy for calculator objects.

Synopsis
#include <rw/currency/moneycalc.h>

Conversion Policies

Four conversion policies are available:

Conversions are carried out through the RWExchangeFactory object that is associated with the particular calculator object.

Rounding Policies

In addition to setting the conversion policy, you must set a rounding policy and an accuracy for the calculator. The accuracy specifies how many digits to the right of the decimal points should be reported. Rounding a negative number is equivalent to rounding the absolute value of the negative number, then multiplying the result by negative one. Briefly, the available rounding policies available for RWMoneyCalculator are:

Member Enumeration Documentation

template<class T>
enum RWMoneyCalculator::ConversionType

Enumeration for the currency conversion policy. For details see the Conversion Policies section.

Enumerator
noConversion 

No Conversion

base 

Base currency conversion

target 

Target currency conversion

source 

Source currency conversion

template<class T>
enum RWMoneyCalculator::RoundMethod

Enumeration for rounding method. For details see the Rounding Policies section.

Enumerator
noRounding 

No rounding

up 

Round up

down 

Round down

plain 

Plain

bankers 

Bankers

Constructor & Destructor Documentation

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

Constructs a calculator object that does no rounding or currency conversion.

template<class T>
RWMoneyCalculator< T >::RWMoneyCalculator ( const RWMoneyCalculator< T > &  calc)

Copy constructor.

template<class T>
RWMoneyCalculator< T >::RWMoneyCalculator ( RoundMethod  rm,
unsigned int  accuracy,
unsigned int  roundDigit = 5 
)
inline

Construct a calculator that does rounding, but does not do currency conversion.

template<class T>
RWMoneyCalculator< T >::RWMoneyCalculator ( const RWExchangeFactory< T > &  ef,
ConversionType  ct,
const RWCString baseCurr = "",
RoundMethod  rm = noRounding,
unsigned int  accuracy = 2,
unsigned int  roundDigit = 5 
)
inline

Construct a calculator that does currency conversion and rounding, if other than the default RoundMethod is provided.

template<class T>
RWMoneyCalculator< T >::RWMoneyCalculator ( const RWExchangeRateTable ert,
ConversionType  ct,
const RWCString baseCurr = "",
RoundMethod  rm = noRounding,
unsigned int  accuracy = 2,
unsigned int  roundDigit = 5 
)
inline

Same as above, except use the given exchange rate table to construct the exchange factory argument.

Member Function Documentation

template<class T >
RWMoney< T > RWMoneyCalculator< T >::abs ( const RWMoney< T > &  x) const
inline

Returns the absolute value of the parameter.

template<class T>
unsigned int RWMoneyCalculator< T >::accuracy ( ) const
inline

Returns the accuracy for this RWMoneyCalculator object.

template<class T>
RWMoney<T> RWMoneyCalculator< T >::add ( const RWMoney< T > &  lhs,
const RWMoney< T > &  rhs 
) const

Adds the two RWMoney operands and returns the result.

Addition and subtraction are allowed on monies of different currency types if the conversion type for the calculator object is set to base, target, or source.

template<class T>
RWCString RWMoneyCalculator< T >::baseCurrency ( ) const
inline

Returns the currency that is used when the conversion type is set to base.

template<class T>
ConversionType RWMoneyCalculator< T >::conversionType ( ) const
inline

Returns the current conversion type for this RWMoneyCalculator object.

template<class T >
RWMoney< T > RWMoneyCalculator< T >::divide ( const RWMoney< T > &  lhs,
const T &  rhs 
) const
inline

Divides the first operand by the second and returns the result.

template<class T >
bool RWMoneyCalculator< T >::equal ( const RWMoney< T > &  lhs,
const RWMoney< T > &  rhs 
) const
inline

Tests for equality for monies of the same or different currency types. If the currency types differ, the conversion type for the calculator object must be set to base, target, or source. This allows the values to be converted before they are compared.

template<class T>
RWExchangeFactory<T> RWMoneyCalculator< T >::exchangeFactory ( ) const
inline

Returns the exchange factory that is being used by the calculator.

template<class T>
RWExchangeFactory<T>& RWMoneyCalculator< T >::exchangeFactory ( )
inline

Returns the exchange factory that is being used by the calculator. This version may be used to modify the exchange factory.

template<class T >
bool RWMoneyCalculator< T >::greaterThan ( const RWMoney< T > &  lhs,
const RWMoney< T > &  rhs 
) const
inline

Relational comparisons for monies of the same or different currency types. If the currency types differ, the conversion type for the calculator object must be set to base, target, or source. This allows the values to be converted before they are compared.

template<class T >
bool RWMoneyCalculator< T >::greaterThanOrEqual ( const RWMoney< T > &  lhs,
const RWMoney< T > &  rhs 
) const
inline

Relational comparisons for monies of the same or different currency types. If the currency types differ, the conversion type for the calculator object must be set to base, target, or source. This allows the values to be converted before they are compared.

template<class T >
bool RWMoneyCalculator< T >::greaterThanZero ( const RWMoney< T > &  x) const
inline

Tests whether the indicated value is greater than zero.

template<class T >
bool RWMoneyCalculator< T >::isZero ( const RWMoney< T > &  x) const
inline

Tests whether the indicated value is equal to zero.

template<class T >
bool RWMoneyCalculator< T >::lessThan ( const RWMoney< T > &  lhs,
const RWMoney< T > &  rhs 
) const
inline

Relational comparisons for monies of the same or different currency types. If the currency types differ, the conversion type for the calculator object must be set to base, target, or source. This allows the values to be converted before they are compared.

template<class T >
bool RWMoneyCalculator< T >::lessThanOrEqual ( const RWMoney< T > &  lhs,
const RWMoney< T > &  rhs 
) const
inline

Relational comparisons for monies of the same or different currency types. If the currency types differ, the conversion type for the calculator object must be set to base, target, or source. This allows the values to be converted before they are compared.

template<class T >
bool RWMoneyCalculator< T >::lessThanZero ( const RWMoney< T > &  x) const
inline

Tests whether the indicated value is less than zero.

template<class T >
RWMoney< T > RWMoneyCalculator< T >::multiply ( const RWMoney< T > &  lhs,
const T &  rhs 
) const
inline

Multiplies the first operand by the second and returns the result.

template<class T >
RWMoney< T > RWMoneyCalculator< T >::multiply ( const T &  lhs,
const RWMoney< T > &  rhs 
) const
inline

Multiplies the first operand by the second and returns the result.

template<class T>
RWMoneyCalculator<T>& RWMoneyCalculator< T >::operator= ( const RWMoneyCalculator< T > &  )

Assignment operator.

template<class T>
RWMoney<T> RWMoneyCalculator< T >::round ( const RWMoney< T > &  ) const

Rounds the provided RWMoney value according to the current rounding method and accuracy for RWMoneyCalculator.

template<class T>
unsigned int RWMoneyCalculator< T >::roundDigit ( ) const
inline

Returns the current value for the round digit.

template<class T>
RoundMethod RWMoneyCalculator< T >::roundMethod ( ) const
inline

Returns the rounding method for this RWMoneyCalculator object.

template<class T>
bool RWMoneyCalculator< T >::sameCurrency ( const RWMoney< T > &  lhs,
const RWMoney< T > &  rhs 
) const
inline

Compares whether the given values have the same currency type.

template<class T>
void RWMoneyCalculator< T >::setAccuracy ( unsigned int  a)
inline

Sets the accuracy value for this RWMoneyCalculator object.

template<class T>
void RWMoneyCalculator< T >::setConversionType ( ConversionType  ct)
inline

Sets the conversion type for this RWMoneyCalculator object.

template<class T>
void RWMoneyCalculator< T >::setExchangeFactory ( const RWExchangeFactory< T > &  f)
inline

Sets the exchange factory used by the calculator.

template<class T>
void RWMoneyCalculator< T >::setRoundDigit ( unsigned int  rd)
inline

Sets the value for the rounding digit. The default value is 5.

template<class T>
void RWMoneyCalculator< T >::setRoundMethod ( RoundMethod  rm)
inline

Sets the rounding method for the calculator.

template<class T>
RWMoney<T> RWMoneyCalculator< T >::subtract ( const RWMoney< T > &  lhs,
const RWMoney< T > &  rhs 
) const

Subtracts the second operand from the first and returns the result.

Addition and subtraction are allowed on monies of different currency types if the conversion type for the calculator object is set to base, target, or source.

Copyright © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.