gcc/libstdc++-v3/include/bits/localefwd.h
Benjamin Kosnik 0214010c60 Preliminary named locales.
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()): 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.

From-SVN: r39347
2001-01-30 09:18:51 +00:00

486 lines
12 KiB
C++

// Locale support -*- C++ -*-
// 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
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
//
// ISO C++ 14882: 22.1 Locales
//
#ifndef _CPP_BITS_LOCCORE_H
#define _CPP_BITS_LOCCORE_H 1
#include <bits/c++config.h>
#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
// in parallel -- ncm
template<unsigned int _Num, int _Shift = (sizeof(unsigned) * CHAR_BIT)/2,
unsigned int _Mask = (~0u >> _Shift) >
struct _Count_ones;
// It is preferable to use enumerators instead of integral static data
// members to avoid emission of superflous variables -- gdr.
template<unsigned int _Num, unsigned int _Mask>
struct _Count_ones<_Num, 0, _Mask>
{
enum
{
_M_count = _Num
};
};
template<unsigned int _Num, int _Shift, unsigned int _Mask>
struct _Count_ones
{
enum
{
_M_halfcount = _Count_ones<_Num, _Shift/2,
(_Mask^((~_Mask)>>(_Shift/2))) >::_M_count,
_M_count = (_M_halfcount&_Mask) + ((_M_halfcount>>_Shift)&_Mask)
};
};
// 22.1.1 Locale
template<typename _Tp> class allocator;
template<typename _Tp, typename _Alloc> class vector;
class locale;
// 22.1.3 Convenience interfaces
template<typename _CharT>
inline bool
isspace(_CharT, const locale&);
template<typename _CharT>
inline bool
isprint(_CharT, const locale&);
template<typename _CharT>
inline bool
iscntrl(_CharT, const locale&);
template<typename _CharT>
inline bool
isupper(_CharT, const locale&);
template<typename _CharT>
inline bool
islower(_CharT, const locale&);
template<typename _CharT>
inline bool
isalpha(_CharT, const locale&);
template<typename _CharT>
inline bool
isdigit(_CharT, const locale&);
template<typename _CharT>
inline bool
ispunct(_CharT, const locale&);
template<typename _CharT>
inline bool
isxdigit(_CharT, const locale&);
template<typename _CharT>
inline bool
isalnum(_CharT, const locale&);
template<typename _CharT>
inline bool
isgraph(_CharT, const locale&);
template<typename _CharT>
inline _CharT
toupper(_CharT, const locale&);
template<typename _CharT>
inline _CharT
tolower(_CharT, const locale&);
// 22.2.1 and 22.2.1.3 ctype
class ctype_base;
template<typename _CharT>
class ctype;
template<> class ctype<char>;
#ifdef _GLIBCPP_USE_WCHAR_T
template<> class ctype<wchar_t>;
#endif
template<typename _CharT>
class ctype_byname;
// NB: Specialized for char and wchar_t in locale_facets.h.
class codecvt_base;
template<typename _InternT, typename _ExternT, typename _StateT>
class codecvt;
template<> class codecvt<char, char, mbstate_t>;
#ifdef _GLIBCPP_USE_WCHAR_T
template<> class codecvt<wchar_t, char, mbstate_t>;
#endif
template<typename _InternT, typename _ExternT, typename _StateT>
class codecvt_byname;
// 22.2.2 and 22.2.3 numeric
template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
class num_get;
template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
class num_put;
template<typename _CharT> class numpunct;
template<typename _CharT> class numpunct_byname;
// 22.2.4 collation
template<typename _CharT>
class collate;
template<typename _CharT> class
collate_byname;
// 22.2.5 date and time
class time_base;
template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
class time_get;
template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
class time_get_byname;
template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
class time_put;
template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
class time_put_byname;
// 22.2.6 money
class money_base;
template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
class money_get;
template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
class money_put;
template<typename _CharT, bool _Intl = false>
class moneypunct;
template<typename _CharT, bool _Intl = false>
class moneypunct_byname;
// 22.2.7 message retrieval
class messages_base;
template<typename _CharT>
class messages;
template<typename _CharT>
class messages_byname;
// 22.1.1 Class locale
class locale
{
public:
// Types:
typedef unsigned int category;
// Forward decls and friends:
class facet;
class id;
class _Impl;
friend class facet;
friend class _Impl;
template<typename _Facet>
friend const _Facet&
use_facet(const locale&);
template<typename _Facet>
friend bool
has_facet(const locale&) throw();
// Category values:
// 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;
static const category collate = 1 << 2;
static const category time = 1 << 3;
static const category monetary = 1 << 4;
static const category messages = 1 << 5;
static const category all = (collate | ctype | monetary |
numeric | time | messages);
// Construct/copy/destroy:
locale() throw();
locale(const locale& __other) throw();
explicit
locale(const char* __std_name);
locale(const locale& __base, const char* __s, category __cat);
locale(const locale& __base, const locale& __add, category __cat);
template<typename _Facet>
locale(const locale& __other, _Facet* __f);
~locale() throw();
const locale&
operator=(const locale& __other) throw();
template<typename _Facet>
locale
combine(const locale& __other);
// Locale operations:
string
name() const;
bool
operator==(const locale& __other) const throw ();
inline bool
operator!=(const locale& __other) const throw ()
{ return !(this->operator==(__other)); }
template<typename _Char, typename _Traits, typename _Alloc>
bool
operator()(const basic_string<_Char, _Traits, _Alloc>& __s1,
const basic_string<_Char, _Traits, _Alloc>& __s2) const;
// Global locale objects:
static locale
global(const locale&);
static const locale&
classic();
private:
// The (shared) implementation
_Impl* _M_impl;
// The "C" reference locale
static _Impl* _S_classic;
// Current global reference locale
static _Impl* _S_global;
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();
static inline void
_S_initialize()
{ if (!_S_classic) classic(); }
static category
_S_normalize_category(category);
void
_M_coalesce(const locale& __base, const locale& __add, category __cat);
};
// locale implementation object
class locale::_Impl
{
public:
// Types.
typedef vector<facet*, allocator<facet*> > __vec_facet;
// Friends.
friend class locale;
friend class locale::facet;
template<typename _Facet>
friend const _Facet&
use_facet(const locale&);
template<typename _Facet>
friend bool
has_facet(const locale&) throw();
private:
// Data Members.
size_t _M_references;
__vec_facet* _M_facets;
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[];
static const locale::id* const _S_id_time[];
static const locale::id* const _S_id_monetary[];
static const locale::id* const _S_id_messages[];
static const locale::id* const* const _S_facet_categories[];
inline void
_M_add_reference() throw()
{ ++_M_references; } // XXX MT
inline void
_M_remove_reference() throw()
{
if (_M_references-- == 0) // XXX MT
{
try
{ delete this; }
catch(...)
{ }
}
}
_Impl(const _Impl&, size_t);
_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);
void
_M_replace_category(const _Impl*, const locale::id* const*);
void
_M_replace_facet(const _Impl*, const locale::id*);
void
_M_install_facet(const locale::id*, facet*);
template<typename _Facet>
inline void
_M_init_facet(_Facet* __facet)
{ _M_install_facet(&_Facet::id, __facet); }
};
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);
for (int __i = 0; __i < _S_num_categories; ++__i)
_M_impl->_M_names[__i] = "*";
}
// 22.1.1.1.2 Class locale::facet
class locale::facet
{
friend class locale;
friend class locale::_Impl;
protected:
explicit
facet(size_t __refs = 0) throw();
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;
void
_M_add_reference() throw();
void
_M_remove_reference() throw();
facet(const facet&); // not defined
void
operator=(const facet&); // not defined
};
// 22.1.1.1.3 Class locale::id
class locale::id
{
private:
friend class locale;
friend class locale::_Impl;
template<typename _Facet>
friend const _Facet&
use_facet(const locale&);
template<typename _Facet>
friend bool
has_facet(const locale&) throw ();
// 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.
mutable size_t _M_index;
// Last id number assigned
static size_t _S_highwater;
void
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>
const _Facet&
use_facet(const locale& __loc);
template<typename _Facet>
bool
has_facet(const locale& __loc) throw();
} // namespace std
#endif /* _CPP_BITS_LOCCORE_H */
// Local Variables:
// mode:c++
// End: