numpunct (3C++std) - Tru64 UNIX
Standard C++ LibraryCopyright 1996, Rogue Wave Software, Inc.
NAME
numpunct, numpunct_byname - 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. This template
provides punctuation based on the "C" locale, while the numpunct_byname
facet provides the same facilities for 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 AND DESTRUCTORS
explicit numpunct(size_t refs = 0)
Construct 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
had, if refs is 1 then the object must be explicitly deleted; the
locale will 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);
Construct a numpunct_byname facet. Use the named locale specified by
the name argument. The refs argument serves the same purpose as it does
for the numpunct constructor.
~numpunct(); // virtual and protected
~numpunct_byname(); // virtual and protected
Destroy 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 provide an interface to protected
members. Each public member xxx has a corresponding virtual protected
member do_xxx. All work is delagated 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_type
do_falsename() const; // for bool
virtual string_type
do_truename() const; // for bool
Returns a string representing the name of the boolean values true and
false respectively . numpunct returns "true" and "false".
virtual string
do_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_type
do_thousands_sep() const;
Returns the decimal digit group seperator. 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 seperator = "
<< 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
STANDARDS CONFORMANCE
ANSI X3J16/ISO WG21 Joint C++ Committee
privacy and legal statement