1 // Locale support -*- C++ -*-
3 // Copyright (C) 2007-2015 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file bits/locale_facets_nonio.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{locale}
31 // ISO C++ 14882: 22.1 Locales
34 #ifndef _LOCALE_FACETS_NONIO_H
35 #define _LOCALE_FACETS_NONIO_H 1
37 #pragma GCC system_header
39 #include <ctime> // For struct tm
41 namespace std
_GLIBCXX_VISIBILITY(default)
43 _GLIBCXX_BEGIN_NAMESPACE_VERSION
46 * @brief Time format ordering data.
49 * This class provides an enum representing different orderings of
50 * time: day, month, and year.
55 enum dateorder
{ no_order
, dmy
, mdy
, ymd
, ydm
};
58 template<typename _CharT
>
59 struct __timepunct_cache
: public locale::facet
61 // List of all known timezones, with GMT first.
62 static const _CharT
* _S_timezones
[14];
64 const _CharT
* _M_date_format
;
65 const _CharT
* _M_date_era_format
;
66 const _CharT
* _M_time_format
;
67 const _CharT
* _M_time_era_format
;
68 const _CharT
* _M_date_time_format
;
69 const _CharT
* _M_date_time_era_format
;
72 const _CharT
* _M_am_pm_format
;
74 // Day names, starting with "C"'s Sunday.
75 const _CharT
* _M_day1
;
76 const _CharT
* _M_day2
;
77 const _CharT
* _M_day3
;
78 const _CharT
* _M_day4
;
79 const _CharT
* _M_day5
;
80 const _CharT
* _M_day6
;
81 const _CharT
* _M_day7
;
83 // Abbreviated day names, starting with "C"'s Sun.
84 const _CharT
* _M_aday1
;
85 const _CharT
* _M_aday2
;
86 const _CharT
* _M_aday3
;
87 const _CharT
* _M_aday4
;
88 const _CharT
* _M_aday5
;
89 const _CharT
* _M_aday6
;
90 const _CharT
* _M_aday7
;
92 // Month names, starting with "C"'s January.
93 const _CharT
* _M_month01
;
94 const _CharT
* _M_month02
;
95 const _CharT
* _M_month03
;
96 const _CharT
* _M_month04
;
97 const _CharT
* _M_month05
;
98 const _CharT
* _M_month06
;
99 const _CharT
* _M_month07
;
100 const _CharT
* _M_month08
;
101 const _CharT
* _M_month09
;
102 const _CharT
* _M_month10
;
103 const _CharT
* _M_month11
;
104 const _CharT
* _M_month12
;
106 // Abbreviated month names, starting with "C"'s Jan.
107 const _CharT
* _M_amonth01
;
108 const _CharT
* _M_amonth02
;
109 const _CharT
* _M_amonth03
;
110 const _CharT
* _M_amonth04
;
111 const _CharT
* _M_amonth05
;
112 const _CharT
* _M_amonth06
;
113 const _CharT
* _M_amonth07
;
114 const _CharT
* _M_amonth08
;
115 const _CharT
* _M_amonth09
;
116 const _CharT
* _M_amonth10
;
117 const _CharT
* _M_amonth11
;
118 const _CharT
* _M_amonth12
;
122 __timepunct_cache(size_t __refs
= 0) : facet(__refs
),
123 _M_date_format(0), _M_date_era_format(0), _M_time_format(0),
124 _M_time_era_format(0), _M_date_time_format(0),
125 _M_date_time_era_format(0), _M_am(0), _M_pm(0),
126 _M_am_pm_format(0), _M_day1(0), _M_day2(0), _M_day3(0),
127 _M_day4(0), _M_day5(0), _M_day6(0), _M_day7(0),
128 _M_aday1(0), _M_aday2(0), _M_aday3(0), _M_aday4(0),
129 _M_aday5(0), _M_aday6(0), _M_aday7(0), _M_month01(0),
130 _M_month02(0), _M_month03(0), _M_month04(0), _M_month05(0),
131 _M_month06(0), _M_month07(0), _M_month08(0), _M_month09(0),
132 _M_month10(0), _M_month11(0), _M_month12(0), _M_amonth01(0),
133 _M_amonth02(0), _M_amonth03(0), _M_amonth04(0),
134 _M_amonth05(0), _M_amonth06(0), _M_amonth07(0),
135 _M_amonth08(0), _M_amonth09(0), _M_amonth10(0),
136 _M_amonth11(0), _M_amonth12(0), _M_allocated(false)
139 ~__timepunct_cache();
143 operator=(const __timepunct_cache
&);
146 __timepunct_cache(const __timepunct_cache
&);
149 template<typename _CharT
>
150 __timepunct_cache
<_CharT
>::~__timepunct_cache()
161 __timepunct_cache
<char>::_S_timezones
[14];
163 #ifdef _GLIBCXX_USE_WCHAR_T
166 __timepunct_cache
<wchar_t>::_S_timezones
[14];
170 template<typename _CharT
>
171 const _CharT
* __timepunct_cache
<_CharT
>::_S_timezones
[14];
173 template<typename _CharT
>
174 class __timepunct
: public locale::facet
178 typedef _CharT __char_type
;
179 typedef __timepunct_cache
<_CharT
> __cache_type
;
182 __cache_type
* _M_data
;
183 __c_locale _M_c_locale_timepunct
;
184 const char* _M_name_timepunct
;
187 /// Numpunct facet id.
188 static locale::id id
;
191 __timepunct(size_t __refs
= 0);
194 __timepunct(__cache_type
* __cache
, size_t __refs
= 0);
197 * @brief Internal constructor. Not for general use.
199 * This is a constructor for use by the library itself to set up new
202 * @param __cloc The C locale.
203 * @param __s The name of a locale.
204 * @param refs Passed to the base facet class.
207 __timepunct(__c_locale __cloc
, const char* __s
, size_t __refs
= 0);
209 // FIXME: for error checking purposes _M_put should return the return
210 // value of strftime/wcsftime.
212 _M_put(_CharT
* __s
, size_t __maxlen
, const _CharT
* __format
,
213 const tm
* __tm
) const throw ();
216 _M_date_formats(const _CharT
** __date
) const
218 // Always have default first.
219 __date
[0] = _M_data
->_M_date_format
;
220 __date
[1] = _M_data
->_M_date_era_format
;
224 _M_time_formats(const _CharT
** __time
) const
226 // Always have default first.
227 __time
[0] = _M_data
->_M_time_format
;
228 __time
[1] = _M_data
->_M_time_era_format
;
232 _M_date_time_formats(const _CharT
** __dt
) const
234 // Always have default first.
235 __dt
[0] = _M_data
->_M_date_time_format
;
236 __dt
[1] = _M_data
->_M_date_time_era_format
;
240 _M_am_pm_format(const _CharT
* __ampm
) const
241 { __ampm
= _M_data
->_M_am_pm_format
; }
244 _M_am_pm(const _CharT
** __ampm
) const
246 __ampm
[0] = _M_data
->_M_am
;
247 __ampm
[1] = _M_data
->_M_pm
;
251 _M_days(const _CharT
** __days
) const
253 __days
[0] = _M_data
->_M_day1
;
254 __days
[1] = _M_data
->_M_day2
;
255 __days
[2] = _M_data
->_M_day3
;
256 __days
[3] = _M_data
->_M_day4
;
257 __days
[4] = _M_data
->_M_day5
;
258 __days
[5] = _M_data
->_M_day6
;
259 __days
[6] = _M_data
->_M_day7
;
263 _M_days_abbreviated(const _CharT
** __days
) const
265 __days
[0] = _M_data
->_M_aday1
;
266 __days
[1] = _M_data
->_M_aday2
;
267 __days
[2] = _M_data
->_M_aday3
;
268 __days
[3] = _M_data
->_M_aday4
;
269 __days
[4] = _M_data
->_M_aday5
;
270 __days
[5] = _M_data
->_M_aday6
;
271 __days
[6] = _M_data
->_M_aday7
;
275 _M_months(const _CharT
** __months
) const
277 __months
[0] = _M_data
->_M_month01
;
278 __months
[1] = _M_data
->_M_month02
;
279 __months
[2] = _M_data
->_M_month03
;
280 __months
[3] = _M_data
->_M_month04
;
281 __months
[4] = _M_data
->_M_month05
;
282 __months
[5] = _M_data
->_M_month06
;
283 __months
[6] = _M_data
->_M_month07
;
284 __months
[7] = _M_data
->_M_month08
;
285 __months
[8] = _M_data
->_M_month09
;
286 __months
[9] = _M_data
->_M_month10
;
287 __months
[10] = _M_data
->_M_month11
;
288 __months
[11] = _M_data
->_M_month12
;
292 _M_months_abbreviated(const _CharT
** __months
) const
294 __months
[0] = _M_data
->_M_amonth01
;
295 __months
[1] = _M_data
->_M_amonth02
;
296 __months
[2] = _M_data
->_M_amonth03
;
297 __months
[3] = _M_data
->_M_amonth04
;
298 __months
[4] = _M_data
->_M_amonth05
;
299 __months
[5] = _M_data
->_M_amonth06
;
300 __months
[6] = _M_data
->_M_amonth07
;
301 __months
[7] = _M_data
->_M_amonth08
;
302 __months
[8] = _M_data
->_M_amonth09
;
303 __months
[9] = _M_data
->_M_amonth10
;
304 __months
[10] = _M_data
->_M_amonth11
;
305 __months
[11] = _M_data
->_M_amonth12
;
312 // For use at construction time only.
314 _M_initialize_timepunct(__c_locale __cloc
= 0);
317 template<typename _CharT
>
318 locale::id __timepunct
<_CharT
>::id
;
323 __timepunct
<char>::_M_initialize_timepunct(__c_locale __cloc
);
327 __timepunct
<char>::_M_put(char*, size_t, const char*, const tm
*) const throw ();
329 #ifdef _GLIBCXX_USE_WCHAR_T
332 __timepunct
<wchar_t>::_M_initialize_timepunct(__c_locale __cloc
);
336 __timepunct
<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*,
337 const tm
*) const throw ();
340 _GLIBCXX_END_NAMESPACE_VERSION
343 // Include host and configuration specific timepunct functions.
344 #include <bits/time_members.h>
346 namespace std
_GLIBCXX_VISIBILITY(default)
348 _GLIBCXX_BEGIN_NAMESPACE_VERSION
350 _GLIBCXX_BEGIN_NAMESPACE_CXX11
353 * @brief Primary class template time_get.
356 * This facet encapsulates the code to parse and return a date or
357 * time from a string. It is used by the istream numeric
358 * extraction operators.
360 * The time_get template uses protected virtual functions to provide the
361 * actual results. The public accessors forward the call to the virtual
362 * functions. These virtual functions are hooks for developers to
363 * implement the behavior they require from the time_get facet.
365 template<typename _CharT
, typename _InIter
>
366 class time_get
: public locale::facet
, public time_base
372 typedef _CharT char_type
;
373 typedef _InIter iter_type
;
376 /// Numpunct facet id.
377 static locale::id id
;
380 * @brief Constructor performs initialization.
382 * This is the constructor provided by the standard.
384 * @param __refs Passed to the base facet class.
387 time_get(size_t __refs
= 0)
391 * @brief Return preferred order of month, day, and year.
393 * This function returns an enum from time_base::dateorder giving the
394 * preferred ordering if the format @a x given to time_put::put() only
395 * uses month, day, and year. If the format @a x for the associated
396 * locale uses other fields, this function returns
397 * time_base::dateorder::noorder.
399 * NOTE: The library always returns noorder at the moment.
401 * @return A member of time_base::dateorder.
405 { return this->do_date_order(); }
408 * @brief Parse input time string.
410 * This function parses a time according to the format @a X and puts the
411 * results into a user-supplied struct tm. The result is returned by
412 * calling time_get::do_get_time().
414 * If there is a valid time string according to format @a X, @a tm will
415 * be filled in accordingly and the returned iterator will point to the
416 * first character beyond the time string. If an error occurs before
417 * the end, err |= ios_base::failbit. If parsing reads all the
418 * characters, err |= ios_base::eofbit.
420 * @param __beg Start of string to parse.
421 * @param __end End of string to parse.
422 * @param __io Source of the locale.
423 * @param __err Error flags to set.
424 * @param __tm Pointer to struct tm to fill in.
425 * @return Iterator to first char beyond time string.
428 get_time(iter_type __beg
, iter_type __end
, ios_base
& __io
,
429 ios_base::iostate
& __err
, tm
* __tm
) const
430 { return this->do_get_time(__beg
, __end
, __io
, __err
, __tm
); }
433 * @brief Parse input date string.
435 * This function parses a date according to the format @a x and puts the
436 * results into a user-supplied struct tm. The result is returned by
437 * calling time_get::do_get_date().
439 * If there is a valid date string according to format @a x, @a tm will
440 * be filled in accordingly and the returned iterator will point to the
441 * first character beyond the date string. If an error occurs before
442 * the end, err |= ios_base::failbit. If parsing reads all the
443 * characters, err |= ios_base::eofbit.
445 * @param __beg Start of string to parse.
446 * @param __end End of string to parse.
447 * @param __io Source of the locale.
448 * @param __err Error flags to set.
449 * @param __tm Pointer to struct tm to fill in.
450 * @return Iterator to first char beyond date string.
453 get_date(iter_type __beg
, iter_type __end
, ios_base
& __io
,
454 ios_base::iostate
& __err
, tm
* __tm
) const
455 { return this->do_get_date(__beg
, __end
, __io
, __err
, __tm
); }
458 * @brief Parse input weekday string.
460 * This function parses a weekday name and puts the results into a
461 * user-supplied struct tm. The result is returned by calling
462 * time_get::do_get_weekday().
464 * Parsing starts by parsing an abbreviated weekday name. If a valid
465 * abbreviation is followed by a character that would lead to the full
466 * weekday name, parsing continues until the full name is found or an
467 * error occurs. Otherwise parsing finishes at the end of the
470 * If an error occurs before the end, err |= ios_base::failbit. If
471 * parsing reads all the characters, err |= ios_base::eofbit.
473 * @param __beg Start of string to parse.
474 * @param __end End of string to parse.
475 * @param __io Source of the locale.
476 * @param __err Error flags to set.
477 * @param __tm Pointer to struct tm to fill in.
478 * @return Iterator to first char beyond weekday name.
481 get_weekday(iter_type __beg
, iter_type __end
, ios_base
& __io
,
482 ios_base::iostate
& __err
, tm
* __tm
) const
483 { return this->do_get_weekday(__beg
, __end
, __io
, __err
, __tm
); }
486 * @brief Parse input month string.
488 * This function parses a month name and puts the results into a
489 * user-supplied struct tm. The result is returned by calling
490 * time_get::do_get_monthname().
492 * Parsing starts by parsing an abbreviated month name. If a valid
493 * abbreviation is followed by a character that would lead to the full
494 * month name, parsing continues until the full name is found or an
495 * error occurs. Otherwise parsing finishes at the end of the
498 * If an error occurs before the end, err |= ios_base::failbit. If
499 * parsing reads all the characters, err |=
502 * @param __beg Start of string to parse.
503 * @param __end End of string to parse.
504 * @param __io Source of the locale.
505 * @param __err Error flags to set.
506 * @param __tm Pointer to struct tm to fill in.
507 * @return Iterator to first char beyond month name.
510 get_monthname(iter_type __beg
, iter_type __end
, ios_base
& __io
,
511 ios_base::iostate
& __err
, tm
* __tm
) const
512 { return this->do_get_monthname(__beg
, __end
, __io
, __err
, __tm
); }
515 * @brief Parse input year string.
517 * This function reads up to 4 characters to parse a year string and
518 * puts the results into a user-supplied struct tm. The result is
519 * returned by calling time_get::do_get_year().
521 * 4 consecutive digits are interpreted as a full year. If there are
522 * exactly 2 consecutive digits, the library interprets this as the
523 * number of years since 1900.
525 * If an error occurs before the end, err |= ios_base::failbit. If
526 * parsing reads all the characters, err |= ios_base::eofbit.
528 * @param __beg Start of string to parse.
529 * @param __end End of string to parse.
530 * @param __io Source of the locale.
531 * @param __err Error flags to set.
532 * @param __tm Pointer to struct tm to fill in.
533 * @return Iterator to first char beyond year.
536 get_year(iter_type __beg
, iter_type __end
, ios_base
& __io
,
537 ios_base::iostate
& __err
, tm
* __tm
) const
538 { return this->do_get_year(__beg
, __end
, __io
, __err
, __tm
); }
540 #if __cplusplus >= 201103L
542 * @brief Parse input string according to format.
544 * This function calls time_get::do_get with the provided
545 * parameters. @see do_get() and get().
547 * @param __s Start of string to parse.
548 * @param __end End of string to parse.
549 * @param __io Source of the locale.
550 * @param __err Error flags to set.
551 * @param __tm Pointer to struct tm to fill in.
552 * @param __format Format specifier.
553 * @param __modifier Format modifier.
554 * @return Iterator to first char not parsed.
557 iter_type
get(iter_type __s
, iter_type __end
, ios_base
& __io
,
558 ios_base::iostate
& __err
, tm
* __tm
, char __format
,
559 char __modifier
= 0) const
561 return this->do_get(__s
, __end
, __io
, __err
, __tm
, __format
,
566 * @brief Parse input string according to format.
568 * This function parses the input string according to a
569 * provided format string. It does the inverse of
570 * time_put::put. The format string follows the format
571 * specified for strftime(3)/strptime(3). The actual parsing
572 * is done by time_get::do_get.
574 * @param __s Start of string to parse.
575 * @param __end End of string to parse.
576 * @param __io Source of the locale.
577 * @param __err Error flags to set.
578 * @param __tm Pointer to struct tm to fill in.
579 * @param __fmt Start of the format string.
580 * @param __fmtend End of the format string.
581 * @return Iterator to first char not parsed.
583 iter_type
get(iter_type __s
, iter_type __end
, ios_base
& __io
,
584 ios_base::iostate
& __err
, tm
* __tm
, const char_type
* __fmt
,
585 const char_type
* __fmtend
) const;
586 #endif // __cplusplus >= 201103L
594 * @brief Return preferred order of month, day, and year.
596 * This function returns an enum from time_base::dateorder giving the
597 * preferred ordering if the format @a x given to time_put::put() only
598 * uses month, day, and year. This function is a hook for derived
599 * classes to change the value returned.
601 * @return A member of time_base::dateorder.
604 do_date_order() const;
607 * @brief Parse input time string.
609 * This function parses a time according to the format @a x and puts the
610 * results into a user-supplied struct tm. This function is a hook for
611 * derived classes to change the value returned. @see get_time() for
614 * @param __beg Start of string to parse.
615 * @param __end End of string to parse.
616 * @param __io Source of the locale.
617 * @param __err Error flags to set.
618 * @param __tm Pointer to struct tm to fill in.
619 * @return Iterator to first char beyond time string.
622 do_get_time(iter_type __beg
, iter_type __end
, ios_base
& __io
,
623 ios_base::iostate
& __err
, tm
* __tm
) const;
626 * @brief Parse input date string.
628 * This function parses a date according to the format @a X and puts the
629 * results into a user-supplied struct tm. This function is a hook for
630 * derived classes to change the value returned. @see get_date() for
633 * @param __beg Start of string to parse.
634 * @param __end End of string to parse.
635 * @param __io Source of the locale.
636 * @param __err Error flags to set.
637 * @param __tm Pointer to struct tm to fill in.
638 * @return Iterator to first char beyond date string.
641 do_get_date(iter_type __beg
, iter_type __end
, ios_base
& __io
,
642 ios_base::iostate
& __err
, tm
* __tm
) const;
645 * @brief Parse input weekday string.
647 * This function parses a weekday name and puts the results into a
648 * user-supplied struct tm. This function is a hook for derived
649 * classes to change the value returned. @see get_weekday() for
652 * @param __beg Start of string to parse.
653 * @param __end End of string to parse.
654 * @param __io Source of the locale.
655 * @param __err Error flags to set.
656 * @param __tm Pointer to struct tm to fill in.
657 * @return Iterator to first char beyond weekday name.
660 do_get_weekday(iter_type __beg
, iter_type __end
, ios_base
&,
661 ios_base::iostate
& __err
, tm
* __tm
) const;
664 * @brief Parse input month string.
666 * This function parses a month name and puts the results into a
667 * user-supplied struct tm. This function is a hook for derived
668 * classes to change the value returned. @see get_monthname() for
671 * @param __beg Start of string to parse.
672 * @param __end End of string to parse.
673 * @param __io Source of the locale.
674 * @param __err Error flags to set.
675 * @param __tm Pointer to struct tm to fill in.
676 * @return Iterator to first char beyond month name.
679 do_get_monthname(iter_type __beg
, iter_type __end
, ios_base
&,
680 ios_base::iostate
& __err
, tm
* __tm
) const;
683 * @brief Parse input year string.
685 * This function reads up to 4 characters to parse a year string and
686 * puts the results into a user-supplied struct tm. This function is a
687 * hook for derived classes to change the value returned. @see
688 * get_year() for details.
690 * @param __beg Start of string to parse.
691 * @param __end End of string to parse.
692 * @param __io Source of the locale.
693 * @param __err Error flags to set.
694 * @param __tm Pointer to struct tm to fill in.
695 * @return Iterator to first char beyond year.
698 do_get_year(iter_type __beg
, iter_type __end
, ios_base
& __io
,
699 ios_base::iostate
& __err
, tm
* __tm
) const;
701 #if __cplusplus >= 201103L
703 * @brief Parse input string according to format.
705 * This function parses the string according to the provided
706 * format and optional modifier. This function is a hook for
707 * derived classes to change the value returned. @see get()
710 * @param __s Start of string to parse.
711 * @param __end End of string to parse.
712 * @param __io Source of the locale.
713 * @param __err Error flags to set.
714 * @param __tm Pointer to struct tm to fill in.
715 * @param __format Format specifier.
716 * @param __modifier Format modifier.
717 * @return Iterator to first char not parsed.
719 #if _GLIBCXX_USE_CXX11_ABI
723 do_get(iter_type __s
, iter_type __end
, ios_base
& __f
,
724 ios_base::iostate
& __err
, tm
* __tm
,
725 char __format
, char __modifier
) const;
726 #endif // __cplusplus >= 201103L
728 // Extract numeric component of length __len.
730 _M_extract_num(iter_type __beg
, iter_type __end
, int& __member
,
731 int __min
, int __max
, size_t __len
,
732 ios_base
& __io
, ios_base::iostate
& __err
) const;
734 // Extract any unique array of string literals in a const _CharT* array.
736 _M_extract_name(iter_type __beg
, iter_type __end
, int& __member
,
737 const _CharT
** __names
, size_t __indexlen
,
738 ios_base
& __io
, ios_base::iostate
& __err
) const;
740 // Extract day or month name in a const _CharT* array.
742 _M_extract_wday_or_month(iter_type __beg
, iter_type __end
, int& __member
,
743 const _CharT
** __names
, size_t __indexlen
,
744 ios_base
& __io
, ios_base::iostate
& __err
) const;
746 // Extract on a component-by-component basis, via __format argument.
748 _M_extract_via_format(iter_type __beg
, iter_type __end
, ios_base
& __io
,
749 ios_base::iostate
& __err
, tm
* __tm
,
750 const _CharT
* __format
) const;
753 template<typename _CharT
, typename _InIter
>
754 locale::id time_get
<_CharT
, _InIter
>::id
;
756 /// class time_get_byname [22.2.5.2].
757 template<typename _CharT
, typename _InIter
>
758 class time_get_byname
: public time_get
<_CharT
, _InIter
>
762 typedef _CharT char_type
;
763 typedef _InIter iter_type
;
766 time_get_byname(const char*, size_t __refs
= 0)
767 : time_get
<_CharT
, _InIter
>(__refs
) { }
769 #if __cplusplus >= 201103L
771 time_get_byname(const string
& __s
, size_t __refs
= 0)
772 : time_get_byname(__s
.c_str(), __refs
) { }
777 ~time_get_byname() { }
780 _GLIBCXX_END_NAMESPACE_CXX11
783 * @brief Primary class template time_put.
786 * This facet encapsulates the code to format and output dates and times
787 * according to formats used by strftime().
789 * The time_put template uses protected virtual functions to provide the
790 * actual results. The public accessors forward the call to the virtual
791 * functions. These virtual functions are hooks for developers to
792 * implement the behavior they require from the time_put facet.
794 template<typename _CharT
, typename _OutIter
>
795 class time_put
: public locale::facet
801 typedef _CharT char_type
;
802 typedef _OutIter iter_type
;
805 /// Numpunct facet id.
806 static locale::id id
;
809 * @brief Constructor performs initialization.
811 * This is the constructor provided by the standard.
813 * @param __refs Passed to the base facet class.
816 time_put(size_t __refs
= 0)
820 * @brief Format and output a time or date.
822 * This function formats the data in struct tm according to the
823 * provided format string. The format string is interpreted as by
826 * @param __s The stream to write to.
827 * @param __io Source of locale.
828 * @param __fill char_type to use for padding.
829 * @param __tm Struct tm with date and time info to format.
830 * @param __beg Start of format string.
831 * @param __end End of format string.
832 * @return Iterator after writing.
835 put(iter_type __s
, ios_base
& __io
, char_type __fill
, const tm
* __tm
,
836 const _CharT
* __beg
, const _CharT
* __end
) const;
839 * @brief Format and output a time or date.
841 * This function formats the data in struct tm according to the
842 * provided format char and optional modifier. The format and modifier
843 * are interpreted as by strftime(). It does so by returning
844 * time_put::do_put().
846 * @param __s The stream to write to.
847 * @param __io Source of locale.
848 * @param __fill char_type to use for padding.
849 * @param __tm Struct tm with date and time info to format.
850 * @param __format Format char.
851 * @param __mod Optional modifier char.
852 * @return Iterator after writing.
855 put(iter_type __s
, ios_base
& __io
, char_type __fill
,
856 const tm
* __tm
, char __format
, char __mod
= 0) const
857 { return this->do_put(__s
, __io
, __fill
, __tm
, __format
, __mod
); }
866 * @brief Format and output a time or date.
868 * This function formats the data in struct tm according to the
869 * provided format char and optional modifier. This function is a hook
870 * for derived classes to change the value returned. @see put() for
873 * @param __s The stream to write to.
874 * @param __io Source of locale.
875 * @param __fill char_type to use for padding.
876 * @param __tm Struct tm with date and time info to format.
877 * @param __format Format char.
878 * @param __mod Optional modifier char.
879 * @return Iterator after writing.
882 do_put(iter_type __s
, ios_base
& __io
, char_type __fill
, const tm
* __tm
,
883 char __format
, char __mod
) const;
886 template<typename _CharT
, typename _OutIter
>
887 locale::id time_put
<_CharT
, _OutIter
>::id
;
889 /// class time_put_byname [22.2.5.4].
890 template<typename _CharT
, typename _OutIter
>
891 class time_put_byname
: public time_put
<_CharT
, _OutIter
>
895 typedef _CharT char_type
;
896 typedef _OutIter iter_type
;
899 time_put_byname(const char*, size_t __refs
= 0)
900 : time_put
<_CharT
, _OutIter
>(__refs
)
903 #if __cplusplus >= 201103L
905 time_put_byname(const string
& __s
, size_t __refs
= 0)
906 : time_put_byname(__s
.c_str(), __refs
) { }
911 ~time_put_byname() { }
916 * @brief Money format ordering data.
919 * This class contains an ordered array of 4 fields to represent the
920 * pattern for formatting a money amount. Each field may contain one entry
921 * from the part enum. symbol, sign, and value must be present and the
922 * remaining field must contain either none or space. @see
923 * moneypunct::pos_format() and moneypunct::neg_format() for details of how
924 * these fields are interpreted.
929 enum part
{ none
, space
, symbol
, sign
, value
};
930 struct pattern
{ char field
[4]; };
932 static const pattern _S_default_pattern
;
941 // String literal of acceptable (narrow) input/output, for
942 // money_get/money_put. "-0123456789"
943 static const char* _S_atoms
;
945 // Construct and return valid pattern consisting of some combination of:
946 // space none symbol sign value
947 _GLIBCXX_CONST
static pattern
948 _S_construct_pattern(char __precedes
, char __space
, char __posn
) throw ();
951 template<typename _CharT
, bool _Intl
>
952 struct __moneypunct_cache
: public locale::facet
954 const char* _M_grouping
;
955 size_t _M_grouping_size
;
956 bool _M_use_grouping
;
957 _CharT _M_decimal_point
;
958 _CharT _M_thousands_sep
;
959 const _CharT
* _M_curr_symbol
;
960 size_t _M_curr_symbol_size
;
961 const _CharT
* _M_positive_sign
;
962 size_t _M_positive_sign_size
;
963 const _CharT
* _M_negative_sign
;
964 size_t _M_negative_sign_size
;
966 money_base::pattern _M_pos_format
;
967 money_base::pattern _M_neg_format
;
969 // A list of valid numeric literals for input and output: in the standard
970 // "C" locale, this is "-0123456789". This array contains the chars after
971 // having been passed through the current locale's ctype<_CharT>.widen().
972 _CharT _M_atoms
[money_base::_S_end
];
976 __moneypunct_cache(size_t __refs
= 0) : facet(__refs
),
977 _M_grouping(0), _M_grouping_size(0), _M_use_grouping(false),
978 _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()),
979 _M_curr_symbol(0), _M_curr_symbol_size(0),
980 _M_positive_sign(0), _M_positive_sign_size(0),
981 _M_negative_sign(0), _M_negative_sign_size(0),
983 _M_pos_format(money_base::pattern()),
984 _M_neg_format(money_base::pattern()), _M_allocated(false)
987 ~__moneypunct_cache();
990 _M_cache(const locale
& __loc
);
994 operator=(const __moneypunct_cache
&);
997 __moneypunct_cache(const __moneypunct_cache
&);
1000 template<typename _CharT
, bool _Intl
>
1001 __moneypunct_cache
<_CharT
, _Intl
>::~__moneypunct_cache()
1005 delete [] _M_grouping
;
1006 delete [] _M_curr_symbol
;
1007 delete [] _M_positive_sign
;
1008 delete [] _M_negative_sign
;
1012 _GLIBCXX_BEGIN_NAMESPACE_CXX11
1015 * @brief Primary class template moneypunct.
1018 * This facet encapsulates the punctuation, grouping and other formatting
1019 * features of money amount string representations.
1021 template<typename _CharT
, bool _Intl
>
1022 class moneypunct
: public locale::facet
, public money_base
1028 typedef _CharT char_type
;
1029 typedef basic_string
<_CharT
> string_type
;
1031 typedef __moneypunct_cache
<_CharT
, _Intl
> __cache_type
;
1034 __cache_type
* _M_data
;
1037 /// This value is provided by the standard, but no reason for its
1039 static const bool intl
= _Intl
;
1040 /// Numpunct facet id.
1041 static locale::id id
;
1044 * @brief Constructor performs initialization.
1046 * This is the constructor provided by the standard.
1048 * @param __refs Passed to the base facet class.
1051 moneypunct(size_t __refs
= 0)
1052 : facet(__refs
), _M_data(0)
1053 { _M_initialize_moneypunct(); }
1056 * @brief Constructor performs initialization.
1058 * This is an internal constructor.
1060 * @param __cache Cache for optimization.
1061 * @param __refs Passed to the base facet class.
1064 moneypunct(__cache_type
* __cache
, size_t __refs
= 0)
1065 : facet(__refs
), _M_data(__cache
)
1066 { _M_initialize_moneypunct(); }
1069 * @brief Internal constructor. Not for general use.
1071 * This is a constructor for use by the library itself to set up new
1074 * @param __cloc The C locale.
1075 * @param __s The name of a locale.
1076 * @param __refs Passed to the base facet class.
1079 moneypunct(__c_locale __cloc
, const char* __s
, size_t __refs
= 0)
1080 : facet(__refs
), _M_data(0)
1081 { _M_initialize_moneypunct(__cloc
, __s
); }
1084 * @brief Return decimal point character.
1086 * This function returns a char_type to use as a decimal point. It
1087 * does so by returning returning
1088 * moneypunct<char_type>::do_decimal_point().
1090 * @return @a char_type representing a decimal point.
1093 decimal_point() const
1094 { return this->do_decimal_point(); }
1097 * @brief Return thousands separator character.
1099 * This function returns a char_type to use as a thousands
1100 * separator. It does so by returning returning
1101 * moneypunct<char_type>::do_thousands_sep().
1103 * @return char_type representing a thousands separator.
1106 thousands_sep() const
1107 { return this->do_thousands_sep(); }
1110 * @brief Return grouping specification.
1112 * This function returns a string representing groupings for the
1113 * integer part of an amount. Groupings indicate where thousands
1114 * separators should be inserted.
1116 * Each char in the return string is interpret as an integer rather
1117 * than a character. These numbers represent the number of digits in a
1118 * group. The first char in the string represents the number of digits
1119 * in the least significant group. If a char is negative, it indicates
1120 * an unlimited number of digits for the group. If more chars from the
1121 * string are required to group a number, the last char is used
1124 * For example, if the grouping() returns <code>\003\002</code>
1125 * and is applied to the number 123456789, this corresponds to
1126 * 12,34,56,789. Note that if the string was <code>32</code>, this would
1127 * put more than 50 digits into the least significant group if
1128 * the character set is ASCII.
1130 * The string is returned by calling
1131 * moneypunct<char_type>::do_grouping().
1133 * @return string representing grouping specification.
1137 { return this->do_grouping(); }
1140 * @brief Return currency symbol string.
1142 * This function returns a string_type to use as a currency symbol. It
1143 * does so by returning returning
1144 * moneypunct<char_type>::do_curr_symbol().
1146 * @return @a string_type representing a currency symbol.
1150 { return this->do_curr_symbol(); }
1153 * @brief Return positive sign string.
1155 * This function returns a string_type to use as a sign for positive
1156 * amounts. It does so by returning returning
1157 * moneypunct<char_type>::do_positive_sign().
1159 * If the return value contains more than one character, the first
1160 * character appears in the position indicated by pos_format() and the
1161 * remainder appear at the end of the formatted string.
1163 * @return @a string_type representing a positive sign.
1166 positive_sign() const
1167 { return this->do_positive_sign(); }
1170 * @brief Return negative sign string.
1172 * This function returns a string_type to use as a sign for negative
1173 * amounts. It does so by returning returning
1174 * moneypunct<char_type>::do_negative_sign().
1176 * If the return value contains more than one character, the first
1177 * character appears in the position indicated by neg_format() and the
1178 * remainder appear at the end of the formatted string.
1180 * @return @a string_type representing a negative sign.
1183 negative_sign() const
1184 { return this->do_negative_sign(); }
1187 * @brief Return number of digits in fraction.
1189 * This function returns the exact number of digits that make up the
1190 * fractional part of a money amount. It does so by returning
1191 * returning moneypunct<char_type>::do_frac_digits().
1193 * The fractional part of a money amount is optional. But if it is
1194 * present, there must be frac_digits() digits.
1196 * @return Number of digits in amount fraction.
1200 { return this->do_frac_digits(); }
1204 * @brief Return pattern for money values.
1206 * This function returns a pattern describing the formatting of a
1207 * positive or negative valued money amount. It does so by returning
1208 * returning moneypunct<char_type>::do_pos_format() or
1209 * moneypunct<char_type>::do_neg_format().
1211 * The pattern has 4 fields describing the ordering of symbol, sign,
1212 * value, and none or space. There must be one of each in the pattern.
1213 * The none and space enums may not appear in the first field and space
1214 * may not appear in the final field.
1216 * The parts of a money string must appear in the order indicated by
1217 * the fields of the pattern. The symbol field indicates that the
1218 * value of curr_symbol() may be present. The sign field indicates
1219 * that the value of positive_sign() or negative_sign() must be
1220 * present. The value field indicates that the absolute value of the
1221 * money amount is present. none indicates 0 or more whitespace
1222 * characters, except at the end, where it permits no whitespace.
1223 * space indicates that 1 or more whitespace characters must be
1226 * For example, for the US locale and pos_format() pattern
1227 * {symbol,sign,value,none}, curr_symbol() == '$'
1228 * positive_sign() == '+', and value 10.01, and
1229 * options set to force the symbol, the corresponding string is
1230 * <code>$+10.01</code>.
1232 * @return Pattern for money values.
1236 { return this->do_pos_format(); }
1240 { return this->do_neg_format(); }
1249 * @brief Return decimal point character.
1251 * Returns a char_type to use as a decimal point. This function is a
1252 * hook for derived classes to change the value returned.
1254 * @return @a char_type representing a decimal point.
1257 do_decimal_point() const
1258 { return _M_data
->_M_decimal_point
; }
1261 * @brief Return thousands separator character.
1263 * Returns a char_type to use as a thousands separator. This function
1264 * is a hook for derived classes to change the value returned.
1266 * @return @a char_type representing a thousands separator.
1269 do_thousands_sep() const
1270 { return _M_data
->_M_thousands_sep
; }
1273 * @brief Return grouping specification.
1275 * Returns a string representing groupings for the integer part of a
1276 * number. This function is a hook for derived classes to change the
1277 * value returned. @see grouping() for details.
1279 * @return String representing grouping specification.
1283 { return _M_data
->_M_grouping
; }
1286 * @brief Return currency symbol string.
1288 * This function returns a string_type to use as a currency symbol.
1289 * This function is a hook for derived classes to change the value
1290 * returned. @see curr_symbol() for details.
1292 * @return @a string_type representing a currency symbol.
1295 do_curr_symbol() const
1296 { return _M_data
->_M_curr_symbol
; }
1299 * @brief Return positive sign string.
1301 * This function returns a string_type to use as a sign for positive
1302 * amounts. This function is a hook for derived classes to change the
1303 * value returned. @see positive_sign() for details.
1305 * @return @a string_type representing a positive sign.
1308 do_positive_sign() const
1309 { return _M_data
->_M_positive_sign
; }
1312 * @brief Return negative sign string.
1314 * This function returns a string_type to use as a sign for negative
1315 * amounts. This function is a hook for derived classes to change the
1316 * value returned. @see negative_sign() for details.
1318 * @return @a string_type representing a negative sign.
1321 do_negative_sign() const
1322 { return _M_data
->_M_negative_sign
; }
1325 * @brief Return number of digits in fraction.
1327 * This function returns the exact number of digits that make up the
1328 * fractional part of a money amount. This function is a hook for
1329 * derived classes to change the value returned. @see frac_digits()
1332 * @return Number of digits in amount fraction.
1335 do_frac_digits() const
1336 { return _M_data
->_M_frac_digits
; }
1339 * @brief Return pattern for money values.
1341 * This function returns a pattern describing the formatting of a
1342 * positive valued money amount. This function is a hook for derived
1343 * classes to change the value returned. @see pos_format() for
1346 * @return Pattern for money values.
1349 do_pos_format() const
1350 { return _M_data
->_M_pos_format
; }
1353 * @brief Return pattern for money values.
1355 * This function returns a pattern describing the formatting of a
1356 * negative valued money amount. This function is a hook for derived
1357 * classes to change the value returned. @see neg_format() for
1360 * @return Pattern for money values.
1363 do_neg_format() const
1364 { return _M_data
->_M_neg_format
; }
1366 // For use at construction time only.
1368 _M_initialize_moneypunct(__c_locale __cloc
= 0,
1369 const char* __name
= 0);
1372 template<typename _CharT
, bool _Intl
>
1373 locale::id moneypunct
<_CharT
, _Intl
>::id
;
1375 template<typename _CharT
, bool _Intl
>
1376 const bool moneypunct
<_CharT
, _Intl
>::intl
;
1379 moneypunct
<char, true>::~moneypunct();
1382 moneypunct
<char, false>::~moneypunct();
1386 moneypunct
<char, true>::_M_initialize_moneypunct(__c_locale
, const char*);
1390 moneypunct
<char, false>::_M_initialize_moneypunct(__c_locale
, const char*);
1392 #ifdef _GLIBCXX_USE_WCHAR_T
1394 moneypunct
<wchar_t, true>::~moneypunct();
1397 moneypunct
<wchar_t, false>::~moneypunct();
1401 moneypunct
<wchar_t, true>::_M_initialize_moneypunct(__c_locale
,
1406 moneypunct
<wchar_t, false>::_M_initialize_moneypunct(__c_locale
,
1410 /// class moneypunct_byname [22.2.6.4].
1411 template<typename _CharT
, bool _Intl
>
1412 class moneypunct_byname
: public moneypunct
<_CharT
, _Intl
>
1415 typedef _CharT char_type
;
1416 typedef basic_string
<_CharT
> string_type
;
1418 static const bool intl
= _Intl
;
1421 moneypunct_byname(const char* __s
, size_t __refs
= 0)
1422 : moneypunct
<_CharT
, _Intl
>(__refs
)
1424 if (__builtin_strcmp(__s
, "C") != 0
1425 && __builtin_strcmp(__s
, "POSIX") != 0)
1428 this->_S_create_c_locale(__tmp
, __s
);
1429 this->_M_initialize_moneypunct(__tmp
);
1430 this->_S_destroy_c_locale(__tmp
);
1434 #if __cplusplus >= 201103L
1436 moneypunct_byname(const string
& __s
, size_t __refs
= 0)
1437 : moneypunct_byname(__s
.c_str(), __refs
) { }
1442 ~moneypunct_byname() { }
1445 template<typename _CharT
, bool _Intl
>
1446 const bool moneypunct_byname
<_CharT
, _Intl
>::intl
;
1448 _GLIBCXX_END_NAMESPACE_CXX11
1450 _GLIBCXX_BEGIN_NAMESPACE_LDBL_OR_CXX11
1453 * @brief Primary class template money_get.
1456 * This facet encapsulates the code to parse and return a monetary
1457 * amount from a string.
1459 * The money_get template uses protected virtual functions to
1460 * provide the actual results. The public accessors forward the
1461 * call to the virtual functions. These virtual functions are
1462 * hooks for developers to implement the behavior they require from
1463 * the money_get facet.
1465 template<typename _CharT
, typename _InIter
>
1466 class money_get
: public locale::facet
1472 typedef _CharT char_type
;
1473 typedef _InIter iter_type
;
1474 typedef basic_string
<_CharT
> string_type
;
1477 /// Numpunct facet id.
1478 static locale::id id
;
1481 * @brief Constructor performs initialization.
1483 * This is the constructor provided by the standard.
1485 * @param __refs Passed to the base facet class.
1488 money_get(size_t __refs
= 0) : facet(__refs
) { }
1491 * @brief Read and parse a monetary value.
1493 * This function reads characters from @a __s, interprets them as a
1494 * monetary value according to moneypunct and ctype facets retrieved
1495 * from io.getloc(), and returns the result in @a units as an integral
1496 * value moneypunct::frac_digits() * the actual amount. For example,
1497 * the string $10.01 in a US locale would store 1001 in @a units.
1499 * Any characters not part of a valid money amount are not consumed.
1501 * If a money value cannot be parsed from the input stream, sets
1502 * err=(err|io.failbit). If the stream is consumed before finishing
1503 * parsing, sets err=(err|io.failbit|io.eofbit). @a units is
1504 * unchanged if parsing fails.
1506 * This function works by returning the result of do_get().
1508 * @param __s Start of characters to parse.
1509 * @param __end End of characters to parse.
1510 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
1511 * @param __io Source of facets and io state.
1512 * @param __err Error field to set if parsing fails.
1513 * @param __units Place to store result of parsing.
1514 * @return Iterator referencing first character beyond valid money
1518 get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
1519 ios_base::iostate
& __err
, long double& __units
) const
1520 { return this->do_get(__s
, __end
, __intl
, __io
, __err
, __units
); }
1523 * @brief Read and parse a monetary value.
1525 * This function reads characters from @a __s, interprets them as
1526 * a monetary value according to moneypunct and ctype facets
1527 * retrieved from io.getloc(), and returns the result in @a
1528 * digits. For example, the string $10.01 in a US locale would
1529 * store <code>1001</code> in @a digits.
1531 * Any characters not part of a valid money amount are not consumed.
1533 * If a money value cannot be parsed from the input stream, sets
1534 * err=(err|io.failbit). If the stream is consumed before finishing
1535 * parsing, sets err=(err|io.failbit|io.eofbit).
1537 * This function works by returning the result of do_get().
1539 * @param __s Start of characters to parse.
1540 * @param __end End of characters to parse.
1541 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
1542 * @param __io Source of facets and io state.
1543 * @param __err Error field to set if parsing fails.
1544 * @param __digits Place to store result of parsing.
1545 * @return Iterator referencing first character beyond valid money
1549 get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
1550 ios_base::iostate
& __err
, string_type
& __digits
) const
1551 { return this->do_get(__s
, __end
, __intl
, __io
, __err
, __digits
); }
1559 * @brief Read and parse a monetary value.
1561 * This function reads and parses characters representing a monetary
1562 * value. This function is a hook for derived classes to change the
1563 * value returned. @see get() for details.
1565 // XXX GLIBCXX_ABI Deprecated
1566 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \
1567 && _GLIBCXX_USE_CXX11_ABI == 0
1569 __do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
1570 ios_base::iostate
& __err
, double& __units
) const;
1573 do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
1574 ios_base::iostate
& __err
, long double& __units
) const;
1578 * @brief Read and parse a monetary value.
1580 * This function reads and parses characters representing a monetary
1581 * value. This function is a hook for derived classes to change the
1582 * value returned. @see get() for details.
1585 do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
1586 ios_base::iostate
& __err
, string_type
& __digits
) const;
1588 // XXX GLIBCXX_ABI Deprecated
1589 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \
1590 && _GLIBCXX_USE_CXX11_ABI == 0
1592 do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
1593 ios_base::iostate
& __err
, long double& __units
) const;
1596 template<bool _Intl
>
1598 _M_extract(iter_type __s
, iter_type __end
, ios_base
& __io
,
1599 ios_base::iostate
& __err
, string
& __digits
) const;
1602 template<typename _CharT
, typename _InIter
>
1603 locale::id money_get
<_CharT
, _InIter
>::id
;
1606 * @brief Primary class template money_put.
1609 * This facet encapsulates the code to format and output a monetary
1612 * The money_put template uses protected virtual functions to
1613 * provide the actual results. The public accessors forward the
1614 * call to the virtual functions. These virtual functions are
1615 * hooks for developers to implement the behavior they require from
1616 * the money_put facet.
1618 template<typename _CharT
, typename _OutIter
>
1619 class money_put
: public locale::facet
1624 typedef _CharT char_type
;
1625 typedef _OutIter iter_type
;
1626 typedef basic_string
<_CharT
> string_type
;
1629 /// Numpunct facet id.
1630 static locale::id id
;
1633 * @brief Constructor performs initialization.
1635 * This is the constructor provided by the standard.
1637 * @param __refs Passed to the base facet class.
1640 money_put(size_t __refs
= 0) : facet(__refs
) { }
1643 * @brief Format and output a monetary value.
1645 * This function formats @a units as a monetary value according to
1646 * moneypunct and ctype facets retrieved from io.getloc(), and writes
1647 * the resulting characters to @a __s. For example, the value 1001 in a
1648 * US locale would write <code>$10.01</code> to @a __s.
1650 * This function works by returning the result of do_put().
1652 * @param __s The stream to write to.
1653 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
1654 * @param __io Source of facets and io state.
1655 * @param __fill char_type to use for padding.
1656 * @param __units Place to store result of parsing.
1657 * @return Iterator after writing.
1660 put(iter_type __s
, bool __intl
, ios_base
& __io
,
1661 char_type __fill
, long double __units
) const
1662 { return this->do_put(__s
, __intl
, __io
, __fill
, __units
); }
1665 * @brief Format and output a monetary value.
1667 * This function formats @a digits as a monetary value
1668 * according to moneypunct and ctype facets retrieved from
1669 * io.getloc(), and writes the resulting characters to @a __s.
1670 * For example, the string <code>1001</code> in a US locale
1671 * would write <code>$10.01</code> to @a __s.
1673 * This function works by returning the result of do_put().
1675 * @param __s The stream to write to.
1676 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
1677 * @param __io Source of facets and io state.
1678 * @param __fill char_type to use for padding.
1679 * @param __digits Place to store result of parsing.
1680 * @return Iterator after writing.
1683 put(iter_type __s
, bool __intl
, ios_base
& __io
,
1684 char_type __fill
, const string_type
& __digits
) const
1685 { return this->do_put(__s
, __intl
, __io
, __fill
, __digits
); }
1693 * @brief Format and output a monetary value.
1695 * This function formats @a units as a monetary value according to
1696 * moneypunct and ctype facets retrieved from io.getloc(), and writes
1697 * the resulting characters to @a __s. For example, the value 1001 in a
1698 * US locale would write <code>$10.01</code> to @a __s.
1700 * This function is a hook for derived classes to change the value
1701 * returned. @see put().
1703 * @param __s The stream to write to.
1704 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
1705 * @param __io Source of facets and io state.
1706 * @param __fill char_type to use for padding.
1707 * @param __units Place to store result of parsing.
1708 * @return Iterator after writing.
1710 // XXX GLIBCXX_ABI Deprecated
1711 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \
1712 && _GLIBCXX_USE_CXX11_ABI == 0
1714 __do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
1715 double __units
) const;
1718 do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
1719 long double __units
) const;
1723 * @brief Format and output a monetary value.
1725 * This function formats @a digits as a monetary value
1726 * according to moneypunct and ctype facets retrieved from
1727 * io.getloc(), and writes the resulting characters to @a __s.
1728 * For example, the string <code>1001</code> in a US locale
1729 * would write <code>$10.01</code> to @a __s.
1731 * This function is a hook for derived classes to change the value
1732 * returned. @see put().
1734 * @param __s The stream to write to.
1735 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
1736 * @param __io Source of facets and io state.
1737 * @param __fill char_type to use for padding.
1738 * @param __digits Place to store result of parsing.
1739 * @return Iterator after writing.
1742 do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
1743 const string_type
& __digits
) const;
1745 // XXX GLIBCXX_ABI Deprecated
1746 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \
1747 && _GLIBCXX_USE_CXX11_ABI == 0
1749 do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
1750 long double __units
) const;
1753 template<bool _Intl
>
1755 _M_insert(iter_type __s
, ios_base
& __io
, char_type __fill
,
1756 const string_type
& __digits
) const;
1759 template<typename _CharT
, typename _OutIter
>
1760 locale::id money_put
<_CharT
, _OutIter
>::id
;
1762 _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11
1765 * @brief Messages facet base class providing catalog typedef.
1768 struct messages_base
1770 typedef int catalog
;
1773 _GLIBCXX_BEGIN_NAMESPACE_CXX11
1776 * @brief Primary class template messages.
1779 * This facet encapsulates the code to retrieve messages from
1780 * message catalogs. The only thing defined by the standard for this facet
1781 * is the interface. All underlying functionality is
1782 * implementation-defined.
1784 * This library currently implements 3 versions of the message facet. The
1785 * first version (gnu) is a wrapper around gettext, provided by libintl.
1786 * The second version (ieee) is a wrapper around catgets. The final
1787 * version (default) does no actual translation. These implementations are
1788 * only provided for char and wchar_t instantiations.
1790 * The messages template uses protected virtual functions to
1791 * provide the actual results. The public accessors forward the
1792 * call to the virtual functions. These virtual functions are
1793 * hooks for developers to implement the behavior they require from
1794 * the messages facet.
1796 template<typename _CharT
>
1797 class messages
: public locale::facet
, public messages_base
1803 typedef _CharT char_type
;
1804 typedef basic_string
<_CharT
> string_type
;
1808 // Underlying "C" library locale information saved from
1809 // initialization, needed by messages_byname as well.
1810 __c_locale _M_c_locale_messages
;
1811 const char* _M_name_messages
;
1814 /// Numpunct facet id.
1815 static locale::id id
;
1818 * @brief Constructor performs initialization.
1820 * This is the constructor provided by the standard.
1822 * @param __refs Passed to the base facet class.
1825 messages(size_t __refs
= 0);
1829 * @brief Internal constructor. Not for general use.
1831 * This is a constructor for use by the library itself to set up new
1834 * @param __cloc The C locale.
1835 * @param __s The name of a locale.
1836 * @param __refs Refcount to pass to the base class.
1839 messages(__c_locale __cloc
, const char* __s
, size_t __refs
= 0);
1842 * @brief Open a message catalog.
1844 * This function opens and returns a handle to a message catalog by
1845 * returning do_open(__s, __loc).
1847 * @param __s The catalog to open.
1848 * @param __loc Locale to use for character set conversions.
1849 * @return Handle to the catalog or value < 0 if open fails.
1852 open(const basic_string
<char>& __s
, const locale
& __loc
) const
1853 { return this->do_open(__s
, __loc
); }
1855 // Non-standard and unorthodox, yet effective.
1857 * @brief Open a message catalog.
1859 * This non-standard function opens and returns a handle to a message
1860 * catalog by returning do_open(s, loc). The third argument provides a
1861 * message catalog root directory for gnu gettext and is ignored
1864 * @param __s The catalog to open.
1865 * @param __loc Locale to use for character set conversions.
1866 * @param __dir Message catalog root directory.
1867 * @return Handle to the catalog or value < 0 if open fails.
1870 open(const basic_string
<char>&, const locale
&, const char*) const;
1873 * @brief Look up a string in a message catalog.
1875 * This function retrieves and returns a message from a catalog by
1876 * returning do_get(c, set, msgid, s).
1878 * For gnu, @a __set and @a msgid are ignored. Returns gettext(s).
1879 * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
1881 * @param __c The catalog to access.
1882 * @param __set Implementation-defined.
1883 * @param __msgid Implementation-defined.
1884 * @param __s Default return value if retrieval fails.
1885 * @return Retrieved message or @a __s if get fails.
1888 get(catalog __c
, int __set
, int __msgid
, const string_type
& __s
) const
1889 { return this->do_get(__c
, __set
, __msgid
, __s
); }
1892 * @brief Close a message catalog.
1894 * Closes catalog @a c by calling do_close(c).
1896 * @param __c The catalog to close.
1899 close(catalog __c
) const
1900 { return this->do_close(__c
); }
1908 * @brief Open a message catalog.
1910 * This function opens and returns a handle to a message catalog in an
1911 * implementation-defined manner. This function is a hook for derived
1912 * classes to change the value returned.
1914 * @param __s The catalog to open.
1915 * @param __loc Locale to use for character set conversions.
1916 * @return Handle to the opened catalog, value < 0 if open failed.
1919 do_open(const basic_string
<char>&, const locale
&) const;
1922 * @brief Look up a string in a message catalog.
1924 * This function retrieves and returns a message from a catalog in an
1925 * implementation-defined manner. This function is a hook for derived
1926 * classes to change the value returned.
1928 * For gnu, @a __set and @a __msgid are ignored. Returns gettext(s).
1929 * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
1931 * @param __c The catalog to access.
1932 * @param __set Implementation-defined.
1933 * @param __msgid Implementation-defined.
1934 * @param __s Default return value if retrieval fails.
1935 * @return Retrieved message or @a __s if get fails.
1938 do_get(catalog
, int, int, const string_type
& __dfault
) const;
1941 * @brief Close a message catalog.
1943 * @param __c The catalog to close.
1946 do_close(catalog
) const;
1948 // Returns a locale and codeset-converted string, given a char* message.
1950 _M_convert_to_char(const string_type
& __msg
) const
1953 return reinterpret_cast<char*>(const_cast<_CharT
*>(__msg
.c_str()));
1956 // Returns a locale and codeset-converted string, given a char* message.
1958 _M_convert_from_char(char*) const
1961 return string_type();
1965 template<typename _CharT
>
1966 locale::id messages
<_CharT
>::id
;
1968 /// Specializations for required instantiations.
1971 messages
<char>::do_get(catalog
, int, int, const string
&) const;
1973 #ifdef _GLIBCXX_USE_WCHAR_T
1976 messages
<wchar_t>::do_get(catalog
, int, int, const wstring
&) const;
1979 /// class messages_byname [22.2.7.2].
1980 template<typename _CharT
>
1981 class messages_byname
: public messages
<_CharT
>
1984 typedef _CharT char_type
;
1985 typedef basic_string
<_CharT
> string_type
;
1988 messages_byname(const char* __s
, size_t __refs
= 0);
1990 #if __cplusplus >= 201103L
1992 messages_byname(const string
& __s
, size_t __refs
= 0)
1993 : messages_byname(__s
.c_str(), __refs
) { }
2002 _GLIBCXX_END_NAMESPACE_CXX11
2004 _GLIBCXX_END_NAMESPACE_VERSION
2007 // Include host and configuration specific messages functions.
2008 #include <bits/messages_members.h>
2010 // 22.2.1.5 Template class codecvt
2011 #include <bits/codecvt.h>
2013 #include <bits/locale_facets_nonio.tcc>