Commit 0dba73e0 by Benjamin Kosnik Committed by Benjamin Kosnik

localefwd.h (locale::_Impl::_M_facets): Change from pointer to vector.


2002-04-09  Benjamin Kosnik  <bkoz@redhat.com>

        libstdc++/1072
        * include/bits/localefwd.h (locale::_Impl::_M_facets): Change from
        pointer to vector.
        Remove forward declaration of vector.
        Include vector.
        * include/bits/locale_facets.tcc: Remove vector include.
        (use_locale): Adjust.
        (has_locale): Adjust.
        * src/locale.cc: Adjust.
        * src/localename.cc: Same.

From-SVN: r52095
parent b47374fa
2002-04-09 Benjamin Kosnik <bkoz@redhat.com> 2002-04-09 Benjamin Kosnik <bkoz@redhat.com>
libstdc++/1072
* include/bits/localefwd.h (locale::_Impl::_M_facets): Change from
pointer to vector.
Remove forward declaration of vector.
Include vector.
* include/bits/locale_facets.tcc: Remove vector include.
(use_locale): Adjust.
(has_locale): Adjust.
* src/locale.cc: Adjust.
* src/localename.cc: Same.
2002-04-09 Benjamin Kosnik <bkoz@redhat.com>
Richard Henderson <rth@redhat.com> Richard Henderson <rth@redhat.com>
* include/bits/sstream.tcc: Clean up bit ops. * include/bits/sstream.tcc: Clean up bit ops.
......
...@@ -42,7 +42,6 @@ ...@@ -42,7 +42,6 @@
#include <cctype> // For isspace #include <cctype> // For isspace
#include <limits> // For numeric_limits #include <limits> // For numeric_limits
#include <bits/streambuf_iterator.h> #include <bits/streambuf_iterator.h>
#include <vector>
#include <typeinfo> // For bad_cast. #include <typeinfo> // For bad_cast.
namespace std namespace std
...@@ -72,9 +71,9 @@ namespace std ...@@ -72,9 +71,9 @@ namespace std
use_facet(const locale& __loc) use_facet(const locale& __loc)
{ {
size_t __i = _Facet::id._M_index; size_t __i = _Facet::id._M_index;
locale::_Impl::__vec_facet* __facet = __loc._M_impl->_M_facets; locale::_Impl::__vec_facet& __facet = __loc._M_impl->_M_facets;
const locale::facet* __fp = (*__facet)[__i]; const locale::facet* __fp = __facet[__i];
if (__fp == 0 || __i >= __facet->size()) if (__fp == 0 || __i >= __facet.size())
__throw_bad_cast(); __throw_bad_cast();
return static_cast<const _Facet&>(*__fp); return static_cast<const _Facet&>(*__fp);
} }
...@@ -84,8 +83,8 @@ namespace std ...@@ -84,8 +83,8 @@ namespace std
has_facet(const locale& __loc) throw() has_facet(const locale& __loc) throw()
{ {
size_t __i = _Facet::id._M_index; size_t __i = _Facet::id._M_index;
locale::_Impl::__vec_facet* __facet = __loc._M_impl->_M_facets; locale::_Impl::__vec_facet& __facet = __loc._M_impl->_M_facets;
return (__i < __facet->size() && (*__facet)[__i] != 0); return (__i < __facet.size() && __facet[__i] != 0);
} }
......
...@@ -46,7 +46,8 @@ ...@@ -46,7 +46,8 @@
#include <bits/c++locale.h> // Defines __c_locale, config-specific includes #include <bits/c++locale.h> // Defines __c_locale, config-specific includes
#include <climits> // For CHAR_BIT #include <climits> // For CHAR_BIT
#include <cctype> // For isspace, etc. #include <cctype> // For isspace, etc.
#include <string> // For string #include <string> // For string.
#include <vector> // For vector.
#include <bits/functexcept.h> #include <bits/functexcept.h>
#include <bits/atomicity.h> #include <bits/atomicity.h>
...@@ -61,8 +62,6 @@ namespace std ...@@ -61,8 +62,6 @@ namespace std
#endif #endif
// 22.1.1 Locale // 22.1.1 Locale
template<typename _Tp, typename _Alloc>
class vector;
class locale; class locale;
// 22.1.3 Convenience interfaces // 22.1.3 Convenience interfaces
...@@ -320,7 +319,7 @@ namespace std ...@@ -320,7 +319,7 @@ namespace std
private: private:
// Data Members. // Data Members.
_Atomic_word _M_references; _Atomic_word _M_references;
__vec_facet* _M_facets; __vec_facet _M_facets;
string _M_names[_S_num_categories]; string _M_names[_S_num_categories];
static const locale::id* const _S_id_ctype[]; static const locale::id* const _S_id_ctype[];
static const locale::id* const _S_id_numeric[]; static const locale::id* const _S_id_numeric[];
......
...@@ -500,7 +500,7 @@ namespace std ...@@ -500,7 +500,7 @@ namespace std
{ {
size_t __i = ctype<char>::id._M_index; size_t __i = ctype<char>::id._M_index;
const locale::_Impl* __tmp = __loc._M_impl; const locale::_Impl* __tmp = __loc._M_impl;
return static_cast<const ctype<char>&>(* (*(__tmp->_M_facets))[__i]); return static_cast<const ctype<char>&>(*(__tmp->_M_facets[__i]));
} }
#ifdef _GLIBCPP_USE_WCHAR_T #ifdef _GLIBCPP_USE_WCHAR_T
...@@ -510,7 +510,7 @@ namespace std ...@@ -510,7 +510,7 @@ namespace std
{ {
size_t __i = ctype<wchar_t>::id._M_index; size_t __i = ctype<wchar_t>::id._M_index;
const locale::_Impl* __tmp = __loc._M_impl; const locale::_Impl* __tmp = __loc._M_impl;
return static_cast<const ctype<wchar_t>&>(* (*(__tmp->_M_facets))[__i]); return static_cast<const ctype<wchar_t>&>(*(__tmp->_M_facets[__i]));
} }
#endif #endif
......
...@@ -36,31 +36,25 @@ namespace std ...@@ -36,31 +36,25 @@ namespace std
locale::_Impl:: locale::_Impl::
~_Impl() throw() ~_Impl() throw()
{ {
__vec_facet::iterator it = _M_facets->begin(); __vec_facet::iterator __it = _M_facets.begin();
for (; it != _M_facets->end(); ++it) __vec_facet::iterator __end = _M_facets.end();
if (*it) for (; __it != __end; ++__it)
(*it)->_M_remove_reference(); if (*__it)
delete _M_facets; (*__it)->_M_remove_reference();
} }
// Clone existing _Impl object. // Clone existing _Impl object.
locale::_Impl:: locale::_Impl::
_Impl(const _Impl& __imp, size_t __refs) _Impl(const _Impl& __imp, size_t __refs)
: _M_references(__refs), _M_facets(0) // XXX : _M_references(__refs) // XXX
{ {
try _M_facets = __imp._M_facets;
{ _M_facets = new __vec_facet(*(__imp._M_facets)); } for (size_t __i = 0; __i < _S_num_categories; ++__i)
catch(...) _M_names[__i] = __imp._M_names[__i];
{
delete _M_facets;
__throw_exception_again;
}
for (size_t i = 0; i < _S_num_categories; ++i) __vec_facet::iterator __it = _M_facets.begin();
_M_names[i] = __imp._M_names[i]; __vec_facet::iterator __end = _M_facets.end();
for (; __it != __end; ++__it)
__vec_facet::iterator __it = _M_facets->begin();
for (; __it != _M_facets->end(); ++__it)
if (*__it) if (*__it)
(*__it)->_M_add_reference(); (*__it)->_M_add_reference();
} }
...@@ -68,7 +62,7 @@ namespace std ...@@ -68,7 +62,7 @@ namespace std
// Construct named _Impl, including the standard "C" locale. // Construct named _Impl, including the standard "C" locale.
locale::_Impl:: locale::_Impl::
_Impl(string __str, size_t __refs) _Impl(string __str, size_t __refs)
: _M_references(__refs), _M_facets(0) : _M_references(__refs)
{ {
// Initialize the underlying locale model, which also checks to // Initialize the underlying locale model, which also checks to
// see if the given name is valid. // see if the given name is valid.
...@@ -81,14 +75,7 @@ namespace std ...@@ -81,14 +75,7 @@ namespace std
if (__str != "C" && __str != "POSIX") if (__str != "C" && __str != "POSIX")
__cloc_c = __cloc; __cloc_c = __cloc;
// Allocate facet container. _M_facets = __vec_facet(_S_num_facets, NULL);
try
{ _M_facets = new __vec_facet(_S_num_facets, NULL); }
catch(...)
{
delete _M_facets;
__throw_exception_again;
}
// Name all the categories. // Name all the categories.
for (size_t i = 0; i < _S_num_categories; ++i) for (size_t i = 0; i < _S_num_categories; ++i)
...@@ -162,12 +149,11 @@ namespace std ...@@ -162,12 +149,11 @@ namespace std
_M_replace_facet(const _Impl* __imp, const locale::id* __idp) _M_replace_facet(const _Impl* __imp, const locale::id* __idp)
{ {
size_t __index = __idp->_M_index; size_t __index = __idp->_M_index;
if (__index == 0 if (__index == 0 || __imp->_M_facets.size() <= __index
|| __imp->_M_facets->size() <= __index || __imp->_M_facets[__index] == 0)
|| (*(__imp->_M_facets))[__index] == 0)
__throw_runtime_error("no locale facet"); __throw_runtime_error("no locale facet");
_M_install_facet(__idp, (*(__imp->_M_facets))[__index]); _M_install_facet(__idp, __imp->_M_facets[__index]);
} }
void void
...@@ -180,14 +166,13 @@ namespace std ...@@ -180,14 +166,13 @@ namespace std
if (!__index) if (!__index)
__index = 1 + __exchange_and_add(&locale::id::_S_highwater, 1); __index = 1 + __exchange_and_add(&locale::id::_S_highwater, 1);
if (__index >= _M_facets->size()) if (__index >= _M_facets.size())
_M_facets->resize(__index + 1, 0); // might throw _M_facets.resize(__index + 1, 0); // might throw
facet*& __fpr = (*_M_facets)[__index]; facet*& __fpr = _M_facets[__index];
if (__fpr) if (__fpr)
{ {
// Replacing an existing facet. // Replacing an existing facet. Order matters.
// Order matters, here:
__fp->_M_add_reference(); __fp->_M_add_reference();
__fpr->_M_remove_reference(); __fpr->_M_remove_reference();
__fpr = __fp; __fpr = __fp;
...@@ -197,7 +182,7 @@ namespace std ...@@ -197,7 +182,7 @@ namespace std
// Installing a newly created facet into an empty // Installing a newly created facet into an empty
// _M_facets container, say a newly-constructed, // _M_facets container, say a newly-constructed,
// swanky-fresh _Impl. // swanky-fresh _Impl.
(*_M_facets)[__index] = __fp; _M_facets[__index] = __fp;
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment