SourcePro® API Reference Guide

 
List of all members | Public Member Functions | Static Public Attributes | Related Functions
RWExchangeRateTable Class Reference

Stores exchange rates as unique pairs of source and target currencies. More...

#include <rw/currency/exchgratetbl.h>

Public Member Functions

 RWExchangeRateTable ()
 
 RWExchangeRateTable (const RWExchangeRateTable &t)
 
bool add (const RWExchangeRate &exchangeRate)
 
bool add (const RWCString &source, const RWCString &target, double convFactor)
 
void clear ()
 
bool contains (const RWCString &source, const RWCString &target) const
 
bool contains (const RWExchangeRate &rate) const
 
size_t entries () const
 
bool findConversionFactor (const RWCString &sourceMnemonic, const RWCString &targetMnemonic, double &factor) const
 
bool findExchangeRate (const RWCString &sourceMnemonic, const RWCString &targetMnemonic, RWExchangeRate &rate) const
 
RWTValSlist< RWExchangeRategetAllExchangeRates () const
 
bool initialize (std::istream &strm)
 
RWExchangeRateTableoperator= (const RWExchangeRateTable &)
 
bool remove (const RWExchangeRate &rate)
 
bool remove (const RWCString &source, const RWCString &target)
 
void restoreFrom (RWvistream &)
 
void restoreFrom (RWFile &)
 
void saveOn (RWvostream &) const
 
void saveOn (RWFile &) const
 
bool setConversionFactor (const RWCString &source, const RWCString &target, double convFactor)
 

Static Public Attributes

static const RWCString conversionFactorTag
 
static const RWCString sourceTag
 
static const RWCString targetTag
 

Related Functions

(Note that these are not member functions.)

RWvostreamoperator<< (RWvostream &s, const RWExchangeRateTable &t)
 
RWFileoperator<< (RWFile &f, const RWExchangeRateTable &t)
 
RWvistreamoperator>> (RWvistream &s, RWExchangeRateTable &t)
 
RWFileoperator>> (RWFile &f, RWExchangeRateTable &t)
 

Detailed Description

Class RWExchangeRateTable stores exchange rates as unique pairs of source and target currencies. No two exchange rates in the table have the same source-target currency pair.

The RWExchangeRateTable class can be initialized from a stream, in particular, from an std::ifstream (file). The format for the stream is:

BEGIN_EXCHANGE
source=
target=
rate=
END_EXCHANGE
Synopsis
#include <rw/currency/exchgratetbl.h>
std::ifstream strm("exchange_rates.txt");
rates.initialize(strm);

Constructor & Destructor Documentation

RWExchangeRateTable::RWExchangeRateTable ( )

Default constructor. Constructs an empty exchange rate table.

RWExchangeRateTable::RWExchangeRateTable ( const RWExchangeRateTable t)

Copy constructor. Copies contents of t to self.

Member Function Documentation

bool RWExchangeRateTable::add ( const RWExchangeRate exchangeRate)

Adds exchangeRate to the table and returns true if there is no exchange rate in the table with the same source and target currency as exchangeRate. If the table already contains an exchange rate with the same source and target currencies as exchangeRate exists, the function returns false without adding to the table.

bool RWExchangeRateTable::add ( const RWCString source,
const RWCString target,
double  convFactor 
)
inline

Adds an exchange rate object with the given source, target and convFactor to the table if none exists, and returns true. If the table already contains an exchange rate with the given source and target, this function returns false without adding to the table.

void RWExchangeRateTable::clear ( )

Removes all exchange rates from the table.

bool RWExchangeRateTable::contains ( const RWCString source,
const RWCString target 
) const

Returns true if the table contains a rate for the given source and target currencies. Returns false otherwise.

bool RWExchangeRateTable::contains ( const RWExchangeRate rate) const

Returns true if the table contains the given rate. Returns false otherwise.

size_t RWExchangeRateTable::entries ( ) const

Returns the number of exchange rates in the table.

