std::locale Class Reference

Container class for localization functionality. More...

#include <locale_classes.h>

List of all members.

Public Types

typedef int category
 Definition of locale::category.


Public Member Functions

 locale () throw ()
 Default constructor.

 locale (const locale &__other) throw ()
 Copy constructor.

 locale (const char *__s)
 Named locale constructor.

 locale (const locale &__base, const char *__s, category __cat)
 Construct locale with facets from another locale.

 locale (const locale &__base, const locale &__add, category __cat)
 Construct locale with facets from another locale.

template<typename _Facet>  locale (const locale &__other, _Facet *__f)
 Construct locale with another facet.

 ~locale () throw ()
 Locale destructor.

const localeoperator= (const locale &__other) throw ()
 Assignment operator.

template<typename _Facet> locale combine (const locale &__other) const
 Construct locale with another facet.

string name () const
 Return locale name.

bool operator== (const locale &__other) const throw ()
 Locale equality.

bool operator!= (const locale &__other) const throw ()
 Locale inequality.

template<typename _Char, typename _Traits, typename _Alloc> bool operator() (const basic_string< _Char, _Traits, _Alloc > &__s1, const basic_string< _Char, _Traits, _Alloc > &__s2) const
 Compare two strings according to collate.


Static Public Member Functions

locale global (const locale &)
 Set global locale.

const localeclassic ()
 Return reference to the "C" locale.


Static Public Attributes

const category none = 0
 Category values.

const category ctype = 1L << 0
const category numeric = 1L << 1
const category collate = 1L << 2
const category time = 1L << 3
const category monetary = 1L << 4
const category messages = 1L << 5
const category all

Private Member Functions

 locale (_Impl *) throw ()
void _M_coalesce (const locale &__base, const locale &__add, category __cat)

Static Private Member Functions

void _S_initialize ()
void _S_initialize_once ()
category _S_normalize_category (category)

Private Attributes

_Impl_M_impl

Static Private Attributes

_Impl_S_classic
_Impl_S_global
const char *const *const  _S_categories
const size_t _S_categories_size = 6 + _GLIBCXX_NUM_CATEGORIES

Friends

class facet
class _Impl
struct __use_cache
template<typename _Facet> bool has_facet (const locale &) throw ()
 Test for the presence of a facet.

template<typename _Facet> const _Facet & use_facet (const locale &)
 Return a facet.


Detailed Description

Container class for localization functionality.

The locale class is first a class wrapper for C library locales. It is also an extensible container for user-defined localization. A locale is a collection of facets that implement various localization features such as money, time, and number printing.

Constructing C++ locales does not change the C library locale.

This library supports efficient construction and copying of locales through a reference counting implementation of the locale class.

Definition at line 67 of file locale_classes.h.


Member Typedef Documentation

typedef int std::locale::category
 

Definition of locale::category.

Definition at line 72 of file locale_classes.h.


Constructor & Destructor Documentation

std::locale::locale  )  throw ()
 

Default constructor.

Constructs a copy of the global locale. If no locale has been explicitly set, this is the "C" locale.

Referenced by combine().

std::locale::locale const locale __other  )  throw ()
 

Copy constructor.

Constructs a copy of other.

Parameters:
other The locale to copy.

std::locale::locale const char *  __s  )  [explicit]
 

Named locale constructor.

Constructs a copy of the named C library locale.

Parameters:
s Name of the locale to construct.
Exceptions:
std::runtime_error if s is null or an undefined locale.

std::locale::locale const locale __base,
const char *  __s,
category  __cat
 

Construct locale with facets from another locale.

Constructs a copy of the locale base. The facets specified by cat are replaced with those from the locale named by s. If base is named, this locale instance will also be named.

Parameters:
base The locale to copy.
s Name of the locale to use facets from.
cat Set of categories defining the facets to use from s.
Exceptions:
std::runtime_error if s is null or an undefined locale.

std::locale::locale const locale __base,
const locale __add,
category  __cat
 

Construct locale with facets from another locale.

Constructs a copy of the locale base. The facets specified by cat are replaced with those from the locale add. If base and add are named, this locale instance will also be named.

Parameters:
base The locale to copy.
add The locale to use facets from.
cat Set of categories defining the facets to use from add.

template<typename _Facet>
std::locale::locale const locale __other,
_Facet *  __f
 

Construct locale with another facet.

Constructs a copy of the locale other. The facet is added to , replacing an existing facet of type Facet if there is one. If is null, this locale is a copy of other.

Parameters:
other The locale to copy.
f The facet to add in.

Definition at line 568 of file locale_classes.h.

References __throw_exception_again, _Impl, _M_impl, std::locale::_Impl::_M_install_facet(), std::locale::_Impl::_M_names, std::locale::_Impl::_M_remove_reference(), and _S_categories_size.

std::locale::~locale  )  throw ()
 

Locale destructor.

std::locale::locale _Impl  )  throw () [explicit, private]
 


Member Function Documentation

void std::locale::_M_coalesce const locale __base,
const locale __add,
category  __cat
[private]
 

void std::locale::_S_initialize  )  [static, private]
 

void std::locale::_S_initialize_once  )  [static, private]
 

category std::locale::_S_normalize_category category   )  [static, private]
 

const locale& std::locale::classic  )  [static]
 

Return reference to the "C" locale.

template<typename _Facet>
locale std::locale::combine const locale __other  )  const
 

Construct locale with another facet.

Constructs and returns a new copy of this locale. Adds or replaces an existing facet of type Facet from the locale other into the new locale.

