📄 _locale.h
字号:
/***************************************************************************
*
* _locale.h - Declarations for the Standard Library locale classes
*
* This is an internal header file used to implement the C++ Standard
* Library. It should never be #included directly by a program.
*
* $Id: _locale.h,v 1.1.1.1 2002/01/10 17:38:30 vkorstan Exp $
*
***************************************************************************
*
* Copyright (c) 1994-2001 Rogue Wave Software, Inc. All Rights Reserved.
*
* This computer software is owned by Rogue Wave Software, Inc. and is
* protected by U.S. copyright laws and other laws and by international
* treaties. This computer software is furnished by Rogue Wave Software,
* Inc. pursuant to a written license agreement and may be used, copied,
* transmitted, and stored only in accordance with the terms of such
* license and with the inclusion of the above copyright notice. This
* computer software or any other copies thereof may not be provided or
* otherwise made available to any other person.
*
* U.S. Government Restricted Rights. This computer software is provided
* with Restricted Rights. Use, duplication, or disclosure by the
* Government is subject to restrictions as set forth in subparagraph (c)
* (1) (ii) of The Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
* Commercial Computer Software--Restricted Rights at 48 CFR 52.227-19,
* as applicable. Manufacturer is Rogue Wave Software, Inc., 5500
* Flatiron Parkway, Boulder, Colorado 80301 USA.
*
**************************************************************************/
#ifndef _RWSTD_LOCALE_H_INCLUDED
#define _RWSTD_LOCALE_H_INCLUDED
#include <string>
#include <iosfwd>
#include <rw/_defs.h>
#include <rw/_error.h>
#include <rw/_locimp.h>
#include _RWSTD_CTIME
#include _RWSTD_CLOCALE
_RWSTD_NAMESPACE_BEGIN (std)
class _RWSTD_EXPORT locale;
template <class _CharT>
class collate;
#ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
template <class _Facet>
inline const _Facet& use_facet (const locale&);
template <class _Facet>
inline bool has_facet (const locale&) _THROWS (());
#else // if defined (_RWSTD_NO_TEMPLATE_ON_RETURN_TYPE)
template <class _Facet>
inline const _Facet& use_facet (const locale&, _Facet*);
template <class _Facet>
inline bool has_facet (const locale&, _Facet*) _THROWS (());
#endif // _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
_RWSTD_NAMESPACE_END // std
_RWSTD_NAMESPACE_BEGIN (std)
class _RWSTD_EXPORT locale
{
public:
class facet;
class id;
friend class facet;
friend class id;
typedef int category;
_RWSTD_STATIC_CONST (category, none = _RW::__rw_locale_imp::_C_none);
_RWSTD_STATIC_CONST (category, collate = _RW::__rw_locale_imp::_C_collate);
_RWSTD_STATIC_CONST (category, ctype = _RW::__rw_locale_imp::_C_ctype);
_RWSTD_STATIC_CONST (category, monetary = _RW::__rw_locale_imp::_C_monetary);
_RWSTD_STATIC_CONST (category, numeric = _RW::__rw_locale_imp::_C_numeric);
_RWSTD_STATIC_CONST (category, time = _RW::__rw_locale_imp::_C_time);
_RWSTD_STATIC_CONST (category, messages = _RW::__rw_locale_imp::_C_messages);
_RWSTD_STATIC_CONST (category, all = _RW::__rw_locale_imp::_C_all);
// The default constructor creates a copy of the current global locale,
// the locale specified in the most recent call to locale::global().
// If locale::global() has not been called, it is the classic "C" locale.
inline locale () _THROWS (());
// The copy constructor (and the assignment operator, below) can be used
// freely. Like a string, most of a locale's contents are in a separate,
// reference-counted implementation object, so copying and assigning
// locales/ has little overhead.
inline locale (const locale& __rhs) _THROWS (())
: _C_imp (__rhs._C_imp) {
_RWSTD_ATOMIC_PREINCREMENT (_C_imp->_C_ref_count, _C_imp->_C_mutex);
}
// The following constructor creates a locale composed of by-name facets
// and assigns it a name. The valid arguments are "", "C", and a set of
// strings defined by the compiler vendor. These cause the facets of
// the locale to be obtained, respectively, from the user's preferred
// locale, from the classic locale, or from the compiler's locale
// database. (In many cases, the preferred locale is specified by
// environment variables such as LANG or LC_ALL.) If the argument is
// not recognized, the constructor throws runtime_error.
_EXPLICIT locale (const char*);
// The following constructor copies its first argument except for
// the facets in the categories identified by the third argument,
// which are obtained by name using the second argument.
// Can throw runtime_error.
locale (const locale&, const char*, category);
// The following templatized constructor copies its first argument except
// the single _Facet of type _Facet
#ifndef _RWSTD_NO_MEMBER_TEMPLATES
template <class _Facet>
locale (const locale&, _Facet*);
#else
// If your compiler does not support member function templates, we provide
// the following work-around to let you accrete facets onto a locale.
// This constructor copies its first argument except for the single
// _Facet of the type of the second argument, for which it uses
// the second argument. To determine the type of the second argument,
// it calls the non-standard virtual method _C_get_id in the second
// argument. If you are creating your own _Facet types on a compiler
// that does not support member templates, you must code a _C_get_id
// member as follows in each new base class _Facet (i.e. in each _Facet
// class that has its own static member id of type locale::id):
//
// virtual locale::id &_C_get_id (void) const { return id; }
//
// See the _C_get_id members in the standard facets below for examples.
locale (const locale&, facet*);
#endif // _RWSTD_NO_MEMBER_TEMPLATES
// The following constructor copies its first argument except for
// the facets in the categories identified by the third argument,
// which are obtained from the second argument.
locale (const locale&, const locale&, category);
~locale () {
// HACK: _C_imp should normally never be 0; internally, though,
// it's set to 0 in locale::_C_make_facet to prevent a deadlock
if (_C_imp && 0 == _RWSTD_ATOMIC_PREDECREMENT (_C_imp->_C_ref_count,
_C_imp->_C_mutex))
delete _C_imp;
}
const locale& operator = (const locale&) _THROWS (());
// The following member function returns a copy of this locale (*this)
// except the single _Facet of type _Facet obtained from the other locale.
#ifndef _RWSTD_NO_MEMBER_TEMPLATES
#ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
template <class _Facet>
locale combine (const locale &__rhs) const {
// The cast from (const _Facet*) to (_Facet*) highlights a possible
// defect in the Standard ... see the issues list.
return locale (*this,
_RWSTD_CONST_CAST(_Facet*, &_USE_FACET (_Facet, __rhs)));
}
#endif // _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
#endif // _RWSTD_NO_MEMBER_TEMPLATES
// The following returns the locale name, or "*" if the locale is unnamed.
string name () const;
// Two locales are equal if they are the same object, or one is a copy
// of the other (i.e. they have the same implementation object),
// or both are named and their names are the same.
bool operator== (const locale &__rhs) const {
return this == &__rhs || _C_imp == __rhs._C_imp
|| name() != "*" && name () == __rhs.name();
}
bool operator != (const locale& __rhs) const {
return !(*this == __rhs);
}
// The following templatized operator () satisfies STL requirements for
// a comparator predicate template argument for comparing strings
// according to the collating sequence of the locale. It lets you use
// a locale directly as a comparator using syntax like
// sort(v.begin(), v.end(), loc),
// where v is a vector of some string type and loc is a locale.
#ifndef _RWSTD_NO_MEMBER_TEMPLATES
template <class _CharT, class _Traits, class _Allocator>
bool
operator() (const basic_string<_CharT, _Traits, _Allocator>& __x,
const basic_string<_CharT, _Traits, _Allocator>& __y) const;
#else // if defined (_RWSTD_NO_MEMBER_TEMPLATES)
bool operator() (const string &__x, const string &__y) const;
#ifndef _RWSTD_NO_WCHAR_T
bool operator() (const wstring &__x, const wstring &__y) const;
#endif // _RWSTD_NO_WCHAR_T
#endif // _RWSTD_NO_MEMBER_TEMPLATES
// Replaces the current global locale
static locale global (const locale&);
// Returns the classic "C" locale
static const locale& classic ();
// class _Facet -- base class for locale feature sets.
// Any class deriving from _Facet that wants to be perceived as a distinct
// _Facet, as opposed to a re-implementation of an existing _Facet, must
// declare a static member: static std::locale::id id;
class _RWSTD_EXPORT facet: public _RW::__rw_facet_base {
friend class _RW::__rw_locale_imp;
friend class locale;
protected:
_EXPLICIT facet (size_t __ref = 0, int __cat = 0)
: _RW::__rw_facet_base (__ref, __cat) { }
#ifdef _RWSTD_NO_MEMBER_TEMPLATES
virtual id &_C_get_id (void) const = 0;
#endif
private:
facet (const facet&); // not defined
void operator= (const facet&); // not defined
};
// class id -- _Facet type identifier.
// This is an implementation class. It is used internally as an index
// to find facets within a locale. Each distinct _Facet (i.e. each T
// that can be the parameter of a use_facet<_TypeT> call) has a unique
// static member of type locale::id named id. The class is made public
// to enable extension of the set of standard facets. Objects of this
// type don't need to be constructed or referenced in any other
// circumstances.
// the class must be `exported' in order for MSVC to collapse
// the static in _C_init into a single object if linking to a DLL
class _RWSTD_EXPORT id {
friend class locale;
_MUTABLE size_t _C_id; // unique id
void _C_init () const;
operator size_t () const {
return _C_id;
}
public:
id (): _C_id (0) { }
private:
id (const id&); // undefined
void operator= (const id&); // undefined
};
// Typedef for the implementation-defined call-back functions
// that must be passed to _C_make_facet (below).
typedef _RW::__rw_facet_maker_func __facet_maker_func;
// MT-safe std::use_facet<>() implementation
const facet& _C_use_facet (const id &__id, bool __implicit, category __cat,
__facet_maker_func __maker) const;
// same as above but not MT-safe
const facet& _C_unsafe_use_facet (const id &__id, bool __implicit,
category __cat,
__facet_maker_func __maker) const;
// The following function retrieves an implicit _Facet from a cache,
// or creates one if needed (via call to the passed call-back
// function), and makes it an explicit _Facet of the locale.
facet* _C_make_facet (const id &__id, bool __implicit,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -