First public contribution.
2 * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
5 * Silicon Graphics Computer Systems, Inc.
10 * This material is provided "as is", with absolutely no warranty expressed
11 * or implied. Any use is at your own risk.
13 * Permission to use or copy this software for any purpose is hereby granted
14 * without fee, provided the above notices are retained on all copies.
15 * Permission to modify the code and to distribute modified code is granted,
16 * provided the above notices are retained, and a notice that the code was
17 * modified is included with the above copyright notice.
20 #include "stlport_prefix.h"
28 #include "aligned_buffer.h"
29 #include "locale_impl.h"
30 #include "message_facets.h"
32 #if defined(__SYMBIAN32__WSD__)
33 #include "libstdcppwsd.h"
35 std::_Stl_aligned_buffer<std::_Locale_impl::Init>& get_Loc_init_buf()
37 return *(std::_Stl_aligned_buffer<std::_Locale_impl::Init> *)(get_libcpp_wsd().__Loc_init_buf);
40 #define __Loc_init_buf get_Loc_init_buf()
41 #define _S_count get_Loc_init_S_count()
42 #define _Index_lock get_locale_Index_lock()
43 #define _S_index get_S_index()
44 #define _S_max get_locale_id_S_max()
45 #define _Stl_classic_locale get_Stl_classic_locale()
46 #define _Stl_global_locale get_Stl_global_locale()
48 #endif //__SYMBIAN32__WSD__
52 #if defined(__SYMBIAN32__WSD__) && defined(_STLP_DEBUG)
53 #define _Nameless *get_Nameless()
55 static const string _Nameless("*");
58 static inline bool is_C_locale_name (const char* name)
59 { return ((name[0] == 'C') && (name[1] == 0)); }
61 _Locale_impl * _STLP_CALL _copy_Locale_impl(_Locale_impl *loc)
63 _STLP_ASSERT( loc != 0 );
65 _Locale_impl *loc_new = new _Locale_impl(*loc);
70 locale::facet * _STLP_CALL _get_facet(locale::facet *f)
77 void _STLP_CALL _release_facet(locale::facet *&f)
79 if ((f != 0) && (f->_M_decr() == 0)) {
84 # if !defined(__SYMBIAN32__WSD__)
85 # if !defined(__SYMBIAN32__NO_STATIC_IMPORTS__)
86 _STLP_STATIC_MEMBER_DECLSPEC size_t locale::id::_S_max = 39;
88 size_t locale::id::_S_max = 39;
90 # endif //__SYMBIAN32__WSD__
92 static void _Stl_loc_assign_ids();
94 #if !defined(__SYMBIAN32__WSD__)
95 static _Stl_aligned_buffer<_Locale_impl::Init> __Loc_init_buf;
98 _Locale_impl::Init::Init() {
99 if (_M_count()._M_incr() == 1) {
100 _Locale_impl::_S_initialize();
104 _Locale_impl::Init::~Init() {
105 if (_M_count()._M_decr() == 0) {
106 _Locale_impl::_S_uninitialize();
110 _Refcount_Base& _Locale_impl::Init::_M_count() const {
111 #if !defined(__SYMBIAN32__WSD__)
112 static _Refcount_Base _S_count(0);
117 _Locale_impl::_Locale_impl(const char* s)
118 : _Refcount_Base(0), name(s), facets_vec() {
119 facets_vec.reserve( locale::id::_S_max );
120 new (&__Loc_init_buf) Init();
123 _Locale_impl::_Locale_impl( _Locale_impl const& locimpl )
124 : _Refcount_Base(0), name(locimpl.name), facets_vec() {
125 for_each( locimpl.facets_vec.begin(), locimpl.facets_vec.end(), _get_facet);
126 facets_vec = locimpl.facets_vec;
127 new (&__Loc_init_buf) Init();
130 _Locale_impl::_Locale_impl( size_t n, const char* s)
131 : _Refcount_Base(0), name(s), facets_vec(n, 0) {
132 new (&__Loc_init_buf) Init();
135 _Locale_impl::~_Locale_impl() {
136 (&__Loc_init_buf)->~Init();
137 for_each( facets_vec.begin(), facets_vec.end(), _release_facet);
140 // Initialization of the locale system. This must be called before
141 // any locales are constructed. (Meaning that it must be called when
142 // the I/O library itself is initialized.)
143 void _STLP_CALL _Locale_impl::_S_initialize() {
145 #if defined(__SYMBIAN32__WSD__)
146 //initialize wsd obj pointer
150 _Stl_loc_assign_ids();
151 make_classic_locale();
153 #if defined(__SYMBIAN32__WSD__)
154 global_iostream_init();
158 // Release of the classic locale ressources. Has to be called after the last
159 // locale destruction and not only after the classic locale destruction as
160 // the facets can be shared between different facets.
161 void _STLP_CALL _Locale_impl::_S_uninitialize() {
162 //Not necessary anymore as classic facets are now 'normal' dynamically allocated
163 //facets with a reference counter telling to _release_facet when the facet can be
165 //free_classic_locale();
168 // _Locale_impl non-inline member functions.
169 void _STLP_CALL _Locale_impl::_M_throw_bad_cast() {
170 _STLP_THROW(bad_cast());
173 void _Locale_impl::insert( _Locale_impl *from, const locale::id& n ) {
174 size_t index = n._M_index;
175 if (index > 0 && index < from->size()) {
176 this->insert( from->facets_vec[index], index);
180 locale::facet* _Locale_impl::insert(locale::facet *f, size_t index) {
181 if (f == 0 || index == 0)
184 if (index >= facets_vec.size()) {
185 facets_vec.resize(index + 1);
188 if (f != facets_vec[index])
190 _release_facet(facets_vec[index]);
191 facets_vec[index] = _get_facet(f);
197 #if !defined (__DMC__)
198 _Locale_name_hint* _Locale_extract_hint(ctype_byname<char>* ct)
199 { return _Locale_get_ctype_hint(ct->_M_ctype); }
200 _Locale_name_hint* _Locale_extract_hint(numpunct_byname<char>* punct)
201 { return _Locale_get_numeric_hint(punct->_M_numeric); }
202 # if defined (__GNUC__) && (__GNUC__ < 3)
203 template <class _Ch, class _InIt>
204 _Locale_name_hint* _Locale_time_extract_hint(time_get_byname<_Ch, _InIt>* tget)
206 _Locale_name_hint* _Locale_time_extract_hint(time_get_byname<char, istreambuf_iterator<char, char_traits<char> > >* tget)
208 { return _Locale_get_time_hint(tget->_M_time); }
209 _Locale_name_hint* _Locale_extract_hint(collate_byname<char>* coll)
210 { return _Locale_get_collate_hint(coll->_M_collate); }
211 _Locale_name_hint* _Locale_extract_hint(moneypunct_byname<char, false>* money)
212 { return _Locale_get_monetary_hint(money->_M_monetary); }
216 // <locale> content which is dependent on the name
218 #if defined(__SYMBIAN32__WSD__)
219 #define id GetFacetLocaleId()
222 template <class Facet>
223 static inline locale::facet* _Locale_insert(_Locale_impl *__that, Facet* f)
224 { return __that->insert(f, Facet::id._M_index); }
227 * Six functions, one for each category. Each of them takes a
228 * _Locale* and a name, constructs that appropriate category
229 * facets by name, and inserts them into the locale.
231 _Locale_name_hint* _Locale_impl::insert_ctype_facets(const char* pname, _Locale_name_hint* hint) {
232 char buf[_Locale_MAX_SIMPLE_NAME];
233 _Locale_impl* i2 = locale::classic()._M_impl;
235 if (pname == 0 || pname[0] == 0)
236 pname = _Locale_ctype_default(buf);
238 if (pname == 0 || pname[0] == 0 || is_C_locale_name(pname)) {
239 this->insert(i2, ctype<char>::id);
240 #ifndef _STLP_NO_MBSTATE_T
241 this->insert(i2, codecvt<char, char, mbstate_t>::id);
243 #ifndef _STLP_NO_WCHAR_T
244 this->insert(i2, ctype<wchar_t>::id);
245 # ifndef _STLP_NO_MBSTATE_T
246 this->insert(i2, codecvt<wchar_t, char, mbstate_t>::id);
251 #ifndef _STLP_NO_MBSTATE_T
252 codecvt<char, char, mbstate_t>* cvt = 0;
254 #ifndef _STLP_NO_WCHAR_T
255 ctype<wchar_t>* wct = 0;
256 codecvt<wchar_t, char, mbstate_t>* wcvt = 0;
259 ctype_byname<char> *ctbn = new ctype_byname<char>(pname, 0, hint);
261 #if !defined (__DMC__)
262 if (hint == 0) hint = _Locale_extract_hint(ctbn);
264 #ifndef _STLP_NO_MBSTATE_T
265 cvt = new codecvt_byname<char, char, mbstate_t>(pname);
267 #ifndef _STLP_NO_WCHAR_T
268 wct = new ctype_byname<wchar_t>(pname, 0, hint);
269 wcvt = new codecvt_byname<wchar_t, char, mbstate_t>(pname, 0, hint);
273 #ifndef _STLP_NO_WCHAR_T
274 # ifdef _STLP_NO_MBSTATE_T
275 _STLP_UNWIND(delete ct; delete wct; delete wcvt);
277 _STLP_UNWIND(delete ct; delete wct; delete cvt; delete wcvt);
280 # ifdef _STLP_NO_MBSTATE_T
281 _STLP_UNWIND(delete ct);
283 _STLP_UNWIND(delete ct; delete cvt);
286 _Locale_insert(this, ct);
287 #ifndef _STLP_NO_MBSTATE_T
288 _Locale_insert(this, cvt);
290 #ifndef _STLP_NO_WCHAR_T
291 _Locale_insert(this, wct);
292 _Locale_insert(this, wcvt);
298 _Locale_name_hint* _Locale_impl::insert_numeric_facets(const char* pname, _Locale_name_hint* hint) {
299 _Locale_impl* i2 = locale::classic()._M_impl;
301 numpunct<char>* punct = 0;
302 num_get<char, istreambuf_iterator<char, char_traits<char> > > *get = 0;
303 num_put<char, ostreambuf_iterator<char, char_traits<char> > > *put = 0;
304 #ifndef _STLP_NO_WCHAR_T
305 numpunct<wchar_t>* wpunct = 0;
306 num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > > *wget = 0;
307 num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > *wput = 0;
310 char buf[_Locale_MAX_SIMPLE_NAME];
311 if (pname == 0 || pname[0] == 0)
312 pname = _Locale_numeric_default(buf);
314 if (pname == 0 || pname[0] == 0 || is_C_locale_name(pname)) {
315 this->insert(i2, numpunct<char>::id);
317 num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
319 num_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
320 #ifndef _STLP_NO_WCHAR_T
321 this->insert(i2, numpunct<wchar_t>::id);
323 num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
325 num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
330 numpunct_byname<char> *punctbn = new numpunct_byname<char>(pname, 0, hint);
332 #if !defined (__DMC__)
333 if (hint == 0) hint = _Locale_extract_hint(punctbn);
335 get = new num_get<char, istreambuf_iterator<char, char_traits<char> > >;
336 put = new num_put<char, ostreambuf_iterator<char, char_traits<char> > >;
337 #ifndef _STLP_NO_WCHAR_T
338 wpunct = new numpunct_byname<wchar_t>(pname, 0, hint);
339 wget = new num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
340 wput = new num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
343 #ifndef _STLP_NO_WCHAR_T
344 _STLP_UNWIND(delete punct; delete wpunct; delete get; delete wget; delete put; delete wput);
346 _STLP_UNWIND(delete punct; delete get;delete put);
349 _Locale_insert(this,punct);
350 _Locale_insert(this,get);
351 _Locale_insert(this,put);
353 #ifndef _STLP_NO_WCHAR_T
354 _Locale_insert(this,wpunct);
355 _Locale_insert(this,wget);
356 _Locale_insert(this,wput);
362 _Locale_name_hint* _Locale_impl::insert_time_facets(const char* pname, _Locale_name_hint* hint) {
363 _Locale_impl* i2 = locale::classic()._M_impl;
364 time_get<char, istreambuf_iterator<char, char_traits<char> > > *get = 0;
365 time_put<char, ostreambuf_iterator<char, char_traits<char> > > *put = 0;
366 #ifndef _STLP_NO_WCHAR_T
367 time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > > *wget = 0;
368 time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > *wput = 0;
371 char buf[_Locale_MAX_SIMPLE_NAME];
372 if (pname == 0 || pname[0] == 0)
373 pname = _Locale_time_default(buf);
375 if (pname == 0 || pname[0] == 0 || is_C_locale_name(pname)) {
378 time_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
380 time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
381 #ifndef _STLP_NO_WCHAR_T
383 time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
385 time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
389 time_get_byname<char, istreambuf_iterator<char, char_traits<char> > > *getbn =
390 new time_get_byname<char, istreambuf_iterator<char, char_traits<char> > >(pname, 0, hint);
392 #if !defined (__DMC__)
393 if (hint == 0) hint = _Locale_time_extract_hint(getbn);
395 put = new time_put_byname<char, ostreambuf_iterator<char, char_traits<char> > >(pname, 0, hint);
396 #ifndef _STLP_NO_WCHAR_T
397 wget = new time_get_byname<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(pname, 0, hint);
398 wput = new time_put_byname<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(pname, 0, hint);
401 #ifndef _STLP_NO_WCHAR_T
402 _STLP_UNWIND(delete get; delete wget; delete put; delete wput);
404 _STLP_UNWIND(delete get; delete put);
406 _Locale_insert(this,get);
407 _Locale_insert(this,put);
408 #ifndef _STLP_NO_WCHAR_T
409 _Locale_insert(this,wget);
410 _Locale_insert(this,wput);
416 _Locale_name_hint* _Locale_impl::insert_collate_facets(const char* nam, _Locale_name_hint* hint) {
417 _Locale_impl* i2 = locale::classic()._M_impl;
419 collate<char> *col = 0;
420 #ifndef _STLP_NO_WCHAR_T
421 collate<wchar_t> *wcol = 0;
424 char buf[_Locale_MAX_SIMPLE_NAME];
425 if (nam == 0 || nam[0] == 0)
426 nam = _Locale_collate_default(buf);
428 if (nam == 0 || nam[0] == 0 || is_C_locale_name(nam)) {
429 this->insert(i2, collate<char>::id);
430 #ifndef _STLP_NO_WCHAR_T
431 this->insert(i2, collate<wchar_t>::id);
436 collate_byname<char> *colbn = new collate_byname<char>(nam, 0, hint);
438 #if !defined (__DMC__)
439 if (hint == 0) hint = _Locale_extract_hint(colbn);
441 #ifndef _STLP_NO_WCHAR_T
442 wcol = new collate_byname<wchar_t>(nam, 0, hint);
445 #ifndef _STLP_NO_WCHAR_T
446 _STLP_UNWIND(delete col; delete wcol);
448 _STLP_UNWIND(delete col);
450 _Locale_insert(this,col);
451 #ifndef _STLP_NO_WCHAR_T
452 _Locale_insert(this,wcol);
458 _Locale_name_hint* _Locale_impl::insert_monetary_facets(const char* pname, _Locale_name_hint* hint) {
459 _Locale_impl* i2 = locale::classic()._M_impl;
461 moneypunct<char, false> *punct = 0;
462 moneypunct<char, true> *ipunct = 0;
463 money_get<char, istreambuf_iterator<char, char_traits<char> > > *get = 0;
464 money_put<char, ostreambuf_iterator<char, char_traits<char> > > *put = 0;
466 #ifndef _STLP_NO_WCHAR_T
467 moneypunct<wchar_t, false>* wpunct = 0;
468 moneypunct<wchar_t, true>* wipunct = 0;
469 money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > > *wget = 0;
470 money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > *wput = 0;
473 char buf[_Locale_MAX_SIMPLE_NAME];
474 if (pname == 0 || pname[0] == 0)
475 pname = _Locale_monetary_default(buf);
477 if (pname == 0 || pname[0] == 0 || is_C_locale_name(pname)) {
478 this->insert(i2, moneypunct<char, false>::id);
479 this->insert(i2, moneypunct<char, true>::id);
480 this->insert(i2, money_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
481 this->insert(i2, money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
482 #ifndef _STLP_NO_WCHAR_T
483 this->insert(i2, moneypunct<wchar_t, false>::id);
484 this->insert(i2, moneypunct<wchar_t, true>::id);
485 this->insert(i2, money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
486 this->insert(i2, money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
491 moneypunct_byname<char, false>* punctbn = new moneypunct_byname<char, false>(pname, 0, hint);
493 #if !defined (__DMC__)
494 if (hint == 0) hint = _Locale_extract_hint(punctbn);
496 ipunct = new moneypunct_byname<char, true>(pname, 0, hint);
497 get = new money_get<char, istreambuf_iterator<char, char_traits<char> > >;
498 put = new money_put<char, ostreambuf_iterator<char, char_traits<char> > >;
499 #ifndef _STLP_NO_WCHAR_T
500 wpunct = new moneypunct_byname<wchar_t, false>(pname, 0, hint);
501 wipunct = new moneypunct_byname<wchar_t, true>(pname, 0, hint);
502 wget = new money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
503 wput = new money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
506 #ifndef _STLP_NO_WCHAR_T
507 _STLP_UNWIND(delete punct; delete ipunct; delete wpunct; delete wipunct; delete get; delete wget; delete put; delete wput);
509 _STLP_UNWIND(delete punct; delete ipunct; delete get; delete put);
511 _Locale_insert(this,punct);
512 _Locale_insert(this,ipunct);
513 _Locale_insert(this,get);
514 _Locale_insert(this,put);
515 #ifndef _STLP_NO_WCHAR_T
516 _Locale_insert(this,wget);
517 _Locale_insert(this,wpunct);
518 _Locale_insert(this,wipunct);
519 _Locale_insert(this,wput);
525 _Locale_name_hint* _Locale_impl::insert_messages_facets(const char* pname, _Locale_name_hint* hint) {
526 _Locale_impl* i2 = locale::classic()._M_impl;
527 messages<char> *msg = 0;
528 #ifndef _STLP_NO_WCHAR_T
529 messages<wchar_t> *wmsg = 0;
532 char buf[_Locale_MAX_SIMPLE_NAME];
533 if (pname == 0 || pname[0] == 0)
534 pname = _Locale_messages_default(buf);
536 if (pname == 0 || pname[0] == 0 || is_C_locale_name(pname)) {
537 this->insert(i2, messages<char>::id);
538 #ifndef _STLP_NO_WCHAR_T
539 this->insert(i2, messages<wchar_t>::id);
544 msg = new messages_byname<char>(pname, 0, hint);
545 #ifndef _STLP_NO_WCHAR_T
546 wmsg = new messages_byname<wchar_t>(pname, 0, hint);
549 #ifndef _STLP_NO_WCHAR_T
550 _STLP_UNWIND(delete msg; delete wmsg);
552 _STLP_UNWIND(delete msg);
554 _Locale_insert(this,msg);
555 #ifndef _STLP_NO_WCHAR_T
556 _Locale_insert(this,wmsg);
562 static void _Stl_loc_assign_ids() {
563 // This assigns ids to every facet that is a member of a category,
564 // and also to money_get/put, num_get/put, and time_get/put
565 // instantiated using ordinary pointers as the input/output
566 // iterators. (The default is [io]streambuf_iterator.)
568 #ifdef __SYMBIAN32__WSD__
569 collate<char>::id._M_index = 1;
570 ctype<char>::id._M_index = 2;
572 #ifndef _STLP_NO_MBSTATE_T
573 codecvt<char, char, mbstate_t>::id._M_index = 3;
574 # ifndef _STLP_NO_WCHAR_T
575 codecvt<wchar_t, char, mbstate_t>::id._M_index = 22;
578 moneypunct<char, true>::id._M_index = 4;
579 moneypunct<char, false>::id._M_index = 5;
580 numpunct<char>::id._M_index = 6;
581 messages<char>::id._M_index =7;
583 collate<wchar_t>::id._M_index = 20;
584 ctype<wchar_t>::id._M_index = 21;
585 moneypunct<wchar_t, true>::id._M_index = 23;
586 moneypunct<wchar_t, false>::id._M_index = 24;
587 numpunct<wchar_t>::id._M_index = 25;
588 messages<wchar_t>::id._M_index = 26;
592 money_get<char, istreambuf_iterator<char, char_traits<char> > >::id._M_index = 8;
593 //money_get<char, const char*>::id._M_index = 9;
594 money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id._M_index = 10;
595 //money_put<char, char*>::id._M_index = 11;
597 num_get<char, istreambuf_iterator<char, char_traits<char> > >::id._M_index = 12;
598 //num_get<char, const char*>::id._M_index = 13;
599 num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id._M_index = 14;
600 //num_put<char, char*>::id._M_index = 15;
601 time_get<char, istreambuf_iterator<char, char_traits<char> > >::id._M_index = 16;
602 //time_get<char, const char*>::id._M_index = 17;
603 time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id._M_index = 18;
604 //time_put<char, char*>::id._M_index = 19;
606 #ifndef _STLP_NO_WCHAR_T
607 money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 27;
608 //money_get<wchar_t, const wchar_t*>::id._M_index = 28;
609 money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 29;
610 //money_put<wchar_t, wchar_t*>::id._M_index = 30;
612 num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 31;
613 //num_get<wchar_t, const wchar_t*>::id._M_index = 32;
614 num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > ::id._M_index = 33;
615 //num_put<wchar_t, wchar_t*>::id._M_index = 34;
616 time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 35;
617 //time_get<wchar_t, const wchar_t*>::id._M_index = 36;
618 time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 37;
619 //time_put<wchar_t, wchar_t*>::id._M_index = 38;
621 // locale::id::_S_max = 39;
624 // To access those static instance use the getter below, they guaranty
625 // a correct initialization.
626 #if !defined(__SYMBIAN32__WSD__)
627 static locale *_Stl_classic_locale = 0;
628 static locale *_Stl_global_locale = 0;
631 static locale* _Stl_get_classic_locale() {
632 #if !defined(__SYMBIAN32__WSD__)
633 static _Locale_impl::Init init;
635 return _Stl_classic_locale;
638 static locale* _Stl_get_global_locale() {
639 #if !defined(__SYMBIAN32__WSD__)
640 static _Locale_impl::Init init;
642 return _Stl_global_locale;
645 #if defined (_STLP_MSVC) || defined (__ICL) || defined (__ISCPP__)
647 * The following static variable needs to be initialized before STLport
648 * users static variable in order for him to be able to use Standard
649 * streams in its variable initialization.
650 * This variable is here because MSVC do not allow to change the initialization
651 * segment in a given translation unit, iostream.cpp already contains an
652 * initialization segment specification.
654 # pragma warning (disable : 4073)
655 # pragma init_seg(lib)
658 #if !defined(__SYMBIAN32__WSD__)
659 static ios_base::Init _IosInit;
662 void _Locale_impl::make_classic_locale() {
663 // This funcion will be called once: during build classic _Locale_impl
665 // The classic locale contains every facet that belongs to a category.
666 static _Stl_aligned_buffer<_Locale_impl> _Locale_classic_impl_buf;
667 _Locale_impl *classic = new(&_Locale_classic_impl_buf) _Locale_impl("C");
669 locale::facet* classic_facets[] = {
671 new collate<char>(1),
672 new ctype<char>(0, false, 1),
673 #ifndef _STLP_NO_MBSTATE_T
674 new codecvt<char, char, mbstate_t>(1),
678 new moneypunct<char, true>(1),
679 new moneypunct<char, false>(1),
680 new numpunct<char>(1),
681 new messages<char>(new _STLP_PRIV _Messages()),
682 new money_get<char, istreambuf_iterator<char, char_traits<char> > >(1),
684 new money_put<char, ostreambuf_iterator<char, char_traits<char> > >(1),
686 new num_get<char, istreambuf_iterator<char, char_traits<char> > >(1),
688 new num_put<char, ostreambuf_iterator<char, char_traits<char> > >(1),
690 new time_get<char, istreambuf_iterator<char, char_traits<char> > >(1),
692 new time_put<char, ostreambuf_iterator<char, char_traits<char> > >(1),
694 #ifndef _STLP_NO_WCHAR_T
695 new collate<wchar_t>(1),
696 new ctype<wchar_t>(1),
698 # ifndef _STLP_NO_MBSTATE_T
699 new codecvt<wchar_t, char, mbstate_t>(1),
703 new moneypunct<wchar_t, true>(1),
704 new moneypunct<wchar_t, false>(1),
705 new numpunct<wchar_t>(1),
706 new messages<wchar_t>(new _STLP_PRIV _Messages()),
708 new money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
710 new money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
713 new num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
715 new num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
717 new time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
719 new time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
725 const size_t nb_classic_facets = sizeof(classic_facets) / sizeof(locale::facet *);
726 classic->facets_vec.reserve(nb_classic_facets);
727 classic->facets_vec.assign(&classic_facets[0], &classic_facets[0] + nb_classic_facets);
729 #if defined(__SYMBIAN32__WSD__)
730 ::set_Stl_classic_locale(new (WSDAlloc(sizeof(locale))) locale(classic));
731 ::set_Stl_global_locale (new (WSDAlloc(sizeof(locale))) locale(_copy_Locale_impl(classic)));
733 static locale _Locale_classic(classic);
734 _Stl_classic_locale = &_Locale_classic;
736 static locale _Locale_global(_copy_Locale_impl(classic));
737 _Stl_global_locale = &_Locale_global;
741 #if defined (__BORLANDC__) && (__BORLANDC__ < 0x564)
743 _STLP_DECLSPEC locale::id time_get<char, istreambuf_iterator<char, char_traits<char> > >::id;
746 _STLP_DECLSPEC locale::id time_get<char, const char*>::id;
750 _STLP_DECLSPEC locale::id time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
753 _STLP_DECLSPEC locale::id time_put<char, char*>::id;
756 # if !defined (_STLP_NO_WCHAR_T)
758 _STLP_DECLSPEC locale::id time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
761 _STLP_DECLSPEC locale::id time_get<wchar_t, const wchar_t*>::id;
765 _STLP_DECLSPEC locale::id time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
768 _STLP_DECLSPEC locale::id time_put<wchar_t, wchar_t*>::id;
770 # endif /* _STLP_NO_WCHAR_T */
773 _STLP_DECLSPEC locale::id money_get<char, istreambuf_iterator<char, char_traits<char> > >::id;
776 _STLP_DECLSPEC locale::id money_get<char, const char*>::id;
780 _STLP_DECLSPEC locale::id money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
783 _STLP_DECLSPEC locale::id money_put<char, char*>::id;
786 # if !defined (_STLP_NO_WCHAR_T)
788 _STLP_DECLSPEC locale::id money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
791 _STLP_DECLSPEC locale::id money_get<wchar_t, const wchar_t*>::id;
795 _STLP_DECLSPEC locale::id money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
798 _STLP_DECLSPEC locale::id money_put<wchar_t, wchar_t*>::id;
803 _STLP_DECLSPEC locale::id num_get<char, istreambuf_iterator<char, char_traits<char> > >::id;
806 _STLP_DECLSPEC locale::id num_get<char, const char*>::id;
809 # if !defined (STLP_NO_WCHAR_T)
811 _STLP_DECLSPEC locale::id num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
814 _STLP_DECLSPEC locale::id num_get<wchar_t, const wchar_t*>::id;
819 _STLP_DECLSPEC locale::id num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
822 _STLP_DECLSPEC locale::id num_put<char, char*>::id;
825 # if !defined (_STLP_NO_WCHAR_T)
827 _STLP_DECLSPEC locale::id num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
830 _STLP_DECLSPEC locale::id num_put<wchar_t, wchar_t*>::id;
835 // Declarations of (non-template) facets' static data members
836 # if defined(__SYMBIAN32__WSD__)
838 #elif defined (__EPOC32__)
840 locale::id collate<char>::id = { 1 };
841 locale::id ctype<char>::id = { 2 };
843 #ifndef _STLP_NO_MBSTATE_T
844 locale::id codecvt<char, char, mbstate_t>::id = { 3 };
845 # ifndef _STLP_NO_WCHAR_T
846 locale::id codecvt<wchar_t, char, mbstate_t>::id = { 22 };
850 locale::id moneypunct<char, true>::id = { 4 };
851 locale::id moneypunct<char, false>::id = { 5 };
852 locale::id numpunct<char>::id = { 6 } ;
853 locale::id messages<char>::id = { 7 };
855 #ifndef _STLP_NO_WCHAR_T
856 locale::id collate<wchar_t>::id = { 20 };
857 locale::id ctype<wchar_t>::id = { 21 };
859 locale::id moneypunct<wchar_t, true>::id = { 23 } ;
860 locale::id moneypunct<wchar_t, false>::id = { 24 } ;
862 locale::id numpunct<wchar_t>::id = { 25 };
863 locale::id messages<wchar_t>::id = { 26 };
866 #if defined(__SYMBIAN32__NO_STATIC_IMPORTS__)
868 _STLP_DECLSPEC locale::id& collate<char>::GetFacetLocaleId()
870 return collate<char>::id;
872 _STLP_DECLSPEC locale::id& ctype<char>::GetFacetLocaleId()
874 return ctype<char>::id;
876 #ifndef _STLP_NO_MBSTATE_T
877 _STLP_DECLSPEC locale::id& codecvt<char, char, mbstate_t>::GetFacetLocaleId()
879 return codecvt<char, char, mbstate_t>::id;
881 # ifndef _STLP_NO_WCHAR_T
882 _STLP_DECLSPEC locale::id& codecvt<wchar_t, char, mbstate_t>::GetFacetLocaleId()
884 return codecvt<wchar_t, char, mbstate_t>::id;
889 _STLP_DECLSPEC locale::id& moneypunct<char, true>::GetFacetLocaleId()
891 return moneypunct<char, true>::id;
893 _STLP_DECLSPEC locale::id& moneypunct<char, false>::GetFacetLocaleId()
895 return moneypunct<char, false>::id;
897 _STLP_DECLSPEC locale::id& numpunct<char>::GetFacetLocaleId()
899 return numpunct<char>::id;
901 _STLP_DECLSPEC locale::id& messages<char>::GetFacetLocaleId()
903 return messages<char>::id;
905 #ifndef _STLP_NO_WCHAR_T
906 _STLP_DECLSPEC locale::id& collate<wchar_t>::GetFacetLocaleId()
908 return collate<wchar_t>::id;
910 _STLP_DECLSPEC locale::id& ctype<wchar_t>::GetFacetLocaleId()
912 return ctype<wchar_t>::id;
914 _STLP_DECLSPEC locale::id& moneypunct<wchar_t, true>::GetFacetLocaleId()
916 return moneypunct<wchar_t, true>::id;
918 _STLP_DECLSPEC locale::id& moneypunct<wchar_t, false>::GetFacetLocaleId()
920 return moneypunct<wchar_t, false>::id;
922 _STLP_DECLSPEC locale::id& numpunct<wchar_t>::GetFacetLocaleId()
924 return numpunct<wchar_t>::id;
926 _STLP_DECLSPEC locale::id& messages<wchar_t>::GetFacetLocaleId()
928 return messages<wchar_t>::id;
932 _STLP_DECLSPEC locale::id& money_get<char, istreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId()
934 return money_get<char, istreambuf_iterator<char, char_traits<char> > >::id;
937 _STLP_DECLSPEC locale::id& money_put<char, ostreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId()
939 return money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
941 # if !defined (_STLP_NO_WCHAR_T)
943 _STLP_DECLSPEC locale::id& money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId()
945 return money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
948 _STLP_DECLSPEC locale::id& money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId()
950 return money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
954 _STLP_DECLSPEC locale::id& num_get<char, istreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId()
956 return num_get<char, istreambuf_iterator<char, char_traits<char> > >::id;
958 # if !defined (STLP_NO_WCHAR_T)
960 _STLP_DECLSPEC locale::id& num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId()
962 return num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
966 _STLP_DECLSPEC locale::id& num_put<char, ostreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId()
968 return num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
970 # if !defined (_STLP_NO_WCHAR_T)
972 _STLP_DECLSPEC locale::id& num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId()
974 return num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
978 _STLP_DECLSPEC locale::id&
979 time_get<char, istreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId()
981 return time_get<char, istreambuf_iterator<char, char_traits<char> > >::id;
984 _STLP_DECLSPEC locale::id&
985 time_put<char, ostreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId()
987 return time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
989 # ifndef _STLP_NO_WCHAR_T
991 _STLP_DECLSPEC locale::id&
992 time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId()
994 return time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
997 _STLP_DECLSPEC locale::id&
998 time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId()
1000 return time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
1004 # endif // __SYMBIAN32__NO_STATIC_IMPORTS__
1007 #else // original STLPort
1009 // size_t locale::id::_S_max = 39; // made before
1011 _STLP_STATIC_MEMBER_DECLSPEC locale::id collate<char>::id = { 1 };
1012 _STLP_STATIC_MEMBER_DECLSPEC locale::id ctype<char>::id = { 2 };
1014 #ifndef _STLP_NO_MBSTATE_T
1015 _STLP_STATIC_MEMBER_DECLSPEC locale::id codecvt<char, char, mbstate_t>::id = { 3 };
1016 # ifndef _STLP_NO_WCHAR_T
1017 _STLP_STATIC_MEMBER_DECLSPEC locale::id codecvt<wchar_t, char, mbstate_t>::id = { 22 };
1021 _STLP_STATIC_MEMBER_DECLSPEC locale::id moneypunct<char, true>::id = { 4 };
1022 _STLP_STATIC_MEMBER_DECLSPEC locale::id moneypunct<char, false>::id = { 5 };
1023 _STLP_STATIC_MEMBER_DECLSPEC locale::id numpunct<char>::id = { 6 } ;
1024 _STLP_STATIC_MEMBER_DECLSPEC locale::id messages<char>::id = { 7 };
1026 #if defined (__BORLANDC__) && (__BORLANDC__ >= 0x564)
1027 _STLP_STATIC_MEMBER_DECLSPEC locale::id money_get<char, istreambuf_iterator<char, char_traits<char> > >::id = { 8 };
1028 _STLP_STATIC_MEMBER_DECLSPEC locale::id money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id = { 10 };
1029 _STLP_STATIC_MEMBER_DECLSPEC locale::id num_get<char, istreambuf_iterator<char, char_traits<char> > >::id = { 12 };
1030 _STLP_STATIC_MEMBER_DECLSPEC locale::id num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id = { 14 };
1031 _STLP_STATIC_MEMBER_DECLSPEC locale::id time_get<char, istreambuf_iterator<char, char_traits<char> > >::id = { 16 };
1032 _STLP_STATIC_MEMBER_DECLSPEC locale::id time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id = { 18 };
1034 _STLP_STATIC_MEMBER_DECLSPEC locale::id money_get<char, const char*>::id = { 9 };
1035 _STLP_STATIC_MEMBER_DECLSPEC locale::id money_put<char, char*>::id = { 11 };
1036 _STLP_STATIC_MEMBER_DECLSPEC locale::id num_get<char, const char*>::id = { 13 };
1037 _STLP_STATIC_MEMBER_DECLSPEC locale::id num_put<char, char*>::id = { 15 };
1038 _STLP_STATIC_MEMBER_DECLSPEC locale::id time_get<char, const char*>::id = { 17 };
1039 _STLP_STATIC_MEMBER_DECLSPEC locale::id time_put<char, char*>::id = { 19 };
1043 #ifndef _STLP_NO_WCHAR_T
1044 _STLP_STATIC_MEMBER_DECLSPEC locale::id collate<wchar_t>::id = { 20 };
1045 _STLP_STATIC_MEMBER_DECLSPEC locale::id ctype<wchar_t>::id = { 21 };
1047 _STLP_STATIC_MEMBER_DECLSPEC locale::id moneypunct<wchar_t, true>::id = { 23 } ;
1048 _STLP_STATIC_MEMBER_DECLSPEC locale::id moneypunct<wchar_t, false>::id = { 24 } ;
1050 _STLP_STATIC_MEMBER_DECLSPEC locale::id numpunct<wchar_t>::id = { 25 };
1051 _STLP_STATIC_MEMBER_DECLSPEC locale::id messages<wchar_t>::id = { 26 };
1053 #if defined (__BORLANDC__) && (__BORLANDC__ >= 0x564)
1054 _STLP_STATIC_MEMBER_DECLSPEC locale::id money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id = { 27 };
1055 _STLP_STATIC_MEMBER_DECLSPEC locale::id money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id = { 29 };
1056 _STLP_STATIC_MEMBER_DECLSPEC locale::id num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id = { 31 };
1057 _STLP_STATIC_MEMBER_DECLSPEC locale::id num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > ::id = { 33 };
1058 _STLP_STATIC_MEMBER_DECLSPEC locale::id time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id = { 35 };
1059 _STLP_STATIC_MEMBER_DECLSPEC locale::id time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id = { 37 };
1061 _STLP_STATIC_MEMBER_DECLSPEC locale::id money_get<wchar_t, const wchar_t*>::id = { 28 };
1062 _STLP_STATIC_MEMBER_DECLSPEC locale::id money_put<wchar_t, wchar_t*>::id = { 30 };
1063 _STLP_STATIC_MEMBER_DECLSPEC locale::id num_get<wchar_t, const wchar_t*>::id = { 32 };
1064 _STLP_STATIC_MEMBER_DECLSPEC locale::id num_put<wchar_t, wchar_t*>::id = { 34 };
1065 _STLP_STATIC_MEMBER_DECLSPEC locale::id time_get<wchar_t, const wchar_t*>::id = { 36 };
1066 _STLP_STATIC_MEMBER_DECLSPEC locale::id time_put<wchar_t, wchar_t*>::id = { 38 };
1070 # endif //!__SYMBIAN32__WSD__
1072 _STLP_DECLSPEC _Locale_impl* _STLP_CALL _get_Locale_impl(_Locale_impl *loc)
1074 _STLP_ASSERT( loc != 0 );
1079 void _STLP_CALL _release_Locale_impl(_Locale_impl *& loc)
1081 _STLP_ASSERT( loc != 0 );
1082 if (loc->_M_decr() == 0) {
1083 if (*loc != *_Stl_classic_locale)
1086 loc->~_Locale_impl();
1091 _STLP_DECLSPEC _Locale_impl* _STLP_CALL _copy_Nameless_Locale_impl(_Locale_impl *loc)
1093 _STLP_ASSERT( loc != 0 );
1095 _Locale_impl *loc_new = new _Locale_impl(*loc);
1097 loc_new->name = _Nameless;
1101 #if defined(__SYMBIAN32__WSD__)
1107 #if defined(__SYMBIAN32__WSD__)
1108 void locale_impl_init()
1111 std::locale::id::get_locale_id_S_max() = 39;
1113 //initialize the mutex lock in locale.cpp
1114 locale_index_lock_init();
1116 //initialize _S_count of Init
1117 std::ios_base::Init::ios_base_Init_S_count_init();
1119 //initialize S_was_synced of ios_base
1120 std::ios_base::ios_base_S_was_synced_init();
1122 //initialize the mutex in locale_catalog.cpp
1123 stlp_priv::locale_catalog_category_hash_lock_init();
1125 //initialize category map in locale_catalog.cpp
1126 stlp_priv::Category_Map_Init();
1128 //initialize empty string in monetary.cpp
1129 monetary_empty_string_init();
1131 # endif //__SYMBIAN32__WSD__
1134 // locale use many static functions/pointers from this file:
1135 // to avoid making ones extern, simple #include implementation of locale
1137 #include "locale.cpp"