SourcePro® API Reference Guide

 
List of all members | Public Member Functions | Static Public Attributes | Friends | Related Functions
RWCurrencyBook Class Reference

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 &)
 
void clear ()
 
bool contains (const RWCString &mnemonic) const
 
size_t entries () const
 
bool find (const RWCString &mnemonic, RWCurrency &currency) const
 
RWTValSlist< RWCurrencygetAllCurrencies () const
 
RWTValSlist< RWCStringgetAllCurrencyMnemonics () const
 
bool initialize (std::istream &strm)
 
bool insert (const RWCurrency &currency)
 
RWCurrencyBookoperator= (const RWCurrencyBook &)
 
bool remove (const RWCString &mnemonic)
 
void restoreFrom (RWvistream &)
 
void restoreFrom (RWFile &)
 
void saveOn (RWvostream &) const
 
void saveOn (RWFile &) const
 

Static Public Attributes

static const RWCString beginToken
 
static const RWCString codeTag
 
static const RWCString endToken
 
static const RWCString expDateTag
 
static const RWCString fractionNameTag
 
static const RWCString introDateTag
 
static const RWCString mnemonicTag
 
static const RWCString nameTag
 
static const RWCString wholeToFractionTag
 

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)
 

Detailed Description

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. The Currency Module includes a file <installdir>/examples/currency/currency_book.in that can be used to initialize an RWCurrencyBook through an std::ifstream. Refer to this file for the currencies supported and their mnemonics. The Currency Module User Guide contains information on how to add currency definitions to this file.

Synopsis
#include <rw/currency/currbook.h>
std::ifstream strm("currency_book.in");
b.initialize(strm);

Constructor & Destructor Documentation

RWCurrencyBook::RWCurrencyBook ( )

Default constructor. Creates an empty currency book.

RWCurrencyBook::RWCurrencyBook ( const RWCurrencyBook )

Copy constructor.

Member Function Documentation

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.

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
bool RWCurrencyBook::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.

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::restoreFrom ( RWFile )

Restores the currency book from an RWFile.

void RWCurrencyBook::saveOn ( RWvostream ) const

Persists the currency book to a virtual stream.

void RWCurrencyBook::saveOn ( RWFile ) const

Persists the currency book to an RWFile.

Friends And Related Function Documentation

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.

Member Data Documentation

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 © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.