localename.cc (locale::_Imp): Remove typedefs.
authorBenjamin Kosnik <bkoz@purist.soma.redhat.com>
Wed, 20 Sep 2000 08:19:07 +0000 (08:19 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Wed, 20 Sep 2000 08:19:07 +0000 (08:19 +0000)
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

libstdc++-v3/ChangeLog
libstdc++-v3/bits/localefwd.h
libstdc++-v3/src/locale.cc
libstdc++-v3/src/localename.cc

index be501f33db36a10d853245ed5ecc4ca8fb15b276..73ea5e5e32c90a278c431754bf406c714b465c04 100644 (file)
@@ -1,3 +1,13 @@
+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>
 
        * docs/21_strings/howto.html:  Fix editor lossage from last commit.
index 252f95dda740f371251117b4bf224654253f6e29..44e85604bdb62bd4414b75844eebd5871294b3a3 100644 (file)
@@ -294,13 +294,14 @@ namespace std
     // The (shared) implementation
     _Impl*             _M_impl;  
 
-    // The one true C reference locale
+    // The "C" reference locale
     static _Impl*      _S_classic; 
 
     // Current global reference locale
     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 
     locale(_Impl*) throw();
@@ -423,7 +424,7 @@ namespace std
   template<typename _Facet>
     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_has_name = false;
       _M_impl->_M_name = "*";
index de57040f9acc5f2262e4e029486e1053bdd0d541..64996efb30427597737da6567643291f904aa922 100644 (file)
@@ -55,7 +55,8 @@ namespace std {
 
   locale::_Impl*               locale::_S_global; 
   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
   const locale::id* const
@@ -552,6 +553,11 @@ namespace std {
   }
 
 
+  locale::locale(_Impl* __ip) throw()
+  : _M_impl(__ip)
+  { __ip->_M_add_reference(); }
+
+
   locale::locale(const char* __name)
   {
     if (__name)
@@ -560,7 +566,7 @@ namespace std {
          (_M_impl = _S_classic)->_M_add_reference();
        // Might throw:
        else
-         _M_impl = new _Impl(*_S_classic, __name, all, 1);
+         _M_impl = new _Impl(_S_facets_num, 1, true, __name);
       }
     else
       throw runtime_error("attempt to create named locale from NULL name");
@@ -580,17 +586,6 @@ namespace std {
       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)
   {
     __cat = _S_normalize_category(__cat);    // might throw
@@ -610,6 +605,13 @@ namespace std {
       _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&
   locale::operator=(const locale& __other) throw()
   {
@@ -647,7 +649,7 @@ namespace std {
        try {
          // 26 Standard facets, 2 references.
          // 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_classic->_M_facet_init(new std::collate<char>);
index 1b231c02bcda30bd0b720a074f031ac3590a3522..7d6f259acce0dfeae9cd86f7b76afa03fb2493ff 100644 (file)
@@ -45,70 +45,80 @@ namespace std {
     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::
   _Impl(const _Impl& __other, size_t __refs)
   : _M_references(__refs - 1), _M_facets(0), _M_category_names(0), 
     _M_has_name(__other._M_has_name), _M_name(__other._M_name)
   {
-    typedef vector<facet*, allocator<facet*> > __vec_facet;
-    typedef vector<string, allocator<string> > __vec_string;
+    try
+      {  _M_facets = new __vec_facet(*(__other._M_facets)); }
+    catch(...) 
+      {
+       delete _M_facets;
+       throw;
+      }
 
-    auto_ptr<__vec_facet> __pvf(new __vec_facet(*(__other._M_facets)));
-    auto_ptr<__vec_string> 
-      __pcn(new __vec_string(*(__other._M_category_names)));
+    try 
+      {        _M_category_names = new __vec_string(*(__other._M_category_names)); }
+    catch(...) 
+      {
+       delete _M_category_names;
+       throw;
+      }
 
-    std::vector<facet*>::iterator __it = __pvf->begin();
-    for (; __it != __pvf->end(); ++__it)
+    std::vector<facet*>::iterator __it = _M_facets->begin();
+    for (; __it != _M_facets->end(); ++__it)
       (*__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
   locale::_Impl::
   _Impl(const _Impl& __other, const string& __name, category __cat, 
        size_t __refs)
     : _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
-    try {
-      _M_facets = new __vec_facet(*(__other._M_facets));
-    }
-    catch(...) {
-      delete _M_facets;
-      throw;
-    }
-    try {
-       _M_category_names = new __vec_string(*(__other._M_category_names));
-    }
-    catch(...) {
-      delete _M_category_names;
-      throw;
-    }
+
+    try 
+      { _M_facets = new __vec_facet(*(__other._M_facets)); }
+    catch(...) 
+      {
+       delete _M_facets;
+       throw;
+      }
+
+    try 
+      {        _M_category_names = new __vec_string(*(__other._M_category_names)); }
+    catch(...) 
+      {
+       delete _M_category_names;
+       throw;
+      }
 
     static void(_Impl::* ctors[]) (const char*) = 
     {