SourcePro C++ 12.0 |
SourcePro® C++ API Reference Guide |
SourcePro C++ Documentation Home |
Stores RWCurrency objects in which each is identified by a unique mnemonic. More...
#include <rw/currency/currbook.h>
Public Member Functions | |
RWCurrencyBook () | |
RWCurrencyBook (const RWCurrencyBook &) | |
bool | initialize (std::istream &strm) |
RWTValSlist< RWCurrency > | getAllCurrencies () const |
RWTValSlist< RWCString > | getAllCurrencyMnemonics () const |
bool | find (const RWCString &mnemonic, RWCurrency ¤cy) const |
bool | contains (const RWCString &mnemonic) const |
size_t | entries () const |
bool | insert (const RWCurrency ¤cy) |
bool | remove (const RWCString &mnemonic) |
void | clear () |
void | saveOn (RWvostream &) const |
void | saveOn (RWFile &) const |
void | restoreFrom (RWvistream &) |
void | restoreFrom (RWFile &) |
RWCurrencyBook & | operator= (const RWCurrencyBook &) |
Static Public Attributes | |
static const RWCString | mnemonicTag |
static const RWCString | codeTag |
static const RWCString | nameTag |
static const RWCString | fractionNameTag |
static const RWCString | wholeToFractionTag |
static const RWCString | introDateTag |
static const RWCString | expDateTag |
static const RWCString | beginToken |
static const RWCString | endToken |
Friends | |
std::ostream & | operator<< (std::ostream &, const RWCurrencyBook &) |
Related Functions | |
(Note that these are not member functions.) | |
std::istream & | operator>> (std::istream &strm, RWCurrencyBook &b) |
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 std::istream. Currency Module includes a file that can be used to initialize an RWCurrencyBook through an std::ifstream. Appendix B lists the countries and the currency mnemonics in the provided file.
#include <rw/currency/currbook.h> std::ifstream strm("currency_book.txt"); RWCurrencyBook b; b.initialize(strm);
RWCurrencyBook::RWCurrencyBook | ( | ) |
Default constructor. Creates an empty currency book.
RWCurrencyBook::RWCurrencyBook | ( | const RWCurrencyBook & | ) |
Copy constructor.
void RWCurrencyBook::clear | ( | ) |
Removes all currencies.
bool RWCurrencyBook::contains | ( | const RWCString & | mnemonic | ) | const |
Returns true
if the currency book contains the currency with the given mnemonic.
size_t RWCurrencyBook::entries | ( | ) | const |
Returns the number of currencies currently in the book.
bool RWCurrencyBook::find | ( | const RWCString & | mnemonic, | |
RWCurrency & | currency | |||
) | const |
Finds the currency indicated by mnemonic, places it in currency and returns true
. If no such currency exists, c is unchanged and the function returns false
.
RWTValSlist<RWCurrency> RWCurrencyBook::getAllCurrencies | ( | ) | const |
Returns a collection of all the currencies in the currency book.
RWTValSlist<RWCString> RWCurrencyBook::getAllCurrencyMnemonics | ( | ) | const |
Returns the mnemonics of all the currencies in the currency book.
bool RWCurrencyBook::initialize | ( | std::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.
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
bool RWCurrencyBook::insert | ( | const RWCurrency & | currency | ) |
RWCurrencyBook& RWCurrencyBook::operator= | ( | const RWCurrencyBook & | ) |
Assignment operator.
bool RWCurrencyBook::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 RWCurrencyBook::restoreFrom | ( | RWvistream & | ) |
Restores the currency book from a virtual stream.
void RWCurrencyBook::saveOn | ( | RWvostream & | ) | const |
Persists the currency book to a virtual stream.
std::ostream& operator<< | ( | std::ostream & | strm, | |
const RWCurrencyBook & | b | |||
) | [friend] |
Outputs the RWCurrencyBook to a stream in the same format shown in the initialize() function.
std::istream & operator>> | ( | std::istream & | strm, | |
RWCurrencyBook & | b | |||
) | [related] |
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.
const RWCString RWCurrencyBook::beginToken [static] |
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 RWCurrencyBook::codeTag [static] |
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 RWCurrencyBook::endToken [static] |
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 RWCurrencyBook::expDateTag [static] |
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 RWCurrencyBook::fractionNameTag [static] |
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 RWCurrencyBook::introDateTag [static] |
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 RWCurrencyBook::mnemonicTag [static] |
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 RWCurrencyBook::nameTag [static] |
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 RWCurrencyBook::wholeToFractionTag [static] |
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().
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.