locale_facets.h

Go to the documentation of this file.
00001 // Locale support -*- C++ -*-
00002 
00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
00004 // Free Software Foundation, Inc.
00005 //
00006 // This file is part of the GNU ISO C++ Library.  This library is free
00007 // software; you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the
00009 // Free Software Foundation; either version 2, or (at your option)
00010 // any later version.
00011 
00012 // This library is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 
00017 // You should have received a copy of the GNU General Public License along
00018 // with this library; see the file COPYING.  If not, write to the Free
00019 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00020 // USA.
00021 
00022 // As a special exception, you may use this file as part of a free software
00023 // library without restriction.  Specifically, if other files instantiate
00024 // templates or use macros or inline functions from this file, or you compile
00025 // this file and link it with other files to produce an executable, this
00026 // file does not by itself cause the resulting executable to be covered by
00027 // the GNU General Public License.  This exception does not however
00028 // invalidate any other reasons why the executable file might be covered by
00029 // the GNU General Public License.
00030 
00031 //
00032 // ISO C++ 14882: 22.1  Locales
00033 //
00034 
00040 #ifndef _CPP_BITS_LOCFACETS_H
00041 #define _CPP_BITS_LOCFACETS_H   1
00042 
00043 #pragma GCC system_header
00044 
00045 #include <ctime>    // For struct tm
00046 #include <cwctype>  // For wctype_t
00047 #include <ios>      // For ios_base
00048 
00049 namespace std
00050 {
00051   // NB: Don't instantiate required wchar_t facets if no wchar_t support.
00052 #ifdef _GLIBCPP_USE_WCHAR_T
00053 # define  _GLIBCPP_NUM_FACETS 28
00054 #else
00055 # define  _GLIBCPP_NUM_FACETS 14
00056 #endif
00057 
00058   // 22.2.1.1  Template class ctype
00059   // Include host and configuration specific ctype enums for ctype_base.
00060   #include <bits/ctype_base.h>
00061 
00062   // Common base for ctype<_CharT>.  
00063   template<typename _CharT>
00064     class __ctype_abstract_base : public locale::facet, public ctype_base
00065     {
00066     public:
00067       // Types:
00068       typedef _CharT char_type;
00069 
00070       bool 
00071       is(mask __m, char_type __c) const
00072       { return this->do_is(__m, __c); }
00073 
00074       const char_type*
00075       is(const char_type *__lo, const char_type *__hi, mask *__vec) const   
00076       { return this->do_is(__lo, __hi, __vec); }
00077 
00078       const char_type*
00079       scan_is(mask __m, const char_type* __lo, const char_type* __hi) const
00080       { return this->do_scan_is(__m, __lo, __hi); }
00081 
00082       const char_type*
00083       scan_not(mask __m, const char_type* __lo, const char_type* __hi) const
00084       { return this->do_scan_not(__m, __lo, __hi); }
00085 
00086       char_type 
00087       toupper(char_type __c) const
00088       { return this->do_toupper(__c); }
00089 
00090       const char_type*
00091       toupper(char_type *__lo, const char_type* __hi) const
00092       { return this->do_toupper(__lo, __hi); }
00093 
00094       char_type 
00095       tolower(char_type __c) const
00096       { return this->do_tolower(__c); }
00097 
00098       const char_type*
00099       tolower(char_type* __lo, const char_type* __hi) const
00100       { return this->do_tolower(__lo, __hi); }
00101 
00102       char_type 
00103       widen(char __c) const
00104       { return this->do_widen(__c); }
00105 
00106       const char*
00107       widen(const char* __lo, const char* __hi, char_type* __to) const
00108       { return this->do_widen(__lo, __hi, __to); }
00109 
00110       char 
00111       narrow(char_type __c, char __dfault) const
00112       { return this->do_narrow(__c, __dfault); }
00113 
00114       const char_type*
00115       narrow(const char_type* __lo, const char_type* __hi,
00116           char __dfault, char *__to) const
00117       { return this->do_narrow(__lo, __hi, __dfault, __to); }
00118 
00119     protected:
00120       explicit 
00121       __ctype_abstract_base(size_t __refs = 0): locale::facet(__refs) { }
00122 
00123       virtual 
00124       ~__ctype_abstract_base() { }
00125       
00126       virtual bool 
00127       do_is(mask __m, char_type __c) const = 0;
00128 
00129       virtual const char_type*
00130       do_is(const char_type* __lo, const char_type* __hi, 
00131         mask* __vec) const = 0;
00132 
00133       virtual const char_type*
00134       do_scan_is(mask __m, const char_type* __lo,
00135          const char_type* __hi) const = 0;
00136 
00137       virtual const char_type*
00138       do_scan_not(mask __m, const char_type* __lo, 
00139           const char_type* __hi) const = 0;
00140 
00141       virtual char_type 
00142       do_toupper(char_type) const = 0;
00143 
00144       virtual const char_type*
00145       do_toupper(char_type* __lo, const char_type* __hi) const = 0;
00146 
00147       virtual char_type 
00148       do_tolower(char_type) const = 0;
00149 
00150       virtual const char_type*
00151       do_tolower(char_type* __lo, const char_type* __hi) const = 0;
00152       
00153       virtual char_type 
00154       do_widen(char) const = 0;
00155 
00156       virtual const char*
00157       do_widen(const char* __lo, const char* __hi, 
00158            char_type* __dest) const = 0;
00159 
00160       virtual char 
00161       do_narrow(char_type, char __dfault) const = 0;
00162 
00163       virtual const char_type*
00164       do_narrow(const char_type* __lo, const char_type* __hi,
00165          char __dfault, char* __dest) const = 0;
00166     };
00167 
00168   // NB: Generic, mostly useless implementation.
00169   template<typename _CharT>
00170     class ctype : public __ctype_abstract_base<_CharT>
00171     {
00172     public:
00173       // Types:
00174       typedef _CharT            char_type;
00175       typedef typename ctype::mask  mask;
00176 
00177       static locale::id             id;
00178 
00179       explicit 
00180       ctype(size_t __refs = 0) : __ctype_abstract_base<_CharT>(__refs) { }
00181 
00182    protected:
00183       virtual 
00184       ~ctype();
00185 
00186       virtual bool 
00187       do_is(mask __m, char_type __c) const;
00188 
00189       virtual const char_type*
00190       do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
00191 
00192       virtual const char_type*
00193       do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
00194 
00195       virtual const char_type*
00196       do_scan_not(mask __m, const char_type* __lo,
00197           const char_type* __hi) const;
00198 
00199       virtual char_type 
00200       do_toupper(char_type __c) const;
00201 
00202       virtual const char_type*
00203       do_toupper(char_type* __lo, const char_type* __hi) const;
00204 
00205       virtual char_type 
00206       do_tolower(char_type __c) const;
00207 
00208       virtual const char_type*
00209       do_tolower(char_type* __lo, const char_type* __hi) const;
00210 
00211       virtual char_type 
00212       do_widen(char __c) const;
00213 
00214       virtual const char*
00215       do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
00216 
00217       virtual char 
00218       do_narrow(char_type, char __dfault) const;
00219 
00220       virtual const char_type*
00221       do_narrow(const char_type* __lo, const char_type* __hi,
00222         char __dfault, char* __dest) const;
00223     };
00224 
00225   template<typename _CharT>
00226     locale::id ctype<_CharT>::id;
00227 
00228   // 22.2.1.3  ctype<char> specialization.
00229   template<>
00230     class ctype<char> : public __ctype_abstract_base<char>
00231     {
00232     public:
00233       // Types:
00234       typedef char          char_type;
00235 
00236     protected:
00237       // Data Members:
00238       __c_locale        _M_c_locale_ctype;
00239       bool              _M_del;
00240       __to_type             _M_toupper;
00241       __to_type             _M_tolower;
00242       const mask*               _M_table;
00243       
00244     public:
00245       static locale::id        id;
00246       static const size_t      table_size = 1 + static_cast<unsigned char>(-1);
00247 
00248       explicit 
00249       ctype(const mask* __table = 0, bool __del = false, size_t __refs = 0);
00250 
00251       explicit 
00252       ctype(__c_locale __cloc, const mask* __table = 0, bool __del = false, 
00253         size_t __refs = 0);
00254 
00255       inline bool 
00256       is(mask __m, char __c) const;
00257  
00258       inline const char*
00259       is(const char* __lo, const char* __hi, mask* __vec) const;
00260  
00261       inline const char*
00262       scan_is(mask __m, const char* __lo, const char* __hi) const;
00263 
00264       inline const char*
00265       scan_not(mask __m, const char* __lo, const char* __hi) const;
00266      
00267     protected:
00268       const mask* 
00269       table() const throw()
00270       { return _M_table; }
00271 
00272       static const mask* 
00273       classic_table() throw();
00274 
00275       virtual 
00276       ~ctype();
00277 
00278       virtual bool 
00279       do_is(mask __m, char_type __c) const;
00280 
00281       virtual const char_type*
00282       do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
00283 
00284       virtual const char_type*
00285       do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
00286 
00287       virtual const char_type*
00288       do_scan_not(mask __m, const char_type* __lo, 
00289           const char_type* __hi) const;
00290 
00291       virtual char_type 
00292       do_toupper(char_type) const;
00293 
00294       virtual const char_type*
00295       do_toupper(char_type* __lo, const char_type* __hi) const;
00296 
00297       virtual char_type 
00298       do_tolower(char_type) const;
00299 
00300       virtual const char_type*
00301       do_tolower(char_type* __lo, const char_type* __hi) const;
00302       
00303       virtual char_type 
00304       do_widen(char) const;
00305 
00306       virtual const char*
00307       do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
00308 
00309       virtual char 
00310       do_narrow(char_type, char __dfault) const;
00311 
00312       virtual const char_type*
00313       do_narrow(const char_type* __lo, const char_type* __hi,
00314         char __dfault, char* __dest) const;
00315     };
00316  
00317   template<>
00318     const ctype<char>&
00319     use_facet<ctype<char> >(const locale& __loc);
00320 
00321 #ifdef _GLIBCPP_USE_WCHAR_T
00322   // 22.2.1.3  ctype<wchar_t> specialization
00323   template<>
00324     class ctype<wchar_t> : public __ctype_abstract_base<wchar_t>
00325     {
00326     public:
00327       // Types:
00328       typedef wchar_t           char_type;
00329       typedef wctype_t          __wmask_type;
00330 
00331     protected:
00332       __c_locale        _M_c_locale_ctype;
00333 
00334     public:
00335       // Data Members:
00336       static locale::id         id;
00337 
00338       explicit 
00339       ctype(size_t __refs = 0);
00340 
00341       explicit 
00342       ctype(__c_locale __cloc, size_t __refs = 0);
00343 
00344     protected:
00345       __wmask_type
00346       _M_convert_to_wmask(const mask __m) const;
00347 
00348       virtual 
00349       ~ctype();
00350 
00351       virtual bool 
00352       do_is(mask __m, char_type __c) const;
00353 
00354       virtual const char_type*
00355       do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
00356 
00357       virtual const char_type*
00358       do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
00359 
00360       virtual const char_type*
00361       do_scan_not(mask __m, const char_type* __lo, 
00362           const char_type* __hi) const;
00363 
00364       virtual char_type 
00365       do_toupper(char_type) const;
00366 
00367       virtual const char_type*
00368       do_toupper(char_type* __lo, const char_type* __hi) const;
00369 
00370       virtual char_type 
00371       do_tolower(char_type) const;
00372 
00373       virtual const char_type*
00374       do_tolower(char_type* __lo, const char_type* __hi) const;
00375       
00376       virtual char_type 
00377       do_widen(char) const;
00378 
00379       virtual const char*
00380       do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
00381 
00382       virtual char 
00383       do_narrow(char_type, char __dfault) const;
00384 
00385       virtual const char_type*
00386       do_narrow(const char_type* __lo, const char_type* __hi,
00387         char __dfault, char* __dest) const;
00388 
00389     };
00390 
00391   template<>
00392     const ctype<wchar_t>&
00393     use_facet<ctype<wchar_t> >(const locale& __loc);
00394 #endif //_GLIBCPP_USE_WCHAR_T
00395 
00396   // Include host and configuration specific ctype inlines.
00397   #include <bits/ctype_inline.h>
00398 
00399   // 22.2.1.2  Template class ctype_byname
00400   template<typename _CharT>
00401     class ctype_byname : public ctype<_CharT>
00402     {
00403     public:
00404       typedef _CharT        char_type;
00405 
00406       explicit 
00407       ctype_byname(const char* __s, size_t __refs = 0);
00408 
00409     protected:
00410       virtual 
00411       ~ctype_byname() { };
00412     };
00413 
00414   // 22.2.1.4  Class ctype_byname specializations.
00415   template<>
00416     ctype_byname<char>::ctype_byname(const char*, size_t refs);
00417 
00418   template<>
00419     ctype_byname<wchar_t>::ctype_byname(const char*, size_t refs);
00420 
00421   // 22.2.1.5  Template class codecvt
00422   #include <bits/codecvt.h>
00423 
00424 
00425   // 22.2.2  The numeric category.
00426   class __num_base 
00427   {
00428   protected:
00429     // String literal of acceptable (narrow) input, for num_get.
00430     // "0123456789eEabcdfABCDF"
00431     static const char _S_atoms[];
00432 
00433     enum 
00434     {  
00435       _M_zero,
00436       _M_e = _M_zero + 10,
00437       _M_E = _M_zero + 11,
00438       _M_size = 21 + 1
00439     };
00440 
00441     // num_put
00442     // Construct and return valid scanf format for floating point types.
00443     static bool
00444     _S_format_float(const ios_base& __io, char* __fptr, char __mod, 
00445             streamsize __prec);
00446     
00447     // Construct and return valid scanf format for integer types.
00448     static void
00449     _S_format_int(const ios_base& __io, char* __fptr, char __mod, char __modl);
00450   };
00451 
00452 
00453   template<typename _CharT>
00454     class numpunct : public locale::facet
00455     {
00456     public:
00457       // Types:
00458       typedef _CharT                char_type;
00459       typedef basic_string<_CharT>  string_type;
00460 
00461       static locale::id         id;
00462 
00463     private:
00464       char_type             _M_decimal_point;
00465       char_type             _M_thousands_sep;
00466       const char*           _M_grouping;
00467       const char_type*          _M_truename;
00468       const char_type*          _M_falsename;
00469 
00470     public:
00471       explicit 
00472       numpunct(size_t __refs = 0) : locale::facet(__refs) 
00473       { _M_initialize_numpunct(); }
00474 
00475       explicit 
00476       numpunct(__c_locale __cloc, size_t __refs = 0) : locale::facet(__refs) 
00477       { _M_initialize_numpunct(__cloc); }
00478 
00479       char_type    
00480       decimal_point() const
00481       { return this->do_decimal_point(); }
00482 
00483       char_type    
00484       thousands_sep() const
00485       { return this->do_thousands_sep(); }
00486 
00487       string       
00488       grouping() const
00489       { return this->do_grouping(); }
00490 
00491       string_type  
00492       truename() const
00493       { return this->do_truename(); }
00494 
00495       string_type  
00496       falsename() const
00497       { return this->do_falsename(); }
00498 
00499     protected:
00500       virtual 
00501       ~numpunct();
00502 
00503       virtual char_type    
00504       do_decimal_point() const
00505       { return _M_decimal_point; }
00506 
00507       virtual char_type    
00508       do_thousands_sep() const
00509       { return _M_thousands_sep; }
00510 
00511       virtual string
00512       do_grouping() const
00513       { return _M_grouping; }
00514 
00515       virtual string_type  
00516       do_truename() const
00517       { return _M_truename; }
00518 
00519       virtual string_type  
00520       do_falsename() const
00521       { return _M_falsename; }
00522 
00523       // For use at construction time only.
00524       void 
00525       _M_initialize_numpunct(__c_locale __cloc = _S_c_locale);
00526     };
00527 
00528   template<typename _CharT>
00529     locale::id numpunct<_CharT>::id;
00530 
00531   template<> 
00532     numpunct<char>::~numpunct();
00533 
00534   template<> 
00535     void
00536     numpunct<char>::_M_initialize_numpunct(__c_locale __cloc);
00537 
00538 #ifdef _GLIBCPP_USE_WCHAR_T
00539   template<> 
00540     numpunct<wchar_t>::~numpunct();
00541 
00542   template<> 
00543     void
00544     numpunct<wchar_t>::_M_initialize_numpunct(__c_locale __cloc);
00545 #endif
00546 
00547   template<typename _CharT>
00548     class numpunct_byname : public numpunct<_CharT>
00549     {
00550       // Data Member.
00551       __c_locale            _M_c_locale_numpunct;
00552 
00553     public:
00554       typedef _CharT                char_type;
00555       typedef basic_string<_CharT>  string_type;
00556 
00557       explicit 
00558       numpunct_byname(const char* __s, size_t __refs = 0)
00559       : numpunct<_CharT>(__refs)
00560       {
00561     _S_create_c_locale(_M_c_locale_numpunct, __s);
00562     _M_initialize_numpunct(_M_c_locale_numpunct);   
00563       }
00564 
00565     protected:
00566       virtual 
00567       ~numpunct_byname() 
00568       { _S_destroy_c_locale(_M_c_locale_numpunct); }
00569     };
00570 
00571   template<typename _CharT, typename _InIter>
00572     class num_get : public locale::facet, public __num_base
00573     {
00574     public:
00575       // Types:
00576       typedef _CharT            char_type;
00577       typedef _InIter           iter_type;
00578 
00579       static locale::id         id;
00580 
00581       explicit 
00582       num_get(size_t __refs = 0) : locale::facet(__refs) { }
00583 
00584       iter_type 
00585       get(iter_type __in, iter_type __end, ios_base& __io,
00586       ios_base::iostate& __err, bool& __v) const
00587       { return this->do_get(__in, __end, __io, __err, __v); }
00588 
00589       iter_type
00590       get(iter_type __in, iter_type __end, ios_base& __io, 
00591       ios_base::iostate& __err, long& __v) const
00592       { return this->do_get(__in, __end, __io, __err, __v); }
00593 
00594       iter_type 
00595       get(iter_type __in, iter_type __end, ios_base& __io,
00596       ios_base::iostate& __err, unsigned short& __v) const
00597       { return this->do_get(__in, __end, __io, __err, __v); }
00598 
00599       iter_type 
00600       get(iter_type __in, iter_type __end, ios_base& __io,
00601       ios_base::iostate& __err, unsigned int& __v)   const
00602       { return this->do_get(__in, __end, __io, __err, __v); }
00603 
00604       iter_type 
00605       get(iter_type __in, iter_type __end, ios_base& __io,
00606       ios_base::iostate& __err, unsigned long& __v)  const
00607       { return this->do_get(__in, __end, __io, __err, __v); }
00608 
00609 #ifdef _GLIBCPP_USE_LONG_LONG
00610       iter_type 
00611       get(iter_type __in, iter_type __end, ios_base& __io,
00612       ios_base::iostate& __err, long long& __v) const
00613       { return this->do_get(__in, __end, __io, __err, __v); }
00614 
00615       iter_type 
00616       get(iter_type __in, iter_type __end, ios_base& __io,
00617       ios_base::iostate& __err, unsigned long long& __v)  const
00618       { return this->do_get(__in, __end, __io, __err, __v); }
00619 #endif
00620 
00621       iter_type 
00622       get(iter_type __in, iter_type __end, ios_base& __io,
00623       ios_base::iostate& __err, float& __v) const
00624       { return this->do_get(__in, __end, __io, __err, __v); }
00625 
00626       iter_type 
00627       get(iter_type __in, iter_type __end, ios_base& __io,
00628       ios_base::iostate& __err, double& __v) const
00629       { return this->do_get(__in, __end, __io, __err, __v); }
00630 
00631       iter_type 
00632       get(iter_type __in, iter_type __end, ios_base& __io,
00633       ios_base::iostate& __err, long double& __v) const
00634       { return this->do_get(__in, __end, __io, __err, __v); }
00635 
00636       iter_type 
00637       get(iter_type __in, iter_type __end, ios_base& __io,
00638       ios_base::iostate& __err, void*& __v) const
00639       { return this->do_get(__in, __end, __io, __err, __v); }      
00640 
00641     protected:
00642       virtual ~num_get() { }
00643 
00644       iter_type 
00645       _M_extract_float(iter_type, iter_type, ios_base&, ios_base::iostate&, 
00646                string& __xtrc) const;
00647 
00648       iter_type 
00649       _M_extract_int(iter_type, iter_type, ios_base&, ios_base::iostate&, 
00650              string& __xtrc, int& __base) const;
00651 
00652       virtual iter_type 
00653       do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const;
00654 
00655       virtual iter_type 
00656       do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, long&) const;
00657 
00658       virtual iter_type 
00659       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 
00660           unsigned short&) const;
00661 
00662       virtual iter_type 
00663       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 
00664          unsigned int&) const;
00665 
00666       virtual iter_type 
00667       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 
00668          unsigned long&) const;
00669 
00670 #ifdef _GLIBCPP_USE_LONG_LONG 
00671       virtual iter_type 
00672       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 
00673          long long&) const;
00674 
00675       virtual iter_type 
00676       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 
00677          unsigned long long&) const;
00678 #endif
00679 
00680       virtual iter_type 
00681       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 
00682          float&) const;
00683 
00684       virtual iter_type 
00685       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 
00686          double&) const;
00687 
00688       virtual iter_type 
00689       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 
00690          long double&) const;
00691 
00692       virtual iter_type 
00693       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 
00694          void*&) const;
00695     };
00696 
00697   template<typename _CharT, typename _InIter>
00698     locale::id num_get<_CharT, _InIter>::id;
00699 
00700   template<typename _CharT, typename _OutIter>
00701     class num_put : public locale::facet, public __num_base
00702     {
00703     public:
00704       // Types:
00705       typedef _CharT        char_type;
00706       typedef _OutIter      iter_type;
00707 
00708       static locale::id     id;
00709 
00710       explicit 
00711       num_put(size_t __refs = 0) : locale::facet(__refs) { }
00712 
00713       iter_type 
00714       put(iter_type __s, ios_base& __f, char_type __fill, bool __v) const
00715       { return this->do_put(__s, __f, __fill, __v); }
00716 
00717       iter_type 
00718       put(iter_type __s, ios_base& __f, char_type __fill, long __v) const
00719       { return this->do_put(__s, __f, __fill, __v); }
00720 
00721       iter_type 
00722       put(iter_type __s, ios_base& __f, char_type __fill, 
00723       unsigned long __v) const
00724       { return this->do_put(__s, __f, __fill, __v); }
00725 
00726 #ifdef _GLIBCPP_USE_LONG_LONG 
00727       iter_type 
00728       put(iter_type __s, ios_base& __f, char_type __fill, long long __v) const
00729       { return this->do_put(__s, __f, __fill, __v); }
00730 
00731       iter_type 
00732       put(iter_type __s, ios_base& __f, char_type __fill, 
00733       unsigned long long __v) const
00734       { return this->do_put(__s, __f, __fill, __v); }
00735 #endif
00736 
00737       iter_type 
00738       put(iter_type __s, ios_base& __f, char_type __fill, double __v) const
00739       { return this->do_put(__s, __f, __fill, __v); }
00740 
00741       iter_type 
00742       put(iter_type __s, ios_base& __f, char_type __fill, 
00743       long double __v) const
00744       { return this->do_put(__s, __f, __fill, __v); }
00745 
00746       iter_type 
00747       put(iter_type __s, ios_base& __f, char_type __fill, 
00748       const void* __v) const
00749       { return this->do_put(__s, __f, __fill, __v); }
00750 
00751     protected:
00752       template<typename _ValueT>
00753         iter_type
00754         _M_convert_float(iter_type, ios_base& __io, char_type __fill, 
00755              char __mod, _ValueT __v) const;
00756 
00757       template<typename _ValueT>
00758         iter_type
00759         _M_convert_int(iter_type, ios_base& __io, char_type __fill, 
00760                char __mod, char __modl, _ValueT __v) const;
00761 
00762       iter_type
00763       _M_widen_float(iter_type, ios_base& __io, char_type __fill, char* __cs, 
00764              int __len) const;
00765 
00766       iter_type
00767       _M_widen_int(iter_type, ios_base& __io, char_type __fill, char* __cs, 
00768            int __len) const;
00769 
00770       iter_type
00771       _M_insert(iter_type, ios_base& __io, char_type __fill, 
00772         const char_type* __ws, int __len) const;
00773 
00774       virtual 
00775       ~num_put() { };
00776 
00777       virtual iter_type 
00778       do_put(iter_type, ios_base&, char_type __fill, bool __v) const;
00779 
00780       virtual iter_type 
00781       do_put(iter_type, ios_base&, char_type __fill, long __v) const;
00782 
00783       virtual iter_type 
00784       do_put(iter_type, ios_base&, char_type __fill, unsigned long) const;
00785 
00786 #ifdef _GLIBCPP_USE_LONG_LONG 
00787       virtual iter_type 
00788       do_put(iter_type, ios_base&, char_type __fill, long long __v) const;
00789 
00790       virtual iter_type
00791       do_put(iter_type, ios_base&, char_type __fill, unsigned long long) const;
00792 #endif
00793 
00794       virtual iter_type 
00795       do_put(iter_type, ios_base&, char_type __fill, double __v) const;
00796 
00797       virtual iter_type 
00798       do_put(iter_type, ios_base&, char_type __fill, long double __v) const;
00799 
00800       virtual iter_type 
00801       do_put(iter_type, ios_base&, char_type __fill, const void* __v) const;
00802     };
00803 
00804   template <typename _CharT, typename _OutIter>
00805     locale::id num_put<_CharT, _OutIter>::id;
00806 
00807 
00808   template<typename _CharT>
00809     class collate : public locale::facet
00810     {
00811     public:
00812       // Types:
00813       typedef _CharT                char_type;
00814       typedef basic_string<_CharT>  string_type;
00815 
00816     protected:
00817       // Underlying "C" library locale information saved from
00818       // initialization, needed by collate_byname as well.
00819       __c_locale            _M_c_locale_collate;
00820  
00821     public:
00822       static locale::id         id;
00823 
00824       explicit 
00825       collate(size_t __refs = 0)
00826       : locale::facet(__refs)
00827       { _M_c_locale_collate = _S_c_locale; }
00828 
00829       // Non-standard.
00830       explicit 
00831       collate(__c_locale __cloc, size_t __refs = 0) 
00832       : locale::facet(__refs)
00833       { _M_c_locale_collate = _S_clone_c_locale(__cloc); }
00834 
00835       int 
00836       compare(const _CharT* __lo1, const _CharT* __hi1,
00837           const _CharT* __lo2, const _CharT* __hi2) const
00838       { return this->do_compare(__lo1, __hi1, __lo2, __hi2); }
00839 
00840       string_type 
00841       transform(const _CharT* __lo, const _CharT* __hi) const
00842       { return this->do_transform(__lo, __hi); }
00843 
00844       long 
00845       hash(const _CharT* __lo, const _CharT* __hi) const
00846       { return this->do_hash(__lo, __hi); }
00847       
00848       // Used to abstract out _CharT bits in virtual member functions, below.
00849       int
00850       _M_compare(const _CharT*, const _CharT*) const;
00851 
00852       size_t
00853       _M_transform(_CharT*, const _CharT*, size_t) const;
00854 
00855   protected:
00856       virtual
00857       ~collate() 
00858       {
00859     if (_M_c_locale_collate != _S_c_locale)
00860       _S_destroy_c_locale(_M_c_locale_collate); 
00861       }
00862 
00863       virtual int  
00864       do_compare(const _CharT* __lo1, const _CharT* __hi1,
00865          const _CharT* __lo2, const _CharT* __hi2) const;
00866 
00867       virtual string_type 
00868       do_transform(const _CharT* __lo, const _CharT* __hi) const;
00869 
00870       virtual long   
00871       do_hash(const _CharT* __lo, const _CharT* __hi) const;
00872     };
00873 
00874   template<typename _CharT>
00875     locale::id collate<_CharT>::id;
00876 
00877   // Specializations.
00878   template<>
00879     int 
00880     collate<char>::_M_compare(const char*, const char*) const;
00881 
00882   template<>
00883     size_t
00884     collate<char>::_M_transform(char*, const char*, size_t) const;
00885 
00886 #ifdef _GLIBCPP_USE_WCHAR_T
00887   template<>
00888     int 
00889     collate<wchar_t>::_M_compare(const wchar_t*, const wchar_t*) const;
00890 
00891   template<>
00892     size_t
00893     collate<wchar_t>::_M_transform(wchar_t*, const wchar_t*, size_t) const;
00894 #endif
00895 
00896   template<typename _CharT>
00897     class collate_byname : public collate<_CharT>
00898     {
00899     public:
00900       typedef _CharT               char_type;
00901       typedef basic_string<_CharT> string_type;
00902 
00903       explicit 
00904       collate_byname(const char* __s, size_t __refs = 0)
00905       : collate<_CharT>(__refs) 
00906       { 
00907     if (_M_c_locale_collate != _S_c_locale)
00908       _S_destroy_c_locale(_M_c_locale_collate);
00909     _S_create_c_locale(_M_c_locale_collate, __s); 
00910       }
00911 
00912     protected:
00913       virtual   
00914       ~collate_byname() { }
00915     };
00916 
00917 
00918   class time_base
00919   {
00920   public:
00921     enum dateorder { no_order, dmy, mdy, ymd, ydm };
00922   };
00923 
00924   template<typename _CharT>
00925     class __timepunct : public locale::facet
00926     {
00927     public:
00928       // Types:
00929       typedef _CharT                __char_type;
00930       typedef basic_string<_CharT>  __string_type;
00931 
00932       static locale::id         id;
00933 
00934       // List of all known timezones, with GMT first.
00935       static const _CharT*      _S_timezones[14];
00936 
00937     protected:
00938       __c_locale            _M_c_locale_timepunct;
00939       const char*           _M_name_timepunct;
00940       const _CharT*             _M_date_format;
00941       const _CharT*             _M_date_era_format;
00942       const _CharT*             _M_time_format;
00943       const _CharT*             _M_time_era_format;
00944       const _CharT*         _M_date_time_format;
00945       const _CharT*         _M_date_time_era_format;
00946       const _CharT*             _M_am;
00947       const _CharT*             _M_pm;
00948       const _CharT*         _M_am_pm_format;
00949 
00950       // Day names, starting with "C"'s Sunday.
00951       const _CharT*             _M_day1;
00952       const _CharT*             _M_day2;
00953       const _CharT*             _M_day3;
00954       const _CharT*             _M_day4;
00955       const _CharT*             _M_day5;
00956       const _CharT*             _M_day6;
00957       const _CharT*             _M_day7;
00958 
00959       // Abbreviated day names, starting with "C"'s Sun.
00960       const _CharT*             _M_day_a1;
00961       const _CharT*             _M_day_a2;
00962       const _CharT*             _M_day_a3;
00963       const _CharT*             _M_day_a4;
00964       const _CharT*             _M_day_a5;
00965       const _CharT*             _M_day_a6;
00966       const _CharT*             _M_day_a7;
00967 
00968       // Month names, starting with "C"'s January.
00969       const _CharT*             _M_month01;
00970       const _CharT*             _M_month02;
00971       const _CharT*             _M_month03;
00972       const _CharT*             _M_month04;
00973       const _CharT*             _M_month05;
00974       const _CharT*             _M_month06;
00975       const _CharT*             _M_month07;
00976       const _CharT*             _M_month08;
00977       const _CharT*             _M_month09;
00978       const _CharT*             _M_month10;
00979       const _CharT*             _M_month11;
00980       const _CharT*             _M_month12;
00981 
00982       // Abbreviated month names, starting with "C"'s Jan.
00983       const _CharT*             _M_month_a01;
00984       const _CharT*             _M_month_a02;
00985       const _CharT*             _M_month_a03;
00986       const _CharT*             _M_month_a04;
00987       const _CharT*             _M_month_a05;
00988       const _CharT*             _M_month_a06;
00989       const _CharT*             _M_month_a07;
00990       const _CharT*             _M_month_a08;
00991       const _CharT*             _M_month_a09;
00992       const _CharT*             _M_month_a10;
00993       const _CharT*             _M_month_a11;
00994       const _CharT*             _M_month_a12;
00995 
00996     public:
00997       explicit 
00998       __timepunct(size_t __refs = 0) 
00999       : locale::facet(__refs), _M_name_timepunct("C")
01000       { _M_initialize_timepunct(); }
01001 
01002       explicit 
01003       __timepunct(__c_locale __cloc, const char* __s, size_t __refs = 0) 
01004       : locale::facet(__refs), _M_name_timepunct(__s)
01005       { _M_initialize_timepunct(__cloc); }
01006 
01007       void
01008       _M_put(_CharT* __s, size_t __maxlen, const _CharT* __format, 
01009          const tm* __tm) const;
01010 
01011       void
01012       _M_date_formats(const _CharT** __date) const
01013       {
01014     // Always have default first.
01015     __date[0] = _M_date_format;
01016     __date[1] = _M_date_era_format; 
01017       }
01018 
01019       void
01020       _M_time_formats(const _CharT** __time) const
01021       {
01022     // Always have default first.
01023     __time[0] = _M_time_format;
01024     __time[1] = _M_time_era_format; 
01025       }
01026 
01027       void
01028       _M_ampm(const _CharT** __ampm) const
01029       { 
01030     __ampm[0] = _M_am;
01031     __ampm[1] = _M_pm;
01032       }      
01033 
01034       void
01035       _M_date_time_formats(const _CharT** __dt) const
01036       {
01037     // Always have default first.
01038     __dt[0] = _M_date_time_format;
01039     __dt[1] = _M_date_time_era_format;  
01040       }
01041 
01042       void
01043       _M_days(const _CharT** __days) const
01044       { 
01045     __days[0] = _M_day1;
01046     __days[1] = _M_day2;
01047     __days[2] = _M_day3;
01048     __days[3] = _M_day4;
01049     __days[4] = _M_day5;
01050     __days[5] = _M_day6;
01051     __days[6] = _M_day7;
01052       }
01053 
01054       void
01055       _M_days_abbreviated(const _CharT** __days) const
01056       { 
01057     __days[0] = _M_day_a1;
01058     __days[1] = _M_day_a2;
01059     __days[2] = _M_day_a3;
01060     __days[3] = _M_day_a4;
01061     __days[4] = _M_day_a5;
01062     __days[5] = _M_day_a6;
01063     __days[6] = _M_day_a7;
01064       }
01065 
01066       void
01067       _M_months(const _CharT** __months) const
01068       { 
01069     __months[0] = _M_month01;
01070     __months[1] = _M_month02;
01071     __months[2] = _M_month03;
01072     __months[3] = _M_month04;
01073     __months[4] = _M_month05;
01074     __months[5] = _M_month06;
01075     __months[6] = _M_month07;
01076     __months[7] = _M_month08;
01077     __months[8] = _M_month09;
01078     __months[9] = _M_month10;
01079     __months[10] = _M_month11;
01080     __months[11] = _M_month12;
01081       }
01082 
01083       void
01084       _M_months_abbreviated(const _CharT** __months) const
01085       { 
01086     __months[0] = _M_month_a01;
01087     __months[1] = _M_month_a02;
01088     __months[2] = _M_month_a03;
01089     __months[3] = _M_month_a04;
01090     __months[4] = _M_month_a05;
01091     __months[5] = _M_month_a06;
01092     __months[6] = _M_month_a07;
01093     __months[7] = _M_month_a08;
01094     __months[8] = _M_month_a09;
01095     __months[9] = _M_month_a10;
01096     __months[10] = _M_month_a11;
01097     __months[11] = _M_month_a12;
01098       }
01099 
01100     protected:
01101       virtual 
01102       ~__timepunct();
01103 
01104       // For use at construction time only.
01105       void 
01106       _M_initialize_timepunct(__c_locale __cloc = _S_c_locale);
01107     };
01108 
01109   template<typename _CharT>
01110     locale::id __timepunct<_CharT>::id;
01111 
01112   // Specializations.
01113   template<>
01114     __timepunct<char>::~__timepunct();
01115 
01116   template<> 
01117     const char*
01118     __timepunct<char>::_S_timezones[14];
01119 
01120   template<> 
01121     void
01122     __timepunct<char>::_M_initialize_timepunct(__c_locale __cloc);
01123 
01124   template<>
01125     void
01126     __timepunct<char>::_M_put(char*, size_t, const char*, const tm*) const;
01127 
01128 #ifdef _GLIBCPP_USE_WCHAR_T
01129   template<>
01130     __timepunct<wchar_t>::~__timepunct();
01131 
01132   template<> 
01133     const wchar_t*
01134     __timepunct<wchar_t>::_S_timezones[14];
01135 
01136   template<> 
01137     void
01138     __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale __cloc);
01139 
01140   template<>
01141     void
01142     __timepunct<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*, 
01143                  const tm*) const;
01144 #endif
01145 
01146   // Generic.
01147   template<typename _CharT>
01148     const _CharT* __timepunct<_CharT>::_S_timezones[14];
01149 
01150 
01151   template<typename _CharT, typename _InIter>
01152     class time_get : public locale::facet, public time_base
01153     {
01154     public:
01155       // Types:
01156       typedef _CharT            char_type;
01157       typedef _InIter           iter_type;
01158       typedef basic_string<_CharT>  __string_type;
01159 
01160       static locale::id         id;
01161 
01162       explicit 
01163       time_get(size_t __refs = 0) 
01164       : locale::facet (__refs) { }
01165 
01166       dateorder 
01167       date_order()  const
01168       { return this->do_date_order(); }
01169 
01170       iter_type 
01171       get_time(iter_type __beg, iter_type __end, ios_base& __io, 
01172            ios_base::iostate& __err, tm* __tm)  const
01173       { return this->do_get_time(__beg, __end, __io, __err, __tm); }
01174 
01175       iter_type 
01176       get_date(iter_type __beg, iter_type __end, ios_base& __io,
01177            ios_base::iostate& __err, tm* __tm)  const
01178       { return this->do_get_date(__beg, __end, __io, __err, __tm); }
01179 
01180       iter_type 
01181       get_weekday(iter_type __beg, iter_type __end, ios_base& __io,
01182           ios_base::iostate& __err, tm* __tm) const
01183       { return this->do_get_weekday(__beg, __end, __io, __err, __tm); }
01184 
01185       iter_type 
01186       get_monthname(iter_type __beg, iter_type __end, ios_base& __io, 
01187             ios_base::iostate& __err, tm* __tm) const
01188       { return this->do_get_monthname(__beg, __end, __io, __err, __tm); }
01189 
01190       iter_type 
01191       get_year(iter_type __beg, iter_type __end, ios_base& __io,
01192            ios_base::iostate& __err, tm* __tm) const
01193       { return this->do_get_year(__beg, __end, __io, __err, __tm); }
01194 
01195     protected:
01196       virtual 
01197       ~time_get() { }
01198 
01199       virtual dateorder 
01200       do_date_order() const;
01201 
01202       virtual iter_type 
01203       do_get_time(iter_type __beg, iter_type __end, ios_base& __io,
01204           ios_base::iostate& __err, tm* __tm) const;
01205 
01206       virtual iter_type 
01207       do_get_date(iter_type __beg, iter_type __end, ios_base& __io,
01208           ios_base::iostate& __err, tm* __tm) const;
01209 
01210       virtual iter_type 
01211       do_get_weekday(iter_type __beg, iter_type __end, ios_base&,
01212              ios_base::iostate& __err, tm* __tm) const;
01213 
01214       virtual iter_type 
01215       do_get_monthname(iter_type __beg, iter_type __end, ios_base&, 
01216                ios_base::iostate& __err, tm* __tm) const;
01217 
01218       virtual iter_type 
01219       do_get_year(iter_type __beg, iter_type __end, ios_base& __io,
01220           ios_base::iostate& __err, tm* __tm) const;
01221 
01222       // Extract numeric component of length __len.
01223       void
01224       _M_extract_num(iter_type& __beg, iter_type& __end, int& __member,
01225              int __min, int __max, size_t __len,
01226              const ctype<_CharT>& __ctype, 
01227              ios_base::iostate& __err) const;
01228       
01229       // Extract day or month name, or any unique array of string
01230       // literals in a const _CharT* array.
01231       void
01232       _M_extract_name(iter_type& __beg, iter_type& __end, int& __member,
01233               const _CharT** __names, size_t __indexlen, 
01234               ios_base::iostate& __err) const;
01235 
01236       // Extract on a component-by-component basis, via __format argument.
01237       void
01238       _M_extract_via_format(iter_type& __beg, iter_type& __end, ios_base& __io,
01239                 ios_base::iostate& __err, tm* __tm, 
01240                 const _CharT* __format) const;
01241     };
01242 
01243   template<typename _CharT, typename _InIter>
01244     locale::id time_get<_CharT, _InIter>::id;
01245 
01246   template<typename _CharT, typename _InIter>
01247     class time_get_byname : public time_get<_CharT, _InIter>
01248     {
01249     public:
01250       // Types:
01251       typedef _CharT            char_type;
01252       typedef _InIter           iter_type;
01253 
01254       explicit 
01255       time_get_byname(const char*, size_t __refs = 0) 
01256       : time_get<_CharT, _InIter>(__refs) { }
01257 
01258     protected:
01259       virtual 
01260       ~time_get_byname() { }
01261     };
01262 
01263   template<typename _CharT, typename _OutIter>
01264     class time_put : public locale::facet, public time_base
01265     {
01266     public:
01267       // Types:
01268       typedef _CharT            char_type;
01269       typedef _OutIter          iter_type;
01270 
01271       static locale::id             id;
01272 
01273       explicit 
01274       time_put(size_t __refs = 0) 
01275       : locale::facet(__refs) { }
01276 
01277       iter_type 
01278       put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm, 
01279       const _CharT* __beg, const _CharT* __end) const;
01280 
01281       iter_type 
01282       put(iter_type __s, ios_base& __io, char_type __fill,
01283       const tm* __tm, char __format, char __mod = 0) const
01284       { return this->do_put(__s, __io, __fill, __tm, __format, __mod); }
01285 
01286     protected:
01287       virtual 
01288       ~time_put()
01289       { }
01290 
01291       virtual iter_type 
01292       do_put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm, 
01293          char __format, char __mod) const;
01294     };
01295 
01296   template<typename _CharT, typename _OutIter>
01297     locale::id time_put<_CharT, _OutIter>::id;
01298 
01299   template<typename _CharT, typename _OutIter>
01300     class time_put_byname : public time_put<_CharT, _OutIter>
01301     {
01302     public:
01303       // Types:
01304       typedef _CharT            char_type;
01305       typedef _OutIter          iter_type;
01306 
01307       explicit 
01308       time_put_byname(const char* /*__s*/, size_t __refs = 0) 
01309       : time_put<_CharT, _OutIter>(__refs) 
01310       { };
01311 
01312     protected:
01313       virtual 
01314       ~time_put_byname() { }
01315     };
01316 
01317 
01318   class money_base
01319   {
01320   public:
01321     enum part { none, space, symbol, sign, value };
01322     struct pattern { char field[4]; };
01323 
01324     static const pattern _S_default_pattern;
01325 
01326     // Construct and return valid pattern consisting of some combination of:
01327     // space none symbol sign value
01328     static pattern 
01329     _S_construct_pattern(char __precedes, char __space, char __posn);
01330   };
01331 
01332   template<typename _CharT, bool _Intl>
01333     class moneypunct : public locale::facet, public money_base
01334     {
01335     public:
01336       // Types:
01337       typedef _CharT            char_type;
01338       typedef basic_string<_CharT>  string_type;
01339 
01340       static const bool         intl = _Intl;
01341       static locale::id         id;
01342 
01343     private:
01344       const char*           _M_grouping;
01345       char_type             _M_decimal_point;
01346       char_type             _M_thousands_sep;
01347       const char_type*          _M_curr_symbol;
01348       const char_type*          _M_positive_sign;
01349       const char_type*          _M_negative_sign;
01350       int               _M_frac_digits;
01351       pattern               _M_pos_format;
01352       pattern               _M_neg_format;
01353 
01354     public:
01355       explicit 
01356       moneypunct(size_t __refs = 0) : locale::facet(__refs)
01357       { _M_initialize_moneypunct(); }
01358 
01359       explicit 
01360       moneypunct(__c_locale __cloc, size_t __refs = 0) : locale::facet(__refs)
01361       { _M_initialize_moneypunct(__cloc); }
01362 
01363       char_type
01364       decimal_point() const
01365       { return this->do_decimal_point(); }
01366       
01367       char_type
01368       thousands_sep() const
01369       { return this->do_thousands_sep(); }
01370       
01371       string 
01372       grouping() const
01373       { return this->do_grouping(); }
01374 
01375       string_type  
01376       curr_symbol() const
01377       { return this->do_curr_symbol(); }
01378 
01379       string_type  
01380       positive_sign() const
01381       { return this->do_positive_sign(); }
01382 
01383       string_type  
01384       negative_sign() const
01385       { return this->do_negative_sign(); }
01386 
01387       int          
01388       frac_digits() const
01389       { return this->do_frac_digits(); }
01390 
01391       pattern      
01392       pos_format() const
01393       { return this->do_pos_format(); }
01394 
01395       pattern      
01396       neg_format() const
01397       { return this->do_neg_format(); }
01398 
01399     protected:
01400       virtual 
01401       ~moneypunct();
01402 
01403       virtual char_type
01404       do_decimal_point() const
01405       { return _M_decimal_point; }
01406       
01407       virtual char_type
01408       do_thousands_sep() const
01409       { return _M_thousands_sep; }
01410       
01411       virtual string 
01412       do_grouping() const
01413       { return _M_grouping; }
01414 
01415       virtual string_type  
01416       do_curr_symbol()   const
01417       { return _M_curr_symbol; }
01418 
01419       virtual string_type  
01420       do_positive_sign() const
01421       { return _M_positive_sign; }
01422 
01423       virtual string_type  
01424       do_negative_sign() const
01425       { return _M_negative_sign; }
01426 
01427       virtual int          
01428       do_frac_digits() const
01429       { return _M_frac_digits; }
01430 
01431       virtual pattern      
01432       do_pos_format() const
01433       { return _M_pos_format; }
01434 
01435       virtual pattern      
01436       do_neg_format() const
01437       { return _M_neg_format; }
01438 
01439       // For use at construction time only.
01440        void 
01441        _M_initialize_moneypunct(__c_locale __cloc = _S_c_locale);
01442     };
01443 
01444   template<typename _CharT, bool _Intl>
01445     locale::id moneypunct<_CharT, _Intl>::id;
01446 
01447   template<typename _CharT, bool _Intl>
01448     const bool moneypunct<_CharT, _Intl>::intl;
01449 
01450   template<>
01451     moneypunct<char, true>::~moneypunct();
01452 
01453   template<>
01454     moneypunct<char, false>::~moneypunct();
01455 
01456   template<> 
01457     void
01458     moneypunct<char, true>::_M_initialize_moneypunct(__c_locale __cloc);
01459 
01460   template<> 
01461     void
01462     moneypunct<char, false>::_M_initialize_moneypunct(__c_locale __cloc);
01463 
01464 #ifdef _GLIBCPP_USE_WCHAR_T
01465   template<>
01466     moneypunct<wchar_t, true>::~moneypunct();
01467 
01468   template<>
01469     moneypunct<wchar_t, false>::~moneypunct();
01470 
01471   template<> 
01472     void
01473     moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale __cloc);
01474 
01475   template<> 
01476     void
01477     moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale __cloc);
01478 #endif
01479 
01480   template<typename _CharT, bool _Intl>
01481     class moneypunct_byname : public moneypunct<_CharT, _Intl>
01482     {
01483       __c_locale            _M_c_locale_moneypunct;
01484 
01485     public:
01486       typedef _CharT            char_type;
01487       typedef basic_string<_CharT>  string_type;
01488 
01489       static const bool intl = _Intl;
01490 
01491       explicit 
01492       moneypunct_byname(const char* __s, size_t __refs = 0)
01493       : moneypunct<_CharT, _Intl>(__refs)
01494       {
01495     _S_create_c_locale(_M_c_locale_moneypunct, __s);
01496     _M_initialize_moneypunct(_M_c_locale_moneypunct);   
01497       }
01498 
01499     protected:
01500       virtual 
01501       ~moneypunct_byname() 
01502       { _S_destroy_c_locale(_M_c_locale_moneypunct); }
01503     };
01504 
01505   template<typename _CharT, bool _Intl>
01506     const bool moneypunct_byname<_CharT, _Intl>::intl;
01507 
01508   template<typename _CharT, typename _InIter>
01509     class money_get : public locale::facet
01510     {
01511     public:
01512       // Types:
01513       typedef _CharT                char_type;
01514       typedef _InIter               iter_type;
01515       typedef basic_string<_CharT>  string_type;
01516 
01517       static locale::id         id;
01518 
01519       explicit 
01520       money_get(size_t __refs = 0) : locale::facet(__refs) { }
01521 
01522       iter_type 
01523       get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 
01524       ios_base::iostate& __err, long double& __units) const
01525       { return this->do_get(__s, __end, __intl, __io, __err, __units); }
01526 
01527       iter_type 
01528       get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 
01529       ios_base::iostate& __err, string_type& __digits) const
01530       { return this->do_get(__s, __end, __intl, __io, __err, __digits); }
01531 
01532     protected:
01533       virtual 
01534       ~money_get() { }
01535 
01536       virtual iter_type 
01537       do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 
01538          ios_base::iostate& __err, long double& __units) const;
01539 
01540       virtual iter_type 
01541       do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 
01542          ios_base::iostate& __err, string_type& __digits) const;
01543     };
01544 
01545   template<typename _CharT, typename _InIter>
01546     locale::id money_get<_CharT, _InIter>::id;
01547 
01548   template<typename _CharT, typename _OutIter>
01549     class money_put : public locale::facet
01550     {
01551     public:
01552       typedef _CharT                char_type;
01553       typedef _OutIter              iter_type;
01554       typedef basic_string<_CharT>  string_type;
01555 
01556       static locale::id         id;
01557 
01558       explicit 
01559       money_put(size_t __refs = 0) : locale::facet(__refs) { }
01560 
01561       iter_type 
01562       put(iter_type __s, bool __intl, ios_base& __io,
01563       char_type __fill, long double __units) const
01564       { return this->do_put(__s, __intl, __io, __fill, __units); }
01565 
01566       iter_type 
01567       put(iter_type __s, bool __intl, ios_base& __io,
01568       char_type __fill, const string_type& __digits) const
01569       { return this->do_put(__s, __intl, __io, __fill, __digits); }
01570 
01571     protected:
01572       virtual 
01573       ~money_put() { }
01574 
01575       virtual iter_type
01576       do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
01577          long double __units) const;
01578 
01579       virtual iter_type
01580       do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
01581          const string_type& __digits) const;
01582     };
01583 
01584   template<typename _CharT, typename _OutIter>
01585     locale::id money_put<_CharT, _OutIter>::id;
01586 
01587 
01588   struct messages_base
01589   {
01590     typedef int catalog;
01591   };
01592 
01593   template<typename _CharT>
01594     class messages : public locale::facet, public messages_base
01595     {
01596     public:
01597       // Types:
01598       typedef _CharT            char_type;
01599       typedef basic_string<_CharT>  string_type;
01600 
01601     protected:
01602       // Underlying "C" library locale information saved from
01603       // initialization, needed by messages_byname as well.
01604       __c_locale            _M_c_locale_messages;
01605 #if 1
01606       // Only needed if glibc < 2.3
01607       const char*           _M_name_messages;
01608 #endif
01609 
01610     public:
01611       static locale::id         id;
01612 
01613       explicit 
01614       messages(size_t __refs = 0) 
01615       : locale::facet(__refs), _M_name_messages("C")
01616       { _M_c_locale_messages = _S_c_locale; }
01617 
01618       // Non-standard.
01619       explicit 
01620       messages(__c_locale __cloc, const char* __name, size_t __refs = 0) 
01621       : locale::facet(__refs)
01622       { 
01623     _M_name_messages = __name;
01624     _M_c_locale_messages = _S_clone_c_locale(__cloc); 
01625       }
01626 
01627       catalog 
01628       open(const basic_string<char>& __s, const locale& __loc) const
01629       { return this->do_open(__s, __loc); }
01630 
01631       // Non-standard and unorthodox, yet effective.
01632       catalog 
01633       open(const basic_string<char>&, const locale&, const char*) const;
01634 
01635       string_type  
01636       get(catalog __c, int __set, int __msgid, const string_type& __s) const
01637       { return this->do_get(__c, __set, __msgid, __s); }
01638 
01639       void 
01640       close(catalog __c) const
01641       { return this->do_close(__c); }
01642 
01643     protected:
01644       virtual 
01645       ~messages()
01646        { 
01647      if (_M_c_locale_messages != _S_c_locale)
01648        _S_destroy_c_locale(_M_c_locale_messages); 
01649        }
01650 
01651       virtual catalog 
01652       do_open(const basic_string<char>&, const locale&) const;
01653 
01654       virtual string_type  
01655       do_get(catalog, int, int, const string_type& __dfault) const;
01656 
01657       virtual void    
01658       do_close(catalog) const;
01659 
01660       // Returns a locale and codeset-converted string, given a char* message.
01661       char*
01662       _M_convert_to_char(const string_type& __msg) const
01663       {
01664     // XXX
01665     return reinterpret_cast<char*>(const_cast<_CharT*>(__msg.c_str()));
01666       }
01667 
01668       // Returns a locale and codeset-converted string, given a char* message.
01669       string_type
01670       _M_convert_from_char(char* __msg) const
01671       {
01672     // Length of message string without terminating null.
01673     size_t __len = char_traits<char>::length(__msg) - 1;
01674 
01675     // "everybody can easily convert the string using
01676     // mbsrtowcs/wcsrtombs or with iconv()"
01677 #if 0
01678     // Convert char* to _CharT in locale used to open catalog.
01679     // XXX need additional template parameter on messages class for this..
01680     // typedef typename codecvt<char, _CharT, _StateT> __codecvt_type;
01681     typedef typename codecvt<char, _CharT, mbstate_t> __codecvt_type;      
01682 
01683     __codecvt_type::state_type __state;
01684     // XXX may need to initialize state.
01685     //initialize_state(__state._M_init());
01686     
01687     char* __from_next;
01688     // XXX what size for this string?
01689     _CharT* __to = static_cast<_CharT*>(__builtin_alloca(__len + 1));
01690     const __codecvt_type& __cvt = use_facet<__codecvt_type>(_M_locale_conv);
01691     __cvt.out(__state, __msg, __msg + __len, __from_next,
01692           __to, __to + __len + 1, __to_next);
01693     return string_type(__to);
01694 #endif
01695 #if 0
01696     typedef ctype<_CharT> __ctype_type;
01697     // const __ctype_type& __cvt = use_facet<__ctype_type>(_M_locale_msg);
01698     const __ctype_type& __cvt = use_facet<__ctype_type>(locale());
01699     // XXX Again, proper length of converted string an issue here.
01700     // For now, assume the converted length is not larger.
01701     _CharT* __dest = static_cast<_CharT*>(__builtin_alloca(__len + 1));
01702     __cvt.widen(__msg, __msg + __len, __dest);
01703     return basic_string<_CharT>(__dest);
01704 #endif
01705     return string_type();
01706       }
01707      };
01708 
01709   template<typename _CharT>
01710     locale::id messages<_CharT>::id;
01711 
01712   // Specializations for required instantiations.
01713   template<>
01714     string
01715     messages<char>::do_get(catalog, int, int, const string&) const;
01716 
01717   // Include host and configuration specific messages virtual functions.
01718   #include <bits/messages_members.h>
01719 
01720   template<typename _CharT>
01721     class messages_byname : public messages<_CharT>
01722     {
01723     public:
01724       typedef _CharT                char_type;
01725       typedef basic_string<_CharT>  string_type;
01726 
01727       explicit 
01728       messages_byname(const char* __s, size_t __refs = 0)
01729       : messages<_CharT>(__refs) 
01730       { 
01731     _M_name_messages = __s;
01732     if (_M_c_locale_messages != _S_c_locale)
01733       _S_destroy_c_locale(_M_c_locale_messages);
01734     _S_create_c_locale(_M_c_locale_messages, __s); 
01735       }
01736 
01737     protected:
01738       virtual 
01739       ~messages_byname() 
01740       { }
01741     };
01742 
01743 
01744   // Subclause convenience interfaces, inlines.
01745   // NB: These are inline because, when used in a loop, some compilers
01746   // can hoist the body out of the loop; then it's just as fast as the
01747   // C is*() function.
01748   template<typename _CharT>
01749     inline bool 
01750     isspace(_CharT __c, const locale& __loc)
01751     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); }
01752 
01753   template<typename _CharT>
01754     inline bool 
01755     isprint(_CharT __c, const locale& __loc)
01756     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); }
01757 
01758   template<typename _CharT>
01759     inline bool 
01760     iscntrl(_CharT __c, const locale& __loc)
01761     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); }
01762 
01763   template<typename _CharT>
01764     inline bool 
01765     isupper(_CharT __c, const locale& __loc)
01766     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); }
01767 
01768   template<typename _CharT>
01769     inline bool islower(_CharT __c, const locale& __loc)
01770     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); }
01771 
01772   template<typename _CharT>
01773     inline bool 
01774     isalpha(_CharT __c, const locale& __loc)
01775     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); }
01776 
01777   template<typename _CharT>
01778     inline bool 
01779     isdigit(_CharT __c, const locale& __loc)
01780     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); }
01781 
01782   template<typename _CharT>
01783     inline bool 
01784     ispunct(_CharT __c, const locale& __loc)
01785     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); }
01786 
01787   template<typename _CharT>
01788     inline bool 
01789     isxdigit(_CharT __c, const locale& __loc)
01790     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); }
01791 
01792   template<typename _CharT>
01793     inline bool 
01794     isalnum(_CharT __c, const locale& __loc)
01795     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); }
01796 
01797   template<typename _CharT>
01798     inline bool 
01799     isgraph(_CharT __c, const locale& __loc)
01800     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); }
01801 
01802   template<typename _CharT>
01803     inline _CharT 
01804     toupper(_CharT __c, const locale& __loc)
01805     { return use_facet<ctype<_CharT> >(__loc).toupper(__c); }
01806 
01807   template<typename _CharT>
01808     inline _CharT 
01809     tolower(_CharT __c, const locale& __loc)
01810     { return use_facet<ctype<_CharT> >(__loc).tolower(__c); }
01811 } // namespace std
01812 
01813 #endif

Generated on Wed May 1 19:19:32 2002 for libstdc++-v3 Source by doxygen1.2.15