Whole document tree
    

Whole document tree

localename.cc Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

localename.cc

Go to the documentation of this file.
00001 // Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
00002 //
00003 // This file is part of the GNU ISO C++ Library.  This library is free
00004 // software; you can redistribute it and/or modify it under the
00005 // terms of the GNU General Public License as published by the
00006 // Free Software Foundation; either version 2, or (at your option)
00007 // any later version.
00008 
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 
00014 // You should have received a copy of the GNU General Public License along
00015 // with this library; see the file COPYING.  If not, write to the Free
00016 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00017 // USA.
00018 
00019 // As a special exception, you may use this file as part of a free software
00020 // library without restriction.  Specifically, if other files instantiate
00021 // templates or use macros or inline functions from this file, or you compile
00022 // this file and link it with other files to produce an executable, this
00023 // file does not by itself cause the resulting executable to be covered by
00024 // the GNU General Public License.  This exception does not however
00025 // invalidate any other reasons why the executable file might be covered by
00026 // the GNU General Public License.
00027 
00028 #include <bits/std_clocale.h>
00029 #include <bits/std_locale.h>
00030 #include <bits/std_cstring.h>
00031 #include <bits/std_vector.h>
00032 #include <bits/std_stdexcept.h>
00033 
00034 namespace std
00035 {
00036   locale::_Impl::
00037   ~_Impl() throw()
00038   {
00039     __vec_facet::iterator it = _M_facets->begin();
00040     for (; it != _M_facets->end(); ++it)
00041       if (*it)
00042     (*it)->_M_remove_reference();
00043     delete _M_facets;
00044     locale::facet::_S_destroy_c_locale(_M_c_locale);
00045   }
00046 
00047   // Clone existing _Impl object.
00048   locale::_Impl::
00049   _Impl(const _Impl& __imp, size_t __refs)
00050   : _M_references(__refs - 1), _M_facets(0), _M_c_locale(0) // XXX
00051   {
00052     try
00053       {  _M_facets = new __vec_facet(*(__imp._M_facets)); }
00054     catch(...) 
00055       {
00056     delete _M_facets;
00057     __throw_exception_again;
00058       }
00059 
00060     for (size_t i = 0; i < _S_num_categories; ++i)
00061       _M_names[i] = __imp._M_names[i];
00062 
00063     __vec_facet::iterator __it = _M_facets->begin();
00064     for (; __it != _M_facets->end(); ++__it)
00065       if (*__it)
00066     (*__it)->_M_add_reference();
00067   }
00068 
00069   // Construct named _Impl, including the standard "C" locale.
00070   locale::_Impl::
00071   _Impl(string __str, size_t __refs)
00072   : _M_references(__refs - 1), _M_facets(0)
00073   {
00074     // Initialize the underlying locale model, which also checks to
00075     // see if the given name is valid.
00076     if (__str != "C" && __str != "POSIX")
00077       locale::facet::_S_create_c_locale(_M_c_locale, __str.c_str());
00078     else
00079       _M_c_locale = NULL;
00080 
00081     // Allocate facet container.
00082     try
00083       {  _M_facets = new __vec_facet(_S_num_facets, NULL); }
00084     catch(...) 
00085       {
00086     delete _M_facets;
00087     __throw_exception_again;
00088       }
00089 
00090     // Name all the categories.
00091     for (size_t i = 0; i < _S_num_categories; ++i)
00092       _M_names[i] = __str;
00093 
00094     // Construct all standard facets and add them to _M_facets.
00095     // XXX Eventually, all should use __c_locale ctor like numpunct
00096     _M_init_facet(new std::collate<char>);
00097     _M_init_facet(new std::ctype<char>);
00098     _M_init_facet(new codecvt<char, char, mbstate_t>);
00099     _M_init_facet(new moneypunct<char, false>(_M_c_locale));
00100     _M_init_facet(new moneypunct<char,true >);
00101     _M_init_facet(new money_get<char>);
00102     _M_init_facet(new money_put<char>);
00103     _M_init_facet(new numpunct<char>(_M_c_locale));
00104     _M_init_facet(new num_get<char>);
00105     _M_init_facet(new num_put<char>);
00106     _M_init_facet(new time_get<char>);
00107     _M_init_facet(new time_put<char>);
00108     _M_init_facet(new std::messages<char>);
00109     
00110 #ifdef  _GLIBCPP_USE_WCHAR_T
00111     _M_init_facet(new std::collate<wchar_t>);
00112     _M_init_facet(new std::ctype<wchar_t>);
00113     _M_init_facet(new codecvt<wchar_t, char, mbstate_t>);
00114     _M_init_facet(new moneypunct<wchar_t, false>(_M_c_locale));
00115     _M_init_facet(new moneypunct<wchar_t,true >);
00116     _M_init_facet(new money_get<wchar_t>);
00117     _M_init_facet(new money_put<wchar_t>);
00118     _M_init_facet(new numpunct<wchar_t>(_M_c_locale));
00119     _M_init_facet(new num_get<wchar_t>);
00120     _M_init_facet(new num_put<wchar_t>);
00121     _M_init_facet(new time_get<wchar_t>);
00122     _M_init_facet(new time_put<wchar_t>);
00123     _M_init_facet(new std::messages<wchar_t>);
00124 #endif    
00125   }
00126   
00127   void
00128   locale::_Impl::
00129   _M_replace_categories(const _Impl* __imp, category __cat)
00130   {
00131     const string __none("*");
00132     category __mask;
00133     for (unsigned int __ix = 0; __ix < _S_num_categories; ++__ix)
00134       {
00135     __mask = 1 << __ix;
00136     if (__mask & __cat)
00137       {
00138         // Need to replace entry in _M_facets with other locale's info.
00139         _M_replace_category(__imp, _S_facet_categories[__ix]);
00140         // If both have names, go ahead and mangle.
00141         if (_M_names[__ix] != __none && __imp->_M_names[__ix] != __none)
00142           _M_names[__ix] = __imp->_M_names[__ix];
00143       }
00144       }
00145   }
00146 
00147   void
00148   locale::_Impl::
00149   _M_replace_category(const _Impl* __imp, const locale::id* const* __idpp)
00150   {
00151     for (; *__idpp; ++__idpp)
00152       _M_replace_facet(__imp, *__idpp);
00153   }
00154   
00155   void
00156   locale::_Impl::
00157   _M_replace_facet(const _Impl* __imp, const locale::id* __idp)
00158   {
00159     size_t __index = __idp->_M_index;
00160     if (__index == 0 
00161     || __imp->_M_facets->size() <= __index 
00162     || (*(__imp->_M_facets))[__index] == 0)
00163       __throw_runtime_error("no locale facet");
00164     
00165     _M_install_facet(__idp, (*(__imp->_M_facets))[__index]); 
00166   }
00167 
00168   void
00169   locale::_Impl::
00170   _M_install_facet(const locale::id* __idp, facet* __fp)
00171   {
00172     if (__fp)
00173       {
00174     size_t& __index = __idp->_M_index;
00175     if (!__index)
00176       __index = ++locale::id::_S_highwater;  // XXX MT
00177     
00178     if (__index >= _M_facets->size())
00179       _M_facets->resize(__index + 1, 0);  // might throw
00180 
00181     facet*& __fpr = (*_M_facets)[__index];
00182     if (__fpr)
00183       {
00184         // Replacing an existing facet.
00185         // Order matters, here:
00186         __fp->_M_add_reference();
00187         if (__fpr) 
00188           __fpr->_M_remove_reference();
00189         __fpr = __fp;
00190       }
00191     else
00192       {
00193         // Installing a newly created facet into an empty
00194         // _M_facets container, say a newly-constructed,
00195         // swanky-fresh _Impl.
00196         (*_M_facets)[__index] = __fp;
00197       }
00198       }
00199   }
00200 } // namespace std
00201 

Generated on Mon Apr 8 03:11:30 2002 for libstdc++-v3 Source by doxygen1.2.15