SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
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 RWCString &source, const RWCString &target, double convFactor)
 
bool add (const RWExchangeRate &exchangeRate)
 
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 RWCString &source, const RWCString &target)
 
bool remove (const RWExchangeRate &rate)
 
void restoreFrom (RWFile &)
 
void restoreFrom (RWvistream &)
 
void saveOn (RWFile &) const
 
void saveOn (RWvostream &) 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 Symbols

(Note that these are not member symbols.)

RWFileoperator<< (RWFile &f, const RWExchangeRateTable &t)
 
RWvostreamoperator<< (RWvostream &s, const RWExchangeRateTable &t)
 
RWFileoperator>> (RWFile &f, RWExchangeRateTable &t)
 
RWvistreamoperator>> (RWvistream &s, 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);
Stores exchange rates as unique pairs of source and target currencies.
Definition exchgratetbl.h:110
bool initialize(std::istream &strm)

Constructor & Destructor Documentation

◆ RWExchangeRateTable() [1/2]

RWExchangeRateTable::RWExchangeRateTable ( )

Default constructor. Constructs an empty exchange rate table.

◆ RWExchangeRateTable() [2/2]

RWExchangeRateTable::RWExchangeRateTable ( const RWExchangeRateTable & t)

Copy constructor. Copies contents of t to self.

Member Function Documentation

◆ add() [1/2]

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.

◆ add() [2/2]

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.

◆ clear()

void RWExchangeRateTable::clear ( )

Removes all exchange rates from the table.

◆ contains() [1/2]

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.

◆ contains() [2/2]

bool RWExchangeRateTable::contains ( const RWExchangeRate & rate) const

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

◆ entries()

size_t RWExchangeRateTable::entries ( ) const

Returns the number of exchange rates in the table.

◆ findConversionFactor()

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.

◆ findExchangeRate()

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.

◆ getAllExchangeRates()

RWTValSlist< RWExchangeRate > RWExchangeRateTable::getAllExchangeRates ( ) const

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

◆ initialize()

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:

static const RWCString targetTag
Definition exchgratetbl.h:128
static const RWCString conversionFactorTag
Definition exchgratetbl.h:134
static const RWCString sourceTag
Definition exchgratetbl.h:122

◆ operator=()

RWExchangeRateTable & RWExchangeRateTable::operator= ( const RWExchangeRateTable & )

Assignment operator.

◆ remove() [1/2]

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.

◆ remove() [2/2]

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.

◆ restoreFrom() [1/2]

void RWExchangeRateTable::restoreFrom ( RWFile & )

Restore from an RWFile.

◆ restoreFrom() [2/2]

void RWExchangeRateTable::restoreFrom ( RWvistream & )

Restore from a virtual stream.

◆ saveOn() [1/2]

void RWExchangeRateTable::saveOn ( RWFile & ) const

Persists to an RWFile.

◆ saveOn() [2/2]

void RWExchangeRateTable::saveOn ( RWvostream & ) const

Persists to a virtual stream.

◆ setConversionFactor()

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 Symbol Documentation

◆ operator<<() [1/2]

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

Saves the object to a RWFile.

◆ operator<<() [2/2]

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

Saves the object to a virtual stream.

◆ operator>>() [1/2]

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

Restores a object from a RWFile.

◆ operator>>() [2/2]

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

Restores a object from a virtual stream.

Member Data Documentation

◆ conversionFactorTag

const RWCString RWExchangeRateTable::conversionFactorTag
static

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

◆ sourceTag

const RWCString RWExchangeRateTable::sourceTag
static

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

◆ targetTag

const RWCString RWExchangeRateTable::targetTag
static

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

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