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