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

moneypunct, moneypunct_byname


moneypunct_base moneypunct_bynamemoneypunct locale::facet

Summary

Monetary punctuation facets.

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

Synopsis

#include <locale>
class money_base;

template <class charT, bool International = false>
class moneypunct;

Description

The moneypunct facets provide formatting specifications and punctuation character for monetary values. The moneypunct facet provides punctuation based on the "C" locale, while the moneypunct_byname facet provides the same facilities for 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 provides a structure, pattern, that specifies the order of syntactic elements in a monetary value and enumeration values representing those elements. The pattern struct provides a simple array of characters, field. Each index in field is taken up by an enumeration value indicating the location of a syntactic element. The enumeration values are described below:

Format Flag
Meaning
none
No grouping seperator
space
Use space for grouping seperator
symbol
Currency symbol
sign
Sign of monetary value
value
The monetary value itself

The do_pos_format an do_neg_format member functions of moneypunct both return the pattern type. See the description of these functions for further elaboration.

Interface

class money_base {
public:
  enum part { none, space, symbol, sign, value };
  struct pattern { char field[4]; };
};

template <class charT, bool International = false>
class moneypunct : public locale::facet, public money_base {
public:
  typedef charT char_type;
  typedef basic_string<charT> string_type;
  explicit moneypunct(size_t = 0);
  charT        decimal_point() const;
  charT        thousands_sep() const;
  string       grouping()      const;
  string_type  curr_symbol()   const;
  string_type  positive_sign() const;
  string_type  negative_sign() const;
  int          frac_digits()   const;
  pattern      pos_format()    const;
  pattern      neg_format()    const;
  static locale::id id;
  static const bool intl = International;
protected:
  ~moneypunct();  // virtual
  virtual charT        do_decimal_point() const;
  virtual charT        do_thousands_sep() const;
  virtual string       do_grouping()      const;
  virtual string_type  do_curr_symbol()   const;
  virtual string_type  do_positive_sign() const;
  virtual string_type  do_negative_sign() const;
  virtual int          do_frac_digits()   const;
  virtual pattern      do_pos_format()    const;
  virtual pattern      do_neg_format()    const;
}; 

template <class charT, bool Intl = false>
class moneypunct_byname : public moneypunct<charT, Intl> {
public:
  explicit moneypunct_byname(const char*, size_t = 0);
protected:
  ~moneypunct_byname();  // virtual
  virtual charT        do_decimal_point() const;
  virtual charT        do_thousands_sep() const;
  virtual string       do_grouping()      const;
  virtual string_type  do_curr_symbol()   const;
  virtual string_type  do_positive_sign() const;
  virtual string_type  do_negative_sign() const;
  virtual int          do_frac_digits()   const;
  virtual pattern      do_pos_format()    const;
  virtual pattern      do_neg_format()    const;
};

Types

char_type
string_type

Constructors and Destructors

explicit moneypunct(size_t refs = 0)





explicit moneypunct_byname(const char* name, size_t refs = 0);
~moneypunct();  // virtual and protected




Static Members

static locale::id id;




static const bool intl = Intl;




Public Member Functions

The public members of the moneypunct and moneypunct_byname facets 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 decimal_point function simply calls its protected cousin do_decimal_point.

string_type  curr_symbol()   const;
charT        decimal_point() const;
int          frac_digits()   const;
string       grouping()      const;
pattern      neg_format()    const;
string_type  negative_sign() const;
pattern      pos_format()    const;
string_type  positive_sign() const;
charT        thousands_sep() const;

Protected Member Functions

virtual string_type  
do_curr_symbol()   const;
virtual charT        
do_decimal_point() const;
virtual int          
do_frac_digits()   const;





virtual string       
do_grouping()      const;
virtual string_type  
do_negative_sign() const;





virtual pattern 
do_neg_format()    const;
virtual pattern 
do_pos_format()    const; 
virtual string_type  
do_positive_sign() const;





virtual charT        
do_thousands_sep() const;

Example

//
// moneypun.cpp
//

#include <string>

#include <iostream>

int main ()
{
  using namespace std;

  locale loc;

  // Get a moneypunct facet
  const moneypunct<char,false>& mp = 
#ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  use_facet<moneypunct<char,false> >(loc);
#else
  use_facet(loc,(moneypunct<char,false>*)0);
#endif

  cout << "Decimal point        = " 
       << mp.decimal_point() << endl; 
  cout << "Thousands separator  = " 
       << mp.thousands_sep() << endl; 
  cout << "Currency symbol      = " 
       << mp.curr_symbol() << endl; 
  cout << "Negative Sign        = " 
       << mp.negative_sign() << endl; 
  cout << "Digits after decimal = " 
       << mp.frac_digits() << endl; 

  return 0;
}

See Also

locale, facets, money_put, money_get


©Copyright 1996, Rogue Wave Software, Inc.