currency< T, N > Class Template Reference

#include <currency.hpp>

List of all members.

Public Types

typedef T int_type
 Storage type.
typedef fixed< T, N > value_type
 Type of the actual value.

Public Member Functions

 currency ()
 Default constructor initializes the value to zero.
 currency (T integer)
 currency (T integer, T fraction)
 currency (double value)
template<class U, int M>
 currency (currency< U, M > const &rhs)
 Copy a value that uses a different precision.
template<class U, int M>
currencyoperator= (currency< U, M > rhs)
 Assign a value that uses a different precision.
std::string as_string () const
template<class Char, class Traits>
bool read (std::basic_istream< Char, Traits > &strm)
template<class U>
convert () const
 Convert to some other type, especially floating point.
int_type round () const
 Round off to the nearest integer, using banker's rounding.
int_type integer () const
 Return the integer part (which is the same as trunc()).
template<int M>
int_type fraction () const
 Return the fractional part, to M places.
int_type fraction () const
 Return the fractional part.
currencyoperator+= (currency c)
currencyoperator-= (currency c)
currencyoperator *= (value_type m)
currencyoperator *= (int_type m)
currencyoperator/= (value_type m)
currencyoperator/= (int_type m)
void negate ()
 Negate this value.
currencyoperator++ ()
 Pre-increment operator.
currency operator++ (int)
 Post-increment operator.
currencyoperator-- ()
 Pre-decrement operator.
currency operator-- (int)
 Post-decrement operator.
value_type value () const
 Return the internal value.


Detailed Description

template<class T = long, int N = 2>
class currency< T, N >

Class to represent a currency value in the global locale.

Definition at line 22 of file currency.hpp.


Constructor & Destructor Documentation

template<class T = long, int N = 2>
currency< T, N >::currency ( integer  )  [inline]

Initialize the value to integer

Parameters:
integer The integer initial value; the fractional part is zero.

Definition at line 32 of file currency.hpp.

template<class T = long, int N = 2>
currency< T, N >::currency ( integer,
fraction 
) [inline]

Initialize the value. The interpretation of the fractional part depends on N. For example, if N is 2, a fraction of 9 represents 0.09, buf if N is 5, fraction of 9 means 0.0009.

Parameters:
integer The integer part of the initial value
fraction The fractional part of the initial value

Definition at line 39 of file currency.hpp.

template<class T = long, int N = 2>
currency< T, N >::currency ( double  value  )  [inline]

Initialize from a floating point number.

Parameters:
value the initial value

Definition at line 42 of file currency.hpp.


Member Function Documentation

template<class T, int N>
std::string currency< T, N >::as_string (  )  const [inline]

Convert to a string.

Returns:
a string representation of the value, e.g., "$123.04"

Definition at line 130 of file currency.hpp.

References currency< T, N >::fraction(), currency< T, N >::integer(), and fixed< T, N >::places.

template<class T, int N>
template<class CharT, class Traits>
bool currency< T, N >::read ( std::basic_istream< CharT, Traits > &  strm  )  [inline]

Overwrite this value with the value read from the stream. The value in the stream must have the correct number of digits. If the showbase flag is set, the currency symbol must be present.

Parameters:
strm Input stream
Returns:
true if the read is success and *this has been modified, or false if the read fails. Check strm for details.

Definition at line 221 of file currency.hpp.

References currency< T, N >::fraction(), currency< T, N >::integer(), and fixed< T, N >::read().

Referenced by operator>>().

template<class T = long, int N = 2>
template<class U>
U currency< T, N >::convert (  )  const [inline]

Convert to some other type, especially floating point.

Convert the value to a different numeric type. Typically, the other type is a floating-point type.

Definition at line 72 of file currency.hpp.

References currency< T, N >::value().

template<class T, int N>
currency< T, N > & currency< T, N >::operator+= ( currency< T, N >  c  )  [inline]

Addition operator.

Parameters:
c the value to add
Returns:
*this

Definition at line 144 of file currency.hpp.

References currency< T, N >::value().

template<class T, int N>
currency< T, N > & currency< T, N >::operator-= ( currency< T, N >  c  )  [inline]

Subtraction operator.

Parameters:
c the value to subtract
Returns:
*this

Definition at line 151 of file currency.hpp.

References currency< T, N >::value().

template<class T, int N>
currency< T, N > & currency< T, N >::operator *= ( value_type  m  )  [inline]

Multiplication operator.

Parameters:
m the value to multiply
Returns:
*this

Definition at line 158 of file currency.hpp.

template<class T, int N>
currency< T, N > & currency< T, N >::operator *= ( int_type  m  )  [inline]

Multiplication operator.

Parameters:
m the value to multiply
Returns:
*this

Definition at line 164 of file currency.hpp.

template<class T, int N>
currency< T, N > & currency< T, N >::operator/= ( value_type  m  )  [inline]

Division operator.

Parameters:
m the divisor
Returns:
*this

Definition at line 171 of file currency.hpp.

template<class T, int N>
currency< T, N > & currency< T, N >::operator/= ( int_type  m  )  [inline]

Division operator.

Parameters:
m the divisor
Returns:
*this

Definition at line 177 of file currency.hpp.


The documentation for this class was generated from the following file:
Generated on Sun Nov 30 10:03:13 2008 for Project 3 - Currency Type by  doxygen 1.5.3