SourcePro® 2023.1 |
SourcePro® API Reference Guide |
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< RWExchangeRate > | getAllExchangeRates () const |
bool | initialize (std::istream &strm) |
RWExchangeRateTable & | operator= (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.) | |
RWvostream & | operator<< (RWvostream &s, const RWExchangeRateTable &t) |
RWFile & | operator<< (RWFile &f, const RWExchangeRateTable &t) |
RWvistream & | operator>> (RWvistream &s, RWExchangeRateTable &t) |
RWFile & | operator>> (RWFile &f, RWExchangeRateTable &t) |
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:
RWExchangeRateTable::RWExchangeRateTable | ( | ) |
Default constructor. Constructs an empty exchange rate table.
RWExchangeRateTable::RWExchangeRateTable | ( | const RWExchangeRateTable & | t | ) |
Copy constructor. Copies contents of t to self.
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.
|
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.
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:
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
.
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::saveOn | ( | RWvostream & | ) | const |
Persists to a virtual stream.
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
.
|
related |
Saves the object to a virtual stream.
|
related |
Saves the object to a RWFile.
|
related |
Restores a object from a virtual stream.
|
related |
Restores a object from a RWFile.
|
static |
Used for the names in the name/value pairs described in the RWExchangeRateTable::initialize() member function.
|
static |
Used for the names in the name/value pairs described in the RWExchangeRateTable::initialize() member function.
|
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. |