bool RWExchangeRateTable::findConversionFactor ( const RWCString sourceMnemonic,
const RWCString targetMnemonic,
double &  factor 
) const

Searches the exchange rate table to find the exchange rate for converting money with currency specified by sourceMnemonic into money in currency specified by targetMnemonic. If the rate is found, the conversion factor is placed in factor and the function returns true. If the rate is not found, the function returns false and factor is unchanged.

bool RWExchangeRateTable::findExchangeRate ( const RWCString sourceMnemonic,
const RWCString targetMnemonic,
RWExchangeRate rate 
) const

Searches the exchange rate table to determine whether an exchange rate for the currency specified by sourceMnemonic into the currency specified by targetMnemonic exists. If an exchange rate is found, it is placed in rate and the function returns true. If an exchange rate is not found, the function returns false and rate is unchanged.

RWTValSlist<RWExchangeRate> RWExchangeRateTable::getAllExchangeRates ( ) const

Returns a list of all the exchange rates in the table.

bool RWExchangeRateTable::initialize ( std::istream &  strm)

Initializes an exchange rate table from the information in strm. Returns false if there is an error in the stream format.

An exchange rate specification begins with the token BEGIN_EXCHANGE on a line by itself. Each attribute of the exchange rate follows, specified as a name/value pair, one per line. The name/value separator is the equal sign `='. The end of an exchange rate specification is indicated by the token END_EXCHANGE. Comment lines start with a # character and are automatically skipped. For example:

# DZD/CAD (Algeria to Canada)
BEGIN_EXCHANGE
source=CAD
target=DZD
rate=35.5
END_EXCHANGE
.
.
.

Name matching is case-insensitive. Valid names for the name/value pairs are:

RWExchangeRateTable& RWExchangeRateTable::operator= ( const RWExchangeRateTable )

Assignment operator.

bool RWExchangeRateTable::remove ( const RWExchangeRate rate)

Removes the given exchange rate. If no such exchange rate was found, this function returns false. Otherwise, it returns true.

bool RWExchangeRateTable::remove ( const RWCString source,
const RWCString target 
)

Removes the exchange rate for the given source and target currencies. If no such exchange rate was found, this function returns false. Otherwise, it returns true.

void RWExchangeRateTable::restoreFrom ( RWvistream )

Restore from a virtual stream.

void RWExchangeRateTable::restoreFrom ( RWFile )

Restore from an RWFile.

void RWExchangeRateTable::saveOn ( RWvostream ) const

Persists to a virtual stream.

void RWExchangeRateTable::saveOn ( RWFile ) const

Persists to an RWFile.

bool RWExchangeRateTable::setConversionFactor ( const RWCString source,
const RWCString target,
double  convFactor 
)

Searches the exchange rate table for an exchange rate with the same source and target currencies as source and target. If one exists, this function replaces its conversion factor with convFactor, and returns true. If one does not exist, this function returns false.

Friends And Related Function Documentation

RWvostream & operator<< ( RWvostream s,
const RWExchangeRateTable t 
)
related

Saves the object to a virtual stream.

RWFile & operator<< ( RWFile f,
const RWExchangeRateTable t 
)
related

Saves the object to a RWFile.

RWvistream & operator>> ( RWvistream s,
RWExchangeRateTable t 
)
related

Restores a object from a virtual stream.

RWFile & operator>> ( RWFile f,
RWExchangeRateTable t 
)
related

Restores a object from a RWFile.

Member Data Documentation

const RWCString RWExchangeRateTable::conversionFactorTag
static

Used for the names in the name/value pairs described in the RWExchangeRateTable::initialize() member function.

const RWCString RWExchangeRateTable::sourceTag
static

Used for the names in the name/value pairs described in the RWExchangeRateTable::initialize() member function.

const RWCString RWExchangeRateTable::targetTag
static

Used for the names in the name/value pairs described in the RWExchangeRateTable::initialize() member function.

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