00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
00048 locale::_Impl::
00049 _Impl(const _Impl& __imp, size_t __refs)
00050 : _M_references(__refs - 1), _M_facets(0), _M_c_locale(0)
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
00070 locale::_Impl::
00071 _Impl(string __str, size_t __refs)
00072 : _M_references(__refs - 1), _M_facets(0)
00073 {
00074
00075
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
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
00091 for (size_t i = 0; i < _S_num_categories; ++i)
00092 _M_names[i] = __str;
00093
00094
00095
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
00139 _M_replace_category(__imp, _S_facet_categories[__ix]);
00140
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;
00177
00178 if (__index >= _M_facets->size())
00179 _M_facets->resize(__index + 1, 0);
00180
00181 facet*& __fpr = (*_M_facets)[__index];
00182 if (__fpr)
00183 {
00184
00185
00186 __fp->_M_add_reference();
00187 if (__fpr)
00188 __fpr->_M_remove_reference();
00189 __fpr = __fp;
00190 }
00191 else
00192 {
00193
00194
00195
00196 (*_M_facets)[__index] = __fp;
00197 }
00198 }
00199 }
00200 }
00201