locale_facets.h

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

Generated on Wed Aug 4 21:43:13 2004 for libstdc++-v3 Source by doxygen 1.3.8