/home/ntakagi/work/STLport-5.1.5/src/locale_impl.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */
00018 #include "stlport_prefix.h"
00019 
00020 #include <locale>
00021 #include <typeinfo>
00022 #include <algorithm>
00023 #include <stdexcept>
00024 
00025 #include "c_locale.h"
00026 #include "aligned_buffer.h"
00027 #include "locale_impl.h"
00028 #include "message_facets.h"
00029 
00030 _STLP_BEGIN_NAMESPACE
00031 
00032 static const string _Nameless("*");
00033 
00034 static inline bool is_C_locale_name (const char* name)
00035 { return ((name[0] == 'C') && (name[1] == 0)); }
00036 
00037 _Locale_impl * _STLP_CALL _copy_Locale_impl(_Locale_impl *loc)
00038 {
00039   _STLP_ASSERT( loc != 0 );
00040   loc->_M_incr();
00041   _Locale_impl *loc_new = new _Locale_impl(*loc);
00042   loc->_M_decr();
00043   return loc_new;
00044 }
00045 
00046 locale::facet * _STLP_CALL _get_facet(locale::facet *f)
00047 {
00048   if (f != 0)
00049     f->_M_incr();
00050   return f;
00051 }
00052 
00053 void _STLP_CALL _release_facet(locale::facet *&f)
00054 {
00055   if ((f != 0) && (f->_M_decr() == 0)) {
00056     delete f;
00057     f = 0;
00058   }
00059 }
00060 
00061 size_t locale::id::_S_max = 39;
00062 
00063 static void _Stl_loc_assign_ids();
00064 
00065 static _Stl_aligned_buffer<_Locale_impl::Init> __Loc_init_buf;
00066 
00067 _Locale_impl::Init::Init() {
00068   if (_M_count()._M_incr() == 1) {
00069     _Locale_impl::_S_initialize();
00070   }
00071 }
00072 
00073 _Locale_impl::Init::~Init() {
00074   if (_M_count()._M_decr() == 0) {
00075     _Locale_impl::_S_uninitialize();
00076   }
00077 }
00078 
00079 _Refcount_Base& _Locale_impl::Init::_M_count() const {
00080   static _Refcount_Base _S_count(0);
00081   return _S_count;
00082 }
00083 
00084 _Locale_impl::_Locale_impl(const char* s)
00085   : _Refcount_Base(0), name(s), facets_vec() {
00086   facets_vec.reserve( locale::id::_S_max );
00087   new (&__Loc_init_buf) Init();
00088 }
00089 
00090 _Locale_impl::_Locale_impl( _Locale_impl const& locimpl )
00091   : _Refcount_Base(0), name(locimpl.name), facets_vec() {
00092   for_each( locimpl.facets_vec.begin(), locimpl.facets_vec.end(), _get_facet);
00093   facets_vec = locimpl.facets_vec;
00094   new (&__Loc_init_buf) Init();
00095 }
00096 
00097 _Locale_impl::_Locale_impl( size_t n, const char* s)
00098   : _Refcount_Base(0), name(s), facets_vec(n, 0) {
00099   new (&__Loc_init_buf) Init();
00100 }
00101 
00102 _Locale_impl::~_Locale_impl() {
00103   (&__Loc_init_buf)->~Init();
00104   for_each( facets_vec.begin(), facets_vec.end(), _release_facet);
00105 }
00106 
00107 // Initialization of the locale system.  This must be called before
00108 // any locales are constructed.  (Meaning that it must be called when
00109 // the I/O library itself is initialized.)
00110 void _STLP_CALL _Locale_impl::_S_initialize() {
00111   _Stl_loc_assign_ids();
00112   make_classic_locale();
00113 }
00114 
00115 // Release of the classic locale ressources. Has to be called after the last
00116 // locale destruction and not only after the classic locale destruction as
00117 // the facets can be shared between different facets.
00118 void _STLP_CALL _Locale_impl::_S_uninitialize() {
00119   //Not necessary anymore as classic facets are now 'normal' dynamically allocated
00120   //facets with a reference counter telling to _release_facet when the facet can be
00121   //deleted.
00122   //free_classic_locale();
00123 }
00124 
00125 // _Locale_impl non-inline member functions.
00126 void _STLP_CALL _Locale_impl::_M_throw_bad_cast() {
00127   _STLP_THROW(bad_cast());
00128 }
00129 
00130 void _Locale_impl::insert( _Locale_impl *from, const locale::id& n ) {
00131   size_t index = n._M_index;
00132   if (index > 0 && index < from->size()) {
00133     this->insert( from->facets_vec[index], index);
00134   }
00135 }
00136 
00137 locale::facet* _Locale_impl::insert(locale::facet *f, size_t index) {
00138   if (f == 0 || index == 0)
00139     return 0;
00140 
00141   if (index >= facets_vec.size()) {
00142     facets_vec.resize(index + 1);
00143   }
00144 
00145   if (f != facets_vec[index])
00146   {
00147     _release_facet(facets_vec[index]);
00148     facets_vec[index] = _get_facet(f);
00149   }
00150 
00151   return f;
00152 }
00153 
00154 #if !defined (__DMC__)
00155 _Locale_name_hint* _Locale_extract_hint(ctype_byname<char>* ct)
00156 { return _Locale_get_ctype_hint(ct->_M_ctype); }
00157 _Locale_name_hint* _Locale_extract_hint(numpunct_byname<char>* punct)
00158 { return _Locale_get_numeric_hint(punct->_M_numeric); }
00159 #  if defined (__GNUC__) && (__GNUC__ < 3)
00160 template <class _Ch, class _InIt>
00161 _Locale_name_hint* _Locale_time_extract_hint(time_get_byname<_Ch, _InIt>* tget)
00162 #  else
00163 _Locale_name_hint* _Locale_time_extract_hint(time_get_byname<char, istreambuf_iterator<char, char_traits<char> > >* tget)
00164 #  endif
00165 { return _Locale_get_time_hint(tget->_M_time); }
00166 _Locale_name_hint* _Locale_extract_hint(collate_byname<char>* coll)
00167 { return _Locale_get_collate_hint(coll->_M_collate); }
00168 _Locale_name_hint* _Locale_extract_hint(moneypunct_byname<char, false>* money)
00169 { return _Locale_get_monetary_hint(money->_M_monetary); }
00170 #endif
00171 
00172 //
00173 // <locale> content which is dependent on the name
00174 //
00175 
00176 template <class Facet>
00177 static inline locale::facet* _Locale_insert(_Locale_impl *__that, Facet* f)
00178 { return __that->insert(f, Facet::id._M_index); }
00179 
00180 /*
00181  * Six functions, one for each category.  Each of them takes a
00182  * _Locale* and a name, constructs that appropriate category
00183  * facets by name, and inserts them into the locale.
00184  */
00185 _Locale_name_hint* _Locale_impl::insert_ctype_facets(const char* pname, _Locale_name_hint* hint) {
00186   char buf[_Locale_MAX_SIMPLE_NAME];
00187   _Locale_impl* i2 = locale::classic()._M_impl;
00188 
00189   if (pname == 0 || pname[0] == 0)
00190     pname = _Locale_ctype_default(buf);
00191 
00192   if (pname == 0 || pname[0] == 0 || is_C_locale_name(pname)) {
00193     this->insert(i2, ctype<char>::id);
00194 #ifndef _STLP_NO_MBSTATE_T
00195     this->insert(i2, codecvt<char, char, mbstate_t>::id);
00196 #endif
00197 #ifndef _STLP_NO_WCHAR_T
00198     this->insert(i2, ctype<wchar_t>::id);
00199 #  ifndef _STLP_NO_MBSTATE_T
00200     this->insert(i2, codecvt<wchar_t, char, mbstate_t>::id);
00201 #  endif
00202 #endif
00203   } else {
00204     ctype<char>*    ct                      = 0;
00205 #ifndef _STLP_NO_MBSTATE_T
00206     codecvt<char, char, mbstate_t>*    cvt  = 0;
00207 #endif
00208 #ifndef _STLP_NO_WCHAR_T
00209     ctype<wchar_t>* wct                     = 0;
00210     codecvt<wchar_t, char, mbstate_t>* wcvt = 0;
00211 #endif
00212     _STLP_TRY {
00213       ctype_byname<char> *ctbn = new ctype_byname<char>(pname, 0, hint);
00214       ct   = ctbn;
00215 #if !defined (__DMC__)
00216       if (hint == 0) hint = _Locale_extract_hint(ctbn);
00217 #endif
00218 #ifndef _STLP_NO_MBSTATE_T
00219       cvt  = new codecvt_byname<char, char, mbstate_t>(pname);
00220 #endif
00221 #ifndef _STLP_NO_WCHAR_T
00222       wct  = new ctype_byname<wchar_t>(pname, 0, hint);
00223       wcvt = new codecvt_byname<wchar_t, char, mbstate_t>(pname, 0, hint);
00224 #endif
00225     }
00226 
00227 #ifndef _STLP_NO_WCHAR_T
00228 #  ifdef _STLP_NO_MBSTATE_T
00229     _STLP_UNWIND(delete ct; delete wct; delete wcvt);
00230 #  else
00231     _STLP_UNWIND(delete ct; delete wct; delete cvt; delete wcvt);
00232 #  endif
00233 #else
00234 #  ifdef _STLP_NO_MBSTATE_T
00235     _STLP_UNWIND(delete ct);
00236 #  else
00237     _STLP_UNWIND(delete ct; delete cvt);
00238 #  endif
00239 #endif
00240     _Locale_insert(this, ct);
00241 #ifndef _STLP_NO_MBSTATE_T
00242     _Locale_insert(this, cvt);
00243 #endif
00244 #ifndef _STLP_NO_WCHAR_T
00245     _Locale_insert(this, wct);
00246     _Locale_insert(this, wcvt);
00247 #endif
00248   }
00249   return hint;
00250 }
00251 
00252 _Locale_name_hint* _Locale_impl::insert_numeric_facets(const char* pname, _Locale_name_hint* hint) {
00253   _Locale_impl* i2 = locale::classic()._M_impl;
00254 
00255   numpunct<char>* punct = 0;
00256   num_get<char, istreambuf_iterator<char, char_traits<char> > > *get = 0;
00257   num_put<char, ostreambuf_iterator<char, char_traits<char> > > *put = 0;
00258 #ifndef _STLP_NO_WCHAR_T
00259   numpunct<wchar_t>* wpunct = 0;
00260   num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > > *wget = 0;
00261   num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > *wput = 0;
00262 #endif
00263 
00264   char buf[_Locale_MAX_SIMPLE_NAME];
00265   if (pname == 0 || pname[0] == 0)
00266     pname = _Locale_numeric_default(buf);
00267 
00268   if (pname == 0 || pname[0] == 0 || is_C_locale_name(pname)) {
00269     this->insert(i2, numpunct<char>::id);
00270     this->insert(i2,
00271                  num_put<char, ostreambuf_iterator<char, char_traits<char> >  >::id);
00272     this->insert(i2,
00273                  num_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
00274 #ifndef _STLP_NO_WCHAR_T
00275     this->insert(i2, numpunct<wchar_t>::id);
00276     this->insert(i2,
00277                  num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> >  >::id);
00278     this->insert(i2,
00279                  num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
00280 #endif
00281   }
00282   else {
00283     _STLP_TRY {
00284       numpunct_byname<char> *punctbn = new numpunct_byname<char>(pname, 0, hint);
00285       punct  = punctbn;
00286 #if !defined (__DMC__)
00287       if (hint == 0) hint = _Locale_extract_hint(punctbn);
00288 #endif
00289       get    = new num_get<char, istreambuf_iterator<char, char_traits<char> > >;
00290       put    = new num_put<char, ostreambuf_iterator<char, char_traits<char> > >;
00291 #ifndef _STLP_NO_WCHAR_T
00292       wpunct = new numpunct_byname<wchar_t>(pname, 0, hint);
00293       wget   = new num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
00294       wput   = new num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
00295 #endif
00296     }
00297 #ifndef _STLP_NO_WCHAR_T
00298     _STLP_UNWIND(delete punct; delete wpunct; delete get; delete wget; delete put; delete wput);
00299 #else
00300     _STLP_UNWIND(delete punct; delete get;delete put);
00301 #endif
00302 
00303     _Locale_insert(this,punct);
00304     _Locale_insert(this,get);
00305     _Locale_insert(this,put);
00306 
00307 #ifndef _STLP_NO_WCHAR_T
00308     _Locale_insert(this,wpunct);
00309     _Locale_insert(this,wget);
00310     _Locale_insert(this,wput);
00311 #endif
00312   }
00313   return hint;
00314 }
00315 
00316 _Locale_name_hint* _Locale_impl::insert_time_facets(const char* pname, _Locale_name_hint* hint) {
00317   _Locale_impl* i2 = locale::classic()._M_impl;
00318   time_get<char, istreambuf_iterator<char, char_traits<char> > > *get = 0;
00319   time_put<char, ostreambuf_iterator<char, char_traits<char> > > *put = 0;
00320 #ifndef _STLP_NO_WCHAR_T
00321   time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > > *wget = 0;
00322   time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > *wput = 0;
00323 #endif
00324 
00325   char buf[_Locale_MAX_SIMPLE_NAME];
00326   if (pname == 0 || pname[0] == 0)
00327     pname = _Locale_time_default(buf);
00328 
00329   if (pname == 0 || pname[0] == 0 || is_C_locale_name(pname)) {
00330 
00331     this->insert(i2,
00332                  time_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
00333     this->insert(i2,
00334                  time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
00335 #ifndef _STLP_NO_WCHAR_T
00336     this->insert(i2,
00337                  time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
00338     this->insert(i2,
00339                  time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
00340 #endif
00341   } else {
00342     _STLP_TRY {
00343       time_get_byname<char, istreambuf_iterator<char, char_traits<char> > > *getbn =
00344         new time_get_byname<char, istreambuf_iterator<char, char_traits<char> > >(pname, 0, hint);
00345       get  = getbn;
00346 #if !defined (__DMC__)
00347       if (hint == 0) hint = _Locale_time_extract_hint(getbn);
00348 #endif
00349       put  = new time_put_byname<char, ostreambuf_iterator<char, char_traits<char> > >(pname, 0, hint);
00350 #ifndef _STLP_NO_WCHAR_T
00351       wget = new time_get_byname<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(pname, 0, hint);
00352       wput = new time_put_byname<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(pname, 0, hint);
00353 #endif
00354     }
00355 #ifndef _STLP_NO_WCHAR_T
00356     _STLP_UNWIND(delete get; delete wget; delete put; delete wput);
00357 #else
00358     _STLP_UNWIND(delete get; delete put);
00359 #endif
00360     _Locale_insert(this,get);
00361     _Locale_insert(this,put);
00362 #ifndef _STLP_NO_WCHAR_T
00363     _Locale_insert(this,wget);
00364     _Locale_insert(this,wput);
00365 #endif
00366   }
00367   return hint;
00368 }
00369 
00370 _Locale_name_hint* _Locale_impl::insert_collate_facets(const char* nam, _Locale_name_hint* hint) {
00371   _Locale_impl* i2 = locale::classic()._M_impl;
00372 
00373   collate<char> *col = 0;
00374 #ifndef _STLP_NO_WCHAR_T
00375   collate<wchar_t> *wcol = 0;
00376 #endif
00377 
00378   char buf[_Locale_MAX_SIMPLE_NAME];
00379   if (nam == 0 || nam[0] == 0)
00380     nam = _Locale_collate_default(buf);
00381 
00382   if (nam == 0 || nam[0] == 0 || is_C_locale_name(nam)) {
00383     this->insert(i2, collate<char>::id);
00384 #ifndef _STLP_NO_WCHAR_T
00385     this->insert(i2, collate<wchar_t>::id);
00386 #endif
00387   }
00388   else {
00389     _STLP_TRY {
00390       collate_byname<char> *colbn = new collate_byname<char>(nam, 0, hint);
00391       col   = colbn;
00392 #if !defined (__DMC__)
00393       if (hint == 0) hint = _Locale_extract_hint(colbn);
00394 #endif
00395 #ifndef _STLP_NO_WCHAR_T
00396       wcol  = new collate_byname<wchar_t>(nam, 0, hint);
00397 #endif
00398     }
00399 #ifndef _STLP_NO_WCHAR_T
00400     _STLP_UNWIND(delete col; delete wcol);
00401 #else
00402     _STLP_UNWIND(delete col);
00403 #endif
00404     _Locale_insert(this,col);
00405 #ifndef _STLP_NO_WCHAR_T
00406     _Locale_insert(this,wcol);
00407 #endif
00408   }
00409   return hint;
00410 }
00411 
00412 _Locale_name_hint* _Locale_impl::insert_monetary_facets(const char* pname, _Locale_name_hint* hint) {
00413   _Locale_impl* i2 = locale::classic()._M_impl;
00414 
00415   moneypunct<char, false> *punct = 0;
00416   moneypunct<char, true> *ipunct = 0;
00417   money_get<char, istreambuf_iterator<char, char_traits<char> > > *get = 0;
00418   money_put<char, ostreambuf_iterator<char, char_traits<char> > > *put = 0;
00419 
00420 #ifndef _STLP_NO_WCHAR_T
00421   moneypunct<wchar_t, false>* wpunct = 0;
00422   moneypunct<wchar_t, true>* wipunct = 0;
00423   money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > > *wget = 0;
00424   money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > *wput = 0;
00425 #endif
00426 
00427   char buf[_Locale_MAX_SIMPLE_NAME];
00428   if (pname == 0 || pname[0] == 0)
00429     pname = _Locale_monetary_default(buf);
00430 
00431   if (pname == 0 || pname[0] == 0 || is_C_locale_name(pname)) {
00432     this->insert(i2, moneypunct<char, false>::id);
00433     this->insert(i2, moneypunct<char, true>::id);
00434     this->insert(i2, money_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
00435     this->insert(i2, money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
00436 #ifndef _STLP_NO_WCHAR_T
00437     this->insert(i2, moneypunct<wchar_t, false>::id);
00438     this->insert(i2, moneypunct<wchar_t, true>::id);
00439     this->insert(i2, money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
00440     this->insert(i2, money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
00441 #endif
00442   }
00443   else {
00444     _STLP_TRY {
00445       moneypunct_byname<char, false>* punctbn = new moneypunct_byname<char, false>(pname, 0, hint);
00446       punct   = punctbn;
00447 #if !defined (__DMC__)
00448       if (hint == 0) hint = _Locale_extract_hint(punctbn);
00449 #endif
00450       ipunct  = new moneypunct_byname<char, true>(pname, 0, hint);
00451       get     = new money_get<char, istreambuf_iterator<char, char_traits<char> > >;
00452       put     = new money_put<char, ostreambuf_iterator<char, char_traits<char> > >;
00453 #ifndef _STLP_NO_WCHAR_T
00454       wpunct  = new moneypunct_byname<wchar_t, false>(pname, 0, hint);
00455       wipunct = new moneypunct_byname<wchar_t, true>(pname, 0, hint);
00456       wget    = new money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
00457       wput    = new money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
00458 #endif
00459     }
00460 #ifndef _STLP_NO_WCHAR_T
00461     _STLP_UNWIND(delete punct; delete ipunct; delete wpunct; delete wipunct; delete get; delete wget; delete put; delete wput);
00462 #else
00463     _STLP_UNWIND(delete punct; delete ipunct; delete get; delete put);
00464 #endif
00465     _Locale_insert(this,punct);
00466     _Locale_insert(this,ipunct);
00467     _Locale_insert(this,get);
00468     _Locale_insert(this,put);
00469 #ifndef _STLP_NO_WCHAR_T
00470     _Locale_insert(this,wget);
00471     _Locale_insert(this,wpunct);
00472     _Locale_insert(this,wipunct);
00473     _Locale_insert(this,wput);
00474 #endif
00475   }
00476   return hint;
00477 }
00478 
00479 _Locale_name_hint* _Locale_impl::insert_messages_facets(const char* pname, _Locale_name_hint* hint) {
00480   _Locale_impl* i2 = locale::classic()._M_impl;
00481   messages<char> *msg = 0;
00482 #ifndef _STLP_NO_WCHAR_T
00483   messages<wchar_t> *wmsg = 0;
00484 #endif
00485 
00486   char buf[_Locale_MAX_SIMPLE_NAME];
00487   if (pname == 0 || pname[0] == 0)
00488     pname = _Locale_messages_default(buf);
00489 
00490   if (pname == 0 || pname[0] == 0 || is_C_locale_name(pname)) {
00491     this->insert(i2, messages<char>::id);
00492 #ifndef _STLP_NO_WCHAR_T
00493     this->insert(i2, messages<wchar_t>::id);
00494 #endif
00495   }
00496   else {
00497     _STLP_TRY {
00498       msg  = new messages_byname<char>(pname, 0, hint);
00499 #ifndef _STLP_NO_WCHAR_T
00500       wmsg = new messages_byname<wchar_t>(pname, 0, hint);
00501 #endif
00502     }
00503 #ifndef _STLP_NO_WCHAR_T
00504     _STLP_UNWIND(delete msg; delete wmsg);
00505 #else
00506     _STLP_UNWIND(delete msg);
00507 #endif
00508     _Locale_insert(this,msg);
00509 #ifndef _STLP_NO_WCHAR_T
00510     _Locale_insert(this,wmsg);
00511 #endif
00512   }
00513   return hint;
00514 }
00515 
00516 static void _Stl_loc_assign_ids() {
00517   // This assigns ids to every facet that is a member of a category,
00518   // and also to money_get/put, num_get/put, and time_get/put
00519   // instantiated using ordinary pointers as the input/output
00520   // iterators.  (The default is [io]streambuf_iterator.)
00521 
00522   money_get<char, istreambuf_iterator<char, char_traits<char> > >::id._M_index          = 8;
00523   //money_get<char, const char*>::id._M_index                                             = 9;
00524   money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id._M_index          = 10;
00525   //money_put<char, char*>::id._M_index                                                   = 11;
00526 
00527   num_get<char, istreambuf_iterator<char, char_traits<char> > >::id._M_index            = 12;
00528   //num_get<char, const char*>::id._M_index                                               = 13;
00529   num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id._M_index            = 14;
00530   //num_put<char, char*>::id._M_index                                                     = 15;
00531   time_get<char, istreambuf_iterator<char, char_traits<char> > >::id._M_index           = 16;
00532   //time_get<char, const char*>::id._M_index                                              = 17;
00533   time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id._M_index           = 18;
00534   //time_put<char, char*>::id._M_index                                                    = 19;
00535 
00536 #ifndef _STLP_NO_WCHAR_T
00537   money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 27;
00538   //money_get<wchar_t, const wchar_t*>::id._M_index                                       = 28;
00539   money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 29;
00540   //money_put<wchar_t, wchar_t*>::id._M_index                                             = 30;
00541 
00542   num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index   = 31;
00543   //num_get<wchar_t, const wchar_t*>::id._M_index                                         = 32;
00544   num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > ::id._M_index  = 33;
00545   //num_put<wchar_t, wchar_t*>::id._M_index                                               = 34;
00546   time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index  = 35;
00547   //time_get<wchar_t, const wchar_t*>::id._M_index                                        = 36;
00548   time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index  = 37;
00549   //time_put<wchar_t, wchar_t*>::id._M_index                                              = 38;
00550 #endif
00551   //  locale::id::_S_max                               = 39;
00552 }
00553 
00554 // To access those static instance use the getter below, they guaranty
00555 // a correct initialization.
00556 static locale *_Stl_classic_locale = 0;
00557 static locale *_Stl_global_locale = 0;
00558 
00559 static locale* _Stl_get_classic_locale() {
00560   static _Locale_impl::Init init;
00561   return _Stl_classic_locale;
00562 }
00563 
00564 static locale* _Stl_get_global_locale() {
00565   static _Locale_impl::Init init;
00566   return _Stl_global_locale;
00567 }
00568 
00569 #if defined (_STLP_MSVC) || defined (__ICL) || defined (__ISCPP__)
00570 /*
00571  * The following static variable needs to be initialized before STLport
00572  * users static variable in order for him to be able to use Standard
00573  * streams in its variable initialization.
00574  * This variable is here because MSVC do not allow to change the initialization
00575  * segment in a given translation unit, iostream.cpp already contains an
00576  * initialization segment specification.
00577  */
00578 #  pragma warning (disable : 4073)
00579 #  pragma init_seg(lib)
00580 #endif
00581 
00582 static ios_base::Init _IosInit;
00583 
00584 void _Locale_impl::make_classic_locale() {
00585   // This funcion will be called once: during build classic _Locale_impl
00586 
00587   // The classic locale contains every facet that belongs to a category.
00588   static _Stl_aligned_buffer<_Locale_impl> _Locale_classic_impl_buf;
00589   _Locale_impl *classic = new(&_Locale_classic_impl_buf) _Locale_impl("C");
00590 
00591   locale::facet* classic_facets[] = {
00592     0,
00593     new collate<char>(1),
00594     new ctype<char>(0, false, 1),
00595 #ifndef _STLP_NO_MBSTATE_T
00596     new codecvt<char, char, mbstate_t>(1),
00597 #else
00598     0,
00599 #endif
00600     new moneypunct<char, true>(1),
00601     new moneypunct<char, false>(1),
00602     new numpunct<char>(1),
00603     new messages<char>(new _STLP_PRIV _Messages()),
00604     new money_get<char, istreambuf_iterator<char, char_traits<char> > >(1),
00605     0,
00606     new money_put<char, ostreambuf_iterator<char, char_traits<char> > >(1),
00607     0,
00608     new num_get<char, istreambuf_iterator<char, char_traits<char> > >(1),
00609     0,
00610     new num_put<char, ostreambuf_iterator<char, char_traits<char> > >(1),
00611     0,
00612     new time_get<char, istreambuf_iterator<char, char_traits<char> > >(1),
00613     0,
00614     new time_put<char, ostreambuf_iterator<char, char_traits<char> > >(1),
00615     0,
00616 #ifndef _STLP_NO_WCHAR_T
00617     new collate<wchar_t>(1),
00618     new ctype<wchar_t>(1),
00619 
00620 #  ifndef _STLP_NO_MBSTATE_T
00621     new codecvt<wchar_t, char, mbstate_t>(1),
00622 #  else
00623     0,
00624 #  endif
00625     new moneypunct<wchar_t, true>(1),
00626     new moneypunct<wchar_t, false>(1),
00627     new numpunct<wchar_t>(1),
00628     new messages<wchar_t>(new _STLP_PRIV _Messages()),
00629 
00630     new money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
00631     0,
00632     new money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
00633     0,
00634 
00635     new num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
00636     0,
00637     new num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
00638     0,
00639     new time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
00640     0,
00641     new time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
00642     0,
00643 #endif
00644     0
00645   };
00646 
00647   const size_t nb_classic_facets = sizeof(classic_facets) / sizeof(locale::facet *);
00648   classic->facets_vec.reserve(nb_classic_facets);
00649   classic->facets_vec.assign(&classic_facets[0], &classic_facets[0] + nb_classic_facets);
00650 
00651   static locale _Locale_classic(classic);
00652   _Stl_classic_locale = &_Locale_classic;
00653 
00654   static locale _Locale_global(_copy_Locale_impl(classic));
00655   _Stl_global_locale = &_Locale_global;
00656 }
00657 
00658 #if defined (__BORLANDC__) && (__BORLANDC__ < 0x564)
00659 template <>
00660 _STLP_DECLSPEC locale::id time_get<char, istreambuf_iterator<char, char_traits<char> > >::id;
00661 /*
00662 template <>
00663 _STLP_DECLSPEC locale::id time_get<char, const char*>::id;
00664 */
00665 
00666 template <>
00667 _STLP_DECLSPEC locale::id time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
00668 /*
00669 template <>
00670 _STLP_DECLSPEC locale::id time_put<char, char*>::id;
00671 */
00672 
00673 #  if !defined (_STLP_NO_WCHAR_T)
00674 template <>
00675 _STLP_DECLSPEC locale::id time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
00676 /*
00677 template <>
00678 _STLP_DECLSPEC locale::id time_get<wchar_t, const wchar_t*>::id;
00679 */
00680 
00681 template <>
00682 _STLP_DECLSPEC locale::id time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
00683 /*
00684 template <>
00685 _STLP_DECLSPEC locale::id time_put<wchar_t, wchar_t*>::id;
00686 */
00687 #  endif /* _STLP_NO_WCHAR_T */
00688 
00689 template <>
00690 _STLP_DECLSPEC locale::id money_get<char, istreambuf_iterator<char, char_traits<char> > >::id;
00691 /*
00692 template <>
00693 _STLP_DECLSPEC locale::id money_get<char, const char*>::id;
00694 */
00695 
00696 template <>
00697 _STLP_DECLSPEC locale::id money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
00698 /*
00699 template <>
00700 _STLP_DECLSPEC locale::id money_put<char, char*>::id;
00701 */
00702 
00703 #  if !defined (_STLP_NO_WCHAR_T)
00704 template <>
00705 _STLP_DECLSPEC locale::id money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
00706 /*
00707 template <>
00708 _STLP_DECLSPEC locale::id money_get<wchar_t, const wchar_t*>::id;
00709 */
00710 
00711 template <>
00712 _STLP_DECLSPEC locale::id money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
00713 /*
00714 template <>
00715 _STLP_DECLSPEC locale::id money_put<wchar_t, wchar_t*>::id;
00716 */
00717 #  endif
00718 
00719 template <>
00720 _STLP_DECLSPEC locale::id num_get<char, istreambuf_iterator<char, char_traits<char> > >::id;
00721 /*
00722 template <>
00723 _STLP_DECLSPEC locale::id num_get<char, const char*>::id;
00724 */
00725 
00726 #  if !defined (STLP_NO_WCHAR_T)
00727 template <>
00728 _STLP_DECLSPEC locale::id num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
00729 /*
00730 template <>
00731 _STLP_DECLSPEC locale::id num_get<wchar_t, const wchar_t*>::id;
00732 */
00733 #  endif
00734 
00735 template <>
00736 _STLP_DECLSPEC locale::id num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
00737 /*
00738 template <>
00739 _STLP_DECLSPEC locale::id num_put<char, char*>::id;
00740 */
00741 
00742 #  if !defined (_STLP_NO_WCHAR_T)
00743 template <>
00744 _STLP_DECLSPEC locale::id num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
00745 /*
00746 template <>
00747 _STLP_DECLSPEC locale::id num_put<wchar_t, wchar_t*>::id;
00748 */
00749 #  endif
00750 #endif
00751 
00752 // Declarations of (non-template) facets' static data members
00753 // size_t locale::id::_S_max = 39; // made before
00754 
00755 _STLP_STATIC_MEMBER_DECLSPEC locale::id collate<char>::id = { 1 };
00756 _STLP_STATIC_MEMBER_DECLSPEC locale::id ctype<char>::id = { 2 };
00757 
00758 #ifndef _STLP_NO_MBSTATE_T
00759 _STLP_STATIC_MEMBER_DECLSPEC locale::id codecvt<char, char, mbstate_t>::id = { 3 };
00760 #  ifndef _STLP_NO_WCHAR_T
00761 _STLP_STATIC_MEMBER_DECLSPEC locale::id codecvt<wchar_t, char, mbstate_t>::id = { 22 };
00762 #  endif
00763 #endif
00764 
00765 _STLP_STATIC_MEMBER_DECLSPEC locale::id moneypunct<char, true>::id = { 4 };
00766 _STLP_STATIC_MEMBER_DECLSPEC locale::id moneypunct<char, false>::id = { 5 };
00767 _STLP_STATIC_MEMBER_DECLSPEC locale::id numpunct<char>::id = { 6 } ;
00768 _STLP_STATIC_MEMBER_DECLSPEC locale::id messages<char>::id = { 7 };
00769 
00770 #if defined (__BORLANDC__) && (__BORLANDC__ >= 0x564)
00771 _STLP_STATIC_MEMBER_DECLSPEC locale::id money_get<char, istreambuf_iterator<char, char_traits<char> > >::id = { 8 };
00772 _STLP_STATIC_MEMBER_DECLSPEC locale::id money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id = { 10 };
00773 _STLP_STATIC_MEMBER_DECLSPEC locale::id num_get<char, istreambuf_iterator<char, char_traits<char> > >::id = { 12 };
00774 _STLP_STATIC_MEMBER_DECLSPEC locale::id num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id = { 14 };
00775 _STLP_STATIC_MEMBER_DECLSPEC locale::id time_get<char, istreambuf_iterator<char, char_traits<char> > >::id = { 16 };
00776 _STLP_STATIC_MEMBER_DECLSPEC locale::id time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id = { 18 };
00777 /*
00778 _STLP_STATIC_MEMBER_DECLSPEC locale::id money_get<char, const char*>::id = { 9 };
00779 _STLP_STATIC_MEMBER_DECLSPEC locale::id money_put<char, char*>::id = { 11 };
00780 _STLP_STATIC_MEMBER_DECLSPEC locale::id num_get<char, const char*>::id = { 13 };
00781 _STLP_STATIC_MEMBER_DECLSPEC locale::id num_put<char, char*>::id = { 15 };
00782 _STLP_STATIC_MEMBER_DECLSPEC locale::id time_get<char, const char*>::id = { 17 };
00783 _STLP_STATIC_MEMBER_DECLSPEC locale::id time_put<char, char*>::id = { 19 };
00784 */
00785 #endif
00786 
00787 #ifndef _STLP_NO_WCHAR_T
00788 _STLP_STATIC_MEMBER_DECLSPEC locale::id collate<wchar_t>::id = { 20 };
00789 _STLP_STATIC_MEMBER_DECLSPEC locale::id ctype<wchar_t>::id = { 21 };
00790 
00791 _STLP_STATIC_MEMBER_DECLSPEC locale::id moneypunct<wchar_t, true>::id = { 23 } ;
00792 _STLP_STATIC_MEMBER_DECLSPEC locale::id moneypunct<wchar_t, false>::id = { 24 } ;
00793 
00794 _STLP_STATIC_MEMBER_DECLSPEC locale::id numpunct<wchar_t>::id = { 25 };
00795 _STLP_STATIC_MEMBER_DECLSPEC locale::id messages<wchar_t>::id = { 26 };
00796 
00797 #if defined (__BORLANDC__) && (__BORLANDC__ >= 0x564)
00798 _STLP_STATIC_MEMBER_DECLSPEC locale::id money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id = { 27 };
00799 _STLP_STATIC_MEMBER_DECLSPEC locale::id money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id = { 29 };
00800 _STLP_STATIC_MEMBER_DECLSPEC locale::id num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id = { 31 };
00801 _STLP_STATIC_MEMBER_DECLSPEC locale::id num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > ::id = { 33 };
00802 _STLP_STATIC_MEMBER_DECLSPEC locale::id time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id = { 35 };
00803 _STLP_STATIC_MEMBER_DECLSPEC locale::id time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id = { 37 };
00804 /*
00805 _STLP_STATIC_MEMBER_DECLSPEC locale::id money_get<wchar_t, const wchar_t*>::id = { 28 };
00806 _STLP_STATIC_MEMBER_DECLSPEC locale::id money_put<wchar_t, wchar_t*>::id = { 30 };
00807 _STLP_STATIC_MEMBER_DECLSPEC locale::id num_get<wchar_t, const wchar_t*>::id = { 32 };
00808 _STLP_STATIC_MEMBER_DECLSPEC locale::id num_put<wchar_t, wchar_t*>::id = { 34 };
00809 _STLP_STATIC_MEMBER_DECLSPEC locale::id time_get<wchar_t, const wchar_t*>::id = { 36 };
00810 _STLP_STATIC_MEMBER_DECLSPEC locale::id time_put<wchar_t, wchar_t*>::id = { 38 };
00811 */
00812 #  endif
00813 #endif
00814 
00815 _STLP_DECLSPEC _Locale_impl* _STLP_CALL _get_Locale_impl(_Locale_impl *loc)
00816 {
00817   _STLP_ASSERT( loc != 0 );
00818   loc->_M_incr();
00819   return loc;
00820 }
00821 
00822 void _STLP_CALL _release_Locale_impl(_Locale_impl *& loc)
00823 {
00824   _STLP_ASSERT( loc != 0 );
00825   if (loc->_M_decr() == 0) {
00826     if (*loc != *_Stl_classic_locale)
00827       delete loc;
00828     else
00829       loc->~_Locale_impl();
00830     loc = 0;
00831   }
00832 }
00833 
00834 _STLP_DECLSPEC _Locale_impl* _STLP_CALL _copy_Nameless_Locale_impl(_Locale_impl *loc)
00835 {
00836   _STLP_ASSERT( loc != 0 );
00837   loc->_M_incr();
00838   _Locale_impl *loc_new = new _Locale_impl(*loc);
00839   loc->_M_decr();
00840   loc_new->name = _Nameless;
00841   return loc_new;
00842 }
00843 
00844 _STLP_END_NAMESPACE
00845 
00846 
00847 // locale use many static functions/pointers from this file:
00848 // to avoid making ones extern, simple #include implementation of locale
00849 
00850 #include "locale.cpp"
00851 



Generated on Mon Mar 10 15:32:17 2008 by  doxygen 1.5.1