Data Types | |||
conversionFactorTag |
sourceTag |
targetTag |
#include<rw/money/exchgratetbl.h> ifstream strm(" exchange_rates.in"); RWExchangeRateTable rates; rates.initialize();
com.roguewave.money.currency.v1_0.ExchangeRateTable
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 ifstream (file). The format for the stream is:
BEGIN_EXCHANGE source= target= rate= END_EXCHANGE
The following values are used for the names in the name/value pairs described in the RWExchangeRateTable::intialize() member function.
const RWCString sourceTag; const RWCString targetTag; const RWCstring conversionFactorTag;
RWExchangeRateTable();
Default constructor. Constructs an empty exchange rate table.
RWExchangeRateTable(const RWExchangeRateTable& t);
Copy constructor. Copies contents of t to self.
RWExchangeRateTable& operator=(const RWExchangeRateTable& rhs);
Assignment operator.
RWBoolean 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.
RWBoolean add(const RWCString& source, const RWCString& target, double convFactor);
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 clear();
Removes all exchange rates from the table.
RWBoolean contains(const RWExchangeRate& rate); RWBoolean contains(const RWCString& sourceMnemonic, const RWCString& targetMnemonic);
Returns TRUE if the table contains a rate for the given source and target currencies. Returns FALSE otherwise.
size_t entries() const;
Returns the number of exchange rates in the table.
RWBoolean findConversionFactor(const RWCString& sourceMnemonic, RWCString targetMnemonic, double& factor);
Searches the exchange rate table to find the exchange rate for converting money with currency specified by sourceMnemonic into money in currency specified my 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.
RWBoolean findExchangeRate(const RWCString& sourceMnemonic, RWCString targetMnemonic, RWExchangeRate& rate);
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> getAllExchangeRates()const;
Returns a list of all the exchange rates in the table.
RWBoolean initialize(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:
source = RWExchangeRateTable::sourceTag target = RWExchangeRateTable::targetTag rate = RWExchangeRateTable::conversionFactorTag
RWBoolean remove(const RWExchangeRate& exchangeRate); RWBoolean remove(const RWCString& sourceMnemonic, const RWCString targetMnemonic);
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 restoreFrom(RWFile&);
Restore from an RWFile.
void restoreFrom(RWvistream&);
Restore from a virtual stream.
void saveOn(RWvostream&) const;
Persist to a virtual stream.
void saveOn(RWFile&) const;
Persist to an RWFile.
RWBoolean 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.
RWvostream& operator<<(RWvostream& strm, const RWExchangeRateTable& r); RWFile& operator<<(RWFile& file, const RWExchangeRateTable& r);
Saves the object to a virtual stream or RWFile, respectively.
RWvistream& operator>>(RWvistream& strm, const RWExchangeRateTable& r); RWFile& operator>>(RWFile& strm, const RWExchangeRateTable& r);
Restores a object from a virtual stream or RWFile, respectively.
ostream& rwdcmlexport operator<<(ostream& strm, const RWExchangeRateTable& t); istream& rwdcmlexport operator>>(istream& strm, RWExchangeRateTable& t);
Writes to and reads from strm using the format described in RWExchangeRateTable::initialize().
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.