Parameters:
Facet The facet type to copy from other
other The locale to copy from.
Returns:
Newly constructed locale.
Exceptions:
std::runtime_error if other has no facet of type Facet.

Definition at line 46 of file locale_facets.tcc.

References __throw_exception_again, _Impl, _M_impl, std::locale::_Impl::_M_remove_reference(), std::locale::_Impl::_M_replace_facet(), and locale().

locale std::locale::global const locale  )  [static]
 

Set global locale.

This function sets the global locale to the argument and returns a copy of the previous global locale. If the argument has a name, it will also call std::setlocale(LC_ALL, loc.name()).

Parameters:
locale The new locale to make global.
Returns:
Copy of the old global locale.

string std::locale::name  )  const
 

Return locale name.

Returns:
Locale name or "*" if unnamed.

bool std::locale::operator!= const locale __other  )  const throw () [inline]
 

Locale inequality.

Parameters:
other The locale to compare against.
Returns:
! (*this == other)

Definition at line 241 of file locale_classes.h.

References operator==().

template<typename _CharT, typename _Traits, typename _Alloc>
bool std::locale::operator() const basic_string< _Char, _Traits, _Alloc > &  __s1,
const basic_string< _Char, _Traits, _Alloc > &  __s2
const
 

Compare two strings according to collate.

Template operator to compare two strings using the compare function of the collate facet in this locale. One use is to provide the locale to the sort function. For example, a vector v of strings could be sorted according to locale loc by doing:

std::sort(v.begin(), v.end(), loc);

Parameters:
s1 First string to compare.
s2 Second string to compare.
Returns:
True if collate<Char> facet compares s1 < s2, else false.

Definition at line 63 of file locale_facets.tcc.

References std::basic_string< _CharT, _Traits, _Alloc >::data(), and std::basic_string< _CharT, _Traits, _Alloc >::length().

const locale& std::locale::operator= const locale __other  )  throw ()
 

Assignment operator.

Set this locale to be a copy of other.

Parameters:
other The locale to copy.
Returns:
A reference to this locale.

bool std::locale::operator== const locale __other  )  const throw ()
 

Locale equality.

Parameters:
other The locale to compare against.
Returns:
True if other and this refer to the same locale instance, are copies, or have the same name. False otherwise.

Referenced by operator!=().


Friends And Related Function Documentation

friend struct __use_cache [friend]
 

Definition at line 91 of file locale_classes.h.

friend class _Impl [friend]
 

Definition at line 80 of file locale_classes.h.

Referenced by combine(), and locale().

friend class facet [friend]
 

Definition at line 79 of file locale_classes.h.

template<typename _Facet>
bool has_facet const locale __loc  )  throw () [friend]
 

Test for the presence of a facet.

has_facet tests the locale argument for the presence of the facet type provided as the template parameter. Facets derived from the facet parameter will also return true.

Parameters:
Facet The facet type to test the presence of.
locale The locale to test.
Returns:
true if locale contains a facet of type Facet, else false.

Definition at line 85 of file locale_facets.tcc.

template<typename _Facet>
const _Facet& use_facet const locale __loc  )  [friend]
 

Return a facet.

use_facet looks for and returns a reference to a facet of type Facet where Facet is the template parameter. If has_facet(locale) is true, there is a suitable facet to return. It throws std::bad_cast if the locale doesn't contain a facet of type Facet.

Parameters:
Facet The facet type to access.
locale The locale to use.
Returns:
Reference to facet of type Facet.
Exceptions:
std::bad_cast if locale doesn't contain a facet of type Facet.

Definition at line 107 of file locale_facets.tcc.


Member Data Documentation

_Impl* std::locale::_M_impl [private]
 

Definition at line 286 of file locale_classes.h.

Referenced by combine(), locale(), std::__use_cache< __moneypunct_cache< _CharT, _Intl > >::operator()(), std::__use_cache< __numpunct_cache< _CharT > >::operator()(), and std::use_facet().

const char* const* const std::locale::_S_categories [static, private]
 

Definition at line 298 of file locale_classes.h.

const size_t std::locale::_S_categories_size = 6 + _GLIBCXX_NUM_CATEGORIES [static, private]
 

Definition at line 310 of file locale_classes.h.

Referenced by locale().

_Impl* std::locale::_S_classic [static, private]
 

Definition at line 289 of file locale_classes.h.

_Impl* std::locale::_S_global [static, private]
 

Definition at line 292 of file locale_classes.h.

const category std::locale::all [static]
 

Initial value:

Definition at line 112 of file locale_classes.h.

const category std::locale::collate = 1L << 2 [static]
 

Definition at line 108 of file locale_classes.h.

const category std::locale::ctype = 1L << 0 [static]
 

Definition at line 106 of file locale_classes.h.

const category std::locale::messages = 1L << 5 [static]
 

Definition at line 111 of file locale_classes.h.

const category std::locale::monetary = 1L << 4 [static]
 

Definition at line 110 of file locale_classes.h.

const category std::locale::none = 0 [static]
 

Category values.

The standard category values are none, ctype, numeric, collate, time, monetary, and messages. They form a bitmask that supports union and intersection. The category all is the union of these values.

Definition at line 105 of file locale_classes.h.

const category std::locale::numeric = 1L << 1 [static]
 

Definition at line 107 of file locale_classes.h.

const category std::locale::time = 1L << 3 [static]
 

Definition at line 109 of file locale_classes.h.


The documentation for this class was generated from the following files:
Generated on Tue Jan 30 17:32:13 2007 for GNU C++ STL by doxygen 1.3.6