summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/bits/localefwd.h
diff options
context:
space:
mode:
authorbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2001-01-30 09:18:51 +0000
committerbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2001-01-30 09:18:51 +0000
commit2075288447ec881925fcc28e26b5b1b74944d48d (patch)
treef4cd5b7db4af6680ea3aecdacddb39448df7480b /libstdc++-v3/include/bits/localefwd.h
parenta53082e99f3957527c9cf36935f4de3e30d71613 (diff)
downloadgcc-2075288447ec881925fcc28e26b5b1b74944d48d.tar.gz
2001-01-29 Benjamin Kosnik <bkoz@redhat.com>
Preliminary named locales. * acinclude.m4 (GLIBCPP_ENABLE_CLOCALE): New macro. * aclocal.m4: Regenerate. * configure.in: Use it. * configure: Regerate. * src/Makefile.am (sources): Add c++locale.cc. (build_headers): Add c++locale.h. * src/Makefile.in: Regenerate. * config/c_locale_gnu.h: New file. * config/c_locale_gnu.cc: New file. Non-inline member functions for named locales, gnu-specific. * config/c_locale_generic.h: New file. * config/c_locale_generic.cc: New file. Non-inline member functions for named locales, generic version. * docs/html/configopts.html: Add documentation on new options. * include/bits/locale_facets.h (class _Messages): Remove. (class _Moneypunct): Remove. * src/locale-inst.cc: Remove. * include/bits/locale_facets.h (class _Collate): Remove. * src/locale-inst.cc (std): Remove. * src/locale.cc: And here. * include/bits/localefwd.h (locale::_M_coalesce): New function. Correctly put together multi-name locales. (_Impl(const _Impl&, category, size_t)): Remove. * include/bits/localefwd.h (locale::_Impl): Remove _M_construct_* member functions. (_M_normalize_category_names): Remove. (_M_replace_categories): Fix. * src/localename.cc (locale::_Impl::_M_construct_collate): Remove. (locale::_Impl::_M_construct_ctype): Remove. (locale::_Impl::_M_construct_monetary): Remove. (locale::_Impl::_M_construct_numeric): Remove. (locale::_Impl::_M_construct_time): Remove. (locale::_Impl::_M_construct_messages): Remove. * include/bits/locale_facets.h (_Bad_use_facet): Remove. (_Use_facet_failure_handle): Remove. * src/locale.cc: Remove definitions. * src/locale-inst.cc: And here. * testsuite/22_locale/ctor_copy_dtor.cc (test01): Fixup. Add tests. * src/localename.cc (locale::facet::_S_create_c_locale): Properly create and error-check underlying locale object. (locale::facet::_S_destroy_c_locale): Add, take care of properly tearing down underlying locale object. * include/bits/localefwd.h (locale::facet): Declare. * testsuite/22_locale/members.cc: Don't test "fr_FR" locale for correctness, as glibc apparently has incorrect info in it. Test with it when it works again..... * include/bits/localefwd.h (locale::_Impl::__vec_string): Remove. Number of categories is fixed at six, so just simplify and make this an array of strings. (locale::_Impl::_M_has_name): Remove. (locale::_Impl::_M_name): Remove. (locale::_Impl::_M_category_names): Turns into... (locale::_Impl::_M_names): ...this. (locale::_Impl::_M_has_same_name()): New function. * src/localename.cc (locale::_Impl::~_Impl()): Remove here. (locale::_Impl::_Impl(size_t __refs, string __str)): Simplify signature. * src/locale.cc (locale::name()): Construct mangled name accurately reflecting combined locale categories. * src/locale.cc (locale::classic()): Don't initialize here. * src/localename.cc (locale::_Impl::_Impl(size_t __num, size_t __refs, bool __has_name, string __str): Do it here. * include/bits/localefwd.h: _S_categories_num to _S_num_categories. _S_facets_num to _S_num_facets. (locale::id::id()): Explicitly set _M_index to zero. * src/locale.cc: Same. * src/locale.cc: (locale::locale(const char*)): Construct named locales uniquely. * src/locale.cc: Remove numpunct_byname ctors. * testsuite/22_locale/numpunct_byname.cc: New file. * testsuite/22_locale/numpunct.cc: New file. * include/bits/localefwd.h (class locale): Change data members to protected, from private. (_Impl::_M_get_c_locale): Add member function. (locale::facet::_M_get_global_impl()): Add member function. * include/bits/locale_facets.h (numpunct::_M_init): Change to take a __c_locale pointer. (numpunct::numpunct( __c_locale*, size_t)): Add additonal ctor for named locales. * testsuite/22_locale/members.cc: New file, test name and combine. * include/bits/locale_facets.h (class numpunct): Remove class _Punct and _Numpunct. Rewrite class numpunct to be correct for named locales. * include/bits/localefwd.h (locale::_Imp::_M_c_locale): Add. * src/localename.cc (_Impl::~_Impl()): Call __frelocale. (_Imp::_Impl(size_t, size_t, bool, string)) Initialize _M_c_locale. * src/locale-inst.cc: Remove _Numpunct, _Punct instantiations. * testsuite/22_locale/numpunct_char_members.cc: New file. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@39347 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/bits/localefwd.h')
-rw-r--r--libstdc++-v3/include/bits/localefwd.h123
1 files changed, 53 insertions, 70 deletions
diff --git a/libstdc++-v3/include/bits/localefwd.h b/libstdc++-v3/include/bits/localefwd.h
index cb86d9102fd..cafa045b410 100644
--- a/libstdc++-v3/include/bits/localefwd.h
+++ b/libstdc++-v3/include/bits/localefwd.h
@@ -1,6 +1,6 @@
// Locale support -*- C++ -*-
-// Copyright (C) 1997-2000 Free Software Foundation, Inc.
+// Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -38,9 +38,16 @@
#include <bits/std_climits.h> // For CHAR_BIT
#include <bits/std_string.h> // For string
#include <bits/std_cctype.h> // For isspace, etc.
+#include <bits/c++locale.h> // Defines __c_locale.
namespace std
{
+ // NB: Don't instantiate required wchar_t facets if no wchar_t support.
+#ifdef _GLIBCPP_USE_WCHAR_T
+# define _GLIBCPP_NUM_FACETS 26
+#else
+# define _GLIBCPP_NUM_FACETS 13
+#endif
// _Count_ones: compile-time computation of number of 1-bits in a value N
// This takes only 5 (or 6) instantiations, doing recursive descent
@@ -163,10 +170,6 @@ namespace std
// 22.2.4 collation
template<typename _CharT>
class collate;
- template<> class collate<char>;
-#ifdef _GLIBCPP_USE_WCHAR_T
- template<> class collate<wchar_t>;
-#endif
template<typename _CharT> class
collate_byname;
@@ -199,19 +202,19 @@ namespace std
template<typename _CharT>
class messages_byname;
-
// 22.1.1 Class locale
class locale
{
public:
// Types:
- typedef unsigned int category;
+ typedef unsigned int category;
// Forward decls and friends:
class facet;
class id;
class _Impl;
+ friend class facet;
friend class _Impl;
template<typename _Facet>
@@ -223,7 +226,7 @@ namespace std
has_facet(const locale&) throw();
// Category values:
- // NB much depends on the order in which these appear:
+ // NB: Order must match _S_facet_categories definition in locale.cc
static const category none = 0;
static const category ctype = 1 << 0;
static const category numeric = 1 << 1;
@@ -235,23 +238,20 @@ namespace std
numeric | time | messages);
// Construct/copy/destroy:
- inline
locale() throw();
- inline
locale(const locale& __other) throw();
explicit
locale(const char* __std_name);
- locale(const locale& __other, const char* __std_name, category __cat);
+ locale(const locale& __base, const char* __s, category __cat);
- locale(const locale& __other, const locale& __one, category __cat);
+ locale(const locale& __base, const locale& __add, category __cat);
template<typename _Facet>
locale(const locale& __other, _Facet* __f);
- inline
~locale() throw();
const locale&
@@ -294,8 +294,8 @@ namespace std
// Current global reference locale
static _Impl* _S_global;
- static const int _S_categories_num = _Count_ones<all>::_M_count;
- static const int _S_facets_num = 26;
+ static const size_t _S_num_categories = _Count_ones<all>::_M_count;
+ static const size_t _S_num_facets = _GLIBCPP_NUM_FACETS;
explicit
locale(_Impl*) throw();
@@ -304,8 +304,11 @@ namespace std
_S_initialize()
{ if (!_S_classic) classic(); }
- static int
- _S_normalize_category(int);
+ static category
+ _S_normalize_category(category);
+
+ void
+ _M_coalesce(const locale& __base, const locale& __add, category __cat);
};
@@ -314,8 +317,7 @@ namespace std
{
public:
// Types.
- typedef vector<facet*, allocator<facet*> > __vec_facet;
- typedef vector<string, allocator<string> > __vec_string;
+ typedef vector<facet*, allocator<facet*> > __vec_facet;
// Friends.
friend class locale;
@@ -333,9 +335,8 @@ namespace std
// Data Members.
size_t _M_references;
__vec_facet* _M_facets;
- __vec_string* _M_category_names;
- bool _M_has_name;
- string _M_name;
+ string _M_names[_S_num_categories];
+ __c_locale _M_c_locale;
static const locale::id* const _S_id_ctype[];
static const locale::id* const _S_id_numeric[];
static const locale::id* const _S_id_collate[];
@@ -353,19 +354,25 @@ namespace std
{
if (_M_references-- == 0) // XXX MT
{
- try {
- delete this;
- }
- catch(...) {
- }
+ try
+ { delete this; }
+ catch(...)
+ { }
}
}
_Impl(const _Impl&, size_t);
- _Impl(const _Impl&, const string&, category, size_t);
- _Impl(size_t, size_t, bool __has_name = false, string __name = "*");
+ _Impl(string __name, size_t);
~_Impl() throw();
+ bool
+ _M_check_same_name()
+ {
+ bool __ret = true;
+ for (size_t i = 0; i < _S_num_categories - 1; ++i)
+ __ret &= _M_names[i] == _M_names[i + 1];
+ return __ret;
+ }
void
_M_replace_categories(const _Impl*, category);
@@ -380,53 +387,19 @@ namespace std
template<typename _Facet>
inline void
- _M_facet_init(_Facet* __facet)
+ _M_init_facet(_Facet* __facet)
{ _M_install_facet(&_Facet::id, __facet); }
-
- void
- _M_construct_collate(const char*);
-
- void
- _M_construct_ctype(const char*);
-
- void
- _M_construct_monetary(const char*);
-
- void
- _M_construct_numeric(const char*);
-
- void
- _M_construct_time(const char*);
-
- void
- _M_construct_messages(const char*);
-
- category
- _M_normalize_category_names(const string&, category __cat);
};
- // class locale inlines, that need declaration of locale::_Imp
- locale::locale() throw()
- {
- _S_initialize();
- (_M_impl = _S_global)->_M_add_reference();
- } // XXX MT
-
- locale::locale(const locale& __other) throw()
- { (_M_impl = __other._M_impl)->_M_add_reference(); }
-
template<typename _Facet>
locale::locale(const locale& __other, _Facet* __f)
{
_M_impl = new _Impl(*__other._M_impl, 1);
_M_impl->_M_install_facet(&_Facet::id, __f);
- _M_impl->_M_has_name = false;
- _M_impl->_M_name = "*";
+ for (int __i = 0; __i < _S_num_categories; ++__i)
+ _M_impl->_M_names[__i] = "*";
}
- locale::~locale() throw()
- { _M_impl->_M_remove_reference(); }
-
// 22.1.1.1.2 Class locale::facet
class locale::facet
{
@@ -440,6 +413,12 @@ namespace std
virtual
~facet() { };
+ static void
+ _S_create_c_locale(__c_locale& __cloc, const char* __s);
+
+ static void
+ _S_destroy_c_locale(__c_locale& __cloc);
+
private:
size_t _M_references;
@@ -459,6 +438,7 @@ namespace std
// 22.1.1.1.3 Class locale::id
class locale::id
{
+ private:
friend class locale;
friend class locale::_Impl;
template<typename _Facet>
@@ -467,9 +447,7 @@ namespace std
template<typename _Facet>
friend bool
has_facet(const locale&) throw ();
- public:
- id() { };
- private:
+
// NB: There is no accessor for _M_index because it may be used
// before the constructor is run; the effect of calling a member
// function (even an inline) would be undefined.
@@ -482,6 +460,12 @@ namespace std
operator=(const id&); // not defined
id(const id&); // not defined
+
+ 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() { }
};
template<typename _Facet>
@@ -491,7 +475,6 @@ namespace std
template<typename _Facet>
bool
has_facet(const locale& __loc) throw();
-
} // namespace std
#endif /* _CPP_BITS_LOCCORE_H */