Class USDollarBaseExchange
The class
USDollarBaseExchange inherits from
RWExchangeImpl<T>, and implements a currency conversion method that converts a source currency to a US Dollar base, then converts the US Dollar base to a target currency.
Here is the code that declares the class:
class USDollarBaseExchange : public RWExchangeImpl<T>
{
public:
// Constructors ---------------------------------------------------
USDollarBaseExchange();
USDollarBaseExchange( const USDollarBaseExchange<T>& e );
USDollarBaseExchange( const RWCString& source,
const RWCString& target,
double srcToUsdFactor,
double usdToTrgFactor );
// Public Member Functions ----------------------------------------
// Inherited from RWExchangeImpl
// Return a copy of self off the heap. The copy ctor in the
// handle class RWExchange<T> group needs this function
virtual RWExchangeImpl<T>* clone() const;
// Performs the exchange.
virtual RWMoney<T> exchange( const RWMoney<T>& m ) const;
// Returns the name of this exchange class
virtual RWCString name() const { return "USDollarBaseMethod"; }
// Accessors ----------------------------------------------------
double sourceToUsdFactor() const { return sourceToUsdFactor_; }
double usdToTargetFactor() const { return usdToTargetFactor_; }
// From RWExchangeImpl
//RWCString source() const;
//RWCString target() const;
// Mutators -----------------------------------------------------
void setSourceToUsdFactor( double f ) { sourceToUsdFactor_ = f; }
void setUsdToTargetFactor( double f ) { usdToTargetFactor_ = f; }
// From RWExchangeImpl
//void setSource( const RWCString& src );
//void setTarget( const RWCString& trg );
// Assignment Operator
USDollarBaseExchange<T>& operator=
( const USDollarBaseExchange<T>& );
private:
double sourceToUsdFactor_;
double usdToTargetFactor_;
};
First, this class declares a default and copy constructor, and a constructor that provides a source currency mnemonic, a target currency mnemonic, a conversion factor for source to US Dollars, and a conversion factor for US Dollars to target.
Next, it adds definitions for the following inherited virtual functions, and for the assignment operator:
clone() -- Returns a copy of self off the heap.
exchange() -- Performs the conversion.
name() -- Returns the name of this conversion method, in this case
USDollarBaseMethod.
operator() After defining the virtual functions, the class defines sourceToUsDFactor() and usdToTargetFactor(), which return the conversion factors required for this method of conversion. Similarly, it defines functions setSourceToUsDFactor() and setUsdToTarget, which allow the conversion factors to be set.