diff options
author | Benjamin Kosnik <bkoz@redhat.com> | 2001-12-15 07:05:04 +0000 |
---|---|---|
committer | Benjamin Kosnik <bkoz@gcc.gnu.org> | 2001-12-15 07:05:04 +0000 |
commit | def9790d51a51a78a700567bb677225a90bc854e (patch) | |
tree | 8de54c61193922ab77a998c6f31861fa57869582 /libstdc++-v3/include/bits | |
parent | 88f92c0f3f41595fb8c7d233f5aacb205495bd87 (diff) | |
download | gcc-def9790d51a51a78a700567bb677225a90bc854e.zip gcc-def9790d51a51a78a700567bb677225a90bc854e.tar.gz gcc-def9790d51a51a78a700567bb677225a90bc854e.tar.bz2 |
Clean up initialization and simplfy caching of underlying "C" locale objects.
2001-12-14 Benjamin Kosnik <bkoz@redhat.com>
Clean up initialization and simplfy caching of underlying "C"
locale objects.
* src/localename.cc (locale::_Impl::_Impl(string, size_t):
Unconditionally create __clocale object for all named locales,
including "C" and "POSIX".
* config/locale/c_locale_generic.cc
(locale::facet::_S_create_c_locale): Always set __cloc to zero.
* config/locale/c_locale_gnu.cc: Always delete.
* include/bits/localefwd.h (locale::facet::_S_c_locale): New.
* src/locale.cc (locale::classic()): Initialize
locale::facet::_S_c_locale.
(locale::facet::_S_c_locale): Define.
* include/bits/locale_facets.h: Add ctype_byname<wchar_t> ctor
specialization.
* src/locale.cc: Add definition here.
* config/os/gnu-linux/bits/ctype_inline.h: Tweak.
* config/os/gnu-linux/bits/ctype_noninline.h: Adjust initializations.
* include/bits/locale_facets.h (ctype<char>::_M_c_locale_ctype): Add.
Adjust ctors, dtors.
(ctype<char>::_M_toupper): Remove const&.
(ctype<char>::_M_tolower): Remove const&.
(ctype<char>::_M_ctable): Remove const&.
* include/bits/locale_facets.h (collate): Clean up initialization
of _M_c_locale_collate in ctors and dtors.
* config/locale/collate_members_gnu.cc: Always use extended
functions.
* include/bits/locale_facets.h (messages): Clean up inits in ctor/dtor.
(messages_byname): Same.
* config/locale/messages_members_generic.h (messages::~messages):
Remove.
* config/locale/messages_members_gnu.h: Same.
* include/bits/localefwd.h: Clean. Move dtor definitions to
* src/locale.cc: Here.
* testsuite/22_locale/facet.cc: Fix spelling.
Named locale support for ctype<wchar_t>.
* acinclude.m4 (GLIBCPP_ENABLE_CLOCALE): Add variable
ctype_members_* bits.
* aclocal.m4: Regenerate.
* configure: Regenerate.
* src/Makefile.am (sources): Add ctype.cc.
* src/Makefile.in: Regenerate.
* config/locale/ctype_members_generic.cc: New file.
* config/locale/ctype_members_gnu.cc: New file.
* src/locale.cc: Remove ctype<wchart_t> definitions.
From-SVN: r48034
Diffstat (limited to 'libstdc++-v3/include/bits')
-rw-r--r-- | libstdc++-v3/include/bits/locale_facets.h | 81 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/localefwd.h | 17 |
2 files changed, 55 insertions, 43 deletions
diff --git a/libstdc++-v3/include/bits/locale_facets.h b/libstdc++-v3/include/bits/locale_facets.h index 967f399..8550709 100644 --- a/libstdc++-v3/include/bits/locale_facets.h +++ b/libstdc++-v3/include/bits/locale_facets.h @@ -171,7 +171,7 @@ namespace std explicit ctype(size_t __refs = 0) : __ctype_abstract_base<_CharT>(__refs) { } - static locale::id id; + static locale::id id; protected: virtual @@ -225,15 +225,16 @@ namespace std { public: // Types: - typedef char char_type; + typedef char char_type; - private: + protected: // Data Members: - bool _M_del; - __to_type const& _M_toupper; - __to_type const& _M_tolower; - const mask* const& _M_ctable; - const mask* _M_table; + __c_locale _M_c_locale_ctype; + bool _M_del; + __to_type _M_toupper; + __to_type _M_tolower; + const mask* _M_ctable; + const mask* _M_table; public: static locale::id id; @@ -259,9 +260,6 @@ namespace std scan_not(mask __m, const char* __lo, const char* __hi) const; protected: - virtual - ~ctype(); - const mask* table() const throw() { return _M_table; } @@ -270,6 +268,9 @@ namespace std classic_table() throw() { return _M_ctable; } + virtual + ~ctype(); + virtual bool do_is(mask __m, char_type __c) const; @@ -306,7 +307,7 @@ namespace std virtual const char_type* do_narrow(const char_type* __lo, const char_type* __hi, - char __dfault, char* __dest) const; + char __dfault, char* __dest) const; }; template<> @@ -320,11 +321,15 @@ namespace std { public: // Types: - typedef wchar_t char_type; - typedef wctype_t __wmask_type; + typedef wchar_t char_type; + typedef wctype_t __wmask_type; + protected: + __c_locale _M_c_locale_ctype; + + public: // Data Members: - static locale::id id; + static locale::id id; explicit ctype(size_t __refs = 0); @@ -375,7 +380,7 @@ namespace std virtual const char_type* do_narrow(const char_type* __lo, const char_type* __hi, - char __dfault, char* __dest) const; + char __dfault, char* __dest) const; }; @@ -395,22 +400,25 @@ namespace std typedef _CharT char_type; explicit - ctype_byname(const char*, size_t __refs = 0); + ctype_byname(const char* __s, size_t __refs = 0); protected: virtual - ~ctype_byname() { } + ~ctype_byname() { }; }; - // 22.2.1.4 Class ctype_byname specialization + // 22.2.1.4 Class ctype_byname specializations. template<> ctype_byname<char>::ctype_byname(const char*, size_t refs); + template<> + ctype_byname<wchar_t>::ctype_byname(const char*, size_t refs); // 22.2.1.5 Template class codecvt #include <bits/codecvt.h> + // 22.2.2 The numeric category. class __num_base { public: @@ -815,17 +823,14 @@ namespace std explicit collate(size_t __refs = 0) - : locale::facet(__refs), _M_c_locale_collate(NULL) - { } + : locale::facet(__refs) + { _M_c_locale_collate = _S_clone_c_locale(_S_c_locale); } // Non-standard. explicit collate(__c_locale __cloc, size_t __refs = 0) : locale::facet(__refs) - { - if (__cloc) - _M_c_locale_collate = _S_clone_c_locale(__cloc); - } + { _M_c_locale_collate = _S_clone_c_locale(__cloc); } int compare(const _CharT* __lo1, const _CharT* __hi1, @@ -850,10 +855,7 @@ namespace std protected: virtual ~collate() - { - if (_M_c_locale_collate) - _S_destroy_c_locale(_M_c_locale_collate); - } + { _S_destroy_c_locale(_M_c_locale_collate); } virtual int do_compare(const _CharT* __lo1, const _CharT* __hi1, @@ -899,10 +901,13 @@ namespace std explicit collate_byname(const char* __s, size_t __refs = 0) : collate<_CharT>(__refs) - { _S_create_c_locale(_M_c_locale_collate, __s); } + { + _S_destroy_c_locale(_M_c_locale_collate); + _S_create_c_locale(_M_c_locale_collate, __s); + } protected: - virtual + virtual ~collate_byname() { } }; @@ -1609,9 +1614,8 @@ namespace std explicit messages(size_t __refs = 0) - : locale::facet(__refs), _M_c_locale_messages(NULL), - _M_name_messages("C") - { } + : locale::facet(__refs), _M_name_messages("C") + { _M_c_locale_messages = _S_clone_c_locale(_S_c_locale); } // Non-standard. explicit @@ -1619,8 +1623,7 @@ namespace std : locale::facet(__refs) { _M_name_messages = __name; - if (__cloc) - _M_c_locale_messages = _S_clone_c_locale(__cloc); + _M_c_locale_messages = _S_clone_c_locale(__cloc); } catalog @@ -1641,7 +1644,8 @@ namespace std protected: virtual - ~messages(); + ~messages() + { _S_destroy_c_locale(_M_c_locale_messages); } virtual catalog do_open(const basic_string<char>&, const locale&) const; @@ -1723,8 +1727,9 @@ namespace std messages_byname(const char* __s, size_t __refs = 0) : messages<_CharT>(__refs) { - _S_create_c_locale(_M_c_locale_messages, __s); _M_name_messages = __s; + _S_destroy_c_locale(_M_c_locale_messages); + _S_create_c_locale(_M_c_locale_messages, __s); } protected: diff --git a/libstdc++-v3/include/bits/localefwd.h b/libstdc++-v3/include/bits/localefwd.h index af48b60..a0fe324 100644 --- a/libstdc++-v3/include/bits/localefwd.h +++ b/libstdc++-v3/include/bits/localefwd.h @@ -282,7 +282,10 @@ namespace std static inline void _S_initialize() - { if (!_S_classic) classic(); } + { + if (!_S_classic) + classic(); + } static category _S_normalize_category(category); @@ -344,7 +347,7 @@ namespace std _Impl(string __name, size_t); ~_Impl() throw(); - bool + inline bool _M_check_same_name() { bool __ret = true; @@ -352,6 +355,7 @@ namespace std __ret &= _M_names[i] == _M_names[i + 1]; return __ret; } + void _M_replace_categories(const _Impl*, category); @@ -387,11 +391,15 @@ namespace std friend class __enc_traits; protected: + // Contains data from the underlying "C" library for default "C" + // and "POSIX" locales. + static __c_locale _S_c_locale; + explicit facet(size_t __refs = 0) throw(); virtual - ~facet() { }; + ~facet(); static void _S_create_c_locale(__c_locale& __cloc, const char* __s); @@ -447,8 +455,7 @@ namespace std public: // NB: This class is always a static data member, and thus can be // counted on to be zero-initialized. - // XXX id() : _M_index(0) { } - id() { } + id(); }; template<typename _Facet> |