locale_facets.h (class collate, [...]): Move...

2007-04-24  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/locale_facets.h (class collate, class collate_byname):
	Move...
	* include/bits/locale_classes.h: ... here.
	* include/bits/locale_facets.tcc (locale::combine, locale::operator(),
	has_facet, use_facet, collate::_M_compare, collate::_M_transform,
	collate::do_compare, collate::do_transform, collate::do_hash): Move...
	* include/bits/locale_classes.tcc: ... here, new.
	* include/Makefile.am: Add.
	* testsuite/util/testsuite_abi.h: Include <locale>.
	* include/std/locale: Tweak.
	* include/std/istream: Likewise.
	* include/std/ostream: Likewise.
	* include/bits/codecvt.h: Likewise.
	* include/Makefile.in: Regenerate.

	* include/bits/codecvt.h: Adjust extern template declarations.
	* include/bits/ostream_insert.h: Likewise.
	* include/bits/ostream.tcc: Likewise.

	* include/bits/locale_facets.h: Do not include <bits/codecvt.h>.
	* include/std/fstream: Do it here.
	* include/bits/locale_facets_nonio.h: Likewise.

From-SVN: r124114
This commit is contained in:
Paolo Carlini 2007-04-24 18:57:12 +00:00 committed by Paolo Carlini
parent 9872ecadbd
commit 84b31797f3
17 changed files with 597 additions and 478 deletions

View File

@ -1,3 +1,28 @@
2007-04-24 Paolo Carlini <pcarlini@suse.de>
* include/bits/locale_facets.h (class collate, class collate_byname):
Move...
* include/bits/locale_classes.h: ... here.
* include/bits/locale_facets.tcc (locale::combine, locale::operator(),
has_facet, use_facet, collate::_M_compare, collate::_M_transform,
collate::do_compare, collate::do_transform, collate::do_hash): Move...
* include/bits/locale_classes.tcc: ... here, new.
* include/Makefile.am: Add.
* testsuite/util/testsuite_abi.h: Include <locale>.
* include/std/locale: Tweak.
* include/std/istream: Likewise.
* include/std/ostream: Likewise.
* include/bits/codecvt.h: Likewise.
* include/Makefile.in: Regenerate.
* include/bits/codecvt.h: Adjust extern template declarations.
* include/bits/ostream_insert.h: Likewise.
* include/bits/ostream.tcc: Likewise.
* include/bits/locale_facets.h: Do not include <bits/codecvt.h>.
* include/std/fstream: Do it here.
* include/bits/locale_facets_nonio.h: Likewise.
2007-04-23 Paolo Carlini <pcarlini@suse.de>
* include/bits/locale_facets.h (class time_base,

View File

@ -89,6 +89,7 @@ bits_headers = \
${bits_srcdir}/istream.tcc \
${bits_srcdir}/list.tcc \
${bits_srcdir}/locale_classes.h \
${bits_srcdir}/locale_classes.tcc \
${bits_srcdir}/locale_facets.h \
${bits_srcdir}/locale_facets.tcc \
${bits_srcdir}/locale_facets_nonio.h \

View File

@ -323,6 +323,7 @@ bits_headers = \
${bits_srcdir}/istream.tcc \
${bits_srcdir}/list.tcc \
${bits_srcdir}/locale_classes.h \
${bits_srcdir}/locale_classes.tcc \
${bits_srcdir}/locale_facets.h \
${bits_srcdir}/locale_facets.tcc \
${bits_srcdir}/locale_facets_nonio.h \

View File

@ -1,6 +1,6 @@
// Locale support (codecvt) -*- C++ -*-
// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005
// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@ -469,6 +469,33 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
~codecvt_byname() { }
};
// Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere.
// NB: This syntax is a GNU extension.
#if _GLIBCXX_EXTERN_TEMPLATE
extern template class codecvt_byname<char, char, mbstate_t>;
extern template
const codecvt<char, char, mbstate_t>&
use_facet<codecvt<char, char, mbstate_t> >(const locale&);
extern template
bool
has_facet<codecvt<char, char, mbstate_t> >(const locale&);
#ifdef _GLIBCXX_USE_WCHAR_T
extern template class codecvt_byname<wchar_t, char, mbstate_t>;
extern template
const codecvt<wchar_t, char, mbstate_t>&
use_facet<codecvt<wchar_t, char, mbstate_t> >(const locale&);
extern template
bool
has_facet<codecvt<wchar_t, char, mbstate_t> >(const locale&);
#endif
#endif
_GLIBCXX_END_NAMESPACE
#endif // _CODECVT_H

View File

@ -1,6 +1,7 @@
// Locale support -*- C++ -*-
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
// 2006, 2007
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@ -561,22 +562,270 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_M_install_cache(const facet*, size_t);
};
template<typename _Facet>
locale::locale(const locale& __other, _Facet* __f)
{
_M_impl = new _Impl(*__other._M_impl, 1);
try
{ _M_impl->_M_install_facet(&_Facet::id, __f); }
catch(...)
{
_M_impl->_M_remove_reference();
__throw_exception_again;
}
delete [] _M_impl->_M_names[0];
_M_impl->_M_names[0] = 0; // Unnamed.
/**
* @brief Test for the presence of a facet.
*
* has_facet tests the locale argument for the presence of the facet type
* provided as the template parameter. Facets derived from the facet
* parameter will also return true.
*
* @param Facet The facet type to test the presence of.
* @param locale The locale to test.
* @return true if locale contains a facet of type Facet, else false.
*/
template<typename _Facet>
inline bool
has_facet(const locale& __loc) throw()
{
const size_t __i = _Facet::id._M_id();
const locale::facet** __facets = __loc._M_impl->_M_facets;
return (__i < __loc._M_impl->_M_facets_size && __facets[__i]);
}
/**
* @brief Return a facet.
*
* use_facet looks for and returns a reference to a facet of type Facet
* where Facet is the template parameter. If has_facet(locale) is true,
* there is a suitable facet to return. It throws std::bad_cast if the
* locale doesn't contain a facet of type Facet.
*
* @param Facet The facet type to access.
* @param locale The locale to use.
* @return Reference to facet of type Facet.
* @throw std::bad_cast if locale doesn't contain a facet of type Facet.
*/
template<typename _Facet>
inline const _Facet&
use_facet(const locale& __loc)
{
const size_t __i = _Facet::id._M_id();
const locale::facet** __facets = __loc._M_impl->_M_facets;
if (!(__i < __loc._M_impl->_M_facets_size && __facets[__i]))
__throw_bad_cast();
return static_cast<const _Facet&>(*__facets[__i]);
}
/**
* @brief Facet for localized string comparison.
*
* This facet encapsulates the code to compare strings in a localized
* manner.
*
* The collate template uses protected virtual functions to provide
* the actual results. The public accessors forward the call to
* the virtual functions. These virtual functions are hooks for
* developers to implement the behavior they require from the
* collate facet.
*/
template<typename _CharT>
class collate : public locale::facet
{
public:
// Types:
//@{
/// Public typedefs
typedef _CharT char_type;
typedef basic_string<_CharT> string_type;
//@}
protected:
// Underlying "C" library locale information saved from
// initialization, needed by collate_byname as well.
__c_locale _M_c_locale_collate;
public:
/// Numpunct facet id.
static locale::id id;
/**
* @brief Constructor performs initialization.
*
* This is the constructor provided by the standard.
*
* @param refs Passed to the base facet class.
*/
explicit
collate(size_t __refs = 0)
: facet(__refs), _M_c_locale_collate(_S_get_c_locale())
{ }
/**
* @brief Internal constructor. Not for general use.
*
* This is a constructor for use by the library itself to set up new
* locales.
*
* @param cloc The "C" locale.
* @param refs Passed to the base facet class.
*/
explicit
collate(__c_locale __cloc, size_t __refs = 0)
: facet(__refs), _M_c_locale_collate(_S_clone_c_locale(__cloc))
{ }
/**
* @brief Compare two strings.
*
* This function compares two strings and returns the result by calling
* collate::do_compare().
*
* @param lo1 Start of string 1.
* @param hi1 End of string 1.
* @param lo2 Start of string 2.
* @param hi2 End of string 2.
* @return 1 if string1 > string2, -1 if string1 < string2, else 0.
*/
int
compare(const _CharT* __lo1, const _CharT* __hi1,
const _CharT* __lo2, const _CharT* __hi2) const
{ return this->do_compare(__lo1, __hi1, __lo2, __hi2); }
/**
* @brief Transform string to comparable form.
*
* This function is a wrapper for strxfrm functionality. It takes the
* input string and returns a modified string that can be directly
* compared to other transformed strings. In the "C" locale, this
* function just returns a copy of the input string. In some other
* locales, it may replace two chars with one, change a char for
* another, etc. It does so by returning collate::do_transform().
*
* @param lo Start of string.
* @param hi End of string.
* @return Transformed string_type.
*/
string_type
transform(const _CharT* __lo, const _CharT* __hi) const
{ return this->do_transform(__lo, __hi); }
/**
* @brief Return hash of a string.
*
* This function computes and returns a hash on the input string. It
* does so by returning collate::do_hash().
*
* @param lo Start of string.
* @param hi End of string.
* @return Hash value.
*/
long
hash(const _CharT* __lo, const _CharT* __hi) const
{ return this->do_hash(__lo, __hi); }
// Used to abstract out _CharT bits in virtual member functions, below.
int
_M_compare(const _CharT*, const _CharT*) const;
size_t
_M_transform(_CharT*, const _CharT*, size_t) const;
protected:
/// Destructor.
virtual
~collate()
{ _S_destroy_c_locale(_M_c_locale_collate); }
/**
* @brief Compare two strings.
*
* This function is a hook for derived classes to change the value
* returned. @see compare().
*
* @param lo1 Start of string 1.
* @param hi1 End of string 1.
* @param lo2 Start of string 2.
* @param hi2 End of string 2.
* @return 1 if string1 > string2, -1 if string1 < string2, else 0.
*/
virtual int
do_compare(const _CharT* __lo1, const _CharT* __hi1,
const _CharT* __lo2, const _CharT* __hi2) const;
/**
* @brief Transform string to comparable form.
*
* This function is a hook for derived classes to change the value
* returned.
*
* @param lo1 Start of string 1.
* @param hi1 End of string 1.
* @param lo2 Start of string 2.
* @param hi2 End of string 2.
* @return 1 if string1 > string2, -1 if string1 < string2, else 0.
*/
virtual string_type
do_transform(const _CharT* __lo, const _CharT* __hi) const;
/**
* @brief Return hash of a string.
*
* This function computes and returns a hash on the input string. This
* function is a hook for derived classes to change the value returned.
*
* @param lo Start of string.
* @param hi End of string.
* @return Hash value.
*/
virtual long
do_hash(const _CharT* __lo, const _CharT* __hi) const;
};
template<typename _CharT>
locale::id collate<_CharT>::id;
// Specializations.
template<>
int
collate<char>::_M_compare(const char*, const char*) const;
template<>
size_t
collate<char>::_M_transform(char*, const char*, size_t) const;
#ifdef _GLIBCXX_USE_WCHAR_T
template<>
int
collate<wchar_t>::_M_compare(const wchar_t*, const wchar_t*) const;
template<>
size_t
collate<wchar_t>::_M_transform(wchar_t*, const wchar_t*, size_t) const;
#endif
/// @brief class collate_byname [22.2.4.2].
template<typename _CharT>
class collate_byname : public collate<_CharT>
{
public:
//@{
/// Public typedefs
typedef _CharT char_type;
typedef basic_string<_CharT> string_type;
//@}
explicit
collate_byname(const char* __s, size_t __refs = 0)
: collate<_CharT>(__refs)
{
if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
{
this->_S_destroy_c_locale(this->_M_c_locale_collate);
this->_S_create_c_locale(this->_M_c_locale_collate, __s);
}
}
protected:
virtual
~collate_byname() { }
};
_GLIBCXX_END_NAMESPACE
#ifndef _GLIBCXX_EXPORT_TEMPLATE
# include <bits/locale_classes.tcc>
#endif
#endif

View File

@ -0,0 +1,243 @@
// Locale support -*- C++ -*-
// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// 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.
/** @file locale_classes.tcc
* This is an internal header file, included by other library headers.
* You should not attempt to use it directly.
*/
//
// ISO C++ 14882: 22.1 Locales
//
#ifndef _LOCALE_CLASSES_TCC
#define _LOCALE_CLASSES_TCC 1
#pragma GCC system_header
_GLIBCXX_BEGIN_NAMESPACE(std)
template<typename _Facet>
locale::locale(const locale& __other, _Facet* __f)
{
_M_impl = new _Impl(*__other._M_impl, 1);
try
{ _M_impl->_M_install_facet(&_Facet::id, __f); }
catch(...)
{
_M_impl->_M_remove_reference();
__throw_exception_again;
}
delete [] _M_impl->_M_names[0];
_M_impl->_M_names[0] = 0; // Unnamed.
}
template<typename _Facet>
locale
locale::combine(const locale& __other) const
{
_Impl* __tmp = new _Impl(*_M_impl, 1);
try
{
__tmp->_M_replace_facet(__other._M_impl, &_Facet::id);
}
catch(...)
{
__tmp->_M_remove_reference();
__throw_exception_again;
}
return locale(__tmp);
}
template<typename _CharT, typename _Traits, typename _Alloc>
bool
locale::operator()(const basic_string<_CharT, _Traits, _Alloc>& __s1,
const basic_string<_CharT, _Traits, _Alloc>& __s2) const
{
typedef std::collate<_CharT> __collate_type;
const __collate_type& __collate = use_facet<__collate_type>(*this);
return (__collate.compare(__s1.data(), __s1.data() + __s1.length(),
__s2.data(), __s2.data() + __s2.length()) < 0);
}
// Generic version does nothing.
template<typename _CharT>
int
collate<_CharT>::_M_compare(const _CharT*, const _CharT*) const
{ return 0; }
// Generic version does nothing.
template<typename _CharT>
size_t
collate<_CharT>::_M_transform(_CharT*, const _CharT*, size_t) const
{ return 0; }
template<typename _CharT>
int
collate<_CharT>::
do_compare(const _CharT* __lo1, const _CharT* __hi1,
const _CharT* __lo2, const _CharT* __hi2) const
{
// strcoll assumes zero-terminated strings so we make a copy
// and then put a zero at the end.
const string_type __one(__lo1, __hi1);
const string_type __two(__lo2, __hi2);
const _CharT* __p = __one.c_str();
const _CharT* __pend = __one.data() + __one.length();
const _CharT* __q = __two.c_str();
const _CharT* __qend = __two.data() + __two.length();
// strcoll stops when it sees a nul character so we break
// the strings into zero-terminated substrings and pass those
// to strcoll.
for (;;)
{
const int __res = _M_compare(__p, __q);
if (__res)
return __res;
__p += char_traits<_CharT>::length(__p);
__q += char_traits<_CharT>::length(__q);
if (__p == __pend && __q == __qend)
return 0;
else if (__p == __pend)
return -1;
else if (__q == __qend)
return 1;
__p++;
__q++;
}
}
template<typename _CharT>
typename collate<_CharT>::string_type
collate<_CharT>::
do_transform(const _CharT* __lo, const _CharT* __hi) const
{
string_type __ret;
// strxfrm assumes zero-terminated strings so we make a copy
const string_type __str(__lo, __hi);
const _CharT* __p = __str.c_str();
const _CharT* __pend = __str.data() + __str.length();
size_t __len = (__hi - __lo) * 2;
_CharT* __c = new _CharT[__len];
try
{
// strxfrm stops when it sees a nul character so we break
// the string into zero-terminated substrings and pass those
// to strxfrm.
for (;;)
{
// First try a buffer perhaps big enough.
size_t __res = _M_transform(__c, __p, __len);
// If the buffer was not large enough, try again with the
// correct size.
if (__res >= __len)
{
__len = __res + 1;
delete [] __c, __c = 0;
__c = new _CharT[__len];
__res = _M_transform(__c, __p, __len);
}
__ret.append(__c, __res);
__p += char_traits<_CharT>::length(__p);
if (__p == __pend)
break;
__p++;
__ret.push_back(_CharT());
}
}
catch(...)
{
delete [] __c;
__throw_exception_again;
}
delete [] __c;
return __ret;
}
template<typename _CharT>
long
collate<_CharT>::
do_hash(const _CharT* __lo, const _CharT* __hi) const
{
unsigned long __val = 0;
for (; __lo < __hi; ++__lo)
__val =
*__lo + ((__val << 7)
| (__val >> (__gnu_cxx::__numeric_traits<unsigned long>::
__digits - 7)));
return static_cast<long>(__val);
}
// Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere.
// NB: This syntax is a GNU extension.
#if _GLIBCXX_EXTERN_TEMPLATE
extern template class collate<char>;
extern template class collate_byname<char>;
extern template
const collate<char>&
use_facet<collate<char> >(const locale&);
extern template
bool
has_facet<collate<char> >(const locale&);
#ifdef _GLIBCXX_USE_WCHAR_T
extern template class collate<wchar_t>;
extern template class collate_byname<wchar_t>;
extern template
const collate<wchar_t>&
use_facet<collate<wchar_t> >(const locale&);
extern template
bool
has_facet<collate<wchar_t> >(const locale&);
#endif
#endif
_GLIBCXX_END_NAMESPACE
#endif

View File

@ -1556,9 +1556,6 @@ _GLIBCXX_END_NAMESPACE
// Include host and configuration specific ctype inlines.
#include <bits/ctype_inline.h>
// 22.2.1.5 Template class codecvt
#include <bits/codecvt.h>
_GLIBCXX_BEGIN_NAMESPACE(std)
// 22.2.2 The numeric category.
@ -2546,220 +2543,6 @@ _GLIBCXX_BEGIN_LDBL_NAMESPACE
_GLIBCXX_END_LDBL_NAMESPACE
/**
* @brief Facet for localized string comparison.
*
* This facet encapsulates the code to compare strings in a localized
* manner.
*
* The collate template uses protected virtual functions to provide
* the actual results. The public accessors forward the call to
* the virtual functions. These virtual functions are hooks for
* developers to implement the behavior they require from the
* collate facet.
*/
template<typename _CharT>
class collate : public locale::facet
{
public:
// Types:
//@{
/// Public typedefs
typedef _CharT char_type;
typedef basic_string<_CharT> string_type;
//@}
protected:
// Underlying "C" library locale information saved from
// initialization, needed by collate_byname as well.
__c_locale _M_c_locale_collate;
public:
/// Numpunct facet id.
static locale::id id;
/**
* @brief Constructor performs initialization.
*
* This is the constructor provided by the standard.
*
* @param refs Passed to the base facet class.
*/
explicit
collate(size_t __refs = 0)
: facet(__refs), _M_c_locale_collate(_S_get_c_locale())
{ }
/**
* @brief Internal constructor. Not for general use.
*
* This is a constructor for use by the library itself to set up new
* locales.
*
* @param cloc The "C" locale.
* @param refs Passed to the base facet class.
*/
explicit
collate(__c_locale __cloc, size_t __refs = 0)
: facet(__refs), _M_c_locale_collate(_S_clone_c_locale(__cloc))
{ }
/**
* @brief Compare two strings.
*
* This function compares two strings and returns the result by calling
* collate::do_compare().
*
* @param lo1 Start of string 1.
* @param hi1 End of string 1.
* @param lo2 Start of string 2.
* @param hi2 End of string 2.
* @return 1 if string1 > string2, -1 if string1 < string2, else 0.
*/
int
compare(const _CharT* __lo1, const _CharT* __hi1,
const _CharT* __lo2, const _CharT* __hi2) const
{ return this->do_compare(__lo1, __hi1, __lo2, __hi2); }
/**
* @brief Transform string to comparable form.
*
* This function is a wrapper for strxfrm functionality. It takes the
* input string and returns a modified string that can be directly
* compared to other transformed strings. In the "C" locale, this
* function just returns a copy of the input string. In some other
* locales, it may replace two chars with one, change a char for
* another, etc. It does so by returning collate::do_transform().
*
* @param lo Start of string.
* @param hi End of string.
* @return Transformed string_type.
*/
string_type
transform(const _CharT* __lo, const _CharT* __hi) const
{ return this->do_transform(__lo, __hi); }
/**
* @brief Return hash of a string.
*
* This function computes and returns a hash on the input string. It
* does so by returning collate::do_hash().
*
* @param lo Start of string.
* @param hi End of string.
* @return Hash value.
*/
long
hash(const _CharT* __lo, const _CharT* __hi) const
{ return this->do_hash(__lo, __hi); }
// Used to abstract out _CharT bits in virtual member functions, below.
int
_M_compare(const _CharT*, const _CharT*) const;
size_t
_M_transform(_CharT*, const _CharT*, size_t) const;
protected:
/// Destructor.
virtual
~collate()
{ _S_destroy_c_locale(_M_c_locale_collate); }
/**
* @brief Compare two strings.
*
* This function is a hook for derived classes to change the value
* returned. @see compare().
*
* @param lo1 Start of string 1.
* @param hi1 End of string 1.
* @param lo2 Start of string 2.
* @param hi2 End of string 2.
* @return 1 if string1 > string2, -1 if string1 < string2, else 0.
*/
virtual int
do_compare(const _CharT* __lo1, const _CharT* __hi1,
const _CharT* __lo2, const _CharT* __hi2) const;
/**
* @brief Transform string to comparable form.
*
* This function is a hook for derived classes to change the value
* returned.
*
* @param lo1 Start of string 1.
* @param hi1 End of string 1.
* @param lo2 Start of string 2.
* @param hi2 End of string 2.
* @return 1 if string1 > string2, -1 if string1 < string2, else 0.
*/
virtual string_type
do_transform(const _CharT* __lo, const _CharT* __hi) const;
/**
* @brief Return hash of a string.
*
* This function computes and returns a hash on the input string. This
* function is a hook for derived classes to change the value returned.
*
* @param lo Start of string.
* @param hi End of string.
* @return Hash value.
*/
virtual long
do_hash(const _CharT* __lo, const _CharT* __hi) const;
};
template<typename _CharT>
locale::id collate<_CharT>::id;
// Specializations.
template<>
int
collate<char>::_M_compare(const char*, const char*) const;
template<>
size_t
collate<char>::_M_transform(char*, const char*, size_t) const;
#ifdef _GLIBCXX_USE_WCHAR_T
template<>
int
collate<wchar_t>::_M_compare(const wchar_t*, const wchar_t*) const;
template<>
size_t
collate<wchar_t>::_M_transform(wchar_t*, const wchar_t*, size_t) const;
#endif
/// @brief class collate_byname [22.2.4.2].
template<typename _CharT>
class collate_byname : public collate<_CharT>
{
public:
//@{
/// Public typedefs
typedef _CharT char_type;
typedef basic_string<_CharT> string_type;
//@}
explicit
collate_byname(const char* __s, size_t __refs = 0)
: collate<_CharT>(__refs)
{
if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
{
this->_S_destroy_c_locale(this->_M_c_locale_collate);
this->_S_create_c_locale(this->_M_c_locale_collate, __s);
}
}
protected:
virtual
~collate_byname() { }
};
// Subclause convenience interfaces, inlines.
// NB: These are inline because, when used in a loop, some compilers
// can hoist the body out of the loop; then it's just as fast as the
@ -2845,4 +2628,8 @@ _GLIBCXX_END_LDBL_NAMESPACE
_GLIBCXX_END_NAMESPACE
#ifndef _GLIBCXX_EXPORT_TEMPLATE
# include <bits/locale_facets.tcc>
#endif
#endif

View File

@ -41,78 +41,6 @@
_GLIBCXX_BEGIN_NAMESPACE(std)
template<typename _Facet>
locale
locale::combine(const locale& __other) const
{
_Impl* __tmp = new _Impl(*_M_impl, 1);
try
{
__tmp->_M_replace_facet(__other._M_impl, &_Facet::id);
}
catch(...)
{
__tmp->_M_remove_reference();
__throw_exception_again;
}
return locale(__tmp);
}
template<typename _CharT, typename _Traits, typename _Alloc>
bool
locale::operator()(const basic_string<_CharT, _Traits, _Alloc>& __s1,
const basic_string<_CharT, _Traits, _Alloc>& __s2) const
{
typedef std::collate<_CharT> __collate_type;
const __collate_type& __collate = use_facet<__collate_type>(*this);
return (__collate.compare(__s1.data(), __s1.data() + __s1.length(),
__s2.data(), __s2.data() + __s2.length()) < 0);
}
/**
* @brief Test for the presence of a facet.
*
* has_facet tests the locale argument for the presence of the facet type
* provided as the template parameter. Facets derived from the facet
* parameter will also return true.
*
* @param Facet The facet type to test the presence of.
* @param locale The locale to test.
* @return true if locale contains a facet of type Facet, else false.
*/
template<typename _Facet>
inline bool
has_facet(const locale& __loc) throw()
{
const size_t __i = _Facet::id._M_id();
const locale::facet** __facets = __loc._M_impl->_M_facets;
return (__i < __loc._M_impl->_M_facets_size && __facets[__i]);
}
/**
* @brief Return a facet.
*
* use_facet looks for and returns a reference to a facet of type Facet
* where Facet is the template parameter. If has_facet(locale) is true,
* there is a suitable facet to return. It throws std::bad_cast if the
* locale doesn't contain a facet of type Facet.
*
* @param Facet The facet type to access.
* @param locale The locale to use.
* @return Reference to facet of type Facet.
* @throw std::bad_cast if locale doesn't contain a facet of type Facet.
*/
template<typename _Facet>
inline const _Facet&
use_facet(const locale& __loc)
{
const size_t __i = _Facet::id._M_id();
const locale::facet** __facets = __loc._M_impl->_M_facets;
if (!(__i < __loc._M_impl->_M_facets_size && __facets[__i]))
__throw_bad_cast();
return static_cast<const _Facet&>(*__facets[__i]);
}
// Routine to access a cache for the facet. If the cache didn't
// exist before, it gets constructed on the fly.
template<typename _Facet>
@ -1252,127 +1180,6 @@ _GLIBCXX_BEGIN_LDBL_NAMESPACE
_GLIBCXX_END_LDBL_NAMESPACE
// Generic version does nothing.
template<typename _CharT>
int
collate<_CharT>::_M_compare(const _CharT*, const _CharT*) const
{ return 0; }
// Generic version does nothing.
template<typename _CharT>
size_t
collate<_CharT>::_M_transform(_CharT*, const _CharT*, size_t) const
{ return 0; }
template<typename _CharT>
int
collate<_CharT>::
do_compare(const _CharT* __lo1, const _CharT* __hi1,
const _CharT* __lo2, const _CharT* __hi2) const
{
// strcoll assumes zero-terminated strings so we make a copy
// and then put a zero at the end.
const string_type __one(__lo1, __hi1);
const string_type __two(__lo2, __hi2);
const _CharT* __p = __one.c_str();
const _CharT* __pend = __one.data() + __one.length();
const _CharT* __q = __two.c_str();
const _CharT* __qend = __two.data() + __two.length();
// strcoll stops when it sees a nul character so we break
// the strings into zero-terminated substrings and pass those
// to strcoll.
for (;;)
{
const int __res = _M_compare(__p, __q);
if (__res)
return __res;
__p += char_traits<_CharT>::length(__p);
__q += char_traits<_CharT>::length(__q);
if (__p == __pend && __q == __qend)
return 0;
else if (__p == __pend)
return -1;
else if (__q == __qend)
return 1;
__p++;
__q++;
}
}
template<typename _CharT>
typename collate<_CharT>::string_type
collate<_CharT>::
do_transform(const _CharT* __lo, const _CharT* __hi) const
{
string_type __ret;
// strxfrm assumes zero-terminated strings so we make a copy
const string_type __str(__lo, __hi);
const _CharT* __p = __str.c_str();
const _CharT* __pend = __str.data() + __str.length();
size_t __len = (__hi - __lo) * 2;
_CharT* __c = new _CharT[__len];
try
{
// strxfrm stops when it sees a nul character so we break
// the string into zero-terminated substrings and pass those
// to strxfrm.
for (;;)
{
// First try a buffer perhaps big enough.
size_t __res = _M_transform(__c, __p, __len);
// If the buffer was not large enough, try again with the
// correct size.
if (__res >= __len)
{
__len = __res + 1;
delete [] __c, __c = 0;
__c = new _CharT[__len];
__res = _M_transform(__c, __p, __len);
}
__ret.append(__c, __res);
__p += char_traits<_CharT>::length(__p);
if (__p == __pend)
break;
__p++;
__ret.push_back(_CharT());
}
}
catch(...)
{
delete [] __c;
__throw_exception_again;
}
delete [] __c;
return __ret;
}
template<typename _CharT>
long
collate<_CharT>::
do_hash(const _CharT* __lo, const _CharT* __hi) const
{
unsigned long __val = 0;
for (; __lo < __hi; ++__lo)
__val =
*__lo + ((__val << 7)
| (__val >> (__gnu_cxx::__numeric_traits<unsigned long>::
__digits - 7)));
return static_cast<long>(__val);
}
// Construct correctly padded string, as per 22.2.2.2.2
// Assumes
// __newlen > __oldlen
@ -1502,17 +1309,6 @@ _GLIBCXX_END_LDBL_NAMESPACE
extern template class _GLIBCXX_LDBL_NAMESPACE num_get<char>;
extern template class _GLIBCXX_LDBL_NAMESPACE num_put<char>;
extern template class ctype_byname<char>;
extern template class codecvt_byname<char, char, mbstate_t>;
extern template class collate<char>;
extern template class collate_byname<char>;
extern template
const codecvt<char, char, mbstate_t>&
use_facet<codecvt<char, char, mbstate_t> >(const locale&);
extern template
const collate<char>&
use_facet<collate<char> >(const locale&);
extern template
const numpunct<char>&
@ -1530,14 +1326,6 @@ _GLIBCXX_END_LDBL_NAMESPACE
bool
has_facet<ctype<char> >(const locale&);
extern template
bool
has_facet<codecvt<char, char, mbstate_t> >(const locale&);
extern template
bool
has_facet<collate<char> >(const locale&);
extern template
bool
has_facet<numpunct<char> >(const locale&);
@ -1556,17 +1344,6 @@ _GLIBCXX_END_LDBL_NAMESPACE
extern template class _GLIBCXX_LDBL_NAMESPACE num_get<wchar_t>;
extern template class _GLIBCXX_LDBL_NAMESPACE num_put<wchar_t>;
extern template class ctype_byname<wchar_t>;
extern template class codecvt_byname<wchar_t, char, mbstate_t>;
extern template class collate<wchar_t>;
extern template class collate_byname<wchar_t>;
extern template
const codecvt<wchar_t, char, mbstate_t>&
use_facet<codecvt<wchar_t, char, mbstate_t> >(locale const&);
extern template
const collate<wchar_t>&
use_facet<collate<wchar_t> >(const locale&);
extern template
const numpunct<wchar_t>&
@ -1584,14 +1361,6 @@ _GLIBCXX_END_LDBL_NAMESPACE
bool
has_facet<ctype<wchar_t> >(const locale&);
extern template
bool
has_facet<codecvt<wchar_t, char, mbstate_t> >(const locale&);
extern template
bool
has_facet<collate<wchar_t> >(const locale&);
extern template
bool
has_facet<numpunct<wchar_t> >(const locale&);

View File

@ -39,6 +39,8 @@
#ifndef _LOCALE_FACETS_NONIO_H
#define _LOCALE_FACETS_NONIO_H 1
#pragma GCC system_header
#include <ctime> // For struct tm
_GLIBCXX_BEGIN_NAMESPACE(std)
@ -1903,7 +1905,14 @@ _GLIBCXX_END_LDBL_NAMESPACE
_GLIBCXX_END_NAMESPACE
// Include host and configuration specific messages functions.
// Include host and configuration specific messages functions.
#include <bits/messages_members.h>
// 22.2.1.5 Template class codecvt
#include <bits/codecvt.h>
#ifndef _GLIBCXX_EXPORT_TEMPLATE
# include <bits/locale_facets_nonio.tcc>
#endif
#endif

View File

@ -35,6 +35,8 @@
#ifndef _LOCALE_FACETS_NONIO_TCC
#define _LOCALE_FACETS_NONIO_TCC 1
#pragma GCC system_header
_GLIBCXX_BEGIN_NAMESPACE(std)
template<typename _CharT, bool _Intl>
@ -1168,6 +1170,7 @@ _GLIBCXX_END_LDBL_NAMESPACE
return std::__write(__s, __res, char_traits<char_type>::length(__res));
}
// Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere.
// NB: This syntax is a GNU extension.

