00001 // Locale support -*- C++ -*- 00002 00003 // Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file locale_facets_nonio.h 00026 * This is an internal header file, included by other library headers. 00027 * You should not attempt to use it directly. 00028 */ 00029 00030 // 00031 // ISO C++ 14882: 22.1 Locales 00032 // 00033 00034 #ifndef _LOCALE_FACETS_NONIO_H 00035 #define _LOCALE_FACETS_NONIO_H 1 00036 00037 #pragma GCC system_header 00038 00039 #include <ctime> // For struct tm 00040 00041 _GLIBCXX_BEGIN_NAMESPACE(std) 00042 00043 /** 00044 * @brief Time format ordering data. 00045 * @ingroup locales 00046 * 00047 * This class provides an enum representing different orderings of 00048 * time: day, month, and year. 00049 */ 00050 class time_base 00051 { 00052 public: 00053 enum dateorder { no_order, dmy, mdy, ymd, ydm }; 00054 }; 00055 00056 template<typename _CharT> 00057 struct __timepunct_cache : public locale::facet 00058 { 00059 // List of all known timezones, with GMT first. 00060 static const _CharT* _S_timezones[14]; 00061 00062 const _CharT* _M_date_format; 00063 const _CharT* _M_date_era_format; 00064 const _CharT* _M_time_format; 00065 const _CharT* _M_time_era_format; 00066 const _CharT* _M_date_time_format; 00067 const _CharT* _M_date_time_era_format; 00068 const _CharT* _M_am; 00069 const _CharT* _M_pm; 00070 const _CharT* _M_am_pm_format; 00071 00072 // Day names, starting with "C"'s Sunday. 00073 const _CharT* _M_day1; 00074 const _CharT* _M_day2; 00075 const _CharT* _M_day3; 00076 const _CharT* _M_day4; 00077 const _CharT* _M_day5; 00078 const _CharT* _M_day6; 00079 const _CharT* _M_day7; 00080 00081 // Abbreviated day names, starting with "C"'s Sun. 00082 const _CharT* _M_aday1; 00083 const _CharT* _M_aday2; 00084 const _CharT* _M_aday3; 00085 const _CharT* _M_aday4; 00086 const _CharT* _M_aday5; 00087 const _CharT* _M_aday6; 00088 const _CharT* _M_aday7; 00089 00090 // Month names, starting with "C"'s January. 00091 const _CharT* _M_month01; 00092 const _CharT* _M_month02; 00093 const _CharT* _M_month03; 00094 const _CharT* _M_month04; 00095 const _CharT* _M_month05; 00096 const _CharT* _M_month06; 00097 const _CharT* _M_month07; 00098 const _CharT* _M_month08; 00099 const _CharT* _M_month09; 00100 const _CharT* _M_month10; 00101 const _CharT* _M_month11; 00102 const _CharT* _M_month12; 00103 00104 // Abbreviated month names, starting with "C"'s Jan. 00105 const _CharT* _M_amonth01; 00106 const _CharT* _M_amonth02; 00107 const _CharT* _M_amonth03; 00108 const _CharT* _M_amonth04; 00109 const _CharT* _M_amonth05; 00110 const _CharT* _M_amonth06; 00111 const _CharT* _M_amonth07; 00112 const _CharT* _M_amonth08; 00113 const _CharT* _M_amonth09; 00114 const _CharT* _M_amonth10; 00115 const _CharT* _M_amonth11; 00116 const _CharT* _M_amonth12; 00117 00118 bool _M_allocated; 00119 00120 __timepunct_cache(size_t __refs = 0) : facet(__refs), 00121 _M_date_format(0), _M_date_era_format(0), _M_time_format(0), 00122 _M_time_era_format(0), _M_date_time_format(0), 00123 _M_date_time_era_format(0), _M_am(0), _M_pm(0), 00124 _M_am_pm_format(0), _M_day1(0), _M_day2(0), _M_day3(0), 00125 _M_day4(0), _M_day5(0), _M_day6(0), _M_day7(0), 00126 _M_aday1(0), _M_aday2(0), _M_aday3(0), _M_aday4(0), 00127 _M_aday5(0), _M_aday6(0), _M_aday7(0), _M_month01(0), 00128 _M_month02(0), _M_month03(0), _M_month04(0), _M_month05(0), 00129 _M_month06(0), _M_month07(0), _M_month08(0), _M_month09(0), 00130 _M_month10(0), _M_month11(0), _M_month12(0), _M_amonth01(0), 00131 _M_amonth02(0), _M_amonth03(0), _M_amonth04(0), 00132 _M_amonth05(0), _M_amonth06(0), _M_amonth07(0), 00133 _M_amonth08(0), _M_amonth09(0), _M_amonth10(0), 00134 _M_amonth11(0), _M_amonth12(0), _M_allocated(false) 00135 { } 00136 00137 ~__timepunct_cache(); 00138 00139 void 00140 _M_cache(const locale& __loc); 00141 00142 private: 00143 __timepunct_cache& 00144 operator=(const __timepunct_cache&); 00145 00146 explicit 00147 __timepunct_cache(const __timepunct_cache&); 00148 }; 00149 00150 template<typename _CharT> 00151 __timepunct_cache<_CharT>::~__timepunct_cache() 00152 { 00153 if (_M_allocated) 00154 { 00155 // Unused. 00156 } 00157 } 00158 00159 // Specializations. 00160 template<> 00161 const char* 00162 __timepunct_cache<char>::_S_timezones[14]; 00163 00164 #ifdef _GLIBCXX_USE_WCHAR_T 00165 template<> 00166 const wchar_t* 00167 __timepunct_cache<wchar_t>::_S_timezones[14]; 00168 #endif 00169 00170 // Generic. 00171 template<typename _CharT> 00172 const _CharT* __timepunct_cache<_CharT>::_S_timezones[14]; 00173 00174 template<typename _CharT> 00175 class __timepunct : public locale::facet 00176 { 00177 public: 00178 // Types: 00179 typedef _CharT __char_type; 00180 typedef basic_string<_CharT> __string_type; 00181 typedef __timepunct_cache<_CharT> __cache_type; 00182 00183 protected: 00184 __cache_type* _M_data; 00185 __c_locale _M_c_locale_timepunct; 00186 const char* _M_name_timepunct; 00187 00188 public: 00189 /// Numpunct facet id. 00190 static locale::id id; 00191 00192 explicit 00193 __timepunct(size_t __refs = 0); 00194 00195 explicit 00196 __timepunct(__cache_type* __cache, size_t __refs = 0); 00197 00198 /** 00199 * @brief Internal constructor. Not for general use. 00200 * 00201 * This is a constructor for use by the library itself to set up new 00202 * locales. 00203 * 00204 * @param cloc The C locale. 00205 * @param s The name of a locale. 00206 * @param refs Passed to the base facet class. 00207 */ 00208 explicit 00209 __timepunct(__c_locale __cloc, const char* __s, size_t __refs = 0); 00210 00211 // FIXME: for error checking purposes _M_put should return the return 00212 // value of strftime/wcsftime. 00213 void 00214 _M_put(_CharT* __s, size_t __maxlen, const _CharT* __format, 00215 const tm* __tm) const throw (); 00216 00217 void 00218 _M_date_formats(const _CharT** __date) const 00219 { 00220 // Always have default first. 00221 __date[0] = _M_data->_M_date_format; 00222 __date[1] = _M_data->_M_date_era_format; 00223 } 00224 00225 void 00226 _M_time_formats(const _CharT** __time) const 00227 { 00228 // Always have default first. 00229 __time[0] = _M_data->_M_time_format; 00230 __time[1] = _M_data->_M_time_era_format; 00231 } 00232 00233 void 00234 _M_date_time_formats(const _CharT** __dt) const 00235 { 00236 // Always have default first. 00237 __dt[0] = _M_data->_M_date_time_format; 00238 __dt[1] = _M_data->_M_date_time_era_format; 00239 } 00240 00241 void 00242 _M_am_pm_format(const _CharT* __ampm) const 00243 { __ampm = _M_data->_M_am_pm_format; } 00244 00245 void 00246 _M_am_pm(const _CharT** __ampm) const 00247 { 00248 __ampm[0] = _M_data->_M_am; 00249 __ampm[1] = _M_data->_M_pm; 00250 } 00251 00252 void 00253 _M_days(const _CharT** __days) const 00254 { 00255 __days[0] = _M_data->_M_day1; 00256 __days[1] = _M_data->_M_day2; 00257 __days[2] = _M_data->_M_day3; 00258 __days[3] = _M_data->_M_day4; 00259 __days[4] = _M_data->_M_day5; 00260 __days[5] = _M_data->_M_day6; 00261 __days[6] = _M_data->_M_day7; 00262 } 00263 00264 void 00265 _M_days_abbreviated(const _CharT** __days) const 00266 { 00267 __days[0] = _M_data->_M_aday1; 00268 __days[1] = _M_data->_M_aday2; 00269 __days[2] = _M_data->_M_aday3; 00270 __days[3] = _M_data->_M_aday4; 00271 __days[4] = _M_data->_M_aday5; 00272 __days[5] = _M_data->_M_aday6; 00273 __days[6] = _M_data->_M_aday7; 00274 } 00275 00276 void 00277 _M_months(const _CharT** __months) const 00278 { 00279 __months[0] = _M_data->_M_month01; 00280 __months[1] = _M_data->_M_month02; 00281 __months[2] = _M_data->_M_month03; 00282 __months[3] = _M_data->_M_month04; 00283 __months[4] = _M_data->_M_month05; 00284 __months[5] = _M_data->_M_month06; 00285 __months[6] = _M_data->_M_month07; 00286 __months[7] = _M_data->_M_month08; 00287 __months[8] = _M_data->_M_month09; 00288 __months[9] = _M_data->_M_month10; 00289 __months[10] = _M_data->_M_month11; 00290 __months[11] = _M_data->_M_month12; 00291 } 00292 00293 void 00294 _M_months_abbreviated(const _CharT** __months) const 00295 { 00296 __months[0] = _M_data->_M_amonth01; 00297 __months[1] = _M_data->_M_amonth02; 00298 __months[2] = _M_data->_M_amonth03; 00299 __months[3] = _M_data->_M_amonth04; 00300 __months[4] = _M_data->_M_amonth05; 00301 __months[5] = _M_data->_M_amonth06; 00302 __months[6] = _M_data->_M_amonth07; 00303 __months[7] = _M_data->_M_amonth08; 00304 __months[8] = _M_data->_M_amonth09; 00305 __months[9] = _M_data->_M_amonth10; 00306 __months[10] = _M_data->_M_amonth11; 00307 __months[11] = _M_data->_M_amonth12; 00308 } 00309 00310 protected: 00311 virtual 00312 ~__timepunct(); 00313 00314 // For use at construction time only. 00315 void 00316 _M_initialize_timepunct(__c_locale __cloc = 0); 00317 }; 00318 00319 template<typename _CharT> 00320 locale::id __timepunct<_CharT>::id; 00321 00322 // Specializations. 00323 template<> 00324 void 00325 __timepunct<char>::_M_initialize_timepunct(__c_locale __cloc); 00326 00327 template<> 00328 void 00329 __timepunct<char>::_M_put(char*, size_t, const char*, const tm*) const throw (); 00330 00331 #ifdef _GLIBCXX_USE_WCHAR_T 00332 template<> 00333 void 00334 __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale __cloc); 00335 00336 template<> 00337 void 00338 __timepunct<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*, 00339 const tm*) const throw (); 00340 #endif 00341 00342 _GLIBCXX_END_NAMESPACE 00343 00344 // Include host and configuration specific timepunct functions. 00345 #include <bits/time_members.h> 00346 00347 _GLIBCXX_BEGIN_NAMESPACE(std) 00348 00349 /** 00350 * @brief Primary class template time_get. 00351 * @ingroup locales 00352 * 00353 * This facet encapsulates the code to parse and return a date or 00354 * time from a string. It is used by the istream numeric 00355 * extraction operators. 00356 * 00357 * The time_get template uses protected virtual functions to provide the 00358 * actual results. The public accessors forward the call to the virtual 00359 * functions. These virtual functions are hooks for developers to 00360 * implement the behavior they require from the time_get facet. 00361 */ 00362 template<typename _CharT, typename _InIter> 00363 class time_get : public locale::facet, public time_base 00364 { 00365 public: 00366 // Types: 00367 //@{ 00368 /// Public typedefs 00369 typedef _CharT char_type; 00370 typedef _InIter iter_type; 00371 //@} 00372 typedef basic_string<_CharT> __string_type; 00373 00374 /// Numpunct facet id. 00375 static locale::id id; 00376 00377 /** 00378 * @brief Constructor performs initialization. 00379 * 00380 * This is the constructor provided by the standard. 00381 * 00382 * @param refs Passed to the base facet class. 00383 */ 00384 explicit 00385 time_get(size_t __refs = 0) 00386 : facet (__refs) { } 00387 00388 /** 00389 * @brief Return preferred order of month, day, and year. 00390 * 00391 * This function returns an enum from timebase::dateorder giving the 00392 * preferred ordering if the format @a x given to time_put::put() only 00393 * uses month, day, and year. If the format @a x for the associated 00394 * locale uses other fields, this function returns 00395 * timebase::dateorder::noorder. 00396 * 00397 * NOTE: The library always returns noorder at the moment. 00398 * 00399 * @return A member of timebase::dateorder. 00400 */ 00401 dateorder 00402 date_order() const 00403 { return this->do_date_order(); } 00404 00405 /** 00406 * @brief Parse input time string. 00407 * 00408 * This function parses a time according to the format @a x and puts the 00409 * results into a user-supplied struct tm. The result is returned by 00410 * calling time_get::do_get_time(). 00411 * 00412 * If there is a valid time string according to format @a x, @a tm will 00413 * be filled in accordingly and the returned iterator will point to the 00414 * first character beyond the time string. If an error occurs before 00415 * the end, err |= ios_base::failbit. If parsing reads all the 00416 * characters, err |= ios_base::eofbit. 00417 * 00418 * @param beg Start of string to parse. 00419 * @param end End of string to parse. 00420 * @param io Source of the locale. 00421 * @param err Error flags to set. 00422 * @param tm Pointer to struct tm to fill in. 00423 * @return Iterator to first char beyond time string. 00424 */ 00425 iter_type 00426 get_time(iter_type __beg, iter_type __end, ios_base& __io, 00427 ios_base::iostate& __err, tm* __tm) const 00428 { return this->do_get_time(__beg, __end, __io, __err, __tm); } 00429 00430 /** 00431 * @brief Parse input date string. 00432 * 00433 * This function parses a date according to the format @a X and puts the 00434 * results into a user-supplied struct tm. The result is returned by 00435 * calling time_get::do_get_date(). 00436 * 00437 * If there is a valid date string according to format @a X, @a tm will 00438 * be filled in accordingly and the returned iterator will point to the 00439 * first character beyond the date string. If an error occurs before 00440 * the end, err |= ios_base::failbit. If parsing reads all the 00441 * characters, err |= ios_base::eofbit. 00442 * 00443 * @param beg Start of string to parse. 00444 * @param end End of string to parse. 00445 * @param io Source of the locale. 00446 * @param err Error flags to set. 00447 * @param tm Pointer to struct tm to fill in. 00448 * @return Iterator to first char beyond date string. 00449 */ 00450 iter_type 00451 get_date(iter_type __beg, iter_type __end, ios_base& __io, 00452 ios_base::iostate& __err, tm* __tm) const 00453 { return this->do_get_date(__beg, __end, __io, __err, __tm); } 00454 00455 /** 00456 * @brief Parse input weekday string. 00457 * 00458 * This function parses a weekday name and puts the results into a 00459 * user-supplied struct tm. The result is returned by calling 00460 * time_get::do_get_weekday(). 00461 * 00462 * Parsing starts by parsing an abbreviated weekday name. If a valid 00463 * abbreviation is followed by a character that would lead to the full 00464 * weekday name, parsing continues until the full name is found or an 00465 * error occurs. Otherwise parsing finishes at the end of the 00466 * abbreviated name. 00467 * 00468 * If an error occurs before the end, err |= ios_base::failbit. If 00469 * parsing reads all the characters, err |= ios_base::eofbit. 00470 * 00471 * @param beg Start of string to parse. 00472 * @param end End of string to parse. 00473 * @param io Source of the locale. 00474 * @param err Error flags to set. 00475 * @param tm Pointer to struct tm to fill in. 00476 * @return Iterator to first char beyond weekday name. 00477 */ 00478 iter_type 00479 get_weekday(iter_type __beg, iter_type __end, ios_base& __io, 00480 ios_base::iostate& __err, tm* __tm) const 00481 { return this->do_get_weekday(__beg, __end, __io, __err, __tm); } 00482 00483 /** 00484 * @brief Parse input month string. 00485 * 00486 * This function parses a month name and puts the results into a 00487 * user-supplied struct tm. The result is returned by calling 00488 * time_get::do_get_monthname(). 00489 * 00490 * Parsing starts by parsing an abbreviated month name. If a valid 00491 * abbreviation is followed by a character that would lead to the full 00492 * month name, parsing continues until the full name is found or an 00493 * error occurs. Otherwise parsing finishes at the end of the 00494 * abbreviated name. 00495 * 00496 * If an error occurs before the end, err |= ios_base::failbit. If 00497 * parsing reads all the characters, err |= 00498 * ios_base::eofbit. 00499 * 00500 * @param beg Start of string to parse. 00501 * @param end End of string to parse. 00502 * @param io Source of the locale. 00503 * @param err Error flags to set. 00504 * @param tm Pointer to struct tm to fill in. 00505 * @return Iterator to first char beyond month name. 00506 */ 00507 iter_type 00508 get_monthname(iter_type __beg, iter_type __end, ios_base& __io, 00509 ios_base::iostate& __err, tm* __tm) const 00510 { return this->do_get_monthname(__beg, __end, __io, __err, __tm); } 00511 00512 /** 00513 * @brief Parse input year string. 00514 * 00515 * This function reads up to 4 characters to parse a year string and 00516 * puts the results into a user-supplied struct tm. The result is 00517 * returned by calling time_get::do_get_year(). 00518 * 00519 * 4 consecutive digits are interpreted as a full year. If there are 00520 * exactly 2 consecutive digits, the library interprets this as the 00521 * number of years since 1900. 00522 * 00523 * If an error occurs before the end, err |= ios_base::failbit. If 00524 * parsing reads all the characters, err |= ios_base::eofbit. 00525 * 00526 * @param beg Start of string to parse. 00527 * @param end End of string to parse. 00528 * @param io Source of the locale. 00529 * @param err Error flags to set. 00530 * @param tm Pointer to struct tm to fill in. 00531 * @return Iterator to first char beyond year. 00532 */ 00533 iter_type 00534 get_year(iter_type __beg, iter_type __end, ios_base& __io, 00535 ios_base::iostate& __err, tm* __tm) const 00536 { return this->do_get_year(__beg, __end, __io, __err, __tm); } 00537 00538 protected: 00539 /// Destructor. 00540 virtual 00541 ~time_get() { } 00542 00543 /** 00544 * @brief Return preferred order of month, day, and year. 00545 * 00546 * This function returns an enum from timebase::dateorder giving the 00547 * preferred ordering if the format @a x given to time_put::put() only 00548 * uses month, day, and year. This function is a hook for derived 00549 * classes to change the value returned. 00550 * 00551 * @return A member of timebase::dateorder. 00552 */ 00553 virtual dateorder 00554 do_date_order() const; 00555 00556 /** 00557 * @brief Parse input time string. 00558 * 00559 * This function parses a time according to the format @a x and puts the 00560 * results into a user-supplied struct tm. This function is a hook for 00561 * derived classes to change the value returned. @see get_time() for 00562 * details. 00563 * 00564 * @param beg Start of string to parse. 00565 * @param end End of string to parse. 00566 * @param io Source of the locale. 00567 * @param err Error flags to set. 00568 * @param tm Pointer to struct tm to fill in. 00569 * @return Iterator to first char beyond time string. 00570 */ 00571 virtual iter_type 00572 do_get_time(iter_type __beg, iter_type __end, ios_base& __io, 00573 ios_base::iostate& __err, tm* __tm) const; 00574 00575 /** 00576 * @brief Parse input date string. 00577 * 00578 * This function parses a date according to the format @a X and puts the 00579 * results into a user-supplied struct tm. This function is a hook for 00580 * derived classes to change the value returned. @see get_date() for 00581 * details. 00582 * 00583 * @param beg Start of string to parse. 00584 * @param end End of string to parse. 00585 * @param io Source of the locale. 00586 * @param err Error flags to set. 00587 * @param tm Pointer to struct tm to fill in. 00588 * @return Iterator to first char beyond date string. 00589 */ 00590 virtual iter_type 00591 do_get_date(iter_type __beg, iter_type __end, ios_base& __io, 00592 ios_base::iostate& __err, tm* __tm) const; 00593 00594 /** 00595 * @brief Parse input weekday string. 00596 * 00597 * This function parses a weekday name and puts the results into a 00598 * user-supplied struct tm. This function is a hook for derived 00599 * classes to change the value returned. @see get_weekday() for 00600 * details. 00601 * 00602 * @param beg Start of string to parse. 00603 * @param end End of string to parse. 00604 * @param io Source of the locale. 00605 * @param err Error flags to set. 00606 * @param tm Pointer to struct tm to fill in. 00607 * @return Iterator to first char beyond weekday name. 00608 */ 00609 virtual iter_type 00610 do_get_weekday(iter_type __beg, iter_type __end, ios_base&, 00611 ios_base::iostate& __err, tm* __tm) const; 00612 00613 /** 00614 * @brief Parse input month string. 00615 * 00616 * This function parses a month name and puts the results into a 00617 * user-supplied struct tm. This function is a hook for derived 00618 * classes to change the value returned. @see get_monthname() for 00619 * details. 00620 * 00621 * @param beg Start of string to parse. 00622 * @param end End of string to parse. 00623 * @param io Source of the locale. 00624 * @param err Error flags to set. 00625 * @param tm Pointer to struct tm to fill in. 00626 * @return Iterator to first char beyond month name. 00627 */ 00628 virtual iter_type 00629 do_get_monthname(iter_type __beg, iter_type __end, ios_base&, 00630 ios_base::iostate& __err, tm* __tm) const; 00631 00632 /** 00633 * @brief Parse input year string. 00634 * 00635 * This function reads up to 4 characters to parse a year string and 00636 * puts the results into a user-supplied struct tm. This function is a 00637 * hook for derived classes to change the value returned. @see 00638 * get_year() for details. 00639 * 00640 * @param beg Start of string to parse. 00641 * @param end End of string to parse. 00642 * @param io Source of the locale. 00643 * @param err Error flags to set. 00644 * @param tm Pointer to struct tm to fill in. 00645 * @return Iterator to first char beyond year. 00646 */ 00647 virtual iter_type 00648 do_get_year(iter_type __beg, iter_type __end, ios_base& __io, 00649 ios_base::iostate& __err, tm* __tm) const; 00650 00651 // Extract numeric component of length __len. 00652 iter_type 00653 _M_extract_num(iter_type __beg, iter_type __end, int& __member, 00654 int __min, int __max, size_t __len, 00655 ios_base& __io, ios_base::iostate& __err) const; 00656 00657 // Extract any unique array of string literals in a const _CharT* array. 00658 iter_type 00659 _M_extract_name(iter_type __beg, iter_type __end, int& __member, 00660 const _CharT** __names, size_t __indexlen, 00661 ios_base& __io, ios_base::iostate& __err) const; 00662 00663 // Extract day or month name in a const _CharT* array. 00664 iter_type 00665 _M_extract_wday_or_month(iter_type __beg, iter_type __end, int& __member, 00666 const _CharT** __names, size_t __indexlen, 00667 ios_base& __io, ios_base::iostate& __err) const; 00668 00669 // Extract on a component-by-component basis, via __format argument. 00670 iter_type 00671 _M_extract_via_format(iter_type __beg, iter_type __end, ios_base& __io, 00672 ios_base::iostate& __err, tm* __tm, 00673 const _CharT* __format) const; 00674 }; 00675 00676 template<typename _CharT, typename _InIter> 00677 locale::id time_get<_CharT, _InIter>::id; 00678 00679 /// class time_get_byname [22.2.5.2]. 00680 template<typename _CharT, typename _InIter> 00681 class time_get_byname : public time_get<_CharT, _InIter> 00682 { 00683 public: 00684 // Types: 00685 typedef _CharT char_type; 00686 typedef _InIter iter_type; 00687 00688 explicit 00689 time_get_byname(const char*, size_t __refs = 0) 00690 : time_get<_CharT, _InIter>(__refs) { } 00691 00692 protected: 00693 virtual 00694 ~time_get_byname() { } 00695 }; 00696 00697 /** 00698 * @brief Primary class template time_put. 00699 * @ingroup locales 00700 * 00701 * This facet encapsulates the code to format and output dates and times 00702 * according to formats used by strftime(). 00703 * 00704 * The time_put template uses protected virtual functions to provide the 00705 * actual results. The public accessors forward the call to the virtual 00706 * functions. These virtual functions are hooks for developers to 00707 * implement the behavior they require from the time_put facet. 00708 */ 00709 template<typename _CharT, typename _OutIter> 00710 class time_put : public locale::facet 00711 { 00712 public: 00713 // Types: 00714 //@{ 00715 /// Public typedefs 00716 typedef _CharT char_type; 00717 typedef _OutIter iter_type; 00718 //@} 00719 00720 /// Numpunct facet id. 00721 static locale::id id; 00722 00723 /** 00724 * @brief Constructor performs initialization. 00725 * 00726 * This is the constructor provided by the standard. 00727 * 00728 * @param refs Passed to the base facet class. 00729 */ 00730 explicit 00731 time_put(size_t __refs = 0) 00732 : facet(__refs) { } 00733 00734 /** 00735 * @brief Format and output a time or date. 00736 * 00737 * This function formats the data in struct tm according to the 00738 * provided format string. The format string is interpreted as by 00739 * strftime(). 00740 * 00741 * @param s The stream to write to. 00742 * @param io Source of locale. 00743 * @param fill char_type to use for padding. 00744 * @param tm Struct tm with date and time info to format. 00745 * @param beg Start of format string. 00746 * @param end End of format string. 00747 * @return Iterator after writing. 00748 */ 00749 iter_type 00750 put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm, 00751 const _CharT* __beg, const _CharT* __end) const; 00752 00753 /** 00754 * @brief Format and output a time or date. 00755 * 00756 * This function formats the data in struct tm according to the 00757 * provided format char and optional modifier. The format and modifier 00758 * are interpreted as by strftime(). It does so by returning 00759 * time_put::do_put(). 00760 * 00761 * @param s The stream to write to. 00762 * @param io Source of locale. 00763 * @param fill char_type to use for padding. 00764 * @param tm Struct tm with date and time info to format. 00765 * @param format Format char. 00766 * @param mod Optional modifier char. 00767 * @return Iterator after writing. 00768 */ 00769 iter_type 00770 put(iter_type __s, ios_base& __io, char_type __fill, 00771 const tm* __tm, char __format, char __mod = 0) const 00772 { return this->do_put(__s, __io, __fill, __tm, __format, __mod); } 00773 00774 protected: 00775 /// Destructor. 00776 virtual 00777 ~time_put() 00778 { } 00779 00780 /** 00781 * @brief Format and output a time or date. 00782 * 00783 * This function formats the data in struct tm according to the 00784 * provided format char and optional modifier. This function is a hook 00785 * for derived classes to change the value returned. @see put() for 00786 * more details. 00787 * 00788 * @param s The stream to write to. 00789 * @param io Source of locale. 00790 * @param fill char_type to use for padding. 00791 * @param tm Struct tm with date and time info to format. 00792 * @param format Format char. 00793 * @param mod Optional modifier char. 00794 * @return Iterator after writing. 00795 */ 00796 virtual iter_type 00797 do_put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm, 00798 char __format, char __mod) const; 00799 }; 00800 00801 template<typename _CharT, typename _OutIter> 00802 locale::id time_put<_CharT, _OutIter>::id; 00803 00804 /// class time_put_byname [22.2.5.4]. 00805 template<typename _CharT, typename _OutIter> 00806 class time_put_byname : public time_put<_CharT, _OutIter> 00807 { 00808 public: 00809 // Types: 00810 typedef _CharT char_type; 00811 typedef _OutIter iter_type; 00812 00813 explicit 00814 time_put_byname(const char*, size_t __refs = 0) 00815 : time_put<_CharT, _OutIter>(__refs) 00816 { }; 00817 00818 protected: 00819 virtual 00820 ~time_put_byname() { } 00821 }; 00822 00823 00824 /** 00825 * @brief Money format ordering data. 00826 * @ingroup locales 00827 * 00828 * This class contains an ordered array of 4 fields to represent the 00829 * pattern for formatting a money amount. Each field may contain one entry 00830 * from the part enum. symbol, sign, and value must be present and the 00831 * remaining field must contain either none or space. @see 00832 * moneypunct::pos_format() and moneypunct::neg_format() for details of how 00833 * these fields are interpreted. 00834 */ 00835 class money_base 00836 { 00837 public: 00838 enum part { none, space, symbol, sign, value }; 00839 struct pattern { char field[4]; }; 00840 00841 static const pattern _S_default_pattern; 00842 00843 enum 00844 { 00845 _S_minus, 00846 _S_zero, 00847 _S_end = 11 00848 }; 00849 00850 // String literal of acceptable (narrow) input/output, for 00851 // money_get/money_put. "-0123456789" 00852 static const char* _S_atoms; 00853 00854 // Construct and return valid pattern consisting of some combination of: 00855 // space none symbol sign value 00856 _GLIBCXX_CONST static pattern 00857 _S_construct_pattern(char __precedes, char __space, char __posn) throw (); 00858 }; 00859 00860 template<typename _CharT, bool _Intl> 00861 struct __moneypunct_cache : public locale::facet 00862 { 00863 const char* _M_grouping; 00864 size_t _M_grouping_size; 00865 bool _M_use_grouping; 00866 _CharT _M_decimal_point; 00867 _CharT _M_thousands_sep; 00868 const _CharT* _M_curr_symbol; 00869 size_t _M_curr_symbol_size; 00870 const _CharT* _M_positive_sign; 00871 size_t _M_positive_sign_size; 00872 const _CharT* _M_negative_sign; 00873 size_t _M_negative_sign_size; 00874 int _M_frac_digits; 00875 money_base::pattern _M_pos_format; 00876 money_base::pattern _M_neg_format; 00877 00878 // A list of valid numeric literals for input and output: in the standard 00879 // "C" locale, this is "-0123456789". This array contains the chars after 00880 // having been passed through the current locale's ctype<_CharT>.widen(). 00881 _CharT _M_atoms[money_base::_S_end]; 00882 00883 bool _M_allocated; 00884 00885 __moneypunct_cache(size_t __refs = 0) : facet(__refs), 00886 _M_grouping(0), _M_grouping_size(0), _M_use_grouping(false), 00887 _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()), 00888 _M_curr_symbol(0), _M_curr_symbol_size(0), 00889 _M_positive_sign(0), _M_positive_sign_size(0), 00890 _M_negative_sign(0), _M_negative_sign_size(0), 00891 _M_frac_digits(0), 00892 _M_pos_format(money_base::pattern()), 00893 _M_neg_format(money_base::pattern()), _M_allocated(false) 00894 { } 00895 00896 ~__moneypunct_cache(); 00897 00898 void 00899 _M_cache(const locale& __loc); 00900 00901 private: 00902 __moneypunct_cache& 00903 operator=(const __moneypunct_cache&); 00904 00905 explicit 00906 __moneypunct_cache(const __moneypunct_cache&); 00907 }; 00908 00909 template<typename _CharT, bool _Intl> 00910 __moneypunct_cache<_CharT, _Intl>::~__moneypunct_cache() 00911 { 00912 if (_M_allocated) 00913 { 00914 delete [] _M_grouping; 00915 delete [] _M_curr_symbol; 00916 delete [] _M_positive_sign; 00917 delete [] _M_negative_sign; 00918 } 00919 } 00920 00921 /** 00922 * @brief Primary class template moneypunct. 00923 * @ingroup locales 00924 * 00925 * This facet encapsulates the punctuation, grouping and other formatting 00926 * features of money amount string representations. 00927 */ 00928 template<typename _CharT, bool _Intl> 00929 class moneypunct : public locale::facet, public money_base 00930 { 00931 public: 00932 // Types: 00933 //@{ 00934 /// Public typedefs 00935 typedef _CharT char_type; 00936 typedef basic_string<_CharT> string_type; 00937 //@} 00938 typedef __moneypunct_cache<_CharT, _Intl> __cache_type; 00939 00940 private: 00941 __cache_type* _M_data; 00942 00943 public: 00944 /// This value is provided by the standard, but no reason for its 00945 /// existence. 00946 static const bool intl = _Intl; 00947 /// Numpunct facet id. 00948 static locale::id id; 00949 00950 /** 00951 * @brief Constructor performs initialization. 00952 * 00953 * This is the constructor provided by the standard. 00954 * 00955 * @param refs Passed to the base facet class. 00956 */ 00957 explicit 00958 moneypunct(size_t __refs = 0) 00959 : facet(__refs), _M_data(0) 00960 { _M_initialize_moneypunct(); } 00961 00962 /** 00963 * @brief Constructor performs initialization. 00964 * 00965 * This is an internal constructor. 00966 * 00967 * @param cache Cache for optimization. 00968 * @param refs Passed to the base facet class. 00969 */ 00970 explicit 00971 moneypunct(__cache_type* __cache, size_t __refs = 0) 00972 : facet(__refs), _M_data(__cache) 00973 { _M_initialize_moneypunct(); } 00974 00975 /** 00976 * @brief Internal constructor. Not for general use. 00977 * 00978 * This is a constructor for use by the library itself to set up new 00979 * locales. 00980 * 00981 * @param cloc The C locale. 00982 * @param s The name of a locale. 00983 * @param refs Passed to the base facet class. 00984 */ 00985 explicit 00986 moneypunct(__c_locale __cloc, const char* __s, size_t __refs = 0) 00987 : facet(__refs), _M_data(0) 00988 { _M_initialize_moneypunct(__cloc, __s); } 00989 00990 /** 00991 * @brief Return decimal point character. 00992 * 00993 * This function returns a char_type to use as a decimal point. It 00994 * does so by returning returning 00995 * moneypunct<char_type>::do_decimal_point(). 00996 * 00997 * @return @a char_type representing a decimal point. 00998 */ 00999 char_type 01000 decimal_point() const 01001 { return this->do_decimal_point(); } 01002 01003 /** 01004 * @brief Return thousands separator character. 01005 * 01006 * This function returns a char_type to use as a thousands 01007 * separator. It does so by returning returning 01008 * moneypunct<char_type>::do_thousands_sep(). 01009 * 01010 * @return char_type representing a thousands separator. 01011 */ 01012 char_type 01013 thousands_sep() const 01014 { return this->do_thousands_sep(); } 01015 01016 /** 01017 * @brief Return grouping specification. 01018 * 01019 * This function returns a string representing groupings for the 01020 * integer part of an amount. Groupings indicate where thousands 01021 * separators should be inserted. 01022 * 01023 * Each char in the return string is interpret as an integer rather 01024 * than a character. These numbers represent the number of digits in a 01025 * group. The first char in the string represents the number of digits 01026 * in the least significant group. If a char is negative, it indicates 01027 * an unlimited number of digits for the group. If more chars from the 01028 * string are required to group a number, the last char is used 01029 * repeatedly. 01030 * 01031 * For example, if the grouping() returns <code>\003\002</code> 01032 * and is applied to the number 123456789, this corresponds to 01033 * 12,34,56,789. Note that if the string was <code>32</code>, this would 01034 * put more than 50 digits into the least significant group if 01035 * the character set is ASCII. 01036 * 01037 * The string is returned by calling 01038 * moneypunct<char_type>::do_grouping(). 01039 * 01040 * @return string representing grouping specification. 01041 */ 01042 string 01043 grouping() const 01044 { return this->do_grouping(); } 01045 01046 /** 01047 * @brief Return currency symbol string. 01048 * 01049 * This function returns a string_type to use as a currency symbol. It 01050 * does so by returning returning 01051 * moneypunct<char_type>::do_curr_symbol(). 01052 * 01053 * @return @a string_type representing a currency symbol. 01054 */ 01055 string_type 01056 curr_symbol() const 01057 { return this->do_curr_symbol(); } 01058 01059 /** 01060 * @brief Return positive sign string. 01061 * 01062 * This function returns a string_type to use as a sign for positive 01063 * amounts. It does so by returning returning 01064 * moneypunct<char_type>::do_positive_sign(). 01065 * 01066 * If the return value contains more than one character, the first 01067 * character appears in the position indicated by pos_format() and the 01068 * remainder appear at the end of the formatted string. 01069 * 01070 * @return @a string_type representing a positive sign. 01071 */ 01072 string_type 01073 positive_sign() const 01074 { return this->do_positive_sign(); } 01075 01076 /** 01077 * @brief Return negative sign string. 01078 * 01079 * This function returns a string_type to use as a sign for negative 01080 * amounts. It does so by returning returning 01081 * moneypunct<char_type>::do_negative_sign(). 01082 * 01083 * If the return value contains more than one character, the first 01084 * character appears in the position indicated by neg_format() and the 01085 * remainder appear at the end of the formatted string. 01086 * 01087 * @return @a string_type representing a negative sign. 01088 */ 01089 string_type 01090 negative_sign() const 01091 { return this->do_negative_sign(); } 01092 01093 /** 01094 * @brief Return number of digits in fraction. 01095 * 01096 * This function returns the exact number of digits that make up the 01097 * fractional part of a money amount. It does so by returning 01098 * returning moneypunct<char_type>::do_frac_digits(). 01099 * 01100 * The fractional part of a money amount is optional. But if it is 01101 * present, there must be frac_digits() digits. 01102 * 01103 * @return Number of digits in amount fraction. 01104 */ 01105 int 01106 frac_digits() const 01107 { return this->do_frac_digits(); } 01108 01109 //@{ 01110 /** 01111 * @brief Return pattern for money values. 01112 * 01113 * This function returns a pattern describing the formatting of a 01114 * positive or negative valued money amount. It does so by returning 01115 * returning moneypunct<char_type>::do_pos_format() or 01116 * moneypunct<char_type>::do_neg_format(). 01117 * 01118 * The pattern has 4 fields describing the ordering of symbol, sign, 01119 * value, and none or space. There must be one of each in the pattern. 01120 * The none and space enums may not appear in the first field and space 01121 * may not appear in the final field. 01122 * 01123 * The parts of a money string must appear in the order indicated by 01124 * the fields of the pattern. The symbol field indicates that the 01125 * value of curr_symbol() may be present. The sign field indicates 01126 * that the value of positive_sign() or negative_sign() must be 01127 * present. The value field indicates that the absolute value of the 01128 * money amount is present. none indicates 0 or more whitespace 01129 * characters, except at the end, where it permits no whitespace. 01130 * space indicates that 1 or more whitespace characters must be 01131 * present. 01132 * 01133 * For example, for the US locale and pos_format() pattern 01134 * {symbol,sign,value,none}, curr_symbol() == '$' 01135 * positive_sign() == '+', and value 10.01, and 01136 * options set to force the symbol, the corresponding string is 01137 * <code>$+10.01</code>. 01138 * 01139 * @return Pattern for money values. 01140 */ 01141 pattern 01142 pos_format() const 01143 { return this->do_pos_format(); } 01144 01145 pattern 01146 neg_format() const 01147 { return this->do_neg_format(); } 01148 //@} 01149 01150 protected: 01151 /// Destructor. 01152 virtual 01153 ~moneypunct(); 01154 01155 /** 01156 * @brief Return decimal point character. 01157 * 01158 * Returns a char_type to use as a decimal point. This function is a 01159 * hook for derived classes to change the value returned. 01160 * 01161 * @return @a char_type representing a decimal point. 01162 */ 01163 virtual char_type 01164 do_decimal_point() const 01165 { return _M_data->_M_decimal_point; } 01166 01167 /** 01168 * @brief Return thousands separator character. 01169 * 01170 * Returns a char_type to use as a thousands separator. This function 01171 * is a hook for derived classes to change the value returned. 01172 * 01173 * @return @a char_type representing a thousands separator. 01174 */ 01175 virtual char_type 01176 do_thousands_sep() const 01177 { return _M_data->_M_thousands_sep; } 01178 01179 /** 01180 * @brief Return grouping specification. 01181 * 01182 * Returns a string representing groupings for the integer part of a 01183 * number. This function is a hook for derived classes to change the 01184 * value returned. @see grouping() for details. 01185 * 01186 * @return String representing grouping specification. 01187 */ 01188 virtual string 01189 do_grouping() const 01190 { return _M_data->_M_grouping; } 01191 01192 /** 01193 * @brief Return currency symbol string. 01194 * 01195 * This function returns a string_type to use as a currency symbol. 01196 * This function is a hook for derived classes to change the value 01197 * returned. @see curr_symbol() for details. 01198 * 01199 * @return @a string_type representing a currency symbol. 01200 */ 01201 virtual string_type 01202 do_curr_symbol() const 01203 { return _M_data->_M_curr_symbol; } 01204 01205 /** 01206 * @brief Return positive sign string. 01207 * 01208 * This function returns a string_type to use as a sign for positive 01209 * amounts. This function is a hook for derived classes to change the 01210 * value returned. @see positive_sign() for details. 01211 * 01212 * @return @a string_type representing a positive sign. 01213 */ 01214 virtual string_type 01215 do_positive_sign() const 01216 { return _M_data->_M_positive_sign; } 01217 01218 /** 01219 * @brief Return negative sign string. 01220 * 01221 * This function returns a string_type to use as a sign for negative 01222 * amounts. This function is a hook for derived classes to change the 01223 * value returned. @see negative_sign() for details. 01224 * 01225 * @return @a string_type representing a negative sign. 01226 */ 01227 virtual string_type 01228 do_negative_sign() const 01229 { return _M_data->_M_negative_sign; } 01230 01231 /** 01232 * @brief Return number of digits in fraction. 01233 * 01234 * This function returns the exact number of digits that make up the 01235 * fractional part of a money amount. This function is a hook for 01236 * derived classes to change the value returned. @see frac_digits() 01237 * for details. 01238 * 01239 * @return Number of digits in amount fraction. 01240 */ 01241 virtual int 01242 do_frac_digits() const 01243 { return _M_data->_M_frac_digits; } 01244 01245 /** 01246 * @brief Return pattern for money values. 01247 * 01248 * This function returns a pattern describing the formatting of a 01249 * positive valued money amount. This function is a hook for derived 01250 * classes to change the value returned. @see pos_format() for 01251 * details. 01252 * 01253 * @return Pattern for money values. 01254 */ 01255 virtual pattern 01256 do_pos_format() const 01257 { return _M_data->_M_pos_format; } 01258 01259 /** 01260 * @brief Return pattern for money values. 01261 * 01262 * This function returns a pattern describing the formatting of a 01263 * negative valued money amount. This function is a hook for derived 01264 * classes to change the value returned. @see neg_format() for 01265 * details. 01266 * 01267 * @return Pattern for money values. 01268 */ 01269 virtual pattern 01270 do_neg_format() const 01271 { return _M_data->_M_neg_format; } 01272 01273 // For use at construction time only. 01274 void 01275 _M_initialize_moneypunct(__c_locale __cloc = 0, 01276 const char* __name = 0); 01277 }; 01278 01279 template<typename _CharT, bool _Intl> 01280 locale::id moneypunct<_CharT, _Intl>::id; 01281 01282 template<typename _CharT, bool _Intl> 01283 const bool moneypunct<_CharT, _Intl>::intl; 01284 01285 template<> 01286 moneypunct<char, true>::~moneypunct(); 01287 01288 template<> 01289 moneypunct<char, false>::~moneypunct(); 01290 01291 template<> 01292 void 01293 moneypunct<char, true>::_M_initialize_moneypunct(__c_locale, const char*); 01294 01295 template<> 01296 void 01297 moneypunct<char, false>::_M_initialize_moneypunct(__c_locale, const char*); 01298 01299 #ifdef _GLIBCXX_USE_WCHAR_T 01300 template<> 01301 moneypunct<wchar_t, true>::~moneypunct(); 01302 01303 template<> 01304 moneypunct<wchar_t, false>::~moneypunct(); 01305 01306 template<> 01307 void 01308 moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale, 01309 const char*); 01310 01311 template<> 01312 void 01313 moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale, 01314 const char*); 01315 #endif 01316 01317 /// class moneypunct_byname [22.2.6.4]. 01318 template<typename _CharT, bool _Intl> 01319 class moneypunct_byname : public moneypunct<_CharT, _Intl> 01320 { 01321 public: 01322 typedef _CharT char_type; 01323 typedef basic_string<_CharT> string_type; 01324 01325 static const bool intl = _Intl; 01326 01327 explicit 01328 moneypunct_byname(const char* __s, size_t __refs = 0) 01329 : moneypunct<_CharT, _Intl>(__refs) 01330 { 01331 if (__builtin_strcmp(__s, "C") != 0 01332 && __builtin_strcmp(__s, "POSIX") != 0) 01333 { 01334 __c_locale __tmp; 01335 this->_S_create_c_locale(__tmp, __s); 01336 this->_M_initialize_moneypunct(__tmp); 01337 this->_S_destroy_c_locale(__tmp); 01338 } 01339 } 01340 01341 protected: 01342 virtual 01343 ~moneypunct_byname() { } 01344 }; 01345 01346 template<typename _CharT, bool _Intl> 01347 const bool moneypunct_byname<_CharT, _Intl>::intl; 01348 01349 _GLIBCXX_BEGIN_LDBL_NAMESPACE 01350 01351 /** 01352 * @brief Primary class template money_get. 01353 * @ingroup locales 01354 * 01355 * This facet encapsulates the code to parse and return a monetary 01356 * amount from a string. 01357 * 01358 * The money_get template uses protected virtual functions to 01359 * provide the actual results. The public accessors forward the 01360 * call to the virtual functions. These virtual functions are 01361 * hooks for developers to implement the behavior they require from 01362 * the money_get facet. 01363 */ 01364 template<typename _CharT, typename _InIter> 01365 class money_get : public locale::facet 01366 { 01367 public: 01368 // Types: 01369 //@{ 01370 /// Public typedefs 01371 typedef _CharT char_type; 01372 typedef _InIter iter_type; 01373 typedef basic_string<_CharT> string_type; 01374 //@} 01375 01376 /// Numpunct facet id. 01377 static locale::id id; 01378 01379 /** 01380 * @brief Constructor performs initialization. 01381 * 01382 * This is the constructor provided by the standard. 01383 * 01384 * @param refs Passed to the base facet class. 01385 */ 01386 explicit 01387 money_get(size_t __refs = 0) : facet(__refs) { } 01388 01389 /** 01390 * @brief Read and parse a monetary value. 01391 * 01392 * This function reads characters from @a s, interprets them as a 01393 * monetary value according to moneypunct and ctype facets retrieved 01394 * from io.getloc(), and returns the result in @a units as an integral 01395 * value moneypunct::frac_digits() * the actual amount. For example, 01396 * the string $10.01 in a US locale would store 1001 in @a units. 01397 * 01398 * Any characters not part of a valid money amount are not consumed. 01399 * 01400 * If a money value cannot be parsed from the input stream, sets 01401 * err=(err|io.failbit). If the stream is consumed before finishing 01402 * parsing, sets err=(err|io.failbit|io.eofbit). @a units is 01403 * unchanged if parsing fails. 01404 * 01405 * This function works by returning the result of do_get(). 01406 * 01407 * @param s Start of characters to parse. 01408 * @param end End of characters to parse. 01409 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >. 01410 * @param io Source of facets and io state. 01411 * @param err Error field to set if parsing fails. 01412 * @param units Place to store result of parsing. 01413 * @return Iterator referencing first character beyond valid money 01414 * amount. 01415 */ 01416 iter_type 01417 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 01418 ios_base::iostate& __err, long double& __units) const 01419 { return this->do_get(__s, __end, __intl, __io, __err, __units); } 01420 01421 /** 01422 * @brief Read and parse a monetary value. 01423 * 01424 * This function reads characters from @a s, interprets them as 01425 * a monetary value according to moneypunct and ctype facets 01426 * retrieved from io.getloc(), and returns the result in @a 01427 * digits. For example, the string $10.01 in a US locale would 01428 * store <code>1001</code> in @a digits. 01429 * 01430 * Any characters not part of a valid money amount are not consumed. 01431 * 01432 * If a money value cannot be parsed from the input stream, sets 01433 * err=(err|io.failbit). If the stream is consumed before finishing 01434 * parsing, sets err=(err|io.failbit|io.eofbit). 01435 * 01436 * This function works by returning the result of do_get(). 01437 * 01438 * @param s Start of characters to parse. 01439 * @param end End of characters to parse. 01440 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >. 01441 * @param io Source of facets and io state. 01442 * @param err Error field to set if parsing fails. 01443 * @param digits Place to store result of parsing. 01444 * @return Iterator referencing first character beyond valid money 01445 * amount. 01446 */ 01447 iter_type 01448 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 01449 ios_base::iostate& __err, string_type& __digits) const 01450 { return this->do_get(__s, __end, __intl, __io, __err, __digits); } 01451 01452 protected: 01453 /// Destructor. 01454 virtual 01455 ~money_get() { } 01456 01457 /** 01458 * @brief Read and parse a monetary value. 01459 * 01460 * This function reads and parses characters representing a monetary 01461 * value. This function is a hook for derived classes to change the 01462 * value returned. @see get() for details. 01463 */ 01464 // XXX GLIBCXX_ABI Deprecated 01465 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ 01466 virtual iter_type 01467 __do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 01468 ios_base::iostate& __err, double& __units) const; 01469 #else 01470 virtual iter_type 01471 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 01472 ios_base::iostate& __err, long double& __units) const; 01473 #endif 01474 01475 /** 01476 * @brief Read and parse a monetary value. 01477 * 01478 * This function reads and parses characters representing a monetary 01479 * value. This function is a hook for derived classes to change the 01480 * value returned. @see get() for details. 01481 */ 01482 virtual iter_type 01483 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 01484 ios_base::iostate& __err, string_type& __digits) const; 01485 01486 // XXX GLIBCXX_ABI Deprecated 01487 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ 01488 virtual iter_type 01489 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 01490 ios_base::iostate& __err, long double& __units) const; 01491 #endif 01492 01493 template<bool _Intl> 01494 iter_type 01495 _M_extract(iter_type __s, iter_type __end, ios_base& __io, 01496 ios_base::iostate& __err, string& __digits) const; 01497 }; 01498 01499 template<typename _CharT, typename _InIter> 01500 locale::id money_get<_CharT, _InIter>::id; 01501 01502 /** 01503 * @brief Primary class template money_put. 01504 * @ingroup locales 01505 * 01506 * This facet encapsulates the code to format and output a monetary 01507 * amount. 01508 * 01509 * The money_put template uses protected virtual functions to 01510 * provide the actual results. The public accessors forward the 01511 * call to the virtual functions. These virtual functions are 01512 * hooks for developers to implement the behavior they require from 01513 * the money_put facet. 01514 */ 01515 template<typename _CharT, typename _OutIter> 01516 class money_put : public locale::facet 01517 { 01518 public: 01519 //@{ 01520 /// Public typedefs 01521 typedef _CharT char_type; 01522 typedef _OutIter iter_type; 01523 typedef basic_string<_CharT> string_type; 01524 //@} 01525 01526 /// Numpunct facet id. 01527 static locale::id id; 01528 01529 /** 01530 * @brief Constructor performs initialization. 01531 * 01532 * This is the constructor provided by the standard. 01533 * 01534 * @param refs Passed to the base facet class. 01535 */ 01536 explicit 01537 money_put(size_t __refs = 0) : facet(__refs) { } 01538 01539 /** 01540 * @brief Format and output a monetary value. 01541 * 01542 * This function formats @a units as a monetary value according to 01543 * moneypunct and ctype facets retrieved from io.getloc(), and writes 01544 * the resulting characters to @a s. For example, the value 1001 in a 01545 * US locale would write <code>$10.01</code> to @a s. 01546 * 01547 * This function works by returning the result of do_put(). 01548 * 01549 * @param s The stream to write to. 01550 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >. 01551 * @param io Source of facets and io state. 01552 * @param fill char_type to use for padding. 01553 * @param units Place to store result of parsing. 01554 * @return Iterator after writing. 01555 */ 01556 iter_type 01557 put(iter_type __s, bool __intl, ios_base& __io, 01558 char_type __fill, long double __units) const 01559 { return this->do_put(__s, __intl, __io, __fill, __units); } 01560 01561 /** 01562 * @brief Format and output a monetary value. 01563 * 01564 * This function formats @a digits as a monetary value 01565 * according to moneypunct and ctype facets retrieved from 01566 * io.getloc(), and writes the resulting characters to @a s. 01567 * For example, the string <code>1001</code> in a US locale 01568 * would write <code>$10.01</code> to @a s. 01569 * 01570 * This function works by returning the result of do_put(). 01571 * 01572 * @param s The stream to write to. 01573 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >. 01574 * @param io Source of facets and io state. 01575 * @param fill char_type to use for padding. 01576 * @param units Place to store result of parsing. 01577 * @return Iterator after writing. 01578 */ 01579 iter_type 01580 put(iter_type __s, bool __intl, ios_base& __io, 01581 char_type __fill, const string_type& __digits) const 01582 { return this->do_put(__s, __intl, __io, __fill, __digits); } 01583 01584 protected: 01585 /// Destructor. 01586 virtual 01587 ~money_put() { } 01588 01589 /** 01590 * @brief Format and output a monetary value. 01591 * 01592 * This function formats @a units as a monetary value according to 01593 * moneypunct and ctype facets retrieved from io.getloc(), and writes 01594 * the resulting characters to @a s. For example, the value 1001 in a 01595 * US locale would write <code>$10.01</code> to @a s. 01596 * 01597 * This function is a hook for derived classes to change the value 01598 * returned. @see put(). 01599 * 01600 * @param s The stream to write to. 01601 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >. 01602 * @param io Source of facets and io state. 01603 * @param fill char_type to use for padding. 01604 * @param units Place to store result of parsing. 01605 * @return Iterator after writing. 01606 */ 01607 // XXX GLIBCXX_ABI Deprecated 01608 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ 01609 virtual iter_type 01610 __do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, 01611 double __units) const; 01612 #else 01613 virtual iter_type 01614 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, 01615 long double __units) const; 01616 #endif 01617 01618 /** 01619 * @brief Format and output a monetary value. 01620 * 01621 * This function formats @a digits as a monetary value 01622 * according to moneypunct and ctype facets retrieved from 01623 * io.getloc(), and writes the resulting characters to @a s. 01624 * For example, the string <code>1001</code> in a US locale 01625 * would write <code>$10.01</code> to @a s. 01626 * 01627 * This function is a hook for derived classes to change the value 01628 * returned. @see put(). 01629 * 01630 * @param s The stream to write to. 01631 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >. 01632 * @param io Source of facets and io state. 01633 * @param fill char_type to use for padding. 01634 * @param units Place to store result of parsing. 01635 * @return Iterator after writing. 01636 */ 01637 virtual iter_type 01638 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, 01639 const string_type& __digits) const; 01640 01641 // XXX GLIBCXX_ABI Deprecated 01642 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ 01643 virtual iter_type 01644 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, 01645 long double __units) const; 01646 #endif 01647 01648 template<bool _Intl> 01649 iter_type 01650 _M_insert(iter_type __s, ios_base& __io, char_type __fill, 01651 const string_type& __digits) const; 01652 }; 01653 01654 template<typename _CharT, typename _OutIter> 01655 locale::id money_put<_CharT, _OutIter>::id; 01656 01657 _GLIBCXX_END_LDBL_NAMESPACE 01658 01659 /** 01660 * @brief Messages facet base class providing catalog typedef. 01661 * @ingroup locales 01662 */ 01663 struct messages_base 01664 { 01665 typedef int catalog; 01666 }; 01667 01668 /** 01669 * @brief Primary class template messages. 01670 * @ingroup locales 01671 * 01672 * This facet encapsulates the code to retrieve messages from 01673 * message catalogs. The only thing defined by the standard for this facet 01674 * is the interface. All underlying functionality is 01675 * implementation-defined. 01676 * 01677 * This library currently implements 3 versions of the message facet. The 01678 * first version (gnu) is a wrapper around gettext, provided by libintl. 01679 * The second version (ieee) is a wrapper around catgets. The final 01680 * version (default) does no actual translation. These implementations are 01681 * only provided for char and wchar_t instantiations. 01682 * 01683 * The messages template uses protected virtual functions to 01684 * provide the actual results. The public accessors forward the 01685 * call to the virtual functions. These virtual functions are 01686 * hooks for developers to implement the behavior they require from 01687 * the messages facet. 01688 */ 01689 template<typename _CharT> 01690 class messages : public locale::facet, public messages_base 01691 { 01692 public: 01693 // Types: 01694 //@{ 01695 /// Public typedefs 01696 typedef _CharT char_type; 01697 typedef basic_string<_CharT> string_type; 01698 //@} 01699 01700 protected: 01701 // Underlying "C" library locale information saved from 01702 // initialization, needed by messages_byname as well. 01703 __c_locale _M_c_locale_messages; 01704 const char* _M_name_messages; 01705 01706 public: 01707 /// Numpunct facet id. 01708 static locale::id id; 01709 01710 /** 01711 * @brief Constructor performs initialization. 01712 * 01713 * This is the constructor provided by the standard. 01714 * 01715 * @param refs Passed to the base facet class. 01716 */ 01717 explicit 01718 messages(size_t __refs = 0); 01719 01720 // Non-standard. 01721 /** 01722 * @brief Internal constructor. Not for general use. 01723 * 01724 * This is a constructor for use by the library itself to set up new 01725 * locales. 01726 * 01727 * @param cloc The C locale. 01728 * @param s The name of a locale. 01729 * @param refs Refcount to pass to the base class. 01730 */ 01731 explicit 01732 messages(__c_locale __cloc, const char* __s, size_t __refs = 0); 01733 01734 /* 01735 * @brief Open a message catalog. 01736 * 01737 * This function opens and returns a handle to a message catalog by 01738 * returning do_open(s, loc). 01739 * 01740 * @param s The catalog to open. 01741 * @param loc Locale to use for character set conversions. 01742 * @return Handle to the catalog or value < 0 if open fails. 01743 */ 01744 catalog 01745 open(const basic_string<char>& __s, const locale& __loc) const 01746 { return this->do_open(__s, __loc); } 01747 01748 // Non-standard and unorthodox, yet effective. 01749 /* 01750 * @brief Open a message catalog. 01751 * 01752 * This non-standard function opens and returns a handle to a message 01753 * catalog by returning do_open(s, loc). The third argument provides a 01754 * message catalog root directory for gnu gettext and is ignored 01755 * otherwise. 01756 * 01757 * @param s The catalog to open. 01758 * @param loc Locale to use for character set conversions. 01759 * @param dir Message catalog root directory. 01760 * @return Handle to the catalog or value < 0 if open fails. 01761 */ 01762 catalog 01763 open(const basic_string<char>&, const locale&, const char*) const; 01764 01765 /* 01766 * @brief Look up a string in a message catalog. 01767 * 01768 * This function retrieves and returns a message from a catalog by 01769 * returning do_get(c, set, msgid, s). 01770 * 01771 * For gnu, @a set and @a msgid are ignored. Returns gettext(s). 01772 * For default, returns s. For ieee, returns catgets(c,set,msgid,s). 01773 * 01774 * @param c The catalog to access. 01775 * @param set Implementation-defined. 01776 * @param msgid Implementation-defined. 01777 * @param s Default return value if retrieval fails. 01778 * @return Retrieved message or @a s if get fails. 01779 */ 01780 string_type 01781 get(catalog __c, int __set, int __msgid, const string_type& __s) const 01782 { return this->do_get(__c, __set, __msgid, __s); } 01783 01784 /* 01785 * @brief Close a message catalog. 01786 * 01787 * Closes catalog @a c by calling do_close(c). 01788 * 01789 * @param c The catalog to close. 01790 */ 01791 void 01792 close(catalog __c) const 01793 { return this->do_close(__c); } 01794 01795 protected: 01796 /// Destructor. 01797 virtual 01798 ~messages(); 01799 01800 /* 01801 * @brief Open a message catalog. 01802 * 01803 * This function opens and returns a handle to a message catalog in an 01804 * implementation-defined manner. This function is a hook for derived 01805 * classes to change the value returned. 01806 * 01807 * @param s The catalog to open. 01808 * @param loc Locale to use for character set conversions. 01809 * @return Handle to the opened catalog, value < 0 if open failed. 01810 */ 01811 virtual catalog 01812 do_open(const basic_string<char>&, const locale&) const; 01813 01814 /* 01815 * @brief Look up a string in a message catalog. 01816 * 01817 * This function retrieves and returns a message from a catalog in an 01818 * implementation-defined manner. This function is a hook for derived 01819 * classes to change the value returned. 01820 * 01821 * For gnu, @a set and @a msgid are ignored. Returns gettext(s). 01822 * For default, returns s. For ieee, returns catgets(c,set,msgid,s). 01823 * 01824 * @param c The catalog to access. 01825 * @param set Implementation-defined. 01826 * @param msgid Implementation-defined. 01827 * @param s Default return value if retrieval fails. 01828 * @return Retrieved message or @a s if get fails. 01829 */ 01830 virtual string_type 01831 do_get(catalog, int, int, const string_type& __dfault) const; 01832 01833 /* 01834 * @brief Close a message catalog. 01835 * 01836 * @param c The catalog to close. 01837 */ 01838 virtual void 01839 do_close(catalog) const; 01840 01841 // Returns a locale and codeset-converted string, given a char* message. 01842 char* 01843 _M_convert_to_char(const string_type& __msg) const 01844 { 01845 // XXX 01846 return reinterpret_cast<char*>(const_cast<_CharT*>(__msg.c_str())); 01847 } 01848 01849 // Returns a locale and codeset-converted string, given a char* message. 01850 string_type 01851 _M_convert_from_char(char*) const 01852 { 01853 #if 0 01854 // Length of message string without terminating null. 01855 size_t __len = char_traits<char>::length(__msg) - 1; 01856 01857 // "everybody can easily convert the string using 01858 // mbsrtowcs/wcsrtombs or with iconv()" 01859 01860 // Convert char* to _CharT in locale used to open catalog. 01861 // XXX need additional template parameter on messages class for this.. 01862 // typedef typename codecvt<char, _CharT, _StateT> __codecvt_type; 01863 typedef typename codecvt<char, _CharT, mbstate_t> __codecvt_type; 01864 01865 __codecvt_type::state_type __state; 01866 // XXX may need to initialize state. 01867 //initialize_state(__state._M_init()); 01868 01869 char* __from_next; 01870 // XXX what size for this string? 01871 _CharT* __to = static_cast<_CharT*>(__builtin_alloca(__len + 1)); 01872 const __codecvt_type& __cvt = use_facet<__codecvt_type>(_M_locale_conv); 01873 __cvt.out(__state, __msg, __msg + __len, __from_next, 01874 __to, __to + __len + 1, __to_next); 01875 return string_type(__to); 01876 #endif 01877 #if 0 01878 typedef ctype<_CharT> __ctype_type; 01879 // const __ctype_type& __cvt = use_facet<__ctype_type>(_M_locale_msg); 01880 const __ctype_type& __cvt = use_facet<__ctype_type>(locale()); 01881 // XXX Again, proper length of converted string an issue here. 01882 // For now, assume the converted length is not larger. 01883 _CharT* __dest = static_cast<_CharT*>(__builtin_alloca(__len + 1)); 01884 __cvt.widen(__msg, __msg + __len, __dest); 01885 return basic_string<_CharT>(__dest); 01886 #endif 01887 return string_type(); 01888 } 01889 }; 01890 01891 template<typename _CharT> 01892 locale::id messages<_CharT>::id; 01893 01894 /// Specializations for required instantiations. 01895 template<> 01896 string 01897 messages<char>::do_get(catalog, int, int, const string&) const; 01898 01899 #ifdef _GLIBCXX_USE_WCHAR_T 01900 template<> 01901 wstring 01902 messages<wchar_t>::do_get(catalog, int, int, const wstring&) const; 01903 #endif 01904 01905 /// class messages_byname [22.2.7.2]. 01906 template<typename _CharT> 01907 class messages_byname : public messages<_CharT> 01908 { 01909 public: 01910 typedef _CharT char_type; 01911 typedef basic_string<_CharT> string_type; 01912 01913 explicit 01914 messages_byname(const char* __s, size_t __refs = 0); 01915 01916 protected: 01917 virtual 01918 ~messages_byname() 01919 { } 01920 }; 01921 01922 _GLIBCXX_END_NAMESPACE 01923 01924 // Include host and configuration specific messages functions. 01925 #include <bits/messages_members.h> 01926 01927 // 22.2.1.5 Template class codecvt 01928 #include <bits/codecvt.h> 01929 01930 #ifndef _GLIBCXX_EXPORT_TEMPLATE 01931 # include <bits/locale_facets_nonio.tcc> 01932 #endif 01933 01934 #endif