home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / src / locale_catalog.cpp < prev    next >
C/C++ Source or Header  |  2002-01-18  |  26KB  |  737 lines

  1. /*
  2.  * Copyright (c) 1999
  3.  * Silicon Graphics Computer Systems, Inc.
  4.  *
  5.  * Copyright (c) 1999 
  6.  * Boris Fomitchev
  7.  *
  8.  * This material is provided "as is", with absolutely no warranty expressed
  9.  * or implied. Any use is at your own risk.
  10.  *
  11.  * Permission to use or copy this software for any purpose is hereby granted 
  12.  * without fee, provided the above notices are retained on all copies.
  13.  * Permission to modify the code and to distribute modified code is granted,
  14.  * provided the above notices are retained, and a notice that the code was
  15.  * modified is included with the above copyright notice.
  16.  *
  17.  */ 
  18. # include "stlport_prefix.h"
  19.  
  20. // #include <locale>
  21. #include <hash_map>
  22. #include "locale_impl.h"
  23. #include "c_locale.h"
  24.  
  25. #include "locale_nonclassic.h"
  26.  
  27.  
  28. #include <stl/_codecvt.h>
  29. #include <stl/_collate.h>
  30. #include <stl/_ctype.h>
  31. #include <stl/_monetary.h>
  32. #include <stl/_time_facets.h>
  33. #include <stl/_messages_facets.h>
  34. #include <stl/_istream.h>
  35. #include <stl/_num_get.h>
  36. #include <stl/_num_put.h>
  37.  
  38.  
  39. _STLP_BEGIN_NAMESPACE
  40.  
  41. // those wrappers are needed to avoid extern "C"
  42.  
  43.  void* _Loc_ctype_create(const char * s)
  44.   { return (void*)_Locale_ctype_create(s); }
  45.  void* _Loc_numeric_create(const char * s)
  46.   { return (void*)_Locale_numeric_create(s); }
  47.  void* _Loc_time_create(const char * s)
  48.   { return (void*)_Locale_time_create(s); }
  49.  void* _Loc_collate_create(const char * s)
  50.   { return (void*)_Locale_collate_create(s); }
  51.  void* _Loc_monetary_create(const char * s)
  52.   { return (void*)_Locale_monetary_create(s); }
  53.  void* _Loc_messages_create(const char * s)
  54.   { return (void*)_Locale_messages_create(s); }
  55.  
  56.  char* _Loc_ctype_name(const void* l, char* s)
  57.   { return _Locale_ctype_name(l, s); }
  58.  char* _Loc_numeric_name(const void* l, char* s)
  59.   { return _Locale_numeric_name(l, s); }
  60.  char* _Loc_time_name(const void* l, char* s)
  61.   { return _Locale_time_name(l,s); }
  62.  char* _Loc_collate_name( const void* l, char* s)
  63.   { return _Locale_collate_name(l,s); }
  64.  char* _Loc_monetary_name(const void* l, char* s)
  65.   { return _Locale_monetary_name(l,s); }
  66.  char* _Loc_messages_name(const void* l, char* s)
  67.   { return _Locale_messages_name(l,s); }
  68.  
  69.  const char* _Loc_ctype_default(char* p)    { return _Locale_ctype_default(p); }
  70.  const char* _Loc_numeric_default(char * p) { return _Locale_numeric_default(p); }
  71.  const char* _Loc_time_default(char* p)     { return _Locale_time_default(p); }
  72.  const char* _Loc_collate_default(char* p)  { return _Locale_collate_default(p); }
  73.  const char* _Loc_monetary_default(char* p) { return _Locale_monetary_default(p); }
  74.  const char* _Loc_messages_default(char* p) { return _Locale_messages_default(p); }
  75.  
  76.  void _Loc_ctype_destroy(void* p)    {_Locale_ctype_destroy(p); }
  77.  void _Loc_numeric_destroy(void* p)  {_Locale_numeric_destroy(p); }
  78.  void _Loc_time_destroy(void* p)     {_Locale_time_destroy(p);}
  79.  void _Loc_collate_destroy(void* p)  {_Locale_collate_destroy(p);}
  80.  void _Loc_monetary_destroy(void* p) {_Locale_monetary_destroy(p);}
  81.  void _Loc_messages_destroy(void* p) {_Locale_messages_destroy(p);}
  82.  
  83. typedef void* (*loc_create_func_t)(const char *);
  84. typedef char* (*loc_name_func_t)(const void* l, char* s);
  85. typedef void (*loc_destroy_func_t)(void* l);
  86. typedef const char* (*loc_default_name_func_t)(char* s);
  87.  
  88. //----------------------------------------------------------------------
  89. // Acquire and release low-level category objects.  The whole point of
  90. // this is so that we don't allocate (say) four different _Locale_ctype
  91. // objects for a single locale.
  92.  
  93. struct __eqstr {
  94.   bool operator()(const char* s1, const char* s2) const
  95.     { return strcmp(s1, s2) == 0; }
  96. };
  97.  
  98. struct __ptr_hash {
  99.   size_t operator()(const void* p) const
  100.     { return __REINTERPRET_CAST(size_t,p); }
  101. };
  102.  
  103. template <class _Category_ptr>
  104. struct __destroy_fun {
  105.   typedef void (*_fun_type)(_Category_ptr);
  106.   _fun_type _M_fun;
  107.   __destroy_fun(_fun_type __f) : _M_fun(__f) {}
  108.   void operator()(_Category_ptr __c) { _M_fun(__c); }  
  109. };
  110.  
  111. // Global hash tables for category objects.
  112. typedef hash_map<const char*, pair<void*, size_t>, hash<const char*>, __eqstr> Category_Map;
  113.  
  114. // Look up a category by name
  115. static hash_map<const char*, pair<void*, size_t>, hash<const char*>, __eqstr>* ctype_hash;
  116. static hash_map<const char*, pair<void*, size_t>, hash<const char*>, __eqstr>* numeric_hash;
  117. static hash_map<const char*, pair<void*, size_t>, hash<const char*>, __eqstr>* time_hash;
  118. static hash_map<const char*, pair<void*, size_t>, hash<const char*>, __eqstr>* collate_hash;
  119. static hash_map<const char*, pair<void*, size_t>, hash<const char*>, __eqstr>* monetary_hash;
  120. static hash_map<const char*, pair<void*, size_t>, hash<const char*>, __eqstr>* messages_hash;
  121.  
  122. // We have a single lock for all of the hash tables.  We may wish to 
  123. // replace it with six different locks.
  124. /* REFERENCED */
  125. _STLP_STATIC_MUTEX __category_hash_lock _STLP_MUTEX_INITIALIZER;
  126.  
  127. static void*
  128. __acquire_category(const char* name, loc_create_func_t create_obj,
  129.                    loc_default_name_func_t default_obj, Category_Map ** M)
  130. {
  131.   typedef Category_Map::iterator Category_iterator;
  132.   pair<Category_iterator, bool> result;
  133.   _STLP_auto_lock sentry(__category_hash_lock);
  134.  
  135.   typedef const char* key_type; 
  136.   pair<const key_type, pair<void*,size_t> > __e(name, pair<void*,size_t>((void*)0,size_t(0)));
  137.  
  138.   if (!*M)
  139.     *M = new Category_Map();
  140.  
  141. #if defined(__SC__)        //*TY 06/01/2000 - added workaround for SCpp
  142.   if(!*M) delete *M;    //*TY 06/01/2000 - it forgets to generate dtor for Category_Map class. This fake code forces to generate one.
  143. #endif                    //*TY 06/01/2000 - 
  144.  
  145.   // Find what name to look for.  Be careful if user requests the default.
  146.   char buf[_Locale_MAX_SIMPLE_NAME];
  147.   if (name == 0 || name[0] == 0)
  148.     name = default_obj(buf);
  149.   if (name == 0 || name[0] == 0)
  150.     name = "C";
  151.  
  152.   // Look for an existing entry with that name.
  153.  
  154.   result = (*M)->insert_noresize(__e);
  155.  
  156.   // There was no entry in the map already.  Create the category.
  157.   if (result.second) 
  158.     (*result.first).second.first = create_obj(name);
  159.  
  160.   // Increment the reference count.
  161.   ++((*result.first).second.second);
  162.  
  163.   return (*result.first).second.first;
  164. }
  165.  
  166.  
  167. static void 
  168. __release_category(void* cat,
  169.                  loc_destroy_func_t destroy_fun,
  170.                  loc_name_func_t get_name,
  171.                  Category_Map* M)
  172. {
  173.   _STLP_auto_lock sentry(__category_hash_lock);
  174.  
  175.   if (cat && M) {
  176.     // Find the name of the category object.
  177.     char buf[_Locale_MAX_SIMPLE_NAME + 1];
  178.     char* name = get_name(cat, buf);
  179.  
  180.     if (name != 0) {
  181.       Category_Map::iterator it = M->find(name);
  182.       if (it != M->end()) {
  183.         // Decrement the ref count.  If it goes to zero, delete this category
  184.         // from the map.
  185.         if (--((*it).second.second) == 0) {
  186.           void* cat1 = (*it).second.first;
  187.           destroy_fun(cat1);
  188.           M->erase(it);
  189.         }
  190.       }
  191.     }
  192.   }
  193. }
  194.  
  195. _Locale_ctype* _STLP_CALL __acquire_ctype(const char* name)
  196. { return __REINTERPRET_CAST(_Locale_ctype*,
  197.                             __acquire_category(name, _Loc_ctype_create, _Loc_ctype_default, &ctype_hash)); }
  198. _Locale_numeric* _STLP_CALL __acquire_numeric(const char* name)
  199. { return __REINTERPRET_CAST(_Locale_numeric*,
  200.                             __acquire_category(name, _Loc_numeric_create, _Loc_numeric_default, &numeric_hash)); }
  201. _Locale_time* _STLP_CALL __acquire_time(const char* name)
  202. { return __REINTERPRET_CAST(_Locale_time*,
  203.                             __acquire_category(name, _Loc_time_create, _Loc_time_default, &time_hash)); }
  204. _Locale_collate* _STLP_CALL __acquire_collate(const char* name)
  205. { return __REINTERPRET_CAST(_Locale_collate*,
  206.                             __acquire_category(name, _Loc_collate_create, _Loc_collate_default, &collate_hash)); }
  207. _Locale_monetary* _STLP_CALL __acquire_monetary(const char* name)
  208. { return __REINTERPRET_CAST(_Locale_monetary*,
  209.                             __acquire_category(name, _Loc_monetary_create, _Loc_monetary_default, &monetary_hash)); }
  210. _Locale_messages* _STLP_CALL __acquire_messages(const char* name)
  211. { return __REINTERPRET_CAST(_Locale_messages*,
  212.                             __acquire_category(name, _Loc_messages_create, _Loc_messages_default, &messages_hash)); }
  213.  
  214. void  _STLP_CALL __release_ctype(_Locale_ctype* cat) {
  215.   __release_category(cat, _Loc_ctype_destroy, _Loc_ctype_name, ctype_hash);
  216. }
  217. void _STLP_CALL __release_numeric(_Locale_numeric* cat) {
  218.   __release_category(cat, _Loc_numeric_destroy, _Loc_numeric_name, numeric_hash);
  219. }
  220. void _STLP_CALL __release_time(_Locale_time* cat) {
  221.   __release_category(cat, _Loc_time_destroy, _Loc_time_name, time_hash);
  222. }
  223. void _STLP_CALL __release_collate(_Locale_collate* cat) {
  224.   __release_category(cat, _Loc_collate_destroy, _Loc_collate_name, collate_hash);
  225. }
  226. void _STLP_CALL __release_monetary(_Locale_monetary* cat) {
  227.   __release_category(cat, _Loc_monetary_destroy, _Loc_monetary_name, monetary_hash);
  228. }
  229. void _STLP_CALL __release_messages(_Locale_messages* cat) {
  230.   __release_category(cat, _Loc_messages_destroy, _Loc_messages_name, messages_hash);
  231. }
  232.  
  233.  
  234. //
  235. // <locale> content which is dependent on the name 
  236. //
  237.  
  238. template <class Facet>
  239. inline locale::facet* 
  240. _Locale_insert(_Locale* __that, Facet* f) {
  241.   return __that->insert(f, Facet::id._M_index, false);
  242. }
  243.  
  244. // Give L a name where all facets except those in category c
  245. // are taken from name1, and those in category c are taken from name2.
  246. void _Stl_loc_combine_names(_Locale* L,
  247.                    const char* name1, const char* name2,
  248.                    locale::category c)
  249. {
  250.   if ((c & locale::all) == 0 || strcmp(name1, name2) == 0)
  251.     L->name = name1;
  252.   else if ((c & locale::all) == locale::all)
  253.     L->name = name2;
  254.   else {
  255.     // Decompose the names.
  256.     char ctype_buf[_Locale_MAX_SIMPLE_NAME];
  257.     char numeric_buf[_Locale_MAX_SIMPLE_NAME];
  258.     char time_buf[_Locale_MAX_SIMPLE_NAME];
  259.     char collate_buf[_Locale_MAX_SIMPLE_NAME];
  260.     char monetary_buf[_Locale_MAX_SIMPLE_NAME];
  261.     char messages_buf[_Locale_MAX_SIMPLE_NAME];
  262.  
  263.     _Locale_extract_ctype_name((c & locale::ctype) ? name2 : name1,
  264.                                ctype_buf); 
  265.     _Locale_extract_numeric_name((c & locale::numeric) ? name2 : name1,
  266.                                  numeric_buf); 
  267.     _Locale_extract_time_name((c & locale::time) ? name2 : name1,
  268.                               time_buf); 
  269.     _Locale_extract_collate_name((c & locale::collate) ? name2 : name1,
  270.                                  collate_buf); 
  271.     _Locale_extract_monetary_name((c & locale::monetary) ? name2 : name1,
  272.                                   monetary_buf); 
  273.     _Locale_extract_messages_name((c & locale::messages) ? name2 : name1,
  274.                                   messages_buf); 
  275.     
  276.     // Construct a new composite name.
  277.     char composite_buf[_Locale_MAX_COMPOSITE_NAME];
  278.     _Locale_compose_name(composite_buf,
  279.                          ctype_buf, numeric_buf, time_buf,
  280.                          collate_buf, monetary_buf, messages_buf);
  281.     L->name = composite_buf;
  282.   }
  283. }
  284.  
  285.  
  286. // Create a locale from a name.
  287. locale::locale(const char* name)
  288.   : _M_impl(0)
  289. {
  290.   if (!name)
  291.     _M_throw_runtime_error(0);
  292.  
  293.   _Locale* impl = 0;
  294.  
  295.   _STLP_TRY {
  296.     impl = new _Locale(locale::id::_S_max, name);
  297.  
  298.     // Insert categories one at a time.
  299.     impl->insert_ctype_facets(name);
  300.     impl->insert_numeric_facets(name);
  301.     impl->insert_time_facets(name);
  302.     impl->insert_collate_facets(name);
  303.     impl->insert_monetary_facets(name);
  304.     impl->insert_messages_facets(name);
  305.     // reassign impl
  306.     _M_impl = impl;
  307.   }
  308.   _STLP_UNWIND(delete impl);
  309. }
  310.  
  311. // Create a locale that's a copy of L, except that all of the facets
  312. // in category c are instead constructed by name.
  313. locale::locale(const locale& L, const char* name, locale::category c)
  314.   : _M_impl(0)
  315. {
  316.   if (name == 0 || strcmp(name, "*") == 0)
  317.     _M_throw_runtime_error(name);
  318.  
  319.   _Locale* impl = 0;
  320.  
  321.   _STLP_TRY {
  322.     impl = new _Locale(*L._M_impl);
  323.     _Stl_loc_combine_names(impl, L._M_impl->name.c_str(), name, c);
  324.  
  325.     if (c & locale::ctype)
  326.       impl->insert_ctype_facets(name);
  327.     if (c & locale::numeric)
  328.       impl->insert_numeric_facets(name);
  329.     if (c & locale::time)
  330.       impl->insert_time_facets(name);
  331.     if (c & locale::collate)
  332.       impl->insert_collate_facets(name);
  333.     if (c & locale::monetary)
  334.       impl->insert_monetary_facets(name);
  335.     if (c & locale::messages)
  336.       impl->insert_messages_facets(name);
  337.     _M_impl = impl;
  338.   }
  339.   _STLP_UNWIND(delete impl)
  340.  
  341. }
  342.  
  343. // Contruct a new locale where all facets that aren't in category c
  344. // come from L1, and all those that are in category c come from L2.
  345. locale::locale(const locale& L1, const locale& L2, category c)
  346.   : _M_impl(0)
  347. {
  348.   _Locale* impl = new _Locale(*L1._M_impl);
  349.   
  350.   _Locale_impl* i2 = L2._M_impl;
  351.  
  352.   static string nameless("*");
  353.   if (L1.name() != nameless && L2.name() != nameless)
  354.     _Stl_loc_combine_names(impl,
  355.                   L1._M_impl->name.c_str(), L2._M_impl->name.c_str(),
  356.                   c);
  357.   else {
  358.     impl->name = "*";
  359.   }
  360.  
  361.   if (c & collate) {
  362.     impl->insert( i2, _STLP_STD::collate<char>::id);
  363. # ifndef _STLP_NO_WCHAR_T
  364.     impl->insert( i2, _STLP_STD::collate<wchar_t>::id);
  365. # endif
  366.   }
  367.   if (c & ctype) {
  368.     impl->insert( i2, _STLP_STD::ctype<char>::id);
  369.     impl->insert( i2, _STLP_STD::codecvt<char, char, mbstate_t>::id);
  370. # ifndef _STLP_NO_WCHAR_T
  371.     impl->insert( i2, _STLP_STD::ctype<wchar_t>::id);
  372.     impl->insert( i2, _STLP_STD::codecvt<wchar_t, char, mbstate_t>::id);
  373. # endif
  374.   }
  375.   if (c & monetary) {
  376.     impl->insert( i2, _STLP_STD::moneypunct<char, true>::id);
  377.     impl->insert( i2, _STLP_STD::moneypunct<char, false>::id);
  378.     impl->insert( i2, _STLP_STD::money_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
  379.     impl->insert( i2, _STLP_STD::money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
  380. # ifndef _STLP_NO_WCHAR_T
  381.     impl->insert( i2, _STLP_STD::moneypunct<wchar_t, true>::id);
  382.     impl->insert( i2, _STLP_STD::moneypunct<wchar_t, false>::id);
  383.     impl->insert( i2, _STLP_STD::money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
  384.     impl->insert( i2, _STLP_STD::money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
  385. # endif
  386.   }
  387.   if (c & numeric) {
  388.     impl->insert( i2, _STLP_STD::numpunct<char>::id);
  389.     impl->insert( i2, _STLP_STD::num_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
  390.     impl->insert( i2, _STLP_STD::num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
  391. # ifndef _STLP_NO_WCHAR_T
  392.     impl->insert( i2, _STLP_STD::numpunct<wchar_t>::id);
  393.     impl->insert( i2, num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
  394.     impl->insert( i2, num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
  395. # endif
  396.   }
  397.   if (c & time) {
  398.     impl->insert( i2, _STLP_STD::time_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
  399.     impl->insert( i2, _STLP_STD::time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
  400. # ifndef _STLP_NO_WCHAR_T
  401.     impl->insert( i2, _STLP_STD::time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
  402.     impl->insert( i2, _STLP_STD::time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
  403. # endif
  404.   }
  405.   if (c & messages) {
  406.     impl->insert( i2, _STLP_STD::messages<char>::id);
  407. # ifndef _STLP_NO_WCHAR_T
  408.     impl->insert( i2, _STLP_STD::messages<wchar_t>::id);
  409. # endif
  410.   }
  411.   _M_impl = impl;
  412. }
  413.  
  414. // Six functions, one for each category.  Each of them takes a 
  415. // _Locale* and a name, constructs that appropriate category
  416. // facets by name, and inserts them into the locale.  
  417.  
  418. void _Locale::insert_ctype_facets(const char* pname)
  419. {
  420.   char buf[_Locale_MAX_SIMPLE_NAME];
  421.   _Locale_impl* i2 = locale::classic()._M_impl;
  422.  
  423.   if (pname == 0 || pname[0] == 0)
  424.     pname = _Locale_ctype_default(buf);
  425.  
  426.   if (pname == 0 || pname[0] == 0 || strcmp(pname, "C") == 0) {
  427.     this->insert(i2, ctype<char>::id);
  428. # ifndef _STLP_NO_MBSTATE_T
  429.     this->insert(i2, codecvt<char, char, mbstate_t>::id);
  430. # endif
  431. # ifndef _STLP_NO_WCHAR_T
  432.     this->insert(i2, ctype<wchar_t>::id);
  433. # ifndef _STLP_NO_MBSTATE_T
  434.     this->insert(i2, codecvt<wchar_t, char, mbstate_t>::id);
  435. # endif
  436. # endif
  437.   }
  438.   else {
  439.     ctype<char>*    ct                      = 0;
  440. # ifndef _STLP_NO_MBSTATE_T
  441.     codecvt<char, char, mbstate_t>*    cvt  = 0;
  442. # endif
  443. # ifndef _STLP_NO_WCHAR_T
  444.     ctype<wchar_t>* wct                     = 0;
  445.     codecvt<wchar_t, char, mbstate_t>* wcvt = 0;
  446. # endif
  447.     _STLP_TRY {
  448.       ct   = new ctype_byname<char>(pname);
  449. # ifndef _STLP_NO_MBSTATE_T
  450.       cvt  = new codecvt_byname<char, char, mbstate_t>(pname);
  451. # endif
  452. # ifndef _STLP_NO_WCHAR_T
  453.       wct  = new ctype_byname<wchar_t>(pname); 
  454.       wcvt = new codecvt_byname<wchar_t, char, mbstate_t>(pname);
  455. # endif
  456.     }
  457.     
  458. # ifndef _STLP_NO_WCHAR_T
  459. #  ifdef _STLP_NO_MBSTATE_T
  460.     _STLP_UNWIND(delete ct; delete wct; delete wcvt);
  461. #  else
  462.     _STLP_UNWIND(delete ct; delete wct; delete cvt; delete wcvt);
  463. #  endif
  464. # else
  465. #  ifdef _STLP_NO_MBSTATE_T
  466.     _STLP_UNWIND(delete ct);
  467. #  else
  468.     _STLP_UNWIND(delete ct; delete cvt);
  469. #  endif
  470. # endif    
  471.     _Locale_insert(this, ct);
  472. #  ifndef _STLP_NO_MBSTATE_T
  473.     _Locale_insert(this, cvt);
  474. #  endif
  475. #  ifndef _STLP_NO_WCHAR_T
  476.     _Locale_insert(this, wct);
  477.     _Locale_insert(this, wcvt);
  478. #  endif
  479.   }
  480. }
  481.  
  482. void _Locale::insert_numeric_facets(const char* pname)
  483. {
  484.   _Locale_impl* i2 = locale::classic()._M_impl;
  485.  
  486.   numpunct<char>*    punct  = 0;
  487.   num_get<char, istreambuf_iterator<char, char_traits<char> > >*     get    = 0;
  488.   num_put<char, ostreambuf_iterator<char, char_traits<char> > >*     put    = 0;
  489. # ifndef _STLP_NO_WCHAR_T
  490.   numpunct<wchar_t>* wpunct = 0;
  491.   num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >*  wget   = 0;
  492.   num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >*  wput   = 0;
  493. # endif
  494.  
  495.   char buf[_Locale_MAX_SIMPLE_NAME];
  496.   if (pname == 0 || pname[0] == 0)
  497.     pname = _Locale_numeric_default(buf);
  498.  
  499.   if (pname == 0 || pname[0] == 0 || strcmp(pname, "C") == 0) {
  500.     this->insert(i2, numpunct<char>::id);
  501.     this->insert(i2, 
  502.          num_put<char, ostreambuf_iterator<char, char_traits<char> >  >::id);
  503.     this->insert(i2, 
  504.          num_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
  505. # ifndef _STLP_NO_WCHAR_T
  506.     this->insert(i2, numpunct<wchar_t>::id);
  507.     this->insert(i2, 
  508.          num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> >  >::id);
  509.     this->insert(i2, 
  510.          num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
  511. # endif
  512.   }
  513.   else {
  514.     _STLP_TRY {
  515.       punct  = new numpunct_byname<char>(pname);
  516.       get    = new num_get<char, istreambuf_iterator<char, char_traits<char> > >;
  517.       put    = new num_put<char, ostreambuf_iterator<char, char_traits<char> > >;
  518. # ifndef _STLP_NO_WCHAR_T
  519.       wpunct = new numpunct_byname<wchar_t>(pname);
  520.       wget   = new num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
  521.       wput   = new num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
  522. # endif
  523.     }
  524. # ifndef _STLP_NO_WCHAR_T
  525.     _STLP_UNWIND(delete punct; delete wpunct; delete get; delete wget;
  526.     delete put; delete wput);
  527. # else
  528.     _STLP_UNWIND(delete punct; delete get;delete put);
  529. # endif
  530.     
  531.   _Locale_insert(this,punct);
  532.   _Locale_insert(this,get);
  533.   _Locale_insert(this,put);
  534.  
  535. # ifndef _STLP_NO_WCHAR_T
  536.   _Locale_insert(this,wpunct);
  537.   _Locale_insert(this,wget);
  538.   _Locale_insert(this,wput);
  539. # endif
  540.   }
  541. }
  542.  
  543. void _Locale::insert_time_facets(const char* pname)
  544. {
  545.   _Locale_impl* i2 = locale::classic()._M_impl;
  546.   time_get<char, istreambuf_iterator<char, char_traits<char> > >*    get  = 0;
  547.   time_put<char, ostreambuf_iterator<char, char_traits<char> > >*    put  = 0;
  548. # ifndef _STLP_NO_WCHAR_T
  549.   time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >* wget = 0;
  550.   time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >* wput = 0;
  551. # endif
  552.  
  553.   char buf[_Locale_MAX_SIMPLE_NAME];
  554.   if (pname == 0 || pname[0] == 0)
  555.     pname = _Locale_time_default(buf);
  556.   
  557.   if (pname == 0 || pname[0] == 0 || strcmp(pname, "C") == 0) {
  558.  
  559.     this->insert(i2, 
  560.          time_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
  561.     this->insert(i2, 
  562.          time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
  563. # ifndef _STLP_NO_WCHAR_T
  564.     this->insert(i2,
  565.          time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
  566.     this->insert(i2,
  567.          time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
  568. # endif
  569.   }
  570.   else {
  571.     _STLP_TRY {
  572.       get  = new time_get_byname<char, istreambuf_iterator<char, char_traits<char> > >(pname);
  573.       put  = new time_put_byname<char, ostreambuf_iterator<char, char_traits<char> > >(pname);
  574. # ifndef _STLP_NO_WCHAR_T
  575.       wget = new time_get_byname<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(pname);
  576.       wput = new time_put_byname<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(pname);
  577. # endif
  578.     }
  579. # ifndef _STLP_NO_WCHAR_T
  580.     _STLP_UNWIND(delete get; delete wget; delete put; delete wput);
  581. # else
  582.     _STLP_UNWIND(delete get; delete put);
  583. # endif
  584.     _Locale_insert(this,get);
  585.     _Locale_insert(this,put);
  586. # ifndef _STLP_NO_WCHAR_T
  587.     _Locale_insert(this,wget);
  588.     _Locale_insert(this,wput);
  589. # endif
  590.   }
  591. }
  592.  
  593. void _Locale::insert_collate_facets(const char* nam)
  594. {
  595.   _Locale_impl* i2 = locale::classic()._M_impl;
  596.  
  597.   collate<char>*    col  = 0;
  598. # ifndef _STLP_NO_WCHAR_T
  599.   collate<wchar_t>* wcol = 0;
  600. # endif
  601.  
  602.   char buf[_Locale_MAX_SIMPLE_NAME];
  603.   if (nam == 0 || nam[0] == 0)
  604.     nam = _Locale_collate_default(buf);
  605.  
  606.   if (nam == 0 || nam[0] == 0 || strcmp(nam, "C") == 0) {
  607.     this->insert(i2, collate<char>::id);
  608. # ifndef _STLP_NO_WCHAR_T
  609.     this->insert(i2, collate<wchar_t>::id);
  610. # endif
  611.   }
  612.   else {
  613.     _STLP_TRY {
  614.       col   = new collate_byname<char>(nam);
  615. # ifndef _STLP_NO_WCHAR_T
  616.       wcol  = new collate_byname<wchar_t>(nam); 
  617. # endif
  618.     }
  619. # ifndef _STLP_NO_WCHAR_T
  620.     _STLP_UNWIND(delete col; delete wcol);
  621. # else
  622.     _STLP_UNWIND(delete col);
  623. # endif
  624.     _Locale_insert(this,col);
  625. # ifndef _STLP_NO_WCHAR_T
  626.     _Locale_insert(this,wcol);
  627. # endif
  628.   }
  629. }
  630.  
  631. void _Locale::insert_monetary_facets(const char* pname)
  632. {
  633.   _Locale_impl* i2 = locale::classic()._M_impl;
  634.  
  635.   moneypunct<char,    false>* punct   = 0;
  636.   moneypunct<char,    true>*  ipunct  = 0;
  637.   money_get<char, istreambuf_iterator<char, char_traits<char> > >*            get     = 0;
  638.   money_put<char, ostreambuf_iterator<char, char_traits<char> > >*            put     = 0;
  639.  
  640. # ifndef _STLP_NO_WCHAR_T
  641.   moneypunct<wchar_t, false>* wpunct  = 0;
  642.   moneypunct<wchar_t, true>*  wipunct = 0;
  643.   money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >*         wget    = 0;
  644.   money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >*         wput    = 0;
  645. # endif
  646.  
  647.   char buf[_Locale_MAX_SIMPLE_NAME];
  648.   if (pname == 0 || pname[0] == 0)
  649.     pname = _Locale_monetary_default(buf);
  650.  
  651.   if (pname == 0 || pname[0] == 0 || strcmp(pname, "C") == 0) {
  652.     this->insert(i2, moneypunct<char, false>::id);
  653.     this->insert(i2, moneypunct<char, true>::id);
  654.     this->insert(i2, money_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
  655.     this->insert(i2, money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
  656. # ifndef _STLP_NO_WCHAR_T
  657.     this->insert(i2, moneypunct<wchar_t, false>::id);
  658.     this->insert(i2, moneypunct<wchar_t, true>::id);
  659.     this->insert(i2, money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
  660.     this->insert(i2, money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
  661. # endif
  662.   }
  663.   else {    
  664.     _STLP_TRY {
  665.       punct   = new moneypunct_byname<char, false>(pname);
  666.       ipunct  = new moneypunct_byname<char, true>(pname);
  667.       get     = new money_get<char, istreambuf_iterator<char, char_traits<char> > >;
  668.       put     = new money_put<char, ostreambuf_iterator<char, char_traits<char> > >;
  669. # ifndef _STLP_NO_WCHAR_T
  670.       wpunct  = new moneypunct_byname<wchar_t, false>(pname);
  671.       wipunct = new moneypunct_byname<wchar_t, true>(pname);
  672.       wget    = new money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
  673.       wput    = new money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
  674. # endif
  675.     }
  676. # ifndef _STLP_NO_WCHAR_T
  677.     _STLP_UNWIND(delete punct; delete ipunct; delete wpunct; delete wipunct;
  678.     delete get; delete wget; delete put; delete wput);
  679. # else
  680.     _STLP_UNWIND(delete punct; delete ipunct; delete get; delete put);
  681. # endif
  682.     _Locale_insert(this,punct);
  683.     _Locale_insert(this,ipunct);
  684.     _Locale_insert(this,get);
  685.     _Locale_insert(this,put);
  686. # ifndef _STLP_NO_WCHAR_T
  687.     _Locale_insert(this,wget);
  688.     _Locale_insert(this,wpunct);
  689.     _Locale_insert(this,wipunct);
  690.     _Locale_insert(this,wput);
  691. # endif
  692.   }
  693. }
  694.  
  695.  
  696. void _Locale::insert_messages_facets(const char* pname)
  697. {
  698.   _Locale_impl* i2 = locale::classic()._M_impl;
  699.   messages<char>*    msg  = 0;
  700. # ifndef _STLP_NO_WCHAR_T
  701.   messages<wchar_t>* wmsg = 0;
  702. # endif
  703.  
  704.   char buf[_Locale_MAX_SIMPLE_NAME];
  705.   if (pname == 0 || pname[0] == 0)
  706.     pname = _Locale_messages_default(buf);
  707.  
  708.   if (pname == 0 || pname[0] == 0 || strcmp(pname, "C") == 0) {
  709.     this->insert(i2, messages<char>::id);
  710. # ifndef _STLP_NO_WCHAR_T
  711.     this->insert(i2, messages<wchar_t>::id);
  712. # endif
  713.   }
  714.   else {
  715.     _STLP_TRY {
  716.       msg  = new messages_byname<char>(pname);
  717. # ifndef _STLP_NO_WCHAR_T
  718.       wmsg = new messages_byname<wchar_t>(pname);
  719. # endif
  720.     }
  721. # ifndef _STLP_NO_WCHAR_T
  722.     _STLP_UNWIND(delete msg; delete wmsg);
  723. # else
  724.     _STLP_UNWIND(delete msg);
  725. # endif
  726.     _Locale_insert(this,msg);
  727. # ifndef _STLP_NO_WCHAR_T
  728.     _Locale_insert(this,wmsg);
  729. # endif
  730.   }
  731. }
  732.  
  733. _STLP_END_NAMESPACE
  734.  
  735.  
  736.  
  737.