Commit 22b9554c by Benjamin Kosnik Committed by Benjamin Kosnik

localename.cc (locale::_Imp): Remove typedefs.


2000-09-19  Benjamin Kosnik  <bkoz@purist.soma.redhat.com>

	* src/localename.cc (locale::_Imp) : Remove typedefs.
	* bits/localefwd.h (locale::locale(const locale& __other, _Facet*
	__f): Consistency check,, call _Imp ctor with refererence argument
	of 1.
	* bits/localefwd.h: Change _S_num_categories to
	_S_categories_num. Add new data member, _S_facets_num, which is
	the number of standard facets.

From-SVN: r36550
parent 98ee0cc5
2000-09-19 Benjamin Kosnik <bkoz@purist.soma.redhat.com>
* src/localename.cc (locale::_Imp) : Remove typedefs.
* bits/localefwd.h (locale::locale(const locale& __other, _Facet*
__f): Consistency check,, call _Imp ctor with refererence argument
of 1.
* bits/localefwd.h: Change _S_num_categories to
_S_categories_num. Add new data member, _S_facets_num, which is
the number of standard facets.
2000-09-19 Phil Edwards <pme@sources.redhat.com> 2000-09-19 Phil Edwards <pme@sources.redhat.com>
* docs/21_strings/howto.html: Fix editor lossage from last commit. * docs/21_strings/howto.html: Fix editor lossage from last commit.
......
...@@ -294,13 +294,14 @@ namespace std ...@@ -294,13 +294,14 @@ namespace std
// The (shared) implementation // The (shared) implementation
_Impl* _M_impl; _Impl* _M_impl;
// The one true C reference locale // The "C" reference locale
static _Impl* _S_classic; static _Impl* _S_classic;
// Current global reference locale // Current global reference locale
static _Impl* _S_global; static _Impl* _S_global;
static const int _S_num_categories = _Count_ones<all>::_S_count; static const int _S_categories_num = _Count_ones<all>::_S_count;
static const int _S_facets_num = 26;
explicit explicit
locale(_Impl*) throw(); locale(_Impl*) throw();
...@@ -423,7 +424,7 @@ namespace std ...@@ -423,7 +424,7 @@ namespace std
template<typename _Facet> template<typename _Facet>
locale::locale(const locale& __other, _Facet* __f) locale::locale(const locale& __other, _Facet* __f)
{ {
_M_impl = new _Impl(*__other._M_impl, 0); _M_impl = new _Impl(*__other._M_impl, 1);
_M_impl->_M_install_facet(&_Facet::id, __f); _M_impl->_M_install_facet(&_Facet::id, __f);
_M_impl->_M_has_name = false; _M_impl->_M_has_name = false;
_M_impl->_M_name = "*"; _M_impl->_M_name = "*";
......
...@@ -55,7 +55,8 @@ namespace std { ...@@ -55,7 +55,8 @@ namespace std {
locale::_Impl* locale::_S_global; locale::_Impl* locale::_S_global;
locale::_Impl* locale::_S_classic; locale::_Impl* locale::_S_classic;
const int locale::_S_num_categories; const int locale::_S_categories_num;
const int locale::_S_facets_num;
// Definitions for static const data members of locale::_Impl // Definitions for static const data members of locale::_Impl
const locale::id* const const locale::id* const
...@@ -552,6 +553,11 @@ namespace std { ...@@ -552,6 +553,11 @@ namespace std {
} }
locale::locale(_Impl* __ip) throw()
: _M_impl(__ip)
{ __ip->_M_add_reference(); }
locale::locale(const char* __name) locale::locale(const char* __name)
{ {
if (__name) if (__name)
...@@ -560,7 +566,7 @@ namespace std { ...@@ -560,7 +566,7 @@ namespace std {
(_M_impl = _S_classic)->_M_add_reference(); (_M_impl = _S_classic)->_M_add_reference();
// Might throw: // Might throw:
else else
_M_impl = new _Impl(*_S_classic, __name, all, 1); _M_impl = new _Impl(_S_facets_num, 1, true, __name);
} }
else else
throw runtime_error("attempt to create named locale from NULL name"); throw runtime_error("attempt to create named locale from NULL name");
...@@ -580,17 +586,6 @@ namespace std { ...@@ -580,17 +586,6 @@ namespace std {
throw runtime_error("attempt to create locale from NULL named locale"); throw runtime_error("attempt to create locale from NULL named locale");
} }
bool
locale::operator==(const locale& __rhs) const throw()
{
return((this->name() != "*" && this->name() == __rhs.name())
|| _M_impl == __rhs._M_impl);
}
locale::locale(_Impl* __ip) throw()
: _M_impl(__ip)
{ __ip->_M_add_reference(); }
locale::locale(const locale& __other, const locale& __one, category __cat) locale::locale(const locale& __other, const locale& __one, category __cat)
{ {
__cat = _S_normalize_category(__cat); // might throw __cat = _S_normalize_category(__cat); // might throw
...@@ -610,6 +605,13 @@ namespace std { ...@@ -610,6 +605,13 @@ namespace std {
_M_impl->_M_has_name = false; _M_impl->_M_has_name = false;
} }
bool
locale::operator==(const locale& __rhs) const throw()
{
return((this->name() != "*" && this->name() == __rhs.name())
|| _M_impl == __rhs._M_impl);
}
const locale& const locale&
locale::operator=(const locale& __other) throw() locale::operator=(const locale& __other) throw()
{ {
...@@ -647,7 +649,7 @@ namespace std { ...@@ -647,7 +649,7 @@ namespace std {
try { try {
// 26 Standard facets, 2 references. // 26 Standard facets, 2 references.
// One reference for _M_classic, one for _M_global // One reference for _M_classic, one for _M_global
_S_classic = new _Impl(26, 2, true, "C"); _S_classic = new _Impl(_S_facets_num, 2, true, "C");
_S_global = _S_classic; _S_global = _S_classic;
_S_classic->_M_facet_init(new std::collate<char>); _S_classic->_M_facet_init(new std::collate<char>);
......
...@@ -45,70 +45,80 @@ namespace std { ...@@ -45,70 +45,80 @@ namespace std {
delete _M_category_names; delete _M_category_names;
} }
// This constructor is used to correctly initialize the standard,
// required facets.
locale::_Impl::
_Impl(size_t __numfacets, size_t __refs, bool __has_name = false,
string __name = "*")
: _M_references(__refs - 1), _M_facets(0), _M_category_names(0),
_M_has_name(__has_name), _M_name(__name)
{
typedef vector<facet*, allocator<facet*> > __vec_facet;
typedef vector<string, allocator<string> > __vec_string;
auto_ptr<__vec_facet> __pvf(new __vec_facet(__numfacets, (facet*)0));
auto_ptr<__vec_string> __pcn(new __vec_string(_S_num_categories, _M_name));
_M_facets = __pvf.release();
_M_category_names = __pcn.release();
}
locale::_Impl:: locale::_Impl::
_Impl(const _Impl& __other, size_t __refs) _Impl(const _Impl& __other, size_t __refs)
: _M_references(__refs - 1), _M_facets(0), _M_category_names(0), : _M_references(__refs - 1), _M_facets(0), _M_category_names(0),
_M_has_name(__other._M_has_name), _M_name(__other._M_name) _M_has_name(__other._M_has_name), _M_name(__other._M_name)
{ {
typedef vector<facet*, allocator<facet*> > __vec_facet; try
typedef vector<string, allocator<string> > __vec_string; { _M_facets = new __vec_facet(*(__other._M_facets)); }
catch(...)
{
delete _M_facets;
throw;
}
auto_ptr<__vec_facet> __pvf(new __vec_facet(*(__other._M_facets))); try
auto_ptr<__vec_string> { _M_category_names = new __vec_string(*(__other._M_category_names)); }
__pcn(new __vec_string(*(__other._M_category_names))); catch(...)
{
delete _M_category_names;
throw;
}
std::vector<facet*>::iterator __it = __pvf->begin(); std::vector<facet*>::iterator __it = _M_facets->begin();
for (; __it != __pvf->end(); ++__it) for (; __it != _M_facets->end(); ++__it)
(*__it)->_M_add_reference(); (*__it)->_M_add_reference();
// These must be last since in the presence of an exception, the
// destructor for 'this' won't run until AFTER execution has passed
// the closing brace of the constructor.
_M_facets = __pvf.release();
_M_category_names = __pcn.release();
} }
// This constructor is used to correctly initialize named locales,
// including the standard "C" locale.
locale::_Impl::
_Impl(size_t __numfacets, size_t __refs, bool __has_name = false,
string __name = "*")
: _M_references(__refs - 1), _M_facets(0), _M_category_names(0),
_M_has_name(__has_name), _M_name(__name)
{
try
{ _M_facets = new __vec_facet(__numfacets, NULL); }
catch(...)
{
delete _M_facets;
throw;
}
try
{ _M_category_names = new __vec_string(_S_categories_num, _M_name); }
catch(...)
{
delete _M_category_names;
throw;
}
}
// Construct specific categories, leaving unselected ones alone // Construct specific categories, leaving unselected ones alone
locale::_Impl:: locale::_Impl::
_Impl(const _Impl& __other, const string& __name, category __cat, _Impl(const _Impl& __other, const string& __name, category __cat,
size_t __refs) size_t __refs)
: _M_references(__refs - 1), _M_has_name(__other._M_name != "*") : _M_references(__refs - 1), _M_has_name(__other._M_name != "*")
{ {
typedef vector<facet*, allocator<facet*> > __vec_facet;
typedef vector<string, allocator<string> > __vec_string;
__cat = _S_normalize_category(__cat); // might throw __cat = _S_normalize_category(__cat); // might throw
try {
_M_facets = new __vec_facet(*(__other._M_facets)); try
} { _M_facets = new __vec_facet(*(__other._M_facets)); }
catch(...) { catch(...)
delete _M_facets; {
throw; delete _M_facets;
} throw;
try { }
_M_category_names = new __vec_string(*(__other._M_category_names));
} try
catch(...) { { _M_category_names = new __vec_string(*(__other._M_category_names)); }
delete _M_category_names; catch(...)
throw; {
} delete _M_category_names;
throw;
}
static void(_Impl::* ctors[]) (const char*) = static void(_Impl::* ctors[]) (const char*) =
{ {
......
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