SourcePro® API Reference Guide

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

Handle class for the abstract body class RWExchangeImpl from which all concrete currency converters derive. More...

#include <rw/currency/currexchange.h>

Public Member Functions

 RWExchange ()
 
 RWExchange (const RWExchange< T > &c)
 
 RWExchange (RWExchangeImpl< T > *impl)
 
RWMoney< T > exchange (const RWMoney< T > &m) const
 
const RWExchangeImpl< T > * impl () const
 
bool isValid () const
 
RWCString name () const
 
RWExchange< T > & operator= (const RWExchange< T > &c)
 
void setImpl (RWExchangeImpl< T > *impl)
 
RWCString source () const
 
RWCString target () const
 

Detailed Description

template<class T>
class RWExchange< T >

Currency exchange objects are responsible for converting money of one currency into money of another currency. They encapsulate the source and target currency mnemonics, an exchange algorithm and any required exchange rates.

RWExchangeImpl is an abstract base class from which all currency implementation classes must derive. Class RWExchange is the handle class, which forwards all conversion requests to its associated implementation class.

Currency Module provides three types of currency exchange objects. The first type implements a triangular exchange algorithm required for converting between local currencies through an intermediate currency, such as the EMU requires for the Euro transition. The second type of exchange object multiplies the source currency amount by the exchange factor to obtain a target amount. The third type of exchange object divides the source currency amount by the exchange factor to obtain the target currency amount. All exchange objects share a common API for performing the actual conversion of money.

Synopsis
#include <rw/currency/currexchange.h>
#include <rw/currency/decimal.h>
#include <rw/currency/divexchange.h>
#include <rw/currency/mp2int.h>
typedef RWDecimal<RWMP2Int> Decimal;
new RWDivisionGroup<Decimal>("LBP", "CAD", 971.8);
Exactly represents a decimal fraction.
Definition decimal.h:246
A collection of currency objects that convert a source currency to a target currency by dividing the ...
Definition divexchggrp.h:69
Handle class for the abstract body class RWExchangeImpl from which all concrete currency converters d...
Definition currexchange.h:69
const RWExchangeImpl< T > * impl() const
Definition currexchange.h:109

Constructor & Destructor Documentation

◆ RWExchange() [1/3]

template<class T >
RWExchange< T >::RWExchange ( )
inline

Default constructor.

◆ RWExchange() [2/3]

template<class T >
RWExchange< T >::RWExchange ( const RWExchange< T > & c)
inline

Makes a (deep) copy of the implementation for currency exchange object c.

◆ RWExchange() [3/3]

template<class T >
RWExchange< T >::RWExchange ( RWExchangeImpl< T > * impl)
inline

Constructs an exchange object with the provided implementation impl. The object's destructor will delete impl.

Member Function Documentation

◆ exchange()

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

Converts the amount m from the source currency to the target currency. If the currency associated with m does not match the source currency of self, an exception is thrown.

◆ impl()

template<class T >
const RWExchangeImpl< T > * RWExchange< T >::impl ( ) const
inline

Returns a pointer to the implementation class.

◆ isValid()

template<class T >
bool RWExchange< T >::isValid ( ) const
inline

Returns true if this exchange object has a valid implementation, false otherwise.

◆ name()

template<class T >
RWCString RWExchange< T >::name ( ) const
inline

Returns the name of the implementation class. Rogue Wave implementation classes return their static data member exchangeMethodName. For example, when an RWExchange object contains an RWTriangularExchange implementation, name() returns RWTriangularExchange::exchangeMethodName.

◆ operator=()

template<class T >
RWExchange< T > & RWExchange< T >::operator= ( const RWExchange< T > & c)
inline

Deletes self's current implementation and clones a copy of the implementation for c.

◆ setImpl()

template<class T >
void RWExchange< T >::setImpl ( RWExchangeImpl< T > * impl)
inline

Sets impl as the implementation for this exchange object.

◆ source()

template<class T >
RWCString RWExchange< T >::source ( ) const
inline

Returns the mnemonic for the source currency.

◆ target()

template<class T >
RWCString RWExchange< T >::target ( ) const
inline

Returns the mnemonic for the target currency.

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