SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
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 (RWFile &)
 
void restoreFrom (RWvistream &)
 
void saveOn (RWFile &) const
 
void saveOn (RWvostream &) 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 &strm, const RWCurrencyBook &b)
 

Related Symbols

(Note that these are not member symbols.)

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);
Stores RWCurrency objects in which each is identified by a unique mnemonic.
Definition currbook.h:63
bool initialize(std::istream &strm)

Constructor & Destructor Documentation

◆ RWCurrencyBook() [1/2]

RWCurrencyBook::RWCurrencyBook ( )

Default constructor. Creates an empty currency book.

◆ RWCurrencyBook() [2/2]

RWCurrencyBook::RWCurrencyBook ( const RWCurrencyBook & )

Copy constructor.

Member Function Documentation

◆ clear()

void RWCurrencyBook::clear ( )

Removes all currencies.

◆ contains()

bool RWCurrencyBook::contains ( const RWCString & mnemonic) const

Returns true if the currency book contains the currency with the given mnemonic.

◆ entries()

size_t RWCurrencyBook::entries ( ) const

Returns the number of currencies currently in the book.

◆ find()

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.

◆ getAllCurrencies()

RWTValSlist< RWCurrency > RWCurrencyBook::getAllCurrencies ( ) const

Returns a collection of all the currencies in the currency book.

◆ getAllCurrencyMnemonics()

RWTValSlist< RWCString > RWCurrencyBook::getAllCurrencyMnemonics ( ) const

Returns the mnemonics of all the currencies in the currency book.

◆ initialize()

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

◆ insert()

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.

◆ operator=()

RWCurrencyBook & RWCurrencyBook::operator= ( const RWCurrencyBook & )

Assignment operator.

◆ remove()

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.

◆ restoreFrom() [1/2]

void RWCurrencyBook::restoreFrom ( RWFile & )

Restores the currency book from an RWFile.

◆ restoreFrom() [2/2]

void RWCurrencyBook::restoreFrom ( RWvistream & )

Restores the currency book from a virtual stream.

◆ saveOn() [1/2]

void RWCurrencyBook::saveOn ( RWFile & ) const

Persists the currency book to an RWFile.

◆ saveOn() [2/2]

void RWCurrencyBook::saveOn ( RWvostream & ) const

Persists the currency book to a virtual stream.

Friends And Related Symbol Documentation

◆ operator<<

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.

◆ operator>>()

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

◆ beginToken

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().

◆ codeTag

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().

◆ endToken

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().

◆ expDateTag

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().

◆ fractionNameTag

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().

◆ introDateTag

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().

◆ mnemonicTag

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().

◆ nameTag

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().

◆ wholeToFractionTag

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