.\" ident @(#)moneypunct.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH moneypunct 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2moneypunct\fP, \f2moneypunct_byname\fP \ - Monetary punctuation facets. .SH SYNOPSIS .br #include .br class money_base; .br template .br class moneypunct; .SH DESCRIPTION The moneypunct_facets include formatting specifications and punctuation character for monetary values. The moneypunct facet is used with the "C" locale, while the_moneypunct_byname facet is used with named locales. The facet is used by money_put_for outputting formatted representations of monetary values and by_money_get for reading these strings back in. money_base includes a structure, \f2pattern\fP, that specifies the order of syntactic elements in a monetary value and enumeration values representing those elements. The \f2pattern\fP struct includes a simple array of characters, \f2field\fP. Each index in \f2field\fP is taken up by an enumeration value indicating the location of a syntactic element. The enumeration values are described below: FORMAT FLAG MEANING \f2none\fP \f2No grouping separator\fP \f2space\fP \f2Use space for grouping separator\fP \f2symbol\fP \f2Currency symbol\fP \f2sign\fP \f2Sign of monetary value\fP \f2value\fP \f2The monetary value itself\fP The \f2do_pos_format\fP and \f2do_neg_format\fP member functions of moneypunct both return the \f2pattern\fP type. See the description of these functions for further elaboration. .SH INTERFACE .br class money_base { .br public: .RE .RS 1 enum part { none, space, symbol, sign, value }; .br struct pattern { char field[4]; }; .RE .RS 0 }; .br .br template .br class moneypunct : public locale::facet, public money_base { .br public: .RE .RS 1 typedef charT char_type; .br typedef basic_string string_type; .br explicit moneypunct(size_t = 0); .br charT decimal_point() const; .br charT thousands_sep() const; .br string grouping() const; .br string_type curr_symbol() const; .br string_type positive_sign() const; .br string_type negative_sign() const; .br int frac_digits() const; .br pattern pos_format() const; .br pattern neg_format() const; .br static locale::id id; .br static const bool intl = International; .RE .RS 0 protected: .RE .RS 2 ~moneypunct(); // virtual .RE .RS 1 virtual charT do_decimal_point() const; .br virtual charT do_thousands_sep() const; .br virtual string do_grouping() const; .br virtual string_type do_curr_symbol() const; .br virtual string_type do_positive_sign() const; .br virtual string_type do_negative_sign() const; .br virtual int do_frac_digits() const; .br virtual pattern do_pos_format() const; .br virtual pattern do_neg_format() const; .RE .RS 0 }; .br .br template .br class moneypunct_byname : public moneypunct { .br public: .RE .RS 1 explicit moneypunct_byname(const char*, size_t = 0); .RE .RS 0 protected: .RE .RS 2 ~moneypunct_byname(); // virtual .RE .RS 1 virtual charT do_decimal_point() const; .br virtual charT do_thousands_sep() const; .br virtual string do_grouping() const; .br virtual string_type do_curr_symbol() const; .br virtual string_type do_positive_sign() const; .br virtual string_type do_negative_sign() const; .br virtual int do_frac_digits() const; .br virtual pattern do_pos_format() const; .br virtual pattern do_neg_format() const; .RE .RS 0 }; .SH TYPES .br char_type .RE .RS 3 Type of character the facet is instantiated on. .RE .br string_type .RE .RS 3 Type of character string returned by member functions. .RE .SH CONSTRUCTORS .br explicit moneypunct(size_t refs = 0) .RE .RS 3 Constructs a moneypunct facet. If the \f2refs\fP argument is \f20\fP, then destruction of the object is delegated to the locale, or locales, containing it. This allows the user to ignore lifetime management issues. On the other hand, if \f2refs\fP is \f21\fP, then the object must be explicitly deleted; the locale does not do so. In this case, the object can be maintained across the lifetime of multiple locales. .RE .br explicit moneypunct_byname(const char* name, .RE .RS 28 size_t refs = 0); .RE .RS 3 Constructs a moneypunct_byname facet. Uses the named locale specified by the \f2name\fP argument. The \f2refs\fP argument serves the same purpose as it does for the moneypunct constructor. .RE .SH DESTRUCTORS .RE .RS 0 ~moneypunct(); // virtual and protected .RE .RS 3 Destroys the facet. .RE .SH STATIC MEMBERS .br static locale::id id; .RE .RS 3 Unique identifier for this type of facet. .RE .br static const bool intl = Intl; .RE .RS 3 \f2true\fP for international representation, \f2false\fP otherwise. .RE .SH PUBLIC MEMBER FUNCTIONS The public members of the moneypunct and_moneypunct_byname facets include an interface to protected members. Each public member \f2xxx\fP has a corresponding virtual protected member \f2do_xxx\fP. All work is delegated to these protected members. For instance, the long version of the public \f2decimal_point\fP function simply calls its protected cousin \f2do_decimal_point\fP. .br string_type curr_symbol() const; .br charT decimal_point() const; .br int frac_digits() const; .br string grouping() const; .br pattern neg_format() const; .br string_type negative_sign() const; .br pattern pos_format() const; .br string_type positive_sign() const; .br charT thousands_sep() const; .RE .RS 3 Each public member function \f2xxx\fP simply calls the corresponding protected \f2do_xxx\fP function. .RE .SH PROTECTED MEMBER FUNCTIONS .br virtual string_type .br do_curr_symbol() const; .RE .RS 3 Returns a string to use as the currency symbol. .RE .br virtual charT .br do_decimal_point() const; .RE .RS 3 Returns the radix separator to use if fractional digits are allowed (see \f2do_frac_digits\fP). .RE .br virtual int .br do_frac_digits() const; .RE .RS 3 Returns the number of digits in the fractional part of the monetary representation. .RE .br virtual string .br do_grouping() const; .RE .RS 3 Returns a string in which each character is used as an integer value to represent the number of digits in a particular grouping, starting with the rightmost group. A group is simply the digits between adjacent thousands' separators. Each group at a position larger than the size of the string gets the same value as the last element in the string. If a value is less than or equal to zero, or equal to \f2CHAR_MAX\fP, then the size of that group is unlimited. moneypunct returns an empty string, indicating no grouping. .RE .br virtual string_type .br do_negative_sign() const; .RE .RS 3 A string to use as the negative sign. The first character of this string is placed in the position indicated by the format pattern (see \f2do_neg_format\fP); the rest of the characters, if any, are placed after all other parts of the monetary value. .RE .br virtual pattern .br do_neg_format() const; .br virtual pattern .br do_pos_format() const; .RE .RS 3 Returns a pattern object specifying the location of the various syntactic elements in a monetary representation. The enumeration values \f2symbol\fP, \f2sign\fP, and \f2value\fP appear exactly once in this pattern, with the remaining location taken by either \f2none\fP or \f2space\fP. \f2none\fP never occupies the first position in the pattern and \f2space\fP never occupies the first or the last position. Beyond these restrictions, elements may appear in any order. moneypunct returns {symbol, sign, none, value}. .RE .br virtual string_type .br do_positive_sign() const; .RE .RS 3 A string to use as the positive sign. The first character of this string is placed in the position indicated by the format pattern (see \f2do_pos_format\fP); the rest of the characters, if any, are placed after all other parts of the monetary value. .RE .br virtual charT .br do_thousands_sep() const; .RE .RS 3 Returns the grouping separator if grouping is allowed (see \f2do_grouping\fP). .RE .SH EXAMPLE .br // .br // moneypun.cpp .br // .br .br #include .br .br #include .br .br int main () .br { .RE .RS 1 using namespace std; .RE .RS 0 .RE .RS 1 locale loc; .RE .RS 0 .RE .RS 2 // Get a moneypunct facet .RE .RS 1 const moneypunct& mp = .RE .RS 0 #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE .RE .RS 1 use_facet >(loc); .RE .RS 0 #else .RE .RS 1 use_facet(loc,(moneypunct*)0); .RE .RS 0 #endif .br .RE .RS 1 cout << "Decimal point = " .RE .RS 7 << mp.decimal_point() << endl; .RE .RS 1 cout << "Thousands separator = " .RE .RS 7 << mp.thousands_sep() << endl; .RE .RS 1 cout << "Currency symbol = " .RE .RS 7 << mp.curr_symbol() << endl; .RE .RS 1 cout << "Negative Sign = " .RE .RS 7 << mp.negative_sign() << endl; .RE .RS 1 cout << "Digits after decimal = " .RE .RS 7 << mp.frac_digits() << endl; .RE .RS 0 .RE .RS 1 return 0; .RE .RS 0 } .SH SEE ALSO locale, facets, money_put, money_get