View File

@ -332,7 +332,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
extern template ostream& operator<<(ostream&, const char*);
extern template ostream& operator<<(ostream&, const unsigned char*);
extern template ostream& operator<<(ostream&, const signed char*);
extern template ostream& __ostream_insert(ostream&, const char*, streamsize);
extern template ostream& ostream::_M_insert(long);
extern template ostream& ostream::_M_insert(unsigned long);
@ -354,8 +353,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
extern template wostream& operator<<(wostream&, char);
extern template wostream& operator<<(wostream&, const wchar_t*);
extern template wostream& operator<<(wostream&, const char*);
extern template wostream& __ostream_insert(wostream&, const wchar_t*,
streamsize);
extern template wostream& wostream::_M_insert(long);
extern template wostream& wostream::_M_insert(unsigned long);

View File

@ -109,6 +109,18 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
return __out;
}
// Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere.
// NB: This syntax is a GNU extension.
#if _GLIBCXX_EXTERN_TEMPLATE
extern template ostream& __ostream_insert(ostream&, const char*, streamsize);
#ifdef _GLIBCXX_USE_WCHAR_T
extern template wostream& __ostream_insert(wostream&, const wchar_t*,
streamsize);
#endif
#endif
_GLIBCXX_END_NAMESPACE
#endif /* _OSTREAM_INSERT_H */

View File

@ -44,7 +44,8 @@
#include <istream>
#include <ostream>
#include <cstdio> // For BUFSIZ
#include <bits/codecvt.h>
#include <cstdio> // For BUFSIZ
#include <bits/basic_file.h> // For __basic_file, __c_lock
_GLIBCXX_BEGIN_NAMESPACE(std)
@ -61,7 +62,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
// Requirements on traits_type, specific to this class:
// traits_type::pos_type must be fpos<traits_type::state_type>
// traits_type::off_type must be streamoff
// traits_type::state_type must be Assignable and DefaultConstructable,
// traits_type::state_type must be Assignable and DefaultConstructible,
// and traits_type::state_type() must be the initial state for codecvt.
template<typename _CharT, typename _Traits>
class basic_filebuf : public basic_streambuf<_CharT, _Traits>

View File

@ -836,7 +836,6 @@ _GLIBCXX_END_NAMESPACE
#ifndef _GLIBCXX_EXPORT_TEMPLATE
# include <bits/istream.tcc>
# include <bits/locale_facets.tcc>
#endif
#endif /* _GLIBCXX_ISTREAM */

View File

@ -1,7 +1,8 @@
// Locale support -*- C++ -*-
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
// 2006, 2007 Free Software Foundation, Inc.
// 2006, 2007
// 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
@ -46,9 +47,4 @@
#include <bits/locale_facets.h>
#include <bits/locale_facets_nonio.h>
#ifndef _GLIBCXX_EXPORT_TEMPLATE
# include <bits/locale_facets.tcc>
# include <bits/locale_facets_nonio.tcc>
#endif
#endif /* _GLIBCXX_LOCALE */

View File

@ -570,7 +570,6 @@ _GLIBCXX_END_NAMESPACE
#ifndef _GLIBCXX_EXPORT_TEMPLATE
# include <bits/ostream.tcc>
# include <bits/locale_facets.tcc>
#endif
#endif /* _GLIBCXX_OSTREAM */

View File

@ -1,6 +1,6 @@
// -*- C++ -*-
// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
// Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
@ -32,6 +32,7 @@
#include <string>
#include <stdexcept>
#include <deque>
#include <locale>
#include <ext/hash_map>
#include <cxxabi.h>