34 #ifndef _LOCALE_CLASSES_H 35 #define _LOCALE_CLASSES_H 1 37 #ifdef _GLIBCXX_SYSHDR 38 #pragma GCC system_header 45 #ifdef __glibcxx_text_encoding 49 namespace std _GLIBCXX_VISIBILITY(default)
51 _GLIBCXX_BEGIN_NAMESPACE_VERSION
83 template<
typename _Facet>
87 template<
typename _Facet>
91 template<
typename _Facet>
93 __try_use_facet(
const locale&) _GLIBCXX_NOTHROW;
95 template<
typename _Cache>
96 friend struct __use_cache;
163 #if __cplusplus >= 201103L 215 template<
typename _Facet>
230 operator=(const
locale& __other) throw();
244 template<typename _Facet>
254 _GLIBCXX_NODISCARD _GLIBCXX_DEFAULT_ABI_TAG
258 #ifdef __glibcxx_text_encoding 259 # if __CHAR_BIT__ == 8 264 encoding()
const =
delete;
279 #if __cpp_impl_three_way_comparison < 201907L 288 operator!=(
const locale& __other)
const throw()
307 template<
typename _Char,
typename _Traits,
typename _Alloc>
310 operator()(
const basic_string<_Char, _Traits, _Alloc>& __s1,
311 const basic_string<_Char, _Traits, _Alloc>& __s2)
const;
339 static _Impl* _S_classic;
342 static _Impl* _S_global;
348 static const char*
const*
const _S_categories;
360 enum { _S_categories_size = 6 + _GLIBCXX_NUM_CATEGORIES };
363 static __gthread_once_t _S_once;
373 _S_initialize_once() throw();
381 #if _GLIBCXX_USE_CXX11_ABI 382 static const id*
const _S_twinned_facets[];
386 #if __cpp_lib_type_trait_variable_templates // C++ >= 17 387 template<
typename _Tp>
388 constexpr
bool __is_facet = is_base_of_v<locale::facet, _Tp>;
389 template<
typename _Tp>
390 constexpr
bool __is_facet<volatile _Tp> =
false;
408 friend class locale::_Impl;
410 mutable _Atomic_word _M_refcount;
413 static __c_locale _S_c_locale;
416 static const char _S_c_name[2];
419 static __gthread_once_t _S_once;
423 _S_initialize_once();
436 facet(
size_t __refs = 0) throw() : _M_refcount(__refs ? 1 : 0)
444 _S_create_c_locale(__c_locale& __cloc,
const char* __s,
445 __c_locale __old = 0);
448 _S_clone_c_locale(__c_locale& __cloc)
throw();
451 _S_destroy_c_locale(__c_locale& __cloc);
454 _S_lc_ctype_c_locale(__c_locale __cloc,
const char* __s);
461 _GLIBCXX_CONST
static const char*
462 _S_get_c_name() throw();
464 #if __cplusplus < 201103L 469 operator=(
const facet&);
474 operator=(
const facet&) =
delete;
479 _M_add_reference()
const throw()
480 { __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); }
483 _M_remove_reference()
const throw()
486 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_refcount);
487 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1) == 1)
489 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_refcount);
497 const facet* _M_sso_shim(
const id*)
const;
498 const facet* _M_cow_shim(
const id*)
const;
520 friend class locale::_Impl;
522 template<
typename _Facet>
526 template<
typename _Facet>
530 template<
typename _Facet>
532 __try_use_facet(
const locale&) _GLIBCXX_NOTHROW;
537 mutable size_t _M_index;
540 static _Atomic_word _S_refcount;
543 operator=(
const id&);
554 _M_id()
const throw();
566 template<
typename _Facet>
570 template<
typename _Facet>
574 template<
typename _Facet>
576 __try_use_facet(
const locale&) _GLIBCXX_NOTHROW;
578 template<
typename _Cache>
579 friend struct __use_cache;
583 _Atomic_word _M_refcount;
584 const facet** _M_facets;
585 size_t _M_facets_size;
586 const facet** _M_caches;
589 static const locale::id*
const _S_id_numeric[];
590 static const locale::id*
const _S_id_collate[];
592 static const locale::id*
const _S_id_monetary[];
593 static const locale::id*
const _S_id_messages[];
594 static const locale::id*
const*
const _S_facet_categories[];
597 _M_add_reference() throw()
598 { __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); }
601 _M_remove_reference() throw()
604 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_refcount);
605 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1) == 1)
607 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_refcount);
615 _Impl(
const _Impl&,
size_t);
616 _Impl(
const char*,
size_t);
617 _Impl(
size_t)
throw();
624 operator=(const _Impl&);
632 for (
size_t __i = 0; __ret && __i < _S_categories_size - 1; ++__i)
633 __ret = __builtin_strcmp(_M_names[__i], _M_names[__i + 1]) == 0;
638 _M_replace_categories(
const _Impl*,
category);
641 _M_replace_category(
const _Impl*,
const locale::id*
const*);
644 _M_replace_facet(
const _Impl*,
const locale::id*);
647 _M_install_facet(
const locale::id*,
const facet*);
649 template<
typename _Facet>
651 _M_init_facet(_Facet* __facet)
652 { _M_install_facet(&_Facet::id, __facet); }
654 template<
typename _Facet>
656 _M_init_facet_unchecked(_Facet* __facet)
658 __facet->_M_add_reference();
659 _M_facets[_Facet::id._M_id()] = __facet;
663 _M_install_cache(
const facet*,
size_t);
665 void _M_init_extra(facet**);
666 void _M_init_extra(
void*,
void*,
const char*,
const char*);
668 #ifdef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT 669 void _M_init_extra_ldbl128(
bool);
686 template<
typename _CharT>
700 __c_locale _M_c_locale_collate;
715 : facet(__refs), _M_c_locale_collate(_S_get_c_locale())
729 : facet(__refs), _M_c_locale_collate(_S_clone_c_locale(__cloc))
745 compare(
const _CharT* __lo1,
const _CharT* __hi1,
746 const _CharT* __lo2,
const _CharT* __hi2)
const 747 {
return this->do_compare(__lo1, __hi1, __lo2, __hi2); }
765 {
return this->do_transform(__lo, __hi); }
778 hash(
const _CharT* __lo,
const _CharT* __hi)
const 779 {
return this->do_hash(__lo, __hi); }
783 _M_compare(
const _CharT*,
const _CharT*)
const throw();
786 _M_transform(_CharT*,
const _CharT*,
size_t)
const throw();
792 { _S_destroy_c_locale(_M_c_locale_collate); }
807 do_compare(
const _CharT* __lo1,
const _CharT* __hi1,
808 const _CharT* __lo2,
const _CharT* __hi2)
const;
821 do_transform(
const _CharT* __lo,
const _CharT* __hi)
const;
834 do_hash(
const _CharT* __lo,
const _CharT* __hi)
const;
837 template<
typename _CharT>
843 collate<char>::_M_compare(
const char*,
const char*)
const throw();
847 collate<char>::_M_transform(
char*,
const char*,
size_t)
const throw();
849 #ifdef _GLIBCXX_USE_WCHAR_T 852 collate<wchar_t>::_M_compare(
const wchar_t*,
const wchar_t*)
const throw();
856 collate<wchar_t>::_M_transform(
wchar_t*,
const wchar_t*,
size_t)
const throw();
860 template<
typename _CharT>
874 if (__builtin_strcmp(__s,
"C") != 0
875 && __builtin_strcmp(__s,
"POSIX") != 0)
877 this->_S_destroy_c_locale(this->_M_c_locale_collate);
878 this->_S_create_c_locale(this->_M_c_locale_collate, __s);
882 #if __cplusplus >= 201103L 890 ~collate_byname() { }
893 _GLIBCXX_END_NAMESPACE_VERSION
_CharT char_type
Public typedefs.
long hash(const _CharT *__lo, const _CharT *__hi) const
Return hash of a string.
Primary class template messages.This facet encapsulates the code to retrieve messages from message ca...
friend const _Facet & use_facet(const locale &)
Return a facet.use_facet looks for and returns a reference to a facet of type Facet where Facet is th...
static const category messages
Category values.
_CharT char_type
Public typedefs.
class collate_byname [22.2.4.2].
virtual ~facet()
Facet destructor.
int category
Definition of locale::category.
static const locale & classic()
Return reference to the C locale.
static const category none
Category values.
~locale()
Locale destructor.
constexpr _Iterator __base(_Iterator __it)
locale(const locale &__base, const std::string &__s, category __cat)
Construct locale with facets from another locale.
int compare(const _CharT *__lo1, const _CharT *__hi1, const _CharT *__lo2, const _CharT *__hi2) const
Compare two strings.
static const category numeric
Category values.
collate(size_t __refs=0)
Constructor performs initialization.
locale()
Default constructor.
locale combine(const locale &__other) const
Construct locale with another facet.
string_type transform(const _CharT *__lo, const _CharT *__hi) const
Transform string to comparable form.
collate(__c_locale __cloc, size_t __refs=0)
Internal constructor. Not for general use.
basic_string< _CharT > string_type
Public typedefs.
locale(const std::string &__s)
Named locale constructor.
static const category monetary
Category values.
Localization functionality base class.The facet class is the base class for a localization feature...
friend bool has_facet(const locale &)
Test for the presence of a facet.has_facet tests the locale argument for the presence of the facet ty...
static locale global(const locale &__loc)
Set global locale.
static const category all
Category values.
bool operator()(const basic_string< _Char, _Traits, _Alloc > &__s1, const basic_string< _Char, _Traits, _Alloc > &__s2) const
Compare two strings according to collate.
ISO C++ entities toplevel namespace is std.
virtual ~collate()
Destructor.
friend const _Facet & use_facet(const locale &)
Return a facet.use_facet looks for and returns a reference to a facet of type Facet where Facet is th...
bool operator==(const locale &__other) const
Locale equality.
Facet for localized string comparison.
Container class for localization functionality.The locale class is first a class wrapper for C librar...
string name() const
Return locale name.
static locale::id id
Numpunct facet id.
facet(size_t __refs=0)
Facet constructor.
friend bool has_facet(const locale &)
Test for the presence of a facet.has_facet tests the locale argument for the presence of the facet ty...
basic_string< _CharT > string_type
Public typedefs.
static const category time
Category values.
Primary class template ctype facet.This template class defines classification and conversion function...
Facet ID class.The ID class provides facets with an index used to identify them. Every facet class mu...