Import GCC-8 to a new vendor branch
[dragonfly.git] / contrib / gcc-8.0 / libstdc++-v3 / include / bits / locale_facets_nonio.h
blob75a70bebea09a84c832b6ed84fc013f27411f290
1 // Locale support -*- C++ -*-
3 // Copyright (C) 2007-2018 Free Software Foundation, Inc.
4 //
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)
9 // any later version.
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
45 /**
46 * @brief Time format ordering data.
47 * @ingroup locales
49 * This class provides an enum representing different orderings of
50 * time: day, month, and year.
52 class time_base
54 public:
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;
70 const _CharT* _M_am;
71 const _CharT* _M_pm;
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;
120 bool _M_allocated;
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();
141 private:
142 __timepunct_cache&
143 operator=(const __timepunct_cache&);
145 explicit
146 __timepunct_cache(const __timepunct_cache&);
149 template<typename _CharT>
150 __timepunct_cache<_CharT>::~__timepunct_cache()
152 if (_M_allocated)
154 // Unused.
158 // Specializations.
159 template<>
160 const char*
161 __timepunct_cache<char>::_S_timezones[14];
163 #ifdef _GLIBCXX_USE_WCHAR_T
164 template<>
165 const wchar_t*
166 __timepunct_cache<wchar_t>::_S_timezones[14];
167 #endif
169 // Generic.
170 template<typename _CharT>
171 const _CharT* __timepunct_cache<_CharT>::_S_timezones[14];
173 template<typename _CharT>
174 class __timepunct : public locale::facet
176 public:
177 // Types:
178 typedef _CharT __char_type;
179 typedef __timepunct_cache<_CharT> __cache_type;
181 protected:
182 __cache_type* _M_data;
183 __c_locale _M_c_locale_timepunct;
184 const char* _M_name_timepunct;
186 public:
187 /// Numpunct facet id.
188 static locale::id id;
190 explicit
191 __timepunct(size_t __refs = 0);
193 explicit
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
200 * locales.
202 * @param __cloc The C locale.
203 * @param __s The name of a locale.
204 * @param refs Passed to the base facet class.
206 explicit
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.
211 void
212 _M_put(_CharT* __s, size_t __maxlen, const _CharT* __format,
213 const tm* __tm) const throw ();
215 void
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;
223 void
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;
231 void
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;
239 #if !_GLIBCXX_INLINE_VERSION
240 void
241 _M_am_pm_format(const _CharT*) const
242 { /* Kept for ABI compatibility, see PR65927 */ }
243 #endif
245 void
246 _M_am_pm(const _CharT** __ampm) const
248 __ampm[0] = _M_data->_M_am;
249 __ampm[1] = _M_data->_M_pm;
252 void
253 _M_days(const _CharT** __days) const
255 __days[0] = _M_data->_M_day1;
256 __days[1] = _M_data->_M_day2;
257 __days[2] = _M_data->_M_day3;
258 __days[3] = _M_data->_M_day4;
259 __days[4] = _M_data->_M_day5;
260 __days[5] = _M_data->_M_day6;
261 __days[6] = _M_data->_M_day7;
264 void
265 _M_days_abbreviated(const _CharT** __days) const
267 __days[0] = _M_data->_M_aday1;
268 __days[1] = _M_data->_M_aday2;
269 __days[2] = _M_data->_M_aday3;
270 __days[3] = _M_data->_M_aday4;
271 __days[4] = _M_data->_M_aday5;
272 __days[5] = _M_data->_M_aday6;
273 __days[6] = _M_data->_M_aday7;
276 void
277 _M_months(const _CharT** __months) const
279 __months[0] = _M_data->_M_month01;
280 __months[1] = _M_data->_M_month02;
281 __months[2] = _M_data->_M_month03;
282 __months[3] = _M_data->_M_month04;
283 __months[4] = _M_data->_M_month05;
284 __months[5] = _M_data->_M_month06;
285 __months[6] = _M_data->_M_month07;
286 __months[7] = _M_data->_M_month08;
287 __months[8] = _M_data->_M_month09;
288 __months[9] = _M_data->_M_month10;
289 __months[10] = _M_data->_M_month11;
290 __months[11] = _M_data->_M_month12;
293 void
294 _M_months_abbreviated(const _CharT** __months) const
296 __months[0] = _M_data->_M_amonth01;
297 __months[1] = _M_data->_M_amonth02;
298 __months[2] = _M_data->_M_amonth03;
299 __months[3] = _M_data->_M_amonth04;
300 __months[4] = _M_data->_M_amonth05;
301 __months[5] = _M_data->_M_amonth06;
302 __months[6] = _M_data->_M_amonth07;
303 __months[7] = _M_data->_M_amonth08;
304 __months[8] = _M_data->_M_amonth09;
305 __months[9] = _M_data->_M_amonth10;
306 __months[10] = _M_data->_M_amonth11;
307 __months[11] = _M_data->_M_amonth12;
310 protected:
311 virtual
312 ~__timepunct();
314 // For use at construction time only.
315 void
316 _M_initialize_timepunct(__c_locale __cloc = 0);
319 template<typename _CharT>
320 locale::id __timepunct<_CharT>::id;
322 // Specializations.
323 template<>
324 void
325 __timepunct<char>::_M_initialize_timepunct(__c_locale __cloc);
327 template<>
328 void
329 __timepunct<char>::_M_put(char*, size_t, const char*, const tm*) const throw ();
331 #ifdef _GLIBCXX_USE_WCHAR_T
332 template<>
333 void
334 __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale __cloc);
336 template<>
337 void
338 __timepunct<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*,
339 const tm*) const throw ();
340 #endif
342 _GLIBCXX_END_NAMESPACE_VERSION
343 } // namespace
345 // Include host and configuration specific timepunct functions.
346 #include <bits/time_members.h>
348 namespace std _GLIBCXX_VISIBILITY(default)
350 _GLIBCXX_BEGIN_NAMESPACE_VERSION
352 _GLIBCXX_BEGIN_NAMESPACE_CXX11
355 * @brief Primary class template time_get.
356 * @ingroup locales
358 * This facet encapsulates the code to parse and return a date or
359 * time from a string. It is used by the istream numeric
360 * extraction operators.
362 * The time_get template uses protected virtual functions to provide the
363 * actual results. The public accessors forward the call to the virtual
364 * functions. These virtual functions are hooks for developers to
365 * implement the behavior they require from the time_get facet.
367 template<typename _CharT, typename _InIter>
368 class time_get : public locale::facet, public time_base
370 public:
371 // Types:
372 //@{
373 /// Public typedefs
374 typedef _CharT char_type;
375 typedef _InIter iter_type;
376 //@}
378 /// Numpunct facet id.
379 static locale::id id;
382 * @brief Constructor performs initialization.
384 * This is the constructor provided by the standard.
386 * @param __refs Passed to the base facet class.
388 explicit
389 time_get(size_t __refs = 0)
390 : facet (__refs) { }
393 * @brief Return preferred order of month, day, and year.
395 * This function returns an enum from time_base::dateorder giving the
396 * preferred ordering if the format @a x given to time_put::put() only
397 * uses month, day, and year. If the format @a x for the associated
398 * locale uses other fields, this function returns
399 * time_base::dateorder::noorder.
401 * NOTE: The library always returns noorder at the moment.
403 * @return A member of time_base::dateorder.
405 dateorder
406 date_order() const
407 { return this->do_date_order(); }
410 * @brief Parse input time string.
412 * This function parses a time according to the format @a X and puts the
413 * results into a user-supplied struct tm. The result is returned by
414 * calling time_get::do_get_time().
416 * If there is a valid time string according to format @a X, @a tm will
417 * be filled in accordingly and the returned iterator will point to the
418 * first character beyond the time string. If an error occurs before
419 * the end, err |= ios_base::failbit. If parsing reads all the
420 * characters, err |= ios_base::eofbit.
422 * @param __beg Start of string to parse.
423 * @param __end End of string to parse.
424 * @param __io Source of the locale.
425 * @param __err Error flags to set.
426 * @param __tm Pointer to struct tm to fill in.
427 * @return Iterator to first char beyond time string.
429 iter_type
430 get_time(iter_type __beg, iter_type __end, ios_base& __io,
431 ios_base::iostate& __err, tm* __tm) const
432 { return this->do_get_time(__beg, __end, __io, __err, __tm); }
435 * @brief Parse input date string.
437 * This function parses a date according to the format @a x and puts the
438 * results into a user-supplied struct tm. The result is returned by
439 * calling time_get::do_get_date().
441 * If there is a valid date string according to format @a x, @a tm will
442 * be filled in accordingly and the returned iterator will point to the
443 * first character beyond the date string. If an error occurs before
444 * the end, err |= ios_base::failbit. If parsing reads all the
445 * characters, err |= ios_base::eofbit.
447 * @param __beg Start of string to parse.
448 * @param __end End of string to parse.
449 * @param __io Source of the locale.
450 * @param __err Error flags to set.
451 * @param __tm Pointer to struct tm to fill in.
452 * @return Iterator to first char beyond date string.
454 iter_type
455 get_date(iter_type __beg, iter_type __end, ios_base& __io,
456 ios_base::iostate& __err, tm* __tm) const
457 { return this->do_get_date(__beg, __end, __io, __err, __tm); }
460 * @brief Parse input weekday string.
462 * This function parses a weekday name and puts the results into a
463 * user-supplied struct tm. The result is returned by calling
464 * time_get::do_get_weekday().
466 * Parsing starts by parsing an abbreviated weekday name. If a valid
467 * abbreviation is followed by a character that would lead to the full
468 * weekday name, parsing continues until the full name is found or an
469 * error occurs. Otherwise parsing finishes at the end of the
470 * abbreviated name.
472 * If an error occurs before the end, err |= ios_base::failbit. If
473 * parsing reads all the characters, err |= ios_base::eofbit.
475 * @param __beg Start of string to parse.
476 * @param __end End of string to parse.
477 * @param __io Source of the locale.
478 * @param __err Error flags to set.
479 * @param __tm Pointer to struct tm to fill in.
480 * @return Iterator to first char beyond weekday name.
482 iter_type
483 get_weekday(iter_type __beg, iter_type __end, ios_base& __io,
484 ios_base::iostate& __err, tm* __tm) const
485 { return this->do_get_weekday(__beg, __end, __io, __err, __tm); }
488 * @brief Parse input month string.
490 * This function parses a month name and puts the results into a
491 * user-supplied struct tm. The result is returned by calling
492 * time_get::do_get_monthname().
494 * Parsing starts by parsing an abbreviated month name. If a valid
495 * abbreviation is followed by a character that would lead to the full
496 * month name, parsing continues until the full name is found or an
497 * error occurs. Otherwise parsing finishes at the end of the
498 * abbreviated name.
500 * If an error occurs before the end, err |= ios_base::failbit. If
501 * parsing reads all the characters, err |=
502 * ios_base::eofbit.
504 * @param __beg Start of string to parse.
505 * @param __end End of string to parse.
506 * @param __io Source of the locale.
507 * @param __err Error flags to set.
508 * @param __tm Pointer to struct tm to fill in.
509 * @return Iterator to first char beyond month name.
511 iter_type
512 get_monthname(iter_type __beg, iter_type __end, ios_base& __io,
513 ios_base::iostate& __err, tm* __tm) const
514 { return this->do_get_monthname(__beg, __end, __io, __err, __tm); }
517 * @brief Parse input year string.
519 * This function reads up to 4 characters to parse a year string and
520 * puts the results into a user-supplied struct tm. The result is
521 * returned by calling time_get::do_get_year().
523 * 4 consecutive digits are interpreted as a full year. If there are
524 * exactly 2 consecutive digits, the library interprets this as the
525 * number of years since 1900.
527 * If an error occurs before the end, err |= ios_base::failbit. If
528 * parsing reads all the characters, err |= ios_base::eofbit.
530 * @param __beg Start of string to parse.
531 * @param __end End of string to parse.
532 * @param __io Source of the locale.
533 * @param __err Error flags to set.
534 * @param __tm Pointer to struct tm to fill in.
535 * @return Iterator to first char beyond year.
537 iter_type
538 get_year(iter_type __beg, iter_type __end, ios_base& __io,
539 ios_base::iostate& __err, tm* __tm) const
540 { return this->do_get_year(__beg, __end, __io, __err, __tm); }
542 #if __cplusplus >= 201103L
544 * @brief Parse input string according to format.
546 * This function calls time_get::do_get with the provided
547 * parameters. @see do_get() and get().
549 * @param __s Start of string to parse.
550 * @param __end End of string to parse.
551 * @param __io Source of the locale.
552 * @param __err Error flags to set.
553 * @param __tm Pointer to struct tm to fill in.
554 * @param __format Format specifier.
555 * @param __modifier Format modifier.
556 * @return Iterator to first char not parsed.
558 inline
559 iter_type get(iter_type __s, iter_type __end, ios_base& __io,
560 ios_base::iostate& __err, tm* __tm, char __format,
561 char __modifier = 0) const
563 return this->do_get(__s, __end, __io, __err, __tm, __format,
564 __modifier);
568 * @brief Parse input string according to format.
570 * This function parses the input string according to a
571 * provided format string. It does the inverse of
572 * time_put::put. The format string follows the format
573 * specified for strftime(3)/strptime(3). The actual parsing
574 * is done by time_get::do_get.
576 * @param __s Start of string to parse.
577 * @param __end End of string to parse.
578 * @param __io Source of the locale.
579 * @param __err Error flags to set.
580 * @param __tm Pointer to struct tm to fill in.
581 * @param __fmt Start of the format string.
582 * @param __fmtend End of the format string.
583 * @return Iterator to first char not parsed.
585 iter_type get(iter_type __s, iter_type __end, ios_base& __io,
586 ios_base::iostate& __err, tm* __tm, const char_type* __fmt,
587 const char_type* __fmtend) const;
588 #endif // __cplusplus >= 201103L
590 protected:
591 /// Destructor.
592 virtual
593 ~time_get() { }
596 * @brief Return preferred order of month, day, and year.
598 * This function returns an enum from time_base::dateorder giving the
599 * preferred ordering if the format @a x given to time_put::put() only
600 * uses month, day, and year. This function is a hook for derived
601 * classes to change the value returned.
603 * @return A member of time_base::dateorder.
605 virtual dateorder
606 do_date_order() const;
609 * @brief Parse input time string.
611 * This function parses a time according to the format @a x and puts the
612 * results into a user-supplied struct tm. This function is a hook for
613 * derived classes to change the value returned. @see get_time() for
614 * details.
616 * @param __beg Start of string to parse.
617 * @param __end End of string to parse.
618 * @param __io Source of the locale.
619 * @param __err Error flags to set.
620 * @param __tm Pointer to struct tm to fill in.
621 * @return Iterator to first char beyond time string.
623 virtual iter_type
624 do_get_time(iter_type __beg, iter_type __end, ios_base& __io,
625 ios_base::iostate& __err, tm* __tm) const;
628 * @brief Parse input date string.
630 * This function parses a date according to the format @a X and puts the
631 * results into a user-supplied struct tm. This function is a hook for
632 * derived classes to change the value returned. @see get_date() for
633 * details.
635 * @param __beg Start of string to parse.
636 * @param __end End of string to parse.
637 * @param __io Source of the locale.
638 * @param __err Error flags to set.
639 * @param __tm Pointer to struct tm to fill in.
640 * @return Iterator to first char beyond date string.
642 virtual iter_type
643 do_get_date(iter_type __beg, iter_type __end, ios_base& __io,
644 ios_base::iostate& __err, tm* __tm) const;
647 * @brief Parse input weekday string.
649 * This function parses a weekday name and puts the results into a
650 * user-supplied struct tm. This function is a hook for derived
651 * classes to change the value returned. @see get_weekday() for
652 * details.
654 * @param __beg Start of string to parse.
655 * @param __end End of string to parse.
656 * @param __io Source of the locale.
657 * @param __err Error flags to set.
658 * @param __tm Pointer to struct tm to fill in.
659 * @return Iterator to first char beyond weekday name.
661 virtual iter_type
662 do_get_weekday(iter_type __beg, iter_type __end, ios_base&,
663 ios_base::iostate& __err, tm* __tm) const;
666 * @brief Parse input month string.
668 * This function parses a month name and puts the results into a
669 * user-supplied struct tm. This function is a hook for derived
670 * classes to change the value returned. @see get_monthname() for
671 * details.
673 * @param __beg Start of string to parse.
674 * @param __end End of string to parse.
675 * @param __io Source of the locale.
676 * @param __err Error flags to set.
677 * @param __tm Pointer to struct tm to fill in.
678 * @return Iterator to first char beyond month name.
680 virtual iter_type
681 do_get_monthname(iter_type __beg, iter_type __end, ios_base&,
682 ios_base::iostate& __err, tm* __tm) const;
685 * @brief Parse input year string.
687 * This function reads up to 4 characters to parse a year string and
688 * puts the results into a user-supplied struct tm. This function is a
689 * hook for derived classes to change the value returned. @see
690 * get_year() for details.
692 * @param __beg Start of string to parse.
693 * @param __end End of string to parse.
694 * @param __io Source of the locale.
695 * @param __err Error flags to set.
696 * @param __tm Pointer to struct tm to fill in.
697 * @return Iterator to first char beyond year.
699 virtual iter_type
700 do_get_year(iter_type __beg, iter_type __end, ios_base& __io,
701 ios_base::iostate& __err, tm* __tm) const;
703 #if __cplusplus >= 201103L
705 * @brief Parse input string according to format.
707 * This function parses the string according to the provided
708 * format and optional modifier. This function is a hook for
709 * derived classes to change the value returned. @see get()
710 * for more details.
712 * @param __s Start of string to parse.
713 * @param __end End of string to parse.
714 * @param __f Source of the locale.
715 * @param __err Error flags to set.
716 * @param __tm Pointer to struct tm to fill in.
717 * @param __format Format specifier.
718 * @param __modifier Format modifier.
719 * @return Iterator to first char not parsed.
721 #if _GLIBCXX_USE_CXX11_ABI
722 virtual
723 #endif
724 iter_type
725 do_get(iter_type __s, iter_type __end, ios_base& __f,
726 ios_base::iostate& __err, tm* __tm,
727 char __format, char __modifier) const;
728 #endif // __cplusplus >= 201103L
730 // Extract numeric component of length __len.
731 iter_type
732 _M_extract_num(iter_type __beg, iter_type __end, int& __member,
733 int __min, int __max, size_t __len,
734 ios_base& __io, ios_base::iostate& __err) const;
736 // Extract any unique array of string literals in a const _CharT* array.
737 iter_type
738 _M_extract_name(iter_type __beg, iter_type __end, int& __member,
739 const _CharT** __names, size_t __indexlen,
740 ios_base& __io, ios_base::iostate& __err) const;
742 // Extract day or month name in a const _CharT* array.
743 iter_type
744 _M_extract_wday_or_month(iter_type __beg, iter_type __end, int& __member,
745 const _CharT** __names, size_t __indexlen,
746 ios_base& __io, ios_base::iostate& __err) const;
748 // Extract on a component-by-component basis, via __format argument.
749 iter_type
750 _M_extract_via_format(iter_type __beg, iter_type __end, ios_base& __io,
751 ios_base::iostate& __err, tm* __tm,
752 const _CharT* __format) const;
755 template<typename _CharT, typename _InIter>
756 locale::id time_get<_CharT, _InIter>::id;
758 /// class time_get_byname [22.2.5.2].
759 template<typename _CharT, typename _InIter>
760 class time_get_byname : public time_get<_CharT, _InIter>
762 public:
763 // Types:
764 typedef _CharT char_type;
765 typedef _InIter iter_type;
767 explicit
768 time_get_byname(const char*, size_t __refs = 0)
769 : time_get<_CharT, _InIter>(__refs) { }
771 #if __cplusplus >= 201103L
772 explicit
773 time_get_byname(const string& __s, size_t __refs = 0)
774 : time_get_byname(__s.c_str(), __refs) { }
775 #endif
777 protected:
778 virtual
779 ~time_get_byname() { }
782 _GLIBCXX_END_NAMESPACE_CXX11
785 * @brief Primary class template time_put.
786 * @ingroup locales
788 * This facet encapsulates the code to format and output dates and times
789 * according to formats used by strftime().
791 * The time_put template uses protected virtual functions to provide the
792 * actual results. The public accessors forward the call to the virtual
793 * functions. These virtual functions are hooks for developers to
794 * implement the behavior they require from the time_put facet.
796 template<typename _CharT, typename _OutIter>
797 class time_put : public locale::facet
799 public:
800 // Types:
801 //@{
802 /// Public typedefs
803 typedef _CharT char_type;
804 typedef _OutIter iter_type;
805 //@}
807 /// Numpunct facet id.
808 static locale::id id;
811 * @brief Constructor performs initialization.
813 * This is the constructor provided by the standard.
815 * @param __refs Passed to the base facet class.
817 explicit
818 time_put(size_t __refs = 0)
819 : facet(__refs) { }
822 * @brief Format and output a time or date.
824 * This function formats the data in struct tm according to the
825 * provided format string. The format string is interpreted as by
826 * strftime().
828 * @param __s The stream to write to.
829 * @param __io Source of locale.
830 * @param __fill char_type to use for padding.
831 * @param __tm Struct tm with date and time info to format.
832 * @param __beg Start of format string.
833 * @param __end End of format string.
834 * @return Iterator after writing.
836 iter_type
837 put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
838 const _CharT* __beg, const _CharT* __end) const;
841 * @brief Format and output a time or date.
843 * This function formats the data in struct tm according to the
844 * provided format char and optional modifier. The format and modifier
845 * are interpreted as by strftime(). It does so by returning
846 * time_put::do_put().
848 * @param __s The stream to write to.
849 * @param __io Source of locale.
850 * @param __fill char_type to use for padding.
851 * @param __tm Struct tm with date and time info to format.
852 * @param __format Format char.
853 * @param __mod Optional modifier char.
854 * @return Iterator after writing.
856 iter_type
857 put(iter_type __s, ios_base& __io, char_type __fill,
858 const tm* __tm, char __format, char __mod = 0) const
859 { return this->do_put(__s, __io, __fill, __tm, __format, __mod); }
861 protected:
862 /// Destructor.
863 virtual
864 ~time_put()
868 * @brief Format and output a time or date.
870 * This function formats the data in struct tm according to the
871 * provided format char and optional modifier. This function is a hook
872 * for derived classes to change the value returned. @see put() for
873 * more details.
875 * @param __s The stream to write to.
876 * @param __io Source of locale.
877 * @param __fill char_type to use for padding.
878 * @param __tm Struct tm with date and time info to format.
879 * @param __format Format char.
880 * @param __mod Optional modifier char.
881 * @return Iterator after writing.
883 virtual iter_type
884 do_put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
885 char __format, char __mod) const;
888 template<typename _CharT, typename _OutIter>
889 locale::id time_put<_CharT, _OutIter>::id;
891 /// class time_put_byname [22.2.5.4].
892 template<typename _CharT, typename _OutIter>
893 class time_put_byname : public time_put<_CharT, _OutIter>
895 public:
896 // Types:
897 typedef _CharT char_type;
898 typedef _OutIter iter_type;
900 explicit
901 time_put_byname(const char*, size_t __refs = 0)
902 : time_put<_CharT, _OutIter>(__refs)
905 #if __cplusplus >= 201103L
906 explicit
907 time_put_byname(const string& __s, size_t __refs = 0)
908 : time_put_byname(__s.c_str(), __refs) { }
909 #endif
911 protected:
912 virtual
913 ~time_put_byname() { }
918 * @brief Money format ordering data.
919 * @ingroup locales
921 * This class contains an ordered array of 4 fields to represent the
922 * pattern for formatting a money amount. Each field may contain one entry
923 * from the part enum. symbol, sign, and value must be present and the
924 * remaining field must contain either none or space. @see
925 * moneypunct::pos_format() and moneypunct::neg_format() for details of how
926 * these fields are interpreted.
928 class money_base
930 public:
931 enum part { none, space, symbol, sign, value };
932 struct pattern { char field[4]; };
934 static const pattern _S_default_pattern;
936 enum
938 _S_minus,
939 _S_zero,
940 _S_end = 11
943 // String literal of acceptable (narrow) input/output, for
944 // money_get/money_put. "-0123456789"
945 static const char* _S_atoms;
947 // Construct and return valid pattern consisting of some combination of:
948 // space none symbol sign value
949 _GLIBCXX_CONST static pattern
950 _S_construct_pattern(char __precedes, char __space, char __posn) throw ();
953 template<typename _CharT, bool _Intl>
954 struct __moneypunct_cache : public locale::facet
956 const char* _M_grouping;
957 size_t _M_grouping_size;
958 bool _M_use_grouping;
959 _CharT _M_decimal_point;
960 _CharT _M_thousands_sep;
961 const _CharT* _M_curr_symbol;
962 size_t _M_curr_symbol_size;
963 const _CharT* _M_positive_sign;
964 size_t _M_positive_sign_size;
965 const _CharT* _M_negative_sign;
966 size_t _M_negative_sign_size;
967 int _M_frac_digits;
968 money_base::pattern _M_pos_format;
969 money_base::pattern _M_neg_format;
971 // A list of valid numeric literals for input and output: in the standard
972 // "C" locale, this is "-0123456789". This array contains the chars after
973 // having been passed through the current locale's ctype<_CharT>.widen().
974 _CharT _M_atoms[money_base::_S_end];
976 bool _M_allocated;
978 __moneypunct_cache(size_t __refs = 0) : facet(__refs),
979 _M_grouping(0), _M_grouping_size(0), _M_use_grouping(false),
980 _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()),
981 _M_curr_symbol(0), _M_curr_symbol_size(0),
982 _M_positive_sign(0), _M_positive_sign_size(0),
983 _M_negative_sign(0), _M_negative_sign_size(0),
984 _M_frac_digits(0),
985 _M_pos_format(money_base::pattern()),
986 _M_neg_format(money_base::pattern()), _M_allocated(false)
989 ~__moneypunct_cache();
991 void
992 _M_cache(const locale& __loc);
994 private:
995 __moneypunct_cache&
996 operator=(const __moneypunct_cache&);
998 explicit
999 __moneypunct_cache(const __moneypunct_cache&);
1002 template<typename _CharT, bool _Intl>
1003 __moneypunct_cache<_CharT, _Intl>::~__moneypunct_cache()
1005 if (_M_allocated)
1007 delete [] _M_grouping;
1008 delete [] _M_curr_symbol;
1009 delete [] _M_positive_sign;
1010 delete [] _M_negative_sign;
1014 _GLIBCXX_BEGIN_NAMESPACE_CXX11
1017 * @brief Primary class template moneypunct.
1018 * @ingroup locales
1020 * This facet encapsulates the punctuation, grouping and other formatting
1021 * features of money amount string representations.
1023 template<typename _CharT, bool _Intl>
1024 class moneypunct : public locale::facet, public money_base
1026 public:
1027 // Types:
1028 //@{
1029 /// Public typedefs
1030 typedef _CharT char_type;
1031 typedef basic_string<_CharT> string_type;
1032 //@}
1033 typedef __moneypunct_cache<_CharT, _Intl> __cache_type;
1035 private:
1036 __cache_type* _M_data;
1038 public:
1039 /// This value is provided by the standard, but no reason for its
1040 /// existence.
1041 static const bool intl = _Intl;
1042 /// Numpunct facet id.
1043 static locale::id id;
1046 * @brief Constructor performs initialization.
1048 * This is the constructor provided by the standard.
1050 * @param __refs Passed to the base facet class.
1052 explicit
1053 moneypunct(size_t __refs = 0)
1054 : facet(__refs), _M_data(0)
1055 { _M_initialize_moneypunct(); }
1058 * @brief Constructor performs initialization.
1060 * This is an internal constructor.
1062 * @param __cache Cache for optimization.
1063 * @param __refs Passed to the base facet class.
1065 explicit
1066 moneypunct(__cache_type* __cache, size_t __refs = 0)
1067 : facet(__refs), _M_data(__cache)
1068 { _M_initialize_moneypunct(); }
1071 * @brief Internal constructor. Not for general use.
1073 * This is a constructor for use by the library itself to set up new
1074 * locales.
1076 * @param __cloc The C locale.
1077 * @param __s The name of a locale.
1078 * @param __refs Passed to the base facet class.
1080 explicit
1081 moneypunct(__c_locale __cloc, const char* __s, size_t __refs = 0)
1082 : facet(__refs), _M_data(0)
1083 { _M_initialize_moneypunct(__cloc, __s); }
1086 * @brief Return decimal point character.
1088 * This function returns a char_type to use as a decimal point. It
1089 * does so by returning returning
1090 * moneypunct<char_type>::do_decimal_point().
1092 * @return @a char_type representing a decimal point.
1094 char_type
1095 decimal_point() const
1096 { return this->do_decimal_point(); }
1099 * @brief Return thousands separator character.
1101 * This function returns a char_type to use as a thousands
1102 * separator. It does so by returning returning
1103 * moneypunct<char_type>::do_thousands_sep().
1105 * @return char_type representing a thousands separator.
1107 char_type
1108 thousands_sep() const
1109 { return this->do_thousands_sep(); }
1112 * @brief Return grouping specification.
1114 * This function returns a string representing groupings for the
1115 * integer part of an amount. Groupings indicate where thousands
1116 * separators should be inserted.
1118 * Each char in the return string is interpret as an integer rather
1119 * than a character. These numbers represent the number of digits in a
1120 * group. The first char in the string represents the number of digits
1121 * in the least significant group. If a char is negative, it indicates
1122 * an unlimited number of digits for the group. If more chars from the
1123 * string are required to group a number, the last char is used
1124 * repeatedly.
1126 * For example, if the grouping() returns <code>\003\002</code>
1127 * and is applied to the number 123456789, this corresponds to
1128 * 12,34,56,789. Note that if the string was <code>32</code>, this would
1129 * put more than 50 digits into the least significant group if
1130 * the character set is ASCII.
1132 * The string is returned by calling
1133 * moneypunct<char_type>::do_grouping().
1135 * @return string representing grouping specification.
1137 string
1138 grouping() const
1139 { return this->do_grouping(); }
1142 * @brief Return currency symbol string.
1144 * This function returns a string_type to use as a currency symbol. It
1145 * does so by returning returning
1146 * moneypunct<char_type>::do_curr_symbol().
1148 * @return @a string_type representing a currency symbol.
1150 string_type
1151 curr_symbol() const
1152 { return this->do_curr_symbol(); }
1155 * @brief Return positive sign string.
1157 * This function returns a string_type to use as a sign for positive
1158 * amounts. It does so by returning returning
1159 * moneypunct<char_type>::do_positive_sign().
1161 * If the return value contains more than one character, the first
1162 * character appears in the position indicated by pos_format() and the
1163 * remainder appear at the end of the formatted string.
1165 * @return @a string_type representing a positive sign.
1167 string_type
1168 positive_sign() const
1169 { return this->do_positive_sign(); }
1172 * @brief Return negative sign string.
1174 * This function returns a string_type to use as a sign for negative
1175 * amounts. It does so by returning returning
1176 * moneypunct<char_type>::do_negative_sign().
1178 * If the return value contains more than one character, the first
1179 * character appears in the position indicated by neg_format() and the
1180 * remainder appear at the end of the formatted string.
1182 * @return @a string_type representing a negative sign.
1184 string_type
1185 negative_sign() const
1186 { return this->do_negative_sign(); }
1189 * @brief Return number of digits in fraction.
1191 * This function returns the exact number of digits that make up the
1192 * fractional part of a money amount. It does so by returning
1193 * returning moneypunct<char_type>::do_frac_digits().
1195 * The fractional part of a money amount is optional. But if it is
1196 * present, there must be frac_digits() digits.
1198 * @return Number of digits in amount fraction.
1201 frac_digits() const
1202 { return this->do_frac_digits(); }
1204 //@{
1206 * @brief Return pattern for money values.
1208 * This function returns a pattern describing the formatting of a
1209 * positive or negative valued money amount. It does so by returning
1210 * returning moneypunct<char_type>::do_pos_format() or
1211 * moneypunct<char_type>::do_neg_format().
1213 * The pattern has 4 fields describing the ordering of symbol, sign,
1214 * value, and none or space. There must be one of each in the pattern.
1215 * The none and space enums may not appear in the first field and space
1216 * may not appear in the final field.
1218 * The parts of a money string must appear in the order indicated by
1219 * the fields of the pattern. The symbol field indicates that the
1220 * value of curr_symbol() may be present. The sign field indicates
1221 * that the value of positive_sign() or negative_sign() must be
1222 * present. The value field indicates that the absolute value of the
1223 * money amount is present. none indicates 0 or more whitespace
1224 * characters, except at the end, where it permits no whitespace.
1225 * space indicates that 1 or more whitespace characters must be
1226 * present.
1228 * For example, for the US locale and pos_format() pattern
1229 * {symbol,sign,value,none}, curr_symbol() == &apos;$&apos;
1230 * positive_sign() == &apos;+&apos;, and value 10.01, and
1231 * options set to force the symbol, the corresponding string is
1232 * <code>$+10.01</code>.
1234 * @return Pattern for money values.
1236 pattern
1237 pos_format() const
1238 { return this->do_pos_format(); }
1240 pattern
1241 neg_format() const
1242 { return this->do_neg_format(); }
1243 //@}
1245 protected:
1246 /// Destructor.
1247 virtual
1248 ~moneypunct();
1251 * @brief Return decimal point character.
1253 * Returns a char_type to use as a decimal point. This function is a
1254 * hook for derived classes to change the value returned.
1256 * @return @a char_type representing a decimal point.
1258 virtual char_type
1259 do_decimal_point() const
1260 { return _M_data->_M_decimal_point; }
1263 * @brief Return thousands separator character.
1265 * Returns a char_type to use as a thousands separator. This function
1266 * is a hook for derived classes to change the value returned.
1268 * @return @a char_type representing a thousands separator.
1270 virtual char_type
1271 do_thousands_sep() const
1272 { return _M_data->_M_thousands_sep; }
1275 * @brief Return grouping specification.
1277 * Returns a string representing groupings for the integer part of a
1278 * number. This function is a hook for derived classes to change the
1279 * value returned. @see grouping() for details.
1281 * @return String representing grouping specification.
1283 virtual string
1284 do_grouping() const
1285 { return _M_data->_M_grouping; }
1288 * @brief Return currency symbol string.
1290 * This function returns a string_type to use as a currency symbol.
1291 * This function is a hook for derived classes to change the value
1292 * returned. @see curr_symbol() for details.
1294 * @return @a string_type representing a currency symbol.
1296 virtual string_type
1297 do_curr_symbol() const
1298 { return _M_data->_M_curr_symbol; }
1301 * @brief Return positive sign string.
1303 * This function returns a string_type to use as a sign for positive
1304 * amounts. This function is a hook for derived classes to change the
1305 * value returned. @see positive_sign() for details.
1307 * @return @a string_type representing a positive sign.
1309 virtual string_type
1310 do_positive_sign() const
1311 { return _M_data->_M_positive_sign; }
1314 * @brief Return negative sign string.
1316 * This function returns a string_type to use as a sign for negative
1317 * amounts. This function is a hook for derived classes to change the
1318 * value returned. @see negative_sign() for details.
1320 * @return @a string_type representing a negative sign.
1322 virtual string_type
1323 do_negative_sign() const
1324 { return _M_data->_M_negative_sign; }
1327 * @brief Return number of digits in fraction.
1329 * This function returns the exact number of digits that make up the
1330 * fractional part of a money amount. This function is a hook for
1331 * derived classes to change the value returned. @see frac_digits()
1332 * for details.
1334 * @return Number of digits in amount fraction.
1336 virtual int
1337 do_frac_digits() const
1338 { return _M_data->_M_frac_digits; }
1341 * @brief Return pattern for money values.
1343 * This function returns a pattern describing the formatting of a
1344 * positive valued money amount. This function is a hook for derived
1345 * classes to change the value returned. @see pos_format() for
1346 * details.
1348 * @return Pattern for money values.
1350 virtual pattern
1351 do_pos_format() const
1352 { return _M_data->_M_pos_format; }
1355 * @brief Return pattern for money values.
1357 * This function returns a pattern describing the formatting of a
1358 * negative valued money amount. This function is a hook for derived
1359 * classes to change the value returned. @see neg_format() for
1360 * details.
1362 * @return Pattern for money values.
1364 virtual pattern
1365 do_neg_format() const
1366 { return _M_data->_M_neg_format; }
1368 // For use at construction time only.
1369 void
1370 _M_initialize_moneypunct(__c_locale __cloc = 0,
1371 const char* __name = 0);
1374 template<typename _CharT, bool _Intl>
1375 locale::id moneypunct<_CharT, _Intl>::id;
1377 template<typename _CharT, bool _Intl>
1378 const bool moneypunct<_CharT, _Intl>::intl;
1380 template<>
1381 moneypunct<char, true>::~moneypunct();
1383 template<>
1384 moneypunct<char, false>::~moneypunct();
1386 template<>
1387 void
1388 moneypunct<char, true>::_M_initialize_moneypunct(__c_locale, const char*);
1390 template<>
1391 void
1392 moneypunct<char, false>::_M_initialize_moneypunct(__c_locale, const char*);
1394 #ifdef _GLIBCXX_USE_WCHAR_T
1395 template<>
1396 moneypunct<wchar_t, true>::~moneypunct();
1398 template<>
1399 moneypunct<wchar_t, false>::~moneypunct();
1401 template<>
1402 void
1403 moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale,
1404 const char*);
1406 template<>
1407 void
1408 moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale,
1409 const char*);
1410 #endif
1412 /// class moneypunct_byname [22.2.6.4].
1413 template<typename _CharT, bool _Intl>
1414 class moneypunct_byname : public moneypunct<_CharT, _Intl>
1416 public:
1417 typedef _CharT char_type;
1418 typedef basic_string<_CharT> string_type;
1420 static const bool intl = _Intl;
1422 explicit
1423 moneypunct_byname(const char* __s, size_t __refs = 0)
1424 : moneypunct<_CharT, _Intl>(__refs)
1426 if (__builtin_strcmp(__s, "C") != 0
1427 && __builtin_strcmp(__s, "POSIX") != 0)
1429 __c_locale __tmp;
1430 this->_S_create_c_locale(__tmp, __s);
1431 this->_M_initialize_moneypunct(__tmp);
1432 this->_S_destroy_c_locale(__tmp);
1436 #if __cplusplus >= 201103L
1437 explicit
1438 moneypunct_byname(const string& __s, size_t __refs = 0)
1439 : moneypunct_byname(__s.c_str(), __refs) { }
1440 #endif
1442 protected:
1443 virtual
1444 ~moneypunct_byname() { }
1447 template<typename _CharT, bool _Intl>
1448 const bool moneypunct_byname<_CharT, _Intl>::intl;
1450 _GLIBCXX_END_NAMESPACE_CXX11
1452 _GLIBCXX_BEGIN_NAMESPACE_LDBL_OR_CXX11
1455 * @brief Primary class template money_get.
1456 * @ingroup locales
1458 * This facet encapsulates the code to parse and return a monetary
1459 * amount from a string.
1461 * The money_get template uses protected virtual functions to
1462 * provide the actual results. The public accessors forward the
1463 * call to the virtual functions. These virtual functions are
1464 * hooks for developers to implement the behavior they require from
1465 * the money_get facet.
1467 template<typename _CharT, typename _InIter>
1468 class money_get : public locale::facet
1470 public:
1471 // Types:
1472 //@{
1473 /// Public typedefs
1474 typedef _CharT char_type;
1475 typedef _InIter iter_type;
1476 typedef basic_string<_CharT> string_type;
1477 //@}
1479 /// Numpunct facet id.
1480 static locale::id id;
1483 * @brief Constructor performs initialization.
1485 * This is the constructor provided by the standard.
1487 * @param __refs Passed to the base facet class.
1489 explicit
1490 money_get(size_t __refs = 0) : facet(__refs) { }
1493 * @brief Read and parse a monetary value.
1495 * This function reads characters from @a __s, interprets them as a
1496 * monetary value according to moneypunct and ctype facets retrieved
1497 * from io.getloc(), and returns the result in @a units as an integral
1498 * value moneypunct::frac_digits() * the actual amount. For example,
1499 * the string $10.01 in a US locale would store 1001 in @a units.
1501 * Any characters not part of a valid money amount are not consumed.
1503 * If a money value cannot be parsed from the input stream, sets
1504 * err=(err|io.failbit). If the stream is consumed before finishing
1505 * parsing, sets err=(err|io.failbit|io.eofbit). @a units is
1506 * unchanged if parsing fails.
1508 * This function works by returning the result of do_get().
1510 * @param __s Start of characters to parse.
1511 * @param __end End of characters to parse.
1512 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
1513 * @param __io Source of facets and io state.
1514 * @param __err Error field to set if parsing fails.
1515 * @param __units Place to store result of parsing.
1516 * @return Iterator referencing first character beyond valid money
1517 * amount.
1519 iter_type
1520 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1521 ios_base::iostate& __err, long double& __units) const
1522 { return this->do_get(__s, __end, __intl, __io, __err, __units); }
1525 * @brief Read and parse a monetary value.
1527 * This function reads characters from @a __s, interprets them as
1528 * a monetary value according to moneypunct and ctype facets
1529 * retrieved from io.getloc(), and returns the result in @a
1530 * digits. For example, the string $10.01 in a US locale would
1531 * store <code>1001</code> in @a digits.
1533 * Any characters not part of a valid money amount are not consumed.
1535 * If a money value cannot be parsed from the input stream, sets
1536 * err=(err|io.failbit). If the stream is consumed before finishing
1537 * parsing, sets err=(err|io.failbit|io.eofbit).
1539 * This function works by returning the result of do_get().
1541 * @param __s Start of characters to parse.
1542 * @param __end End of characters to parse.
1543 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
1544 * @param __io Source of facets and io state.
1545 * @param __err Error field to set if parsing fails.
1546 * @param __digits Place to store result of parsing.
1547 * @return Iterator referencing first character beyond valid money
1548 * amount.
1550 iter_type
1551 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1552 ios_base::iostate& __err, string_type& __digits) const
1553 { return this->do_get(__s, __end, __intl, __io, __err, __digits); }
1555 protected:
1556 /// Destructor.
1557 virtual
1558 ~money_get() { }
1561 * @brief Read and parse a monetary value.
1563 * This function reads and parses characters representing a monetary
1564 * value. This function is a hook for derived classes to change the
1565 * value returned. @see get() for details.
1567 // XXX GLIBCXX_ABI Deprecated
1568 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \
1569 && _GLIBCXX_USE_CXX11_ABI == 0
1570 virtual iter_type
1571 __do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1572 ios_base::iostate& __err, double& __units) const;
1573 #else
1574 virtual iter_type
1575 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1576 ios_base::iostate& __err, long double& __units) const;
1577 #endif
1580 * @brief Read and parse a monetary value.
1582 * This function reads and parses characters representing a monetary
1583 * value. This function is a hook for derived classes to change the
1584 * value returned. @see get() for details.
1586 virtual iter_type
1587 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1588 ios_base::iostate& __err, string_type& __digits) const;
1590 // XXX GLIBCXX_ABI Deprecated
1591 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \
1592 && _GLIBCXX_USE_CXX11_ABI == 0
1593 virtual iter_type
1594 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1595 ios_base::iostate& __err, long double& __units) const;
1596 #endif
1598 template<bool _Intl>
1599 iter_type
1600 _M_extract(iter_type __s, iter_type __end, ios_base& __io,
1601 ios_base::iostate& __err, string& __digits) const;
1604 template<typename _CharT, typename _InIter>
1605 locale::id money_get<_CharT, _InIter>::id;
1608 * @brief Primary class template money_put.
1609 * @ingroup locales
1611 * This facet encapsulates the code to format and output a monetary
1612 * amount.
1614 * The money_put template uses protected virtual functions to
1615 * provide the actual results. The public accessors forward the
1616 * call to the virtual functions. These virtual functions are
1617 * hooks for developers to implement the behavior they require from
1618 * the money_put facet.
1620 template<typename _CharT, typename _OutIter>
1621 class money_put : public locale::facet
1623 public:
1624 //@{
1625 /// Public typedefs
1626 typedef _CharT char_type;
1627 typedef _OutIter iter_type;
1628 typedef basic_string<_CharT> string_type;
1629 //@}
1631 /// Numpunct facet id.
1632 static locale::id id;
1635 * @brief Constructor performs initialization.
1637 * This is the constructor provided by the standard.
1639 * @param __refs Passed to the base facet class.
1641 explicit
1642 money_put(size_t __refs = 0) : facet(__refs) { }
1645 * @brief Format and output a monetary value.
1647 * This function formats @a units as a monetary value according to
1648 * moneypunct and ctype facets retrieved from io.getloc(), and writes
1649 * the resulting characters to @a __s. For example, the value 1001 in a
1650 * US locale would write <code>$10.01</code> to @a __s.
1652 * This function works by returning the result of do_put().
1654 * @param __s The stream to write to.
1655 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
1656 * @param __io Source of facets and io state.
1657 * @param __fill char_type to use for padding.
1658 * @param __units Place to store result of parsing.
1659 * @return Iterator after writing.
1661 iter_type
1662 put(iter_type __s, bool __intl, ios_base& __io,
1663 char_type __fill, long double __units) const
1664 { return this->do_put(__s, __intl, __io, __fill, __units); }
1667 * @brief Format and output a monetary value.
1669 * This function formats @a digits as a monetary value
1670 * according to moneypunct and ctype facets retrieved from
1671 * io.getloc(), and writes the resulting characters to @a __s.
1672 * For example, the string <code>1001</code> in a US locale
1673 * would write <code>$10.01</code> to @a __s.
1675 * This function works by returning the result of do_put().
1677 * @param __s The stream to write to.
1678 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
1679 * @param __io Source of facets and io state.
1680 * @param __fill char_type to use for padding.
1681 * @param __digits Place to store result of parsing.
1682 * @return Iterator after writing.
1684 iter_type
1685 put(iter_type __s, bool __intl, ios_base& __io,
1686 char_type __fill, const string_type& __digits) const
1687 { return this->do_put(__s, __intl, __io, __fill, __digits); }
1689 protected:
1690 /// Destructor.
1691 virtual
1692 ~money_put() { }
1695 * @brief Format and output a monetary value.
1697 * This function formats @a units as a monetary value according to
1698 * moneypunct and ctype facets retrieved from io.getloc(), and writes
1699 * the resulting characters to @a __s. For example, the value 1001 in a
1700 * US locale would write <code>$10.01</code> to @a __s.
1702 * This function is a hook for derived classes to change the value
1703 * returned. @see put().
1705 * @param __s The stream to write to.
1706 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
1707 * @param __io Source of facets and io state.
1708 * @param __fill char_type to use for padding.
1709 * @param __units Place to store result of parsing.
1710 * @return Iterator after writing.
1712 // XXX GLIBCXX_ABI Deprecated
1713 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \
1714 && _GLIBCXX_USE_CXX11_ABI == 0
1715 virtual iter_type
1716 __do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1717 double __units) const;
1718 #else
1719 virtual iter_type
1720 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1721 long double __units) const;
1722 #endif
1725 * @brief Format and output a monetary value.
1727 * This function formats @a digits as a monetary value
1728 * according to moneypunct and ctype facets retrieved from
1729 * io.getloc(), and writes the resulting characters to @a __s.
1730 * For example, the string <code>1001</code> in a US locale
1731 * would write <code>$10.01</code> to @a __s.
1733 * This function is a hook for derived classes to change the value
1734 * returned. @see put().
1736 * @param __s The stream to write to.
1737 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
1738 * @param __io Source of facets and io state.
1739 * @param __fill char_type to use for padding.
1740 * @param __digits Place to store result of parsing.
1741 * @return Iterator after writing.
1743 virtual iter_type
1744 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1745 const string_type& __digits) const;
1747 // XXX GLIBCXX_ABI Deprecated
1748 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \
1749 && _GLIBCXX_USE_CXX11_ABI == 0
1750 virtual iter_type
1751 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1752 long double __units) const;
1753 #endif
1755 template<bool _Intl>
1756 iter_type
1757 _M_insert(iter_type __s, ios_base& __io, char_type __fill,
1758 const string_type& __digits) const;
1761 template<typename _CharT, typename _OutIter>
1762 locale::id money_put<_CharT, _OutIter>::id;
1764 _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11
1767 * @brief Messages facet base class providing catalog typedef.
1768 * @ingroup locales
1770 struct messages_base
1772 typedef int catalog;
1775 _GLIBCXX_BEGIN_NAMESPACE_CXX11
1778 * @brief Primary class template messages.
1779 * @ingroup locales
1781 * This facet encapsulates the code to retrieve messages from
1782 * message catalogs. The only thing defined by the standard for this facet
1783 * is the interface. All underlying functionality is
1784 * implementation-defined.
1786 * This library currently implements 3 versions of the message facet. The
1787 * first version (gnu) is a wrapper around gettext, provided by libintl.
1788 * The second version (ieee) is a wrapper around catgets. The final
1789 * version (default) does no actual translation. These implementations are
1790 * only provided for char and wchar_t instantiations.
1792 * The messages template uses protected virtual functions to
1793 * provide the actual results. The public accessors forward the
1794 * call to the virtual functions. These virtual functions are
1795 * hooks for developers to implement the behavior they require from
1796 * the messages facet.
1798 template<typename _CharT>
1799 class messages : public locale::facet, public messages_base
1801 public:
1802 // Types:
1803 //@{
1804 /// Public typedefs
1805 typedef _CharT char_type;
1806 typedef basic_string<_CharT> string_type;
1807 //@}
1809 protected:
1810 // Underlying "C" library locale information saved from
1811 // initialization, needed by messages_byname as well.
1812 __c_locale _M_c_locale_messages;
1813 const char* _M_name_messages;
1815 public:
1816 /// Numpunct facet id.
1817 static locale::id id;
1820 * @brief Constructor performs initialization.
1822 * This is the constructor provided by the standard.
1824 * @param __refs Passed to the base facet class.
1826 explicit
1827 messages(size_t __refs = 0);
1829 // Non-standard.
1831 * @brief Internal constructor. Not for general use.
1833 * This is a constructor for use by the library itself to set up new
1834 * locales.
1836 * @param __cloc The C locale.
1837 * @param __s The name of a locale.
1838 * @param __refs Refcount to pass to the base class.
1840 explicit
1841 messages(__c_locale __cloc, const char* __s, size_t __refs = 0);
1844 * @brief Open a message catalog.
1846 * This function opens and returns a handle to a message catalog by
1847 * returning do_open(__s, __loc).
1849 * @param __s The catalog to open.
1850 * @param __loc Locale to use for character set conversions.
1851 * @return Handle to the catalog or value < 0 if open fails.
1853 catalog
1854 open(const basic_string<char>& __s, const locale& __loc) const
1855 { return this->do_open(__s, __loc); }
1857 // Non-standard and unorthodox, yet effective.
1859 * @brief Open a message catalog.
1861 * This non-standard function opens and returns a handle to a message
1862 * catalog by returning do_open(s, loc). The third argument provides a
1863 * message catalog root directory for gnu gettext and is ignored
1864 * otherwise.
1866 * @param __s The catalog to open.
1867 * @param __loc Locale to use for character set conversions.
1868 * @param __dir Message catalog root directory.
1869 * @return Handle to the catalog or value < 0 if open fails.
1871 catalog
1872 open(const basic_string<char>&, const locale&, const char*) const;
1875 * @brief Look up a string in a message catalog.
1877 * This function retrieves and returns a message from a catalog by
1878 * returning do_get(c, set, msgid, s).
1880 * For gnu, @a __set and @a msgid are ignored. Returns gettext(s).
1881 * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
1883 * @param __c The catalog to access.
1884 * @param __set Implementation-defined.
1885 * @param __msgid Implementation-defined.
1886 * @param __s Default return value if retrieval fails.
1887 * @return Retrieved message or @a __s if get fails.
1889 string_type
1890 get(catalog __c, int __set, int __msgid, const string_type& __s) const
1891 { return this->do_get(__c, __set, __msgid, __s); }
1894 * @brief Close a message catalog.
1896 * Closes catalog @a c by calling do_close(c).
1898 * @param __c The catalog to close.
1900 void
1901 close(catalog __c) const
1902 { return this->do_close(__c); }
1904 protected:
1905 /// Destructor.
1906 virtual
1907 ~messages();
1910 * @brief Open a message catalog.
1912 * This function opens and returns a handle to a message catalog in an
1913 * implementation-defined manner. This function is a hook for derived
1914 * classes to change the value returned.
1916 * @param __s The catalog to open.
1917 * @param __loc Locale to use for character set conversions.
1918 * @return Handle to the opened catalog, value < 0 if open failed.
1920 virtual catalog
1921 do_open(const basic_string<char>&, const locale&) const;
1924 * @brief Look up a string in a message catalog.
1926 * This function retrieves and returns a message from a catalog in an
1927 * implementation-defined manner. This function is a hook for derived
1928 * classes to change the value returned.
1930 * For gnu, @a __set and @a __msgid are ignored. Returns gettext(s).
1931 * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
1933 * @param __c The catalog to access.
1934 * @param __set Implementation-defined.
1935 * @param __msgid Implementation-defined.
1936 * @param __s Default return value if retrieval fails.
1937 * @return Retrieved message or @a __s if get fails.
1939 virtual string_type
1940 do_get(catalog, int, int, const string_type& __dfault) const;
1943 * @brief Close a message catalog.
1945 * @param __c The catalog to close.
1947 virtual void
1948 do_close(catalog) const;
1950 // Returns a locale and codeset-converted string, given a char* message.
1951 char*
1952 _M_convert_to_char(const string_type& __msg) const
1954 // XXX
1955 return reinterpret_cast<char*>(const_cast<_CharT*>(__msg.c_str()));
1958 // Returns a locale and codeset-converted string, given a char* message.
1959 string_type
1960 _M_convert_from_char(char*) const
1962 // XXX
1963 return string_type();
1967 template<typename _CharT>
1968 locale::id messages<_CharT>::id;
1970 /// Specializations for required instantiations.
1971 template<>
1972 string
1973 messages<char>::do_get(catalog, int, int, const string&) const;
1975 #ifdef _GLIBCXX_USE_WCHAR_T
1976 template<>
1977 wstring
1978 messages<wchar_t>::do_get(catalog, int, int, const wstring&) const;
1979 #endif
1981 /// class messages_byname [22.2.7.2].
1982 template<typename _CharT>
1983 class messages_byname : public messages<_CharT>
1985 public:
1986 typedef _CharT char_type;
1987 typedef basic_string<_CharT> string_type;
1989 explicit
1990 messages_byname(const char* __s, size_t __refs = 0);
1992 #if __cplusplus >= 201103L
1993 explicit
1994 messages_byname(const string& __s, size_t __refs = 0)
1995 : messages_byname(__s.c_str(), __refs) { }
1996 #endif
1998 protected:
1999 virtual
2000 ~messages_byname()
2004 _GLIBCXX_END_NAMESPACE_CXX11
2006 _GLIBCXX_END_NAMESPACE_VERSION
2007 } // namespace
2009 // Include host and configuration specific messages functions.
2010 #include <bits/messages_members.h>
2012 // 22.2.1.5 Template class codecvt
2013 #include <bits/codecvt.h>
2015 #include <bits/locale_facets_nonio.tcc>
2017 #endif