Data Types | |||
beginToken codeTag endToken |
expDateTag fractionNameTag introDateTag |
mnemonicTag nameTag wholeToFractionTag |
Member Functions | |||
clear() contains() entries() find() |
getAllCurrencies() getAllCurrencyMnemonics() initialize() insert() |
operator>>() operator<<() operator=() remove() |
restoreFrom() saveOn() |
#include <rw/money/currbook.h> ifstream strm("currency_book.in"); RWCurrencyBook b; b.initialize(strm);
com.roguewave.money.currency.v1_0.CurrencyBook
Class RWCurrencyBook stores RWCurrency objects. Each currency in the currency book is identified by a unique mnemonic. A currency's mnemonic can only appear once--duplicates are not allowed.
Class RWCurrencyBook can be initialized from an istream. Money.h++ includes a file that can be used to initialize an RWCurrencyBook through an ifstream. Appendix B lists the countries and the currency mnemonics in the provided file.
The following static data members define the strings that provide names for the name/value pairs used when initializing from a stream. They are initialized to the valid names described in RWCurrencyBook::initialize().
const RWCString mnemonicTag; const RWCString codeTag; const RWCString nameTag; const RWCString fractionNameTag; const RWCString wholeToFractionTag; const RWCString introDateTag; const RWCString expDateTag; const RWCString beginToken; const RWCString endToken;
RWCurrencyBook();
Default constructor. Creates an empty currency book.
RWCurrencyBook(const RWCurrencyBook& cb);
Copy constructor.
RWCurrencyBook& operator=(const RWCurrencyBook& cb);
Assignment operator.
void clear();
Removes all currencies.
RWBoolean contains(const RWCString& mnemonic) const;
Returns TRUE if the currency book contains the currency with the given mnemonic.
size_t entries() const;
Returns the number of currencies currently in the book.
RWBoolean find(const RWCString& mnemonic, RWCurrency& c) const;
Finds the currency indicated by mnemonic, places it in c and returns TRUE. If no such currency exists, c is unchanged and the function returns FALSE.
RWTValSlist<RWCurrency> getAllCurrencies() const;
Returns a collection of all the currencies in the currency book.
RWTValSlist<RWString> getAllCurrencyMnemonics() const;
Returns the mnemonics of all the currencies in the currency book.
RWBoolean initialize(istream& strm);
Initializes a currency book with currencies from strm. This method returns FALSE if there is an error in the stream format, or if one or more of the currencies is missing a mnemonic.
NOTE:The previous contents of self are deleted when this function is invoked.
A currency specification begins with the token BEGIN_CURRENCY, on a line by itself. Each attribute of the currency is specified as a name/value pair, one per line. The name/value separator is the equal sign `='. The end of a currency specification is indicated by the token END_CURRENCY. Comment lines start with a # character and are automatically skipped. For example:
#Kenya BEGIN_CURRENCY mnemonic=KES ratio =.01 name=shilling fraction=cents code=404 introduced= expires= END_CURRENCY
Name matching is case-insensitive and the only required value is mnemonic. The initialize() function returns FALSE if one or more of the currencies is missing a mnemonic.
Valid names are:
mnemonic ratio name fraction code introduced expires
RWBoolean insert(const RWCurrency& currency);
Adds the given currency to the currency book. If the currency book already contains an entry that matches currency, insert() does not add currency, and it returns FALSE. Otherwise, insert() adds currency to the currency book and returns TRUE.
RWBoolean remove(const RWCString& mnemonic);
Removes the currency indicated by mnemonic if it exists in the currency book, and returns TRUE. If mnemonic does not exist, returns FALSE.
void restoreFrom(RWFile&);
Restores the currency book from an RWFile.
void restoreFrom(RWvistream&);
Restores the currency book from a virtual stream.
void saveOn(RWFile&) const;
Persists the currency book to an RWFile.
void saveOn(RWvostream&) const;
Persists the currency book to a virtual stream.
RWvostream& operator<<(RWvostream& strm, const RWCurrencyBook& c); RWFile& operator<<(RWFile& file, const RWCurrencyBook& c);
Saves the object to a virtual stream or RWFile.
RWvistream& operator>>(RWvistream& strm, const RWCurrencyBook& c); RWFile& operator>>(RWFile& strm, const RWCurrencyBook& c);
Restores a object from a virtual stream or RWFile.
ostream& operator<<(ostream& strm, const RWCurrencyBook& b);
Outputs the RWCurrencyBook to a stream in the same format shown in the initialize() function.
ostream& operator>>(istream& strm, RWCurrencyBook& b);
Replaces the contents of the currency book with the contents of the stream. The format of the stream is the same as that described in the initialize() member function.
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.