1 // Locale support -*- C++ -*-
3 // Copyright (C) 2007, 2008, 2009, 2010 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 locale_facets_nonio.h
26 * This is an internal header file, included by other library headers.
27 * You should not attempt to use it directly.
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 _GLIBCXX_BEGIN_NAMESPACE(std
)
44 * @brief Time format ordering data.
46 * This class provides an enum representing different orderings of day,
52 enum dateorder
{ no_order
, dmy
, mdy
, ymd
, ydm
};
55 template<typename _CharT
>
56 struct __timepunct_cache
: public locale::facet
58 // List of all known timezones, with GMT first.
59 static const _CharT
* _S_timezones
[14];
61 const _CharT
* _M_date_format
;
62 const _CharT
* _M_date_era_format
;
63 const _CharT
* _M_time_format
;
64 const _CharT
* _M_time_era_format
;
65 const _CharT
* _M_date_time_format
;
66 const _CharT
* _M_date_time_era_format
;
69 const _CharT
* _M_am_pm_format
;
71 // Day names, starting with "C"'s Sunday.
72 const _CharT
* _M_day1
;
73 const _CharT
* _M_day2
;
74 const _CharT
* _M_day3
;
75 const _CharT
* _M_day4
;
76 const _CharT
* _M_day5
;
77 const _CharT
* _M_day6
;
78 const _CharT
* _M_day7
;
80 // Abbreviated day names, starting with "C"'s Sun.
81 const _CharT
* _M_aday1
;
82 const _CharT
* _M_aday2
;
83 const _CharT
* _M_aday3
;
84 const _CharT
* _M_aday4
;
85 const _CharT
* _M_aday5
;
86 const _CharT
* _M_aday6
;
87 const _CharT
* _M_aday7
;
89 // Month names, starting with "C"'s January.
90 const _CharT
* _M_month01
;
91 const _CharT
* _M_month02
;
92 const _CharT
* _M_month03
;
93 const _CharT
* _M_month04
;
94 const _CharT
* _M_month05
;
95 const _CharT
* _M_month06
;
96 const _CharT
* _M_month07
;
97 const _CharT
* _M_month08
;
98 const _CharT
* _M_month09
;
99 const _CharT
* _M_month10
;
100 const _CharT
* _M_month11
;
101 const _CharT
* _M_month12
;
103 // Abbreviated month names, starting with "C"'s Jan.
104 const _CharT
* _M_amonth01
;
105 const _CharT
* _M_amonth02
;
106 const _CharT
* _M_amonth03
;
107 const _CharT
* _M_amonth04
;
108 const _CharT
* _M_amonth05
;
109 const _CharT
* _M_amonth06
;
110 const _CharT
* _M_amonth07
;
111 const _CharT
* _M_amonth08
;
112 const _CharT
* _M_amonth09
;
113 const _CharT
* _M_amonth10
;
114 const _CharT
* _M_amonth11
;
115 const _CharT
* _M_amonth12
;
119 __timepunct_cache(size_t __refs
= 0) : facet(__refs
),
120 _M_date_format(NULL
), _M_date_era_format(NULL
), _M_time_format(NULL
),
121 _M_time_era_format(NULL
), _M_date_time_format(NULL
),
122 _M_date_time_era_format(NULL
), _M_am(NULL
), _M_pm(NULL
),
123 _M_am_pm_format(NULL
), _M_day1(NULL
), _M_day2(NULL
), _M_day3(NULL
),
124 _M_day4(NULL
), _M_day5(NULL
), _M_day6(NULL
), _M_day7(NULL
),
125 _M_aday1(NULL
), _M_aday2(NULL
), _M_aday3(NULL
), _M_aday4(NULL
),
126 _M_aday5(NULL
), _M_aday6(NULL
), _M_aday7(NULL
), _M_month01(NULL
),
127 _M_month02(NULL
), _M_month03(NULL
), _M_month04(NULL
), _M_month05(NULL
),
128 _M_month06(NULL
), _M_month07(NULL
), _M_month08(NULL
), _M_month09(NULL
),
129 _M_month10(NULL
), _M_month11(NULL
), _M_month12(NULL
), _M_amonth01(NULL
),
130 _M_amonth02(NULL
), _M_amonth03(NULL
), _M_amonth04(NULL
),
131 _M_amonth05(NULL
), _M_amonth06(NULL
), _M_amonth07(NULL
),
132 _M_amonth08(NULL
), _M_amonth09(NULL
), _M_amonth10(NULL
),
133 _M_amonth11(NULL
), _M_amonth12(NULL
), _M_allocated(false)
136 ~__timepunct_cache();
139 _M_cache(const locale
& __loc
);
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 basic_string
<_CharT
> __string_type
;
180 typedef __timepunct_cache
<_CharT
> __cache_type
;
183 __cache_type
* _M_data
;
184 __c_locale _M_c_locale_timepunct
;
185 const char* _M_name_timepunct
;
188 /// Numpunct facet id.
189 static locale::id id
;
192 __timepunct(size_t __refs
= 0);
195 __timepunct(__cache_type
* __cache
, size_t __refs
= 0);
198 * @brief Internal constructor. Not for general use.
200 * This is a constructor for use by the library itself to set up new
203 * @param cloc The C locale.
204 * @param s The name of a locale.
205 * @param refs Passed to the base facet class.
208 __timepunct(__c_locale __cloc
, const char* __s
, size_t __refs
= 0);
210 // FIXME: for error checking purposes _M_put should return the return
211 // value of strftime/wcsftime.
213 _M_put(_CharT
* __s
, size_t __maxlen
, const _CharT
* __format
,
214 const tm
* __tm
) const throw ();
217 _M_date_formats(const _CharT
** __date
) const
219 // Always have default first.
220 __date
[0] = _M_data
->_M_date_format
;
221 __date
[1] = _M_data
->_M_date_era_format
;
225 _M_time_formats(const _CharT
** __time
) const
227 // Always have default first.
228 __time
[0] = _M_data
->_M_time_format
;
229 __time
[1] = _M_data
->_M_time_era_format
;
233 _M_date_time_formats(const _CharT
** __dt
) const
235 // Always have default first.
236 __dt
[0] = _M_data
->_M_date_time_format
;
237 __dt
[1] = _M_data
->_M_date_time_era_format
;
241 _M_am_pm_format(const _CharT
* __ampm
) const
242 { __ampm
= _M_data
->_M_am_pm_format
; }
245 _M_am_pm(const _CharT
** __ampm
) const
247 __ampm
[0] = _M_data
->_M_am
;
248 __ampm
[1] = _M_data
->_M_pm
;
252 _M_days(const _CharT
** __days
) const
254 __days
[0] = _M_data
->_M_day1
;
255 __days
[1] = _M_data
->_M_day2
;
256 __days
[2] = _M_data
->_M_day3
;
257 __days
[3] = _M_data
->_M_day4
;
258 __days
[4] = _M_data
->_M_day5
;
259 __days
[5] = _M_data
->_M_day6
;
260 __days
[6] = _M_data
->_M_day7
;
264 _M_days_abbreviated(const _CharT
** __days
) const
266 __days
[0] = _M_data
->_M_aday1
;
267 __days
[1] = _M_data
->_M_aday2
;
268 __days
[2] = _M_data
->_M_aday3
;
269 __days
[3] = _M_data
->_M_aday4
;
270 __days
[4] = _M_data
->_M_aday5
;
271 __days
[5] = _M_data
->_M_aday6
;
272 __days
[6] = _M_data
->_M_aday7
;
276 _M_months(const _CharT
** __months
) const
278 __months
[0] = _M_data
->_M_month01
;
279 __months
[1] = _M_data
->_M_month02
;
280 __months
[2] = _M_data
->_M_month03
;
281 __months
[3] = _M_data
->_M_month04
;
282 __months
[4] = _M_data
->_M_month05
;
283 __months
[5] = _M_data
->_M_month06
;
284 __months
[6] = _M_data
->_M_month07
;
285 __months
[7] = _M_data
->_M_month08
;
286 __months
[8] = _M_data
->_M_month09
;
287 __months
[9] = _M_data
->_M_month10
;
288 __months
[10] = _M_data
->_M_month11
;
289 __months
[11] = _M_data
->_M_month12
;
293 _M_months_abbreviated(const _CharT
** __months
) const
295 __months
[0] = _M_data
->_M_amonth01
;
296 __months
[1] = _M_data
->_M_amonth02
;
297 __months
[2] = _M_data
->_M_amonth03
;
298 __months
[3] = _M_data
->_M_amonth04
;
299 __months
[4] = _M_data
->_M_amonth05
;
300 __months
[5] = _M_data
->_M_amonth06
;
301 __months
[6] = _M_data
->_M_amonth07
;
302 __months
[7] = _M_data
->_M_amonth08
;
303 __months
[8] = _M_data
->_M_amonth09
;
304 __months
[9] = _M_data
->_M_amonth10
;
305 __months
[10] = _M_data
->_M_amonth11
;
306 __months
[11] = _M_data
->_M_amonth12
;
313 // For use at construction time only.
315 _M_initialize_timepunct(__c_locale __cloc
= NULL
);
318 template<typename _CharT
>
319 locale::id __timepunct
<_CharT
>::id
;
324 __timepunct
<char>::_M_initialize_timepunct(__c_locale __cloc
);
328 __timepunct
<char>::_M_put(char*, size_t, const char*, const tm
*) const throw ();
330 #ifdef _GLIBCXX_USE_WCHAR_T
333 __timepunct
<wchar_t>::_M_initialize_timepunct(__c_locale __cloc
);
337 __timepunct
<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*,
338 const tm
*) const throw ();
341 _GLIBCXX_END_NAMESPACE
343 // Include host and configuration specific timepunct functions.
344 #include <bits/time_members.h>
346 _GLIBCXX_BEGIN_NAMESPACE(std
)
349 * @brief Facet for parsing dates and times.
351 * This facet encapsulates the code to parse and return a date or
352 * time from a string. It is used by the istream numeric
353 * extraction operators.
355 * The time_get template uses protected virtual functions to provide the
356 * actual results. The public accessors forward the call to the virtual
357 * functions. These virtual functions are hooks for developers to
358 * implement the behavior they require from the time_get facet.
360 template<typename _CharT
, typename _InIter
>
361 class time_get
: public locale::facet
, public time_base
367 typedef _CharT char_type
;
368 typedef _InIter iter_type
;
370 typedef basic_string
<_CharT
> __string_type
;
372 /// Numpunct facet id.
373 static locale::id id
;
376 * @brief Constructor performs initialization.
378 * This is the constructor provided by the standard.
380 * @param refs Passed to the base facet class.
383 time_get(size_t __refs
= 0)
387 * @brief Return preferred order of month, day, and year.
389 * This function returns an enum from timebase::dateorder giving the
390 * preferred ordering if the format @a x given to time_put::put() only
391 * uses month, day, and year. If the format @a x for the associated
392 * locale uses other fields, this function returns
393 * timebase::dateorder::noorder.
395 * NOTE: The library always returns noorder at the moment.
397 * @return A member of timebase::dateorder.
401 { return this->do_date_order(); }
404 * @brief Parse input time string.
406 * This function parses a time according to the format @a x and puts the
407 * results into a user-supplied struct tm. The result is returned by
408 * calling time_get::do_get_time().
410 * If there is a valid time string according to format @a x, @a tm will
411 * be filled in accordingly and the returned iterator will point to the
412 * first character beyond the time string. If an error occurs before
413 * the end, err |= ios_base::failbit. If parsing reads all the
414 * characters, err |= ios_base::eofbit.
416 * @param beg Start of string to parse.
417 * @param end End of string to parse.
418 * @param io Source of the locale.
419 * @param err Error flags to set.
420 * @param tm Pointer to struct tm to fill in.
421 * @return Iterator to first char beyond time string.
424 get_time(iter_type __beg
, iter_type __end
, ios_base
& __io
,
425 ios_base::iostate
& __err
, tm
* __tm
) const
426 { return this->do_get_time(__beg
, __end
, __io
, __err
, __tm
); }
429 * @brief Parse input date string.
431 * This function parses a date according to the format @a X and puts the
432 * results into a user-supplied struct tm. The result is returned by
433 * calling time_get::do_get_date().
435 * If there is a valid date string according to format @a X, @a tm will
436 * be filled in accordingly and the returned iterator will point to the
437 * first character beyond the date string. If an error occurs before
438 * the end, err |= ios_base::failbit. If parsing reads all the
439 * characters, err |= ios_base::eofbit.
441 * @param beg Start of string to parse.
442 * @param end End of string to parse.
443 * @param io Source of the locale.
444 * @param err Error flags to set.
445 * @param tm Pointer to struct tm to fill in.
446 * @return Iterator to first char beyond date string.
449 get_date(iter_type __beg
, iter_type __end
, ios_base
& __io
,
450 ios_base::iostate
& __err
, tm
* __tm
) const
451 { return this->do_get_date(__beg
, __end
, __io
, __err
, __tm
); }
454 * @brief Parse input weekday string.
456 * This function parses a weekday name and puts the results into a
457 * user-supplied struct tm. The result is returned by calling
458 * time_get::do_get_weekday().
460 * Parsing starts by parsing an abbreviated weekday name. If a valid
461 * abbreviation is followed by a character that would lead to the full
462 * weekday name, parsing continues until the full name is found or an
463 * error occurs. Otherwise parsing finishes at the end of the
466 * If an error occurs before the end, err |= ios_base::failbit. If
467 * parsing reads all the characters, err |= ios_base::eofbit.
469 * @param beg Start of string to parse.
470 * @param end End of string to parse.
471 * @param io Source of the locale.
472 * @param err Error flags to set.
473 * @param tm Pointer to struct tm to fill in.
474 * @return Iterator to first char beyond weekday name.
477 get_weekday(iter_type __beg
, iter_type __end
, ios_base
& __io
,
478 ios_base::iostate
& __err
, tm
* __tm
) const
479 { return this->do_get_weekday(__beg
, __end
, __io
, __err
, __tm
); }
482 * @brief Parse input month string.
484 * This function parses a month name and puts the results into a
485 * user-supplied struct tm. The result is returned by calling
486 * time_get::do_get_monthname().
488 * Parsing starts by parsing an abbreviated month name. If a valid
489 * abbreviation is followed by a character that would lead to the full
490 * month name, parsing continues until the full name is found or an
491 * error occurs. Otherwise parsing finishes at the end of the
494 * If an error occurs before the end, err |= ios_base::failbit. If
495 * parsing reads all the characters, err |=
498 * @param beg Start of string to parse.
499 * @param end End of string to parse.
500 * @param io Source of the locale.
501 * @param err Error flags to set.
502 * @param tm Pointer to struct tm to fill in.
503 * @return Iterator to first char beyond month name.
506 get_monthname(iter_type __beg
, iter_type __end
, ios_base
& __io
,
507 ios_base::iostate
& __err
, tm
* __tm
) const
508 { return this->do_get_monthname(__beg
, __end
, __io
, __err
, __tm
); }
511 * @brief Parse input year string.
513 * This function reads up to 4 characters to parse a year string and
514 * puts the results into a user-supplied struct tm. The result is
515 * returned by calling time_get::do_get_year().
517 * 4 consecutive digits are interpreted as a full year. If there are
518 * exactly 2 consecutive digits, the library interprets this as the
519 * number of years since 1900.
521 * If an error occurs before the end, err |= ios_base::failbit. If
522 * parsing reads all the characters, err |= ios_base::eofbit.
524 * @param beg Start of string to parse.
525 * @param end End of string to parse.
526 * @param io Source of the locale.
527 * @param err Error flags to set.
528 * @param tm Pointer to struct tm to fill in.
529 * @return Iterator to first char beyond year.
532 get_year(iter_type __beg
, iter_type __end
, ios_base
& __io
,
533 ios_base::iostate
& __err
, tm
* __tm
) const
534 { return this->do_get_year(__beg
, __end
, __io
, __err
, __tm
); }
542 * @brief Return preferred order of month, day, and year.
544 * This function returns an enum from timebase::dateorder giving the
545 * preferred ordering if the format @a x given to time_put::put() only
546 * uses month, day, and year. This function is a hook for derived
547 * classes to change the value returned.
549 * @return A member of timebase::dateorder.
552 do_date_order() const;
555 * @brief Parse input time string.
557 * This function parses a time according to the format @a x and puts the
558 * results into a user-supplied struct tm. This function is a hook for
559 * derived classes to change the value returned. @see get_time() for
562 * @param beg Start of string to parse.
563 * @param end End of string to parse.
564 * @param io Source of the locale.
565 * @param err Error flags to set.
566 * @param tm Pointer to struct tm to fill in.
567 * @return Iterator to first char beyond time string.
570 do_get_time(iter_type __beg
, iter_type __end
, ios_base
& __io
,
571 ios_base::iostate
& __err
, tm
* __tm
) const;
574 * @brief Parse input date string.
576 * This function parses a date according to the format @a X and puts the
577 * results into a user-supplied struct tm. This function is a hook for
578 * derived classes to change the value returned. @see get_date() for
581 * @param beg Start of string to parse.
582 * @param end End of string to parse.
583 * @param io Source of the locale.
584 * @param err Error flags to set.
585 * @param tm Pointer to struct tm to fill in.
586 * @return Iterator to first char beyond date string.
589 do_get_date(iter_type __beg
, iter_type __end
, ios_base
& __io
,
590 ios_base::iostate
& __err
, tm
* __tm
) const;
593 * @brief Parse input weekday string.
595 * This function parses a weekday name and puts the results into a
596 * user-supplied struct tm. This function is a hook for derived
597 * classes to change the value returned. @see get_weekday() for
600 * @param beg Start of string to parse.
601 * @param end End of string to parse.
602 * @param io Source of the locale.
603 * @param err Error flags to set.
604 * @param tm Pointer to struct tm to fill in.
605 * @return Iterator to first char beyond weekday name.
608 do_get_weekday(iter_type __beg
, iter_type __end
, ios_base
&,
609 ios_base::iostate
& __err
, tm
* __tm
) const;
612 * @brief Parse input month string.
614 * This function parses a month name and puts the results into a
615 * user-supplied struct tm. This function is a hook for derived
616 * classes to change the value returned. @see get_monthname() for
619 * @param beg Start of string to parse.
620 * @param end End of string to parse.
621 * @param io Source of the locale.
622 * @param err Error flags to set.
623 * @param tm Pointer to struct tm to fill in.
624 * @return Iterator to first char beyond month name.
627 do_get_monthname(iter_type __beg
, iter_type __end
, ios_base
&,
628 ios_base::iostate
& __err
, tm
* __tm
) const;
631 * @brief Parse input year string.
633 * This function reads up to 4 characters to parse a year string and
634 * puts the results into a user-supplied struct tm. This function is a
635 * hook for derived classes to change the value returned. @see
636 * get_year() for details.
638 * @param beg Start of string to parse.
639 * @param end End of string to parse.
640 * @param io Source of the locale.
641 * @param err Error flags to set.
642 * @param tm Pointer to struct tm to fill in.
643 * @return Iterator to first char beyond year.
646 do_get_year(iter_type __beg
, iter_type __end
, ios_base
& __io
,
647 ios_base::iostate
& __err
, tm
* __tm
) const;
649 // Extract numeric component of length __len.
651 _M_extract_num(iter_type __beg
, iter_type __end
, int& __member
,
652 int __min
, int __max
, size_t __len
,
653 ios_base
& __io
, ios_base::iostate
& __err
) const;
655 // Extract any unique array of string literals in a const _CharT* array.
657 _M_extract_name(iter_type __beg
, iter_type __end
, int& __member
,
658 const _CharT
** __names
, size_t __indexlen
,
659 ios_base
& __io
, ios_base::iostate
& __err
) const;
661 // Extract day or month name in a const _CharT* array.
663 _M_extract_wday_or_month(iter_type __beg
, iter_type __end
, int& __member
,
664 const _CharT
** __names
, size_t __indexlen
,
665 ios_base
& __io
, ios_base::iostate
& __err
) const;
667 // Extract on a component-by-component basis, via __format argument.
669 _M_extract_via_format(iter_type __beg
, iter_type __end
, ios_base
& __io
,
670 ios_base::iostate
& __err
, tm
* __tm
,
671 const _CharT
* __format
) const;
674 template<typename _CharT
, typename _InIter
>
675 locale::id time_get
<_CharT
, _InIter
>::id
;
677 /// class time_get_byname [22.2.5.2].
678 template<typename _CharT
, typename _InIter
>
679 class time_get_byname
: public time_get
<_CharT
, _InIter
>
683 typedef _CharT char_type
;
684 typedef _InIter iter_type
;
687 time_get_byname(const char*, size_t __refs
= 0)
688 : time_get
<_CharT
, _InIter
>(__refs
) { }
692 ~time_get_byname() { }
696 * @brief Facet for outputting dates and times.
698 * This facet encapsulates the code to format and output dates and times
699 * according to formats used by strftime().
701 * The time_put template uses protected virtual functions to provide the
702 * actual results. The public accessors forward the call to the virtual
703 * functions. These virtual functions are hooks for developers to
704 * implement the behavior they require from the time_put facet.
706 template<typename _CharT
, typename _OutIter
>
707 class time_put
: public locale::facet
713 typedef _CharT char_type
;
714 typedef _OutIter iter_type
;
717 /// Numpunct facet id.
718 static locale::id id
;
721 * @brief Constructor performs initialization.
723 * This is the constructor provided by the standard.
725 * @param refs Passed to the base facet class.
728 time_put(size_t __refs
= 0)
732 * @brief Format and output a time or date.
734 * This function formats the data in struct tm according to the
735 * provided format string. The format string is interpreted as by
738 * @param s The stream to write to.
739 * @param io Source of locale.
740 * @param fill char_type to use for padding.
741 * @param tm Struct tm with date and time info to format.
742 * @param beg Start of format string.
743 * @param end End of format string.
744 * @return Iterator after writing.
747 put(iter_type __s
, ios_base
& __io
, char_type __fill
, const tm
* __tm
,
748 const _CharT
* __beg
, const _CharT
* __end
) const;
751 * @brief Format and output a time or date.
753 * This function formats the data in struct tm according to the
754 * provided format char and optional modifier. The format and modifier
755 * are interpreted as by strftime(). It does so by returning
756 * time_put::do_put().
758 * @param s The stream to write to.
759 * @param io Source of locale.
760 * @param fill char_type to use for padding.
761 * @param tm Struct tm with date and time info to format.
762 * @param format Format char.
763 * @param mod Optional modifier char.
764 * @return Iterator after writing.
767 put(iter_type __s
, ios_base
& __io
, char_type __fill
,
768 const tm
* __tm
, char __format
, char __mod
= 0) const
769 { return this->do_put(__s
, __io
, __fill
, __tm
, __format
, __mod
); }
778 * @brief Format and output a time or date.
780 * This function formats the data in struct tm according to the
781 * provided format char and optional modifier. This function is a hook
782 * for derived classes to change the value returned. @see put() for
785 * @param s The stream to write to.
786 * @param io Source of locale.
787 * @param fill char_type to use for padding.
788 * @param tm Struct tm with date and time info to format.
789 * @param format Format char.
790 * @param mod Optional modifier char.
791 * @return Iterator after writing.
794 do_put(iter_type __s
, ios_base
& __io
, char_type __fill
, const tm
* __tm
,
795 char __format
, char __mod
) const;
798 template<typename _CharT
, typename _OutIter
>
799 locale::id time_put
<_CharT
, _OutIter
>::id
;
801 /// class time_put_byname [22.2.5.4].
802 template<typename _CharT
, typename _OutIter
>
803 class time_put_byname
: public time_put
<_CharT
, _OutIter
>
807 typedef _CharT char_type
;
808 typedef _OutIter iter_type
;
811 time_put_byname(const char*, size_t __refs
= 0)
812 : time_put
<_CharT
, _OutIter
>(__refs
)
817 ~time_put_byname() { }
822 * @brief Money format ordering data.
824 * This class contains an ordered array of 4 fields to represent the
825 * pattern for formatting a money amount. Each field may contain one entry
826 * from the part enum. symbol, sign, and value must be present and the
827 * remaining field must contain either none or space. @see
828 * moneypunct::pos_format() and moneypunct::neg_format() for details of how
829 * these fields are interpreted.
834 enum part
{ none
, space
, symbol
, sign
, value
};
835 struct pattern
{ char field
[4]; };
837 static const pattern _S_default_pattern
;
846 // String literal of acceptable (narrow) input/output, for
847 // money_get/money_put. "-0123456789"
848 static const char* _S_atoms
;
850 // Construct and return valid pattern consisting of some combination of:
851 // space none symbol sign value
852 _GLIBCXX_CONST
static pattern
853 _S_construct_pattern(char __precedes
, char __space
, char __posn
) throw ();
856 template<typename _CharT
, bool _Intl
>
857 struct __moneypunct_cache
: public locale::facet
859 const char* _M_grouping
;
860 size_t _M_grouping_size
;
861 bool _M_use_grouping
;
862 _CharT _M_decimal_point
;
863 _CharT _M_thousands_sep
;
864 const _CharT
* _M_curr_symbol
;
865 size_t _M_curr_symbol_size
;
866 const _CharT
* _M_positive_sign
;
867 size_t _M_positive_sign_size
;
868 const _CharT
* _M_negative_sign
;
869 size_t _M_negative_sign_size
;
871 money_base::pattern _M_pos_format
;
872 money_base::pattern _M_neg_format
;
874 // A list of valid numeric literals for input and output: in the standard
875 // "C" locale, this is "-0123456789". This array contains the chars after
876 // having been passed through the current locale's ctype<_CharT>.widen().
877 _CharT _M_atoms
[money_base::_S_end
];
881 __moneypunct_cache(size_t __refs
= 0) : facet(__refs
),
882 _M_grouping(NULL
), _M_grouping_size(0), _M_use_grouping(false),
883 _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()),
884 _M_curr_symbol(NULL
), _M_curr_symbol_size(0),
885 _M_positive_sign(NULL
), _M_positive_sign_size(0),
886 _M_negative_sign(NULL
), _M_negative_sign_size(0),
888 _M_pos_format(money_base::pattern()),
889 _M_neg_format(money_base::pattern()), _M_allocated(false)
892 ~__moneypunct_cache();
895 _M_cache(const locale
& __loc
);
899 operator=(const __moneypunct_cache
&);
902 __moneypunct_cache(const __moneypunct_cache
&);
905 template<typename _CharT
, bool _Intl
>
906 __moneypunct_cache
<_CharT
, _Intl
>::~__moneypunct_cache()
910 delete [] _M_grouping
;
911 delete [] _M_curr_symbol
;
912 delete [] _M_positive_sign
;
913 delete [] _M_negative_sign
;
918 * @brief Facet for formatting data for money amounts.
920 * This facet encapsulates the punctuation, grouping and other formatting
921 * features of money amount string representations.
923 template<typename _CharT
, bool _Intl
>
924 class moneypunct
: public locale::facet
, public money_base
930 typedef _CharT char_type
;
931 typedef basic_string
<_CharT
> string_type
;
933 typedef __moneypunct_cache
<_CharT
, _Intl
> __cache_type
;
936 __cache_type
* _M_data
;
939 /// This value is provided by the standard, but no reason for its
941 static const bool intl
= _Intl
;
942 /// Numpunct facet id.
943 static locale::id id
;
946 * @brief Constructor performs initialization.
948 * This is the constructor provided by the standard.
950 * @param refs Passed to the base facet class.
953 moneypunct(size_t __refs
= 0) : facet(__refs
), _M_data(NULL
)
954 { _M_initialize_moneypunct(); }
957 * @brief Constructor performs initialization.
959 * This is an internal constructor.
961 * @param cache Cache for optimization.
962 * @param refs Passed to the base facet class.
965 moneypunct(__cache_type
* __cache
, size_t __refs
= 0)
966 : facet(__refs
), _M_data(__cache
)
967 { _M_initialize_moneypunct(); }
970 * @brief Internal constructor. Not for general use.
972 * This is a constructor for use by the library itself to set up new
975 * @param cloc The C locale.
976 * @param s The name of a locale.
977 * @param refs Passed to the base facet class.
980 moneypunct(__c_locale __cloc
, const char* __s
, size_t __refs
= 0)
981 : facet(__refs
), _M_data(NULL
)
982 { _M_initialize_moneypunct(__cloc
, __s
); }
985 * @brief Return decimal point character.
987 * This function returns a char_type to use as a decimal point. It
988 * does so by returning returning
989 * moneypunct<char_type>::do_decimal_point().
991 * @return @a char_type representing a decimal point.
994 decimal_point() const
995 { return this->do_decimal_point(); }
998 * @brief Return thousands separator character.
1000 * This function returns a char_type to use as a thousands
1001 * separator. It does so by returning returning
1002 * moneypunct<char_type>::do_thousands_sep().
1004 * @return char_type representing a thousands separator.
1007 thousands_sep() const
1008 { return this->do_thousands_sep(); }
1011 * @brief Return grouping specification.
1013 * This function returns a string representing groupings for the
1014 * integer part of an amount. Groupings indicate where thousands
1015 * separators should be inserted.
1017 * Each char in the return string is interpret as an integer rather
1018 * than a character. These numbers represent the number of digits in a
1019 * group. The first char in the string represents the number of digits
1020 * in the least significant group. If a char is negative, it indicates
1021 * an unlimited number of digits for the group. If more chars from the
1022 * string are required to group a number, the last char is used
1025 * For example, if the grouping() returns <code>\003\002</code>
1026 * and is applied to the number 123456789, this corresponds to
1027 * 12,34,56,789. Note that if the string was <code>32</code>, this would
1028 * put more than 50 digits into the least significant group if
1029 * the character set is ASCII.
1031 * The string is returned by calling
1032 * moneypunct<char_type>::do_grouping().
1034 * @return string representing grouping specification.
1038 { return this->do_grouping(); }
1041 * @brief Return currency symbol string.
1043 * This function returns a string_type to use as a currency symbol. It
1044 * does so by returning returning
1045 * moneypunct<char_type>::do_curr_symbol().
1047 * @return @a string_type representing a currency symbol.
1051 { return this->do_curr_symbol(); }
1054 * @brief Return positive sign string.
1056 * This function returns a string_type to use as a sign for positive
1057 * amounts. It does so by returning returning
1058 * moneypunct<char_type>::do_positive_sign().
1060 * If the return value contains more than one character, the first
1061 * character appears in the position indicated by pos_format() and the
1062 * remainder appear at the end of the formatted string.
1064 * @return @a string_type representing a positive sign.
1067 positive_sign() const
1068 { return this->do_positive_sign(); }
1071 * @brief Return negative sign string.
1073 * This function returns a string_type to use as a sign for negative
1074 * amounts. It does so by returning returning
1075 * moneypunct<char_type>::do_negative_sign().
1077 * If the return value contains more than one character, the first
1078 * character appears in the position indicated by neg_format() and the
1079 * remainder appear at the end of the formatted string.
1081 * @return @a string_type representing a negative sign.
1084 negative_sign() const
1085 { return this->do_negative_sign(); }
1088 * @brief Return number of digits in fraction.
1090 * This function returns the exact number of digits that make up the
1091 * fractional part of a money amount. It does so by returning
1092 * returning moneypunct<char_type>::do_frac_digits().
1094 * The fractional part of a money amount is optional. But if it is
1095 * present, there must be frac_digits() digits.
1097 * @return Number of digits in amount fraction.
1101 { return this->do_frac_digits(); }
1105 * @brief Return pattern for money values.
1107 * This function returns a pattern describing the formatting of a
1108 * positive or negative valued money amount. It does so by returning
1109 * returning moneypunct<char_type>::do_pos_format() or
1110 * moneypunct<char_type>::do_neg_format().
1112 * The pattern has 4 fields describing the ordering of symbol, sign,
1113 * value, and none or space. There must be one of each in the pattern.
1114 * The none and space enums may not appear in the first field and space
1115 * may not appear in the final field.
1117 * The parts of a money string must appear in the order indicated by
1118 * the fields of the pattern. The symbol field indicates that the
1119 * value of curr_symbol() may be present. The sign field indicates
1120 * that the value of positive_sign() or negative_sign() must be
1121 * present. The value field indicates that the absolute value of the
1122 * money amount is present. none indicates 0 or more whitespace
1123 * characters, except at the end, where it permits no whitespace.
1124 * space indicates that 1 or more whitespace characters must be
1127 * For example, for the US locale and pos_format() pattern
1128 * {symbol,sign,value,none}, curr_symbol() == '$'
1129 * positive_sign() == '+', and value 10.01, and
1130 * options set to force the symbol, the corresponding string is
1131 * <code>$+10.01</code>.
1133 * @return Pattern for money values.
1137 { return this->do_pos_format(); }
1141 { return this->do_neg_format(); }
1150 * @brief Return decimal point character.
1152 * Returns a char_type to use as a decimal point. This function is a
1153 * hook for derived classes to change the value returned.
1155 * @return @a char_type representing a decimal point.
1158 do_decimal_point() const
1159 { return _M_data
->_M_decimal_point
; }
1162 * @brief Return thousands separator character.
1164 * Returns a char_type to use as a thousands separator. This function
1165 * is a hook for derived classes to change the value returned.
1167 * @return @a char_type representing a thousands separator.
1170 do_thousands_sep() const
1171 { return _M_data
->_M_thousands_sep
; }
1174 * @brief Return grouping specification.
1176 * Returns a string representing groupings for the integer part of a
1177 * number. This function is a hook for derived classes to change the
1178 * value returned. @see grouping() for details.
1180 * @return String representing grouping specification.
1184 { return _M_data
->_M_grouping
; }
1187 * @brief Return currency symbol string.
1189 * This function returns a string_type to use as a currency symbol.
1190 * This function is a hook for derived classes to change the value
1191 * returned. @see curr_symbol() for details.
1193 * @return @a string_type representing a currency symbol.
1196 do_curr_symbol() const
1197 { return _M_data
->_M_curr_symbol
; }
1200 * @brief Return positive sign string.
1202 * This function returns a string_type to use as a sign for positive
1203 * amounts. This function is a hook for derived classes to change the
1204 * value returned. @see positive_sign() for details.
1206 * @return @a string_type representing a positive sign.
1209 do_positive_sign() const
1210 { return _M_data
->_M_positive_sign
; }
1213 * @brief Return negative sign string.
1215 * This function returns a string_type to use as a sign for negative
1216 * amounts. This function is a hook for derived classes to change the
1217 * value returned. @see negative_sign() for details.
1219 * @return @a string_type representing a negative sign.
1222 do_negative_sign() const
1223 { return _M_data
->_M_negative_sign
; }
1226 * @brief Return number of digits in fraction.
1228 * This function returns the exact number of digits that make up the
1229 * fractional part of a money amount. This function is a hook for
1230 * derived classes to change the value returned. @see frac_digits()
1233 * @return Number of digits in amount fraction.
1236 do_frac_digits() const
1237 { return _M_data
->_M_frac_digits
; }
1240 * @brief Return pattern for money values.
1242 * This function returns a pattern describing the formatting of a
1243 * positive valued money amount. This function is a hook for derived
1244 * classes to change the value returned. @see pos_format() for
1247 * @return Pattern for money values.
1250 do_pos_format() const
1251 { return _M_data
->_M_pos_format
; }
1254 * @brief Return pattern for money values.
1256 * This function returns a pattern describing the formatting of a
1257 * negative valued money amount. This function is a hook for derived
1258 * classes to change the value returned. @see neg_format() for
1261 * @return Pattern for money values.
1264 do_neg_format() const
1265 { return _M_data
->_M_neg_format
; }
1267 // For use at construction time only.
1269 _M_initialize_moneypunct(__c_locale __cloc
= NULL
,
1270 const char* __name
= NULL
);
1273 template<typename _CharT
, bool _Intl
>
1274 locale::id moneypunct
<_CharT
, _Intl
>::id
;
1276 template<typename _CharT
, bool _Intl
>
1277 const bool moneypunct
<_CharT
, _Intl
>::intl
;
1280 moneypunct
<char, true>::~moneypunct();
1283 moneypunct
<char, false>::~moneypunct();
1287 moneypunct
<char, true>::_M_initialize_moneypunct(__c_locale
, const char*);
1291 moneypunct
<char, false>::_M_initialize_moneypunct(__c_locale
, const char*);
1293 #ifdef _GLIBCXX_USE_WCHAR_T
1295 moneypunct
<wchar_t, true>::~moneypunct();
1298 moneypunct
<wchar_t, false>::~moneypunct();
1302 moneypunct
<wchar_t, true>::_M_initialize_moneypunct(__c_locale
,
1307 moneypunct
<wchar_t, false>::_M_initialize_moneypunct(__c_locale
,
1311 /// class moneypunct_byname [22.2.6.4].
1312 template<typename _CharT
, bool _Intl
>
1313 class moneypunct_byname
: public moneypunct
<_CharT
, _Intl
>
1316 typedef _CharT char_type
;
1317 typedef basic_string
<_CharT
> string_type
;
1319 static const bool intl
= _Intl
;
1322 moneypunct_byname(const char* __s
, size_t __refs
= 0)
1323 : moneypunct
<_CharT
, _Intl
>(__refs
)
1325 if (__builtin_strcmp(__s
, "C") != 0
1326 && __builtin_strcmp(__s
, "POSIX") != 0)
1329 this->_S_create_c_locale(__tmp
, __s
);
1330 this->_M_initialize_moneypunct(__tmp
);
1331 this->_S_destroy_c_locale(__tmp
);
1337 ~moneypunct_byname() { }
1340 template<typename _CharT
, bool _Intl
>
1341 const bool moneypunct_byname
<_CharT
, _Intl
>::intl
;
1343 _GLIBCXX_BEGIN_LDBL_NAMESPACE
1346 * @brief Facet for parsing monetary amounts.
1348 * This facet encapsulates the code to parse and return a monetary
1349 * amount from a string.
1351 * The money_get template uses protected virtual functions to
1352 * provide the actual results. The public accessors forward the
1353 * call to the virtual functions. These virtual functions are
1354 * hooks for developers to implement the behavior they require from
1355 * the money_get facet.
1357 template<typename _CharT
, typename _InIter
>
1358 class money_get
: public locale::facet
1364 typedef _CharT char_type
;
1365 typedef _InIter iter_type
;
1366 typedef basic_string
<_CharT
> string_type
;
1369 /// Numpunct facet id.
1370 static locale::id id
;
1373 * @brief Constructor performs initialization.
1375 * This is the constructor provided by the standard.
1377 * @param refs Passed to the base facet class.
1380 money_get(size_t __refs
= 0) : facet(__refs
) { }
1383 * @brief Read and parse a monetary value.
1385 * This function reads characters from @a s, interprets them as a
1386 * monetary value according to moneypunct and ctype facets retrieved
1387 * from io.getloc(), and returns the result in @a units as an integral
1388 * value moneypunct::frac_digits() * the actual amount. For example,
1389 * the string $10.01 in a US locale would store 1001 in @a units.
1391 * Any characters not part of a valid money amount are not consumed.
1393 * If a money value cannot be parsed from the input stream, sets
1394 * err=(err|io.failbit). If the stream is consumed before finishing
1395 * parsing, sets err=(err|io.failbit|io.eofbit). @a units is
1396 * unchanged if parsing fails.
1398 * This function works by returning the result of do_get().
1400 * @param s Start of characters to parse.
1401 * @param end End of characters to parse.
1402 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
1403 * @param io Source of facets and io state.
1404 * @param err Error field to set if parsing fails.
1405 * @param units Place to store result of parsing.
1406 * @return Iterator referencing first character beyond valid money
1410 get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
1411 ios_base::iostate
& __err
, long double& __units
) const
1412 { return this->do_get(__s
, __end
, __intl
, __io
, __err
, __units
); }
1415 * @brief Read and parse a monetary value.
1417 * This function reads characters from @a s, interprets them as
1418 * a monetary value according to moneypunct and ctype facets
1419 * retrieved from io.getloc(), and returns the result in @a
1420 * digits. For example, the string $10.01 in a US locale would
1421 * store <code>1001</code> in @a digits.
1423 * Any characters not part of a valid money amount are not consumed.
1425 * If a money value cannot be parsed from the input stream, sets
1426 * err=(err|io.failbit). If the stream is consumed before finishing
1427 * parsing, sets err=(err|io.failbit|io.eofbit).
1429 * This function works by returning the result of do_get().
1431 * @param s Start of characters to parse.
1432 * @param end End of characters to parse.
1433 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
1434 * @param io Source of facets and io state.
1435 * @param err Error field to set if parsing fails.
1436 * @param digits Place to store result of parsing.
1437 * @return Iterator referencing first character beyond valid money
1441 get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
1442 ios_base::iostate
& __err
, string_type
& __digits
) const
1443 { return this->do_get(__s
, __end
, __intl
, __io
, __err
, __digits
); }
1451 * @brief Read and parse a monetary value.
1453 * This function reads and parses characters representing a monetary
1454 * value. This function is a hook for derived classes to change the
1455 * value returned. @see get() for details.
1457 // XXX GLIBCXX_ABI Deprecated
1458 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1460 __do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
1461 ios_base::iostate
& __err
, double& __units
) const;
1464 do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
1465 ios_base::iostate
& __err
, long double& __units
) const;
1469 * @brief Read and parse a monetary value.
1471 * This function reads and parses characters representing a monetary
1472 * value. This function is a hook for derived classes to change the
1473 * value returned. @see get() for details.
1476 do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
1477 ios_base::iostate
& __err
, string_type
& __digits
) const;
1479 // XXX GLIBCXX_ABI Deprecated
1480 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1482 do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
1483 ios_base::iostate
& __err
, long double& __units
) const;
1486 template<bool _Intl
>
1488 _M_extract(iter_type __s
, iter_type __end
, ios_base
& __io
,
1489 ios_base::iostate
& __err
, string
& __digits
) const;
1492 template<typename _CharT
, typename _InIter
>
1493 locale::id money_get
<_CharT
, _InIter
>::id
;
1496 * @brief Facet for outputting monetary amounts.
1498 * This facet encapsulates the code to format and output a monetary
1501 * The money_put template uses protected virtual functions to
1502 * provide the actual results. The public accessors forward the
1503 * call to the virtual functions. These virtual functions are
1504 * hooks for developers to implement the behavior they require from
1505 * the money_put facet.
1507 template<typename _CharT
, typename _OutIter
>
1508 class money_put
: public locale::facet
1513 typedef _CharT char_type
;
1514 typedef _OutIter iter_type
;
1515 typedef basic_string
<_CharT
> string_type
;
1518 /// Numpunct facet id.
1519 static locale::id id
;
1522 * @brief Constructor performs initialization.
1524 * This is the constructor provided by the standard.
1526 * @param refs Passed to the base facet class.
1529 money_put(size_t __refs
= 0) : facet(__refs
) { }
1532 * @brief Format and output a monetary value.
1534 * This function formats @a units as a monetary value according to
1535 * moneypunct and ctype facets retrieved from io.getloc(), and writes
1536 * the resulting characters to @a s. For example, the value 1001 in a
1537 * US locale would write <code>$10.01</code> to @a s.
1539 * This function works by returning the result of do_put().
1541 * @param s The stream to write to.
1542 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
1543 * @param io Source of facets and io state.
1544 * @param fill char_type to use for padding.
1545 * @param units Place to store result of parsing.
1546 * @return Iterator after writing.
1549 put(iter_type __s
, bool __intl
, ios_base
& __io
,
1550 char_type __fill
, long double __units
) const
1551 { return this->do_put(__s
, __intl
, __io
, __fill
, __units
); }
1554 * @brief Format and output a monetary value.
1556 * This function formats @a digits as a monetary value
1557 * according to moneypunct and ctype facets retrieved from
1558 * io.getloc(), and writes the resulting characters to @a s.
1559 * For example, the string <code>1001</code> in a US locale
1560 * would write <code>$10.01</code> to @a s.
1562 * This function works by returning the result of do_put().
1564 * @param s The stream to write to.
1565 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
1566 * @param io Source of facets and io state.
1567 * @param fill char_type to use for padding.
1568 * @param units Place to store result of parsing.
1569 * @return Iterator after writing.
1572 put(iter_type __s
, bool __intl
, ios_base
& __io
,
1573 char_type __fill
, const string_type
& __digits
) const
1574 { return this->do_put(__s
, __intl
, __io
, __fill
, __digits
); }
1582 * @brief Format and output a monetary value.
1584 * This function formats @a units as a monetary value according to
1585 * moneypunct and ctype facets retrieved from io.getloc(), and writes
1586 * the resulting characters to @a s. For example, the value 1001 in a
1587 * US locale would write <code>$10.01</code> to @a s.
1589 * This function is a hook for derived classes to change the value
1590 * returned. @see put().
1592 * @param s The stream to write to.
1593 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
1594 * @param io Source of facets and io state.
1595 * @param fill char_type to use for padding.
1596 * @param units Place to store result of parsing.
1597 * @return Iterator after writing.
1599 // XXX GLIBCXX_ABI Deprecated
1600 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1602 __do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
1603 double __units
) const;
1606 do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
1607 long double __units
) const;
1611 * @brief Format and output a monetary value.
1613 * This function formats @a digits as a monetary value
1614 * according to moneypunct and ctype facets retrieved from
1615 * io.getloc(), and writes the resulting characters to @a s.
1616 * For example, the string <code>1001</code> in a US locale
1617 * would write <code>$10.01</code> to @a s.
1619 * This function is a hook for derived classes to change the value
1620 * returned. @see put().
1622 * @param s The stream to write to.
1623 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
1624 * @param io Source of facets and io state.
1625 * @param fill char_type to use for padding.
1626 * @param units Place to store result of parsing.
1627 * @return Iterator after writing.
1630 do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
1631 const string_type
& __digits
) const;
1633 // XXX GLIBCXX_ABI Deprecated
1634 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1636 do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
1637 long double __units
) const;
1640 template<bool _Intl
>
1642 _M_insert(iter_type __s
, ios_base
& __io
, char_type __fill
,
1643 const string_type
& __digits
) const;
1646 template<typename _CharT
, typename _OutIter
>
1647 locale::id money_put
<_CharT
, _OutIter
>::id
;
1649 _GLIBCXX_END_LDBL_NAMESPACE
1652 * @brief Messages facet base class providing catalog typedef.
1654 struct messages_base
1656 typedef int catalog
;
1660 * @brief Facet for handling message catalogs
1662 * This facet encapsulates the code to retrieve messages from
1663 * message catalogs. The only thing defined by the standard for this facet
1664 * is the interface. All underlying functionality is
1665 * implementation-defined.
1667 * This library currently implements 3 versions of the message facet. The
1668 * first version (gnu) is a wrapper around gettext, provided by libintl.
1669 * The second version (ieee) is a wrapper around catgets. The final
1670 * version (default) does no actual translation. These implementations are
1671 * only provided for char and wchar_t instantiations.
1673 * The messages template uses protected virtual functions to
1674 * provide the actual results. The public accessors forward the
1675 * call to the virtual functions. These virtual functions are
1676 * hooks for developers to implement the behavior they require from
1677 * the messages facet.
1679 template<typename _CharT
>
1680 class messages
: public locale::facet
, public messages_base
1686 typedef _CharT char_type
;
1687 typedef basic_string
<_CharT
> string_type
;
1691 // Underlying "C" library locale information saved from
1692 // initialization, needed by messages_byname as well.
1693 __c_locale _M_c_locale_messages
;
1694 const char* _M_name_messages
;
1697 /// Numpunct facet id.
1698 static locale::id id
;
1701 * @brief Constructor performs initialization.
1703 * This is the constructor provided by the standard.
1705 * @param refs Passed to the base facet class.
1708 messages(size_t __refs
= 0);
1712 * @brief Internal constructor. Not for general use.
1714 * This is a constructor for use by the library itself to set up new
1717 * @param cloc The C locale.
1718 * @param s The name of a locale.
1719 * @param refs Refcount to pass to the base class.
1722 messages(__c_locale __cloc
, const char* __s
, size_t __refs
= 0);
1725 * @brief Open a message catalog.
1727 * This function opens and returns a handle to a message catalog by
1728 * returning do_open(s, loc).
1730 * @param s The catalog to open.
1731 * @param loc Locale to use for character set conversions.
1732 * @return Handle to the catalog or value < 0 if open fails.
1735 open(const basic_string
<char>& __s
, const locale
& __loc
) const
1736 { return this->do_open(__s
, __loc
); }
1738 // Non-standard and unorthodox, yet effective.
1740 * @brief Open a message catalog.
1742 * This non-standard function opens and returns a handle to a message
1743 * catalog by returning do_open(s, loc). The third argument provides a
1744 * message catalog root directory for gnu gettext and is ignored
1747 * @param s The catalog to open.
1748 * @param loc Locale to use for character set conversions.
1749 * @param dir Message catalog root directory.
1750 * @return Handle to the catalog or value < 0 if open fails.
1753 open(const basic_string
<char>&, const locale
&, const char*) const;
1756 * @brief Look up a string in a message catalog.
1758 * This function retrieves and returns a message from a catalog by
1759 * returning do_get(c, set, msgid, s).
1761 * For gnu, @a set and @a msgid are ignored. Returns gettext(s).
1762 * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
1764 * @param c The catalog to access.
1765 * @param set Implementation-defined.
1766 * @param msgid Implementation-defined.
1767 * @param s Default return value if retrieval fails.
1768 * @return Retrieved message or @a s if get fails.
1771 get(catalog __c
, int __set
, int __msgid
, const string_type
& __s
) const
1772 { return this->do_get(__c
, __set
, __msgid
, __s
); }
1775 * @brief Close a message catalog.
1777 * Closes catalog @a c by calling do_close(c).
1779 * @param c The catalog to close.
1782 close(catalog __c
) const
1783 { return this->do_close(__c
); }
1791 * @brief Open a message catalog.
1793 * This function opens and returns a handle to a message catalog in an
1794 * implementation-defined manner. This function is a hook for derived
1795 * classes to change the value returned.
1797 * @param s The catalog to open.
1798 * @param loc Locale to use for character set conversions.
1799 * @return Handle to the opened catalog, value < 0 if open failed.
1802 do_open(const basic_string
<char>&, const locale
&) const;
1805 * @brief Look up a string in a message catalog.
1807 * This function retrieves and returns a message from a catalog in an
1808 * implementation-defined manner. This function is a hook for derived
1809 * classes to change the value returned.
1811 * For gnu, @a set and @a msgid are ignored. Returns gettext(s).
1812 * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
1814 * @param c The catalog to access.
1815 * @param set Implementation-defined.
1816 * @param msgid Implementation-defined.
1817 * @param s Default return value if retrieval fails.
1818 * @return Retrieved message or @a s if get fails.
1821 do_get(catalog
, int, int, const string_type
& __dfault
) const;
1824 * @brief Close a message catalog.
1826 * @param c The catalog to close.
1829 do_close(catalog
) const;
1831 // Returns a locale and codeset-converted string, given a char* message.
1833 _M_convert_to_char(const string_type
& __msg
) const
1836 return reinterpret_cast<char*>(const_cast<_CharT
*>(__msg
.c_str()));
1839 // Returns a locale and codeset-converted string, given a char* message.
1841 _M_convert_from_char(char*) const
1844 // Length of message string without terminating null.
1845 size_t __len
= char_traits
<char>::length(__msg
) - 1;
1847 // "everybody can easily convert the string using
1848 // mbsrtowcs/wcsrtombs or with iconv()"
1850 // Convert char* to _CharT in locale used to open catalog.
1851 // XXX need additional template parameter on messages class for this..
1852 // typedef typename codecvt<char, _CharT, _StateT> __codecvt_type;
1853 typedef typename codecvt
<char, _CharT
, mbstate_t> __codecvt_type
;
1855 __codecvt_type::state_type __state
;
1856 // XXX may need to initialize state.
1857 //initialize_state(__state._M_init());
1860 // XXX what size for this string?
1861 _CharT
* __to
= static_cast<_CharT
*>(__builtin_alloca(__len
+ 1));
1862 const __codecvt_type
& __cvt
= use_facet
<__codecvt_type
>(_M_locale_conv
);
1863 __cvt
.out(__state
, __msg
, __msg
+ __len
, __from_next
,
1864 __to
, __to
+ __len
+ 1, __to_next
);
1865 return string_type(__to
);
1868 typedef ctype
<_CharT
> __ctype_type
;
1869 // const __ctype_type& __cvt = use_facet<__ctype_type>(_M_locale_msg);
1870 const __ctype_type
& __cvt
= use_facet
<__ctype_type
>(locale());
1871 // XXX Again, proper length of converted string an issue here.
1872 // For now, assume the converted length is not larger.
1873 _CharT
* __dest
= static_cast<_CharT
*>(__builtin_alloca(__len
+ 1));
1874 __cvt
.widen(__msg
, __msg
+ __len
, __dest
);
1875 return basic_string
<_CharT
>(__dest
);
1877 return string_type();
1881 template<typename _CharT
>
1882 locale::id messages
<_CharT
>::id
;
1884 // Specializations for required instantiations.
1887 messages
<char>::do_get(catalog
, int, int, const string
&) const;
1889 #ifdef _GLIBCXX_USE_WCHAR_T
1892 messages
<wchar_t>::do_get(catalog
, int, int, const wstring
&) const;
1895 /// class messages_byname [22.2.7.2].
1896 template<typename _CharT
>
1897 class messages_byname
: public messages
<_CharT
>
1900 typedef _CharT char_type
;
1901 typedef basic_string
<_CharT
> string_type
;
1904 messages_byname(const char* __s
, size_t __refs
= 0);
1912 _GLIBCXX_END_NAMESPACE
1914 // Include host and configuration specific messages functions.
1915 #include <bits/messages_members.h>
1917 // 22.2.1.5 Template class codecvt
1918 #include <bits/codecvt.h>
1920 #ifndef _GLIBCXX_EXPORT_TEMPLATE
1921 # include <bits/locale_facets_nonio.tcc>