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