.\" ident @(#)numpunct.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH numpunct 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2numpunct\fP, \f2numpunct_byname\fP \ - A numeric punctuation facet. .SH SYNOPSIS .RE .RS 0 #include .br template class numpunct; .br template class numpunct_byname; .SH DESCRIPTION The numpunct_facet specifies numeric punctuation. numpunct is used with the "C" locale, while the numpunct_byname facet is used with named locales. Both num_put and num_get make use of this facet. .SH INTERFACE .br template .br class numpunct : public locale::facet { .br public: .RE .RS 1 typedef charT char_type; .br typedef basic_string string_type; .br explicit numpunct(size_t refs = 0); .br char_type decimal_point() const; .br char_type thousands_sep() const; .br string grouping() const; .br string_type truename() const; .br string_type falsename() const; .br static locale::id id; .RE .RS 0 protected: .RE .RS 2 ~numpunct(); // virtual .RE .RS 1 virtual char_type do_decimal_point() const; .br virtual char_type do_thousands_sep() const; .br virtual string do_grouping() const; .br virtual string_type do_truename() const; // for bool .br virtual string_type do_falsename() const; // for bool .RE .RS 0 }; .br .br template .br class numpunct_byname : public numpunct { .br public: .RE .RS 1 explicit numpunct_byname(const char*, size_t refs = 0); .RE .RS 0 protected: .RE .RS 2 ~numpunct_byname(); // virtual .RE .RS 1 virtual char_type do_decimal_point() const; .br virtual char_type do_thousands_sep() const; .br virtual string do_grouping() const; .br virtual string_type do_truename() const; // for bool .br virtual string_type do_falsename() const; // for bool .RE .RS 0 }; .SH TYPES .br char_type .RE .RS 3 Type of character upon which the facet is instantiated. .RE .br string_type .RE .RS 3 Type of character string returned by member functions. .RE .SH CONSTRUCTORS .br explicit numpunct(size_t refs = 0) .RE .RS 3 Constructs a numpunct 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 numpunct_byname(const char* name, .RE .RS 8 size_t refs = 0); .RE .RS 3 Constructs a numpunct_byname facet. Uses the named locale specified by the name argument. The \f2refs\fP argument serves the same purpose as it does for the numpunct constructor. .RE .SH DESTRUCTORS .RE .RS 0 ~numpunct(); // virtual and protected .br ~numpunct_byname(); // virtual and protected .RE .RS 3 Destroys the facet. .RE .SH FACET ID .br static locale::id id; .RE .RS 3 Unique identifier for this type of facet. .RE .SH PUBLIC MEMBER FUNCTIONS The public members of the numpunct facet 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 \f2grouping\fP function simply calls its protected cousin \f2do_grouping\fP. .br char_type decimal_point() const; .br string_type falsename() const; .br string grouping() const; .br char_type thousands_sep() const; .br string_type truename() const; .RE .RS 3 Each of these public member functions \f2xxx\fP simply call the corresponding protected \f2do_xxx\fP function. .RE .SH PROTECTED MEMBER FUNCTIONS .br virtual char_type .br do_decimal_point() const; .RE .RS 3 Returns the decimal radix separator. numpunct returns `\f2.\fP'. .RE .br virtual string_type .br do_falsename() const; // for bool .br virtual string_type .br do_truename() const; // for bool .RE .RS 3 Returns a string containing \f2true\fP or \f2false\fP. .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. numpunct returns an empty string, indicating no grouping. .RE .br virtual char_type .br do_thousands_sep() const; .RE .RS 3 Returns the decimal digit group separator. numpunct returns `\f2,\fP'. .RE .SH EXAMPLE .br // .br // numpunct.cpp .br // .br .br #include .br .br int main () .br { .RE .RS 1 using namespace std; .br locale loc; .RE .RS 0 .RE .RS 2 // Get a numpunct facet .RE .RS 1 const numpunct& np = .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,(numpunct*)0); .RE .RS 0 #endif .br .RE .RS 1 cout << "Decimal point = " .RE .RS 7 << np.decimal_point() << endl; .RE .RS 1 cout << "Thousands separator = " .RE .RS 7 << np.thousands_sep() << endl; .RE .RS 1 cout << "True name = " .RE .RS 7 << np.truename() << endl; .RE .RS 1 cout << "False name = " .RE .RS 7 << np.falsename() << endl; .RE .RS 0 .RE .RS 1 return 0; .RE .RS 0 } .SH SEE ALSO locale, facets, num_put, num_get, ctype