Click on the banner to return to the class reference home page.

numpunct, numpunct_byname


numpunctlocale::facet

Summary

Numeric punctuation facet.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

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
string_type




Constructors and Destructors

explicit numpunct(size_t refs = 0)




explicit numpunct_byname(const char* name, size_t refs = 0);




~numpunct();  // virtual and protected
~numpunct_byname();  // virtual and protected




Facet ID

static locale::id id;




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 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;

Protected Member Functions

virtual char_type    
do_decimal_point() const;




virtual string_type  
do_falsename()     const;  // for bool
virtual string_type  
do_truename()      const;  // for bool




virtual string       
do_grouping()      const;




virtual char_type    
do_thousands_sep() const;




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


©Copyright 1996, Rogue Wave Software, Inc.