SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
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 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)
 
 RWMoneyCalculator (const RWMoneyCalculator< T > &calc)
 
 RWMoneyCalculator (RoundMethod rm, unsigned int accuracy, 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 ()
 
RWExchangeFactory< T > exchangeFactory () const
 
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>
Performs algebraic operations when the money operands in an equation are not of the same currency.
Definition moneycalc.h:101

Conversion Policies

Four conversion policies are available:

  • No Conversion. Any operations performed on monies of different currencies will throw an exception.
  • Base Currency Conversion. When arithmetic operations are performed on monies of different currencies both operands will first be converted to the base currency. The operation will then be performed and the result returned in the base currency.
  • Target Currency Conversion. When arithmetic operations are performed on monies of different currencies, the source operand (first argument) is converted to the target operand (second argument) currency and the result is returned in the target currency.
  • Source Currency Conversion. When arithmetic operations are performed on monies of different currencies, the target operand (second argument) is converted to the source operand (first argument) currency and the result is returned in the source currency.

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:

  • Don't round. No rounding will occur, and accuracy is ignored.
  • Round up. Always add one to the digit at the specified accuracy decimal place, then truncate any digits to the right.
  • Round down. Truncate all digits to the right of the specified accuracy decimal place.
  • Plain. If the digit one to the right of the specified accuracy decimal place is greater than a comparison digit, increase the digit at the accuracy position by one and truncate all numbers to the right. Otherwise, truncate all digits to the right of the accuracy place digit.
  • Bankers. If the digit one to the right of the specified accuracy decimal place is equal to a comparison digit, round so that the digit at the specified accuracy position is even. If the digit one to the right of the specified accuracy position is greater than a comparison digit, increment by one the digit at the specified accuracy position. If the digit one to the right of the specified accuracy position is less than a comparison digit, truncate all numbers to the right of the accuracy position.

Member Enumeration Documentation

◆ ConversionType

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

◆ RoundMethod

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

◆ RWMoneyCalculator() [1/5]

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

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

◆ RWMoneyCalculator() [2/5]

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

Copy constructor.

◆ RWMoneyCalculator() [3/5]

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.

◆ RWMoneyCalculator() [4/5]

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.

◆ RWMoneyCalculator() [5/5]

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

◆ abs()

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

Returns the absolute value of the parameter.

◆ accuracy()

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

Returns the accuracy for this RWMoneyCalculator object.

◆ add()

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.

◆ baseCurrency()

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

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

◆ conversionType()

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

Returns the current conversion type for this RWMoneyCalculator object.

◆ divide()

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.

◆ equal()

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.

◆ exchangeFactory() [1/2]

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.

◆ exchangeFactory() [2/2]

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

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

◆ greaterThan()

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.

◆ greaterThanOrEqual()

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.

◆ greaterThanZero()

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

Tests whether the indicated value is greater than zero.

◆ isZero()

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

Tests whether the indicated value is equal to zero.

◆ lessThan()

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.

◆ lessThanOrEqual()

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.

◆ lessThanZero()

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

Tests whether the indicated value is less than zero.

◆ multiply() [1/2]

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.

◆ multiply() [2/2]

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.

◆ operator=()

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

Assignment operator.

◆ round()

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.

◆ roundDigit()

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

Returns the current value for the round digit.

◆ roundMethod()

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

Returns the rounding method for this RWMoneyCalculator object.

◆ sameCurrency()

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.

◆ setAccuracy()

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

Sets the accuracy value for this RWMoneyCalculator object.

◆ setConversionType()

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

Sets the conversion type for this RWMoneyCalculator object.

◆ setExchangeFactory()

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

Sets the exchange factory used by the calculator.

◆ setRoundDigit()

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

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

◆ setRoundMethod()

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

Sets the rounding method for the calculator.

◆ subtract()

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