numpunct(3C++) - numpunct(3C++)
Standard C++ Library Copyright 1998, Rogue Wave Software, Inc.
NAME
numpunct, numpunct_byname
- A numeric punctuation facet.
SYNOPSIS
#include <locale>
template <class charT> class numpunct;
template <class charT> class numpunct_byname;
DESCRIPTION
The numpunct<charT>_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.
INTERFACE
template <class charT>
class numpunct : public locale::facet {
public:
typedef charT char_type;
typedef basic_string<charT> string_type;
explicit numpunct(size_t refs = 0);
char_type decimal_point() const;
char_type thousands_sep() const;
string grouping() const;
string_type truename() const;
string_type falsename() const;
static locale::id id;
protected:
~numpunct(); // virtual
virtual char_type do_decimal_point() const;
virtual char_type do_thousands_sep() const;
virtual string do_grouping() const;
virtual string_type do_truename() const; // for bool
virtual string_type do_falsename() const; // for bool
};
template <class charT>
class numpunct_byname : public numpunct<charT> {
public:
explicit numpunct_byname(const char*, size_t refs = 0);
protected:
~numpunct_byname(); // virtual
virtual char_type do_decimal_point() const;
virtual char_type do_thousands_sep() const;
virtual string do_grouping() const;
virtual string_type do_truename() const; // for bool
virtual string_type do_falsename() const; // for bool
};
TYPES
char_type
Type of character upon which the facet is instantiated.
string_type
Type of character string returned by member functions.
CONSTRUCTORS
explicit numpunct(size_t refs = 0)
Constructs a numpunct facet. If the refs argument is 0, 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
refs is 1, 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.
explicit numpunct_byname(const char* name,
size_t refs = 0);
Constructs a numpunct_byname facet. Uses the named locale specified by the
name argument. The refs argument serves the same purpose as it does for the
numpunct constructor.
DESTRUCTORS
~numpunct(); // virtual and protected
~numpunct_byname(); // virtual and protected
Destroys the facet.
FACET ID
static locale::id id;
Unique identifier for this type of facet.
PUBLIC MEMBER FUNCTIONS
The public members of the numpunct facet include an interface to pro‐
tected members. Each public member xxx has a corresponding virtual pro‐
tected member do_xxx. All work is delegated to these protected members.
For instance, the long version of the public grouping function simply
calls its protected cousin do_grouping.
char_type decimal_point() const;
string_type falsename() const;
string grouping() const;
char_type thousands_sep() const;
string_type truename() const;
Each of these public member functions xxx simply call the corresponding
protected do_xxx function.
PROTECTED MEMBER FUNCTIONS
virtual char_type
do_decimal_point() const;
Returns the decimal radix separator. numpunct returns `.'.
virtual string_typedo_falsename() const; // for bool
virtual string_typedo_truename() const; // for bool
Returns a string containing true or false.
virtual stringdo_grouping() const;
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 CHAR_MAX, then the size of that group is
unlimited. numpunct returns an empty string, indicating no grouping.
virtual char_typedo_thousands_sep() const;
Returns the decimal digit group separator. numpunct returns `,'.
EXAMPLE
//
// numpunct.cpp
//
#include <iostream>
int main ()
{
using namespace std;
locale loc;
// Get a numpunct facet
const numpunct<char>& np =
#ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
use_facet<numpunct<char> >(loc);
#else
use_facet(loc,(numpunct<char>*)0);
#endif
cout << "Decimal point = "
<< np.decimal_point() << endl;
cout << "Thousands separator = "
<< np.thousands_sep() << endl;
cout << "True name = "
<< np.truename() << endl;
cout << "False name = "
<< np.falsename() << endl;
return 0;
}
SEE ALSO
locale, facets, num_put, num_get, ctype
Rogue Wave Software 02 Apr 1998 numpunct(3C++)