moneypunct class template — Facet for punctuation of monetary values
template <typename charT, bool International = false> class moneypunct : public locale::facet, public money_base { public: typedef charT char_type; typedef basic_string<charT> string_type; explicit moneypunct(size_t refs = 0); charT decimal_point( ) const; charT thousands_sep( ) const; string grouping( ) const; string_type curr_symbol( ) const; string_type positive_sign( ) const; string_type negative_sign( ) const; int frac_digits( ) const; pattern pos_format( ) const; pattern neg_format( ) const; static locale::id id; static const bool intl = International; protected: virtual ~moneypunct( ); virtual charT do_decimal_point( ) const; virtual charT do_thousands_sep( ) const; virtual string do_grouping( ) const; virtual string_type do_curr_symbol( ) const; virtual string_type do_positive_sign( ) const; virtual string_type do_negative_sign( ) const; virtual int do_frac_digits( ) const; virtual pattern do_pos_format( ) const; virtual pattern do_neg_format( ) const; };
The moneypunct
class
template is a facet that describes the punctuation characters used
to format a monetary value.
The moneypunct<char,false>
, moneypunct<wchar_t,false>
, moneypunct<char,true>
, and moneypunct<wchar_t,true>
instantiations are standard.
Specify true
for the
International
template parameter
to obtain an international format, or false
to obtain a local format. In an
international format, the currency symbol is always four characters,
usually three characters followed by a space.
The money_get
and money_put
facets use a pattern to parse or
format a monetary value. The pattern specifies the order in which
parts of a monetary value must appear. Each pattern has four fields,
in which each field has type part
(cast to char
). The symbol
, sign
, and value
parts must appear exactly once, and
the remaining field must be space
or none
. The value none
cannot be first (field[0]
); space
cannot be first or last (field[3]
).
Where sign
appears in the
pattern, the first character of the sign string (positive_sign( )
or negative_sign( )
) is output, and the
remaining characters of the sign string appear at the end of the
formatted output. Thus, if negative_sign(
)
returns "( )
", the
value -12.34
might be formatted
as "(12.34)
".
As with other facets, the public members call virtual,
protected members with the same name prefaced by do_
. Thus, to use the facet, call the
public functions, such as grouping
, which calls do_grouping
. The descriptions below are
for the virtual functions because they do the real work. Imagine
that for each virtual-function description, there is a corresponding
description for a public, nonvirtual function, such as:
The following are the virtual, protected members of moneypunct
:
virtual
string_type
do_curr_symbol
( )
const
Returns the currency symbol, such as "$
" (which is used by some U.S.
locales) or "USD
" (which
is the international currency symbol for U.S. dollars). In the
"C
" locale, the currency
symbol is "" or L"
".
virtual
charT
do_decimal_point
( )
const
Returns the character used before the fractional part
when do_frac_digits
is
greater than 0
. For
example, in the U.S., this is typically '.
', and in Europe, it is typically
',
'. In the "C
" locale, the decimal point is
'.
' or L'.
'.
virtual
int
do_frac_digits
( )
const
Returns the number of digits to print after the decimal
point. This value can be 0
.
In the "C
" locale, the
number of digits is std::numeric_limits<char>.max(
)
.
virtual
string
do_grouping
( )
const
Returns a string that specifies the positions of
thousands separators. The string is interpreted as a vector of
integers, in which each value is a number of digits, starting
from the right. Thus, the string "\3
" means every three digits form a
group. In the "C
" locale,
the grouping is "" or L"
".
virtual
pattern
do_neg_format
( )
const
Returns the pattern used to format negative values. In
the "C
" locale, the
negative format is {
symbol
, sign
, none
, value
}
.
virtual
string_type
do_negative_sign
( )
const
Returns the string (which may be empty) used to identify
negative values. The position of the sign is dictated by the
do_neg_format
pattern. In
the "C
" locale, the
negative sign is "-
" or
L"-
".
virtual
pattern
do_pos_format
( )
const
Returns the pattern used to format positive values. In
the "C
" locale, the
positive format is {
symbol
, sign
, none
, value
}
.
virtual
string_type
do_positive_sign
( )
const
Returns the string (which may be empty) used to identify
positive values. The position of the sign is dictated by the
do_pos_format
pattern. In
the "C
" locale, the
positive sign is "" or L"
".
virtual
charT
do_thousands_sep
( )
const
Returns the character used to separate groups of digits,
in which the groups are specified by do_grouping
. In the U.S., the
separator is typically ',
',
and in Europe, it is often '.
'. In the "C
" locale, the thousands separator
is '\0
' or L'\0
'.