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 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 _GLIBCXX_BEGIN_NAMESPACE(std
)
44 * @brief Time format ordering data.
47 * This class provides an enum representing different orderings of
48 * time: day, month, and year.
53 enum dateorder
{ no_order
, dmy
, mdy
, ymd
, ydm
};
56 template<typename _CharT
>
57 struct __timepunct_cache
: public locale::facet
59 // List of all known timezones, with GMT first.
60 static const _CharT
* _S_timezones
[14];
62 const _CharT
* _M_date_format
;
63 const _CharT
* _M_date_era_format
;
64 const _CharT
* _M_time_format
;
65 const _CharT
* _M_time_era_format
;
66 const _CharT
* _M_date_time_format
;
67 const _CharT
* _M_date_time_era_format
;
70 const _CharT
* _M_am_pm_format
;
72 // Day names, starting with "C"'s Sunday.
73 const _CharT
* _M_day1
;
74 const _CharT
* _M_day2
;
75 const _CharT
* _M_day3
;
76 const _CharT
* _M_day4
;
77 const _CharT
* _M_day5
;
78 const _CharT
* _M_day6
;
79 const _CharT
* _M_day7
;
81 // Abbreviated day names, starting with "C"'s Sun.
82 const _CharT
* _M_aday1
;
83 const _CharT
* _M_aday2
;
84 const _CharT
* _M_aday3
;
85 const _CharT
* _M_aday4
;
86 const _CharT
* _M_aday5
;
87 const _CharT
* _M_aday6
;
88 const _CharT
* _M_aday7
;
90 // Month names, starting with "C"'s January.
91 const _CharT
* _M_month01
;
92 const _CharT
* _M_month02
;
93 const _CharT
* _M_month03
;
94 const _CharT
* _M_month04
;
95 const _CharT
* _M_month05
;
96 const _CharT
* _M_month06
;
97 const _CharT
* _M_month07
;
98 const _CharT
* _M_month08
;
99 const _CharT
* _M_month09
;
100 const _CharT
* _M_month10
;
101 const _CharT
* _M_month11
;
102 const _CharT
* _M_month12
;
104 // Abbreviated month names, starting with "C"'s Jan.
105 const _CharT
* _M_amonth01
;
106 const _CharT
* _M_amonth02
;
107 const _CharT
* _M_amonth03
;
108 const _CharT
* _M_amonth04
;
109 const _CharT
* _M_amonth05
;
110 const _CharT
* _M_amonth06
;
111 const _CharT
* _M_amonth07
;
112 const _CharT
* _M_amonth08
;
113 const _CharT
* _M_amonth09
;
114 const _CharT
* _M_amonth10
;
115 const _CharT
* _M_amonth11
;
116 const _CharT
* _M_amonth12
;
120 __timepunct_cache(size_t __refs
= 0) : facet(__refs
),
121 _M_date_format(0), _M_date_era_format(0), _M_time_format(0),
122 _M_time_era_format(0), _M_date_time_format(0),
123 _M_date_time_era_format(0), _M_am(0), _M_pm(0),
124 _M_am_pm_format(0), _M_day1(0), _M_day2(0), _M_day3(0),
125 _M_day4(0), _M_day5(0), _M_day6(0), _M_day7(0),
126 _M_aday1(0), _M_aday2(0), _M_aday3(0), _M_aday4(0),
127 _M_aday5(0), _M_aday6(0), _M_aday7(0), _M_month01(0),
128 _M_month02(0), _M_month03(0), _M_month04(0), _M_month05(0),
129 _M_month06(0), _M_month07(0), _M_month08(0), _M_month09(0),
130 _M_month10(0), _M_month11(0), _M_month12(0), _M_amonth01(0),
131 _M_amonth02(0), _M_amonth03(0), _M_amonth04(0),
132 _M_amonth05(0), _M_amonth06(0), _M_amonth07(0),
133 _M_amonth08(0), _M_amonth09(0), _M_amonth10(0),
134 _M_amonth11(0), _M_amonth12(0), _M_allocated(false)
137 ~__timepunct_cache();
140 _M_cache(const locale
& __loc
);
144 operator=(const __timepunct_cache
&);
147 __timepunct_cache(const __timepunct_cache
&);
150 template<typename _CharT
>
151 __timepunct_cache
<_CharT
>::~__timepunct_cache()
162 __timepunct_cache
<char>::_S_timezones
[14];
164 #ifdef _GLIBCXX_USE_WCHAR_T
167 __timepunct_cache
<wchar_t>::_S_timezones
[14];
171 template<typename _CharT
>
172 const _CharT
* __timepunct_cache
<_CharT
>::_S_timezones
[14];
174 template<typename _CharT
>
175 class __timepunct
: public locale::facet
179 typedef _CharT __char_type
;
180 typedef basic_string
<_CharT
> __string_type
;
181 typedef __timepunct_cache
<_CharT
> __cache_type
;
184 __cache_type
* _M_data
;
185 __c_locale _M_c_locale_timepunct
;
186 const char* _M_name_timepunct
;
189 /// Numpunct facet id.
190 static locale::id id
;
193 __timepunct(size_t __refs
= 0);
196 __timepunct(__cache_type
* __cache
, size_t __refs
= 0);
199 * @brief Internal constructor. Not for general use.
201 * This is a constructor for use by the library itself to set up new
204 * @param cloc The C locale.
205 * @param s The name of a locale.
206 * @param refs Passed to the base facet class.
209 __timepunct(__c_locale __cloc
, const char* __s
, size_t __refs
= 0);
211 // FIXME: for error checking purposes _M_put should return the return
212 // value of strftime/wcsftime.
214 _M_put(_CharT
* __s
, size_t __maxlen
, const _CharT
* __format
,
215 const tm
* __tm
) const throw ();
218 _M_date_formats(const _CharT
** __date
) const
220 // Always have default first.
221 __date
[0] = _M_data
->_M_date_format
;
222 __date
[1] = _M_data
->_M_date_era_format
;
226 _M_time_formats(const _CharT
** __time
) const
228 // Always have default first.
229 __time
[0] = _M_data
->_M_time_format
;
230 __time
[1] = _M_data
->_M_time_era_format
;
234 _M_date_time_formats(const _CharT
** __dt
) const
236 // Always have default first.
237 __dt
[0] = _M_data
->_M_date_time_format
;
238 __dt
[1] = _M_data
->_M_date_time_era_format
;
242 _M_am_pm_format(const _CharT
* __ampm
) const
243 { __ampm
= _M_data
->_M_am_pm_format
; }
246 _M_am_pm(const _CharT
** __ampm
) const
248 __ampm
[0] = _M_data
->_M_am
;
249 __ampm
[1] = _M_data
->_M_pm
;
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
;
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
;
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
;
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
;
314 // For use at construction time only.
316 _M_initialize_timepunct(__c_locale __cloc
= 0);
319 template<typename _CharT
>
320 locale::id __timepunct
<_CharT
>::id
;
325 __timepunct
<char>::_M_initialize_timepunct(__c_locale __cloc
);
329 __timepunct
<char>::_M_put(char*, size_t, const char*, const tm
*) const throw ();
331 #ifdef _GLIBCXX_USE_WCHAR_T
334 __timepunct
<wchar_t>::_M_initialize_timepunct(__c_locale __cloc
);
338 __timepunct
<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*,
339 const tm
*) const throw ();
342 _GLIBCXX_END_NAMESPACE
344 // Include host and configuration specific timepunct functions.
345 #include <bits/time_members.h>
347 _GLIBCXX_BEGIN_NAMESPACE(std
)
350 * @brief Primary class template time_get.
353 * This facet encapsulates the code to parse and return a date or
354 * time from a string. It is used by the istream numeric
355 * extraction operators.
357 * The time_get template uses protected virtual functions to provide the
358 * actual results. The public accessors forward the call to the virtual
359 * functions. These virtual functions are hooks for developers to
360 * implement the behavior they require from the time_get facet.
362 template<typename _CharT
, typename _InIter
>
363 class time_get
: public locale::facet
, public time_base
369 typedef _CharT char_type
;
370 typedef _InIter iter_type
;
372 typedef basic_string
<_CharT
> __string_type
;
374 /// Numpunct facet id.
375 static locale::id id
;
378 * @brief Constructor performs initialization.
380 * This is the constructor provided by the standard.
382 * @param refs Passed to the base facet class.
385 time_get(size_t __refs
= 0)
389 * @brief Return preferred order of month, day, and year.
391 * This function returns an enum from timebase::dateorder giving the
392 * preferred ordering if the format @a x given to time_put::put() only
393 * uses month, day, and year. If the format @a x for the associated
394 * locale uses other fields, this function returns
395 * timebase::dateorder::noorder.
397 * NOTE: The library always returns noorder at the moment.
399 * @return A member of timebase::dateorder.
403 { return this->do_date_order(); }
406 * @brief Parse input time string.
408 * This function parses a time according to the format @a X and puts the
409 * results into a user-supplied struct tm. The result is returned by
410 * calling time_get::do_get_time().
412 * If there is a valid time string according to format @a X, @a tm will
413 * be filled in accordingly and the returned iterator will point to the
414 * first character beyond the time string. If an error occurs before
415 * the end, err |= ios_base::failbit. If parsing reads all the
416 * characters, err |= ios_base::eofbit.
418 * @param beg Start of string to parse.
419 * @param end End of string to parse.
420 * @param io Source of the locale.
421 * @param err Error flags to set.
422 * @param tm Pointer to struct tm to fill in.
423 * @return Iterator to first char beyond time string.
426 get_time(iter_type __beg
, iter_type __end
, ios_base
& __io
,
427 ios_base::iostate
& __err
, tm
* __tm
) const
428 { return this->do_get_time(__beg
, __end
, __io
, __err
, __tm
); }
431 * @brief Parse input date string.
433 * This function parses a date according to the format @a x and puts the
434 * results into a user-supplied struct tm. The result is returned by
435 * calling time_get::do_get_date().
437 * If there is a valid date string according to format @a x, @a tm will
438 * be filled in accordingly and the returned iterator will point to the
439 * first character beyond the date string. If an error occurs before
440 * the end, err |= ios_base::failbit. If parsing reads all the
441 * characters, err |= ios_base::eofbit.
443 * @param beg Start of string to parse.
444 * @param end End of string to parse.
445 * @param io Source of the locale.
446 * @param err Error flags to set.
447 * @param tm Pointer to struct tm to fill in.
448 * @return Iterator to first char beyond date string.
451 get_date(iter_type __beg
, iter_type __end
, ios_base
& __io
,
452 ios_base::iostate
& __err
, tm
* __tm
) const
453 { return this->do_get_date(__beg
, __end
, __io
, __err
, __tm
); }
456 * @brief Parse input weekday string.
458 * This function parses a weekday name and puts the results into a
459 * user-supplied struct tm. The result is returned by calling
460 * time_get::do_get_weekday().
462 * Parsing starts by parsing an abbreviated weekday name. If a valid
463 * abbreviation is followed by a character that would lead to the full
464 * weekday name, parsing continues until the full name is found or an
465 * error occurs. Otherwise parsing finishes at the end of the
468 * If an error occurs before the end, err |= ios_base::failbit. If
469 * parsing reads all the characters, err |= ios_base::eofbit.
471 * @param beg Start of string to parse.
472 * @param end End of string to parse.
473 * @param io Source of the locale.
474 * @param err Error flags to set.
475 * @param tm Pointer to struct tm to fill in.
476 * @return Iterator to first char beyond weekday name.
479 get_weekday(iter_type __beg
, iter_type __end
, ios_base
& __io
,
480 ios_base::iostate
& __err
, tm
* __tm
) const
481 { return this->do_get_weekday(__beg
, __end
, __io
, __err
, __tm
); }
484 * @brief Parse input month string.
486 * This function parses a month name and puts the results into a
487 * user-supplied struct tm. The result is returned by calling
488 * time_get::do_get_monthname().
490 * Parsing starts by parsing an abbreviated month name. If a valid
491 * abbreviation is followed by a character that would lead to the full
492 * month name, parsing continues until the full name is found or an
493 * error occurs. Otherwise parsing finishes at the end of the
496 * If an error occurs before the end, err |= ios_base::failbit. If
497 * parsing reads all the characters, err |=
500 * @param beg Start of string to parse.
501 * @param end End of string to parse.
502 * @param io Source of the locale.
503 * @param err Error flags to set.
504 * @param tm Pointer to struct tm to fill in.
505 * @return Iterator to first char beyond month name.
508 get_monthname(iter_type __beg
, iter_type __end
, ios_base
& __io
,
509 ios_base::iostate
& __err
, tm
* __tm
) const
510 { return this->do_get_monthname(__beg
, __end
, __io
, __err
, __tm
); }
513 * @brief Parse input year string.
515 * This function reads up to 4 characters to parse a year string and
516 * puts the results into a user-supplied struct tm. The result is
517 * returned by calling time_get::do_get_year().
519 * 4 consecutive digits are interpreted as a full year. If there are
520 * exactly 2 consecutive digits, the library interprets this as the
521 * number of years since 1900.
523 * If an error occurs before the end, err |= ios_base::failbit. If
524 * parsing reads all the characters, err |= ios_base::eofbit.
526 * @param beg Start of string to parse.
527 * @param end End of string to parse.
528 * @param io Source of the locale.
529 * @param err Error flags to set.
530 * @param tm Pointer to struct tm to fill in.
531 * @return Iterator to first char beyond year.
534 get_year(iter_type __beg
, iter_type __end
, ios_base
& __io
,
535 ios_base::iostate
& __err
, tm
* __tm
) const
536 { return this->do_get_year(__beg
, __end
, __io
, __err
, __tm
); }
544 * @brief Return preferred order of month, day, and year.
546 * This function returns an enum from timebase::dateorder giving the
547 * preferred ordering if the format @a x given to time_put::put() only
548 * uses month, day, and year. This function is a hook for derived
549 * classes to change the value returned.
551 * @return A member of timebase::dateorder.
554 do_date_order() const;
557 * @brief Parse input time string.
559 * This function parses a time according to the format @a x and puts the
560 * results into a user-supplied struct tm. This function is a hook for
561 * derived classes to change the value returned. @see get_time() for
564 * @param beg Start of string to parse.
565 * @param end End of string to parse.
566 * @param io Source of the locale.
567 * @param err Error flags to set.
568 * @param tm Pointer to struct tm to fill in.
569 * @return Iterator to first char beyond time string.
572 do_get_time(iter_type __beg
, iter_type __end
, ios_base
& __io
,
573 ios_base::iostate
& __err
, tm
* __tm
) const;
576 * @brief Parse input date string.
578 * This function parses a date according to the format @a X and puts the
579 * results into a user-supplied struct tm. This function is a hook for
580 * derived classes to change the value returned. @see get_date() for
583 * @param beg Start of string to parse.
584 * @param end End of string to parse.
585 * @param io Source of the locale.
586 * @param err Error flags to set.
587 * @param tm Pointer to struct tm to fill in.
588 * @return Iterator to first char beyond date string.
591 do_get_date(iter_type __beg
, iter_type __end
, ios_base
& __io
,
592 ios_base::iostate
& __err
, tm
* __tm
) const;
595 * @brief Parse input weekday string.
597 * This function parses a weekday name and puts the results into a
598 * user-supplied struct tm. This function is a hook for derived
599 * classes to change the value returned. @see get_weekday() for
602 * @param beg Start of string to parse.
603 * @param end End of string to parse.
604 * @param io Source of the locale.
605 * @param err Error flags to set.
606 * @param tm Pointer to struct tm to fill in.
607 * @return Iterator to first char beyond weekday name.
610 do_get_weekday(iter_type __beg
, iter_type __end
, ios_base
&,
611 ios_base::iostate
& __err
, tm
* __tm
) const;
614 * @brief Parse input month string.
616 * This function parses a month name and puts the results into a
617 * user-supplied struct tm. This function is a hook for derived
618 * classes to change the value returned. @see get_monthname() for
621 * @param beg Start of string to parse.
622 * @param end End of string to parse.
623 * @param io Source of the locale.
624 * @param err Error flags to set.
625 * @param tm Pointer to struct tm to fill in.
626 * @return Iterator to first char beyond month name.
629 do_get_monthname(iter_type __beg
, iter_type __end
, ios_base
&,
630 ios_base::iostate
& __err
, tm
* __tm
) const;
633 * @brief Parse input year string.
635 * This function reads up to 4 characters to parse a year string and
636 * puts the results into a user-supplied struct tm. This function is a
637 * hook for derived classes to change the value returned. @see
638 * get_year() for details.
640 * @param beg Start of string to parse.
641 * @param end End of string to parse.
642 * @param io Source of the locale.
643 * @param err Error flags to set.
644 * @param tm Pointer to struct tm to fill in.
645 * @return Iterator to first char beyond year.
648 do_get_year(iter_type __beg
, iter_type __end
, ios_base
& __io
,
649 ios_base::iostate
& __err
, tm
* __tm
) const;
651 // Extract numeric component of length __len.
653 _M_extract_num(iter_type __beg
, iter_type __end
, int& __member
,
654 int __min
, int __max
, size_t __len
,
655 ios_base
& __io
, ios_base::iostate
& __err
) const;
657 // Extract any unique array of string literals in a const _CharT* array.
659 _M_extract_name(iter_type __beg
, iter_type __end
, int& __member
,
660 const _CharT
** __names
, size_t __indexlen
,
661 ios_base
& __io
, ios_base::iostate
& __err
) const;
663 // Extract day or month name in a const _CharT* array.
665 _M_extract_wday_or_month(iter_type __beg
, iter_type __end
, int& __member
,
666 const _CharT
** __names
, size_t __indexlen
,
667 ios_base
& __io
, ios_base::iostate
& __err
) const;
669 // Extract on a component-by-component basis, via __format argument.
671 _M_extract_via_format(iter_type __beg
, iter_type __end
, ios_base
& __io
,
672 ios_base::iostate
& __err
, tm
* __tm
,
673 const _CharT
* __format
) const;
676 template<typename _CharT
, typename _InIter
>
677 locale::id time_get
<_CharT
, _InIter
>::id
;
679 /// class time_get_byname [22.2.5.2].
680 template<typename _CharT
, typename _InIter
>
681 class time_get_byname
: public time_get
<_CharT
, _InIter
>
685 typedef _CharT char_type
;
686 typedef _InIter iter_type
;
689 time_get_byname(const char*, size_t __refs
= 0)
690 : time_get
<_CharT
, _InIter
>(__refs
) { }
694 ~time_get_byname() { }
698 * @brief Primary class template time_put.
701 * This facet encapsulates the code to format and output dates and times
702 * according to formats used by strftime().
704 * The time_put template uses protected virtual functions to provide the
705 * actual results. The public accessors forward the call to the virtual
706 * functions. These virtual functions are hooks for developers to
707 * implement the behavior they require from the time_put facet.
709 template<typename _CharT
, typename _OutIter
>
710 class time_put
: public locale::facet
716 typedef _CharT char_type
;
717 typedef _OutIter iter_type
;
720 /// Numpunct facet id.
721 static locale::id id
;
724 * @brief Constructor performs initialization.
726 * This is the constructor provided by the standard.
728 * @param refs Passed to the base facet class.
731 time_put(size_t __refs
= 0)
735 * @brief Format and output a time or date.
737 * This function formats the data in struct tm according to the
738 * provided format string. The format string is interpreted as by
741 * @param s The stream to write to.
742 * @param io Source of locale.
743 * @param fill char_type to use for padding.
744 * @param tm Struct tm with date and time info to format.
745 * @param beg Start of format string.
746 * @param end End of format string.
747 * @return Iterator after writing.
750 put(iter_type __s
, ios_base
& __io
, char_type __fill
, const tm
* __tm
,
751 const _CharT
* __beg
, const _CharT
* __end
) const;
754 * @brief Format and output a time or date.
756 * This function formats the data in struct tm according to the
757 * provided format char and optional modifier. The format and modifier
758 * are interpreted as by strftime(). It does so by returning
759 * time_put::do_put().
761 * @param s The stream to write to.
762 * @param io Source of locale.
763 * @param fill char_type to use for padding.
764 * @param tm Struct tm with date and time info to format.
765 * @param format Format char.
766 * @param mod Optional modifier char.
767 * @return Iterator after writing.
770 put(iter_type __s
, ios_base
& __io
, char_type __fill
,
771 const tm
* __tm
, char __format
, char __mod
= 0) const
772 { return this->do_put(__s
, __io
, __fill
, __tm
, __format
, __mod
); }
781 * @brief Format and output a time or date.
783 * This function formats the data in struct tm according to the
784 * provided format char and optional modifier. This function is a hook
785 * for derived classes to change the value returned. @see put() for
788 * @param s The stream to write to.
789 * @param io Source of locale.
790 * @param fill char_type to use for padding.
791 * @param tm Struct tm with date and time info to format.
792 * @param format Format char.
793 * @param mod Optional modifier char.
794 * @return Iterator after writing.
797 do_put(iter_type __s
, ios_base
& __io
, char_type __fill
, const tm
* __tm
,
798 char __format
, char __mod
) const;
801 template<typename _CharT
, typename _OutIter
>
802 locale::id time_put
<_CharT
, _OutIter
>::id
;
804 /// class time_put_byname [22.2.5.4].
805 template<typename _CharT
, typename _OutIter
>
806 class time_put_byname
: public time_put
<_CharT
, _OutIter
>
810 typedef _CharT char_type
;
811 typedef _OutIter iter_type
;
814 time_put_byname(const char*, size_t __refs
= 0)
815 : time_put
<_CharT
, _OutIter
>(__refs
)
820 ~time_put_byname() { }
825 * @brief Money format ordering data.
828 * This class contains an ordered array of 4 fields to represent the
829 * pattern for formatting a money amount. Each field may contain one entry
830 * from the part enum. symbol, sign, and value must be present and the
831 * remaining field must contain either none or space. @see
832 * moneypunct::pos_format() and moneypunct::neg_format() for details of how
833 * these fields are interpreted.
838 enum part
{ none
, space
, symbol
, sign
, value
};
839 struct pattern
{ char field
[4]; };
841 static const pattern _S_default_pattern
;
850 // String literal of acceptable (narrow) input/output, for
851 // money_get/money_put. "-0123456789"
852 static const char* _S_atoms
;
854 // Construct and return valid pattern consisting of some combination of:
855 // space none symbol sign value
856 _GLIBCXX_CONST
static pattern
857 _S_construct_pattern(char __precedes
, char __space
, char __posn
) throw ();
860 template<typename _CharT
, bool _Intl
>
861 struct __moneypunct_cache
: public locale::facet
863 const char* _M_grouping
;
864 size_t _M_grouping_size
;
865 bool _M_use_grouping
;
866 _CharT _M_decimal_point
;
867 _CharT _M_thousands_sep
;
868 const _CharT
* _M_curr_symbol
;
869 size_t _M_curr_symbol_size
;
870 const _CharT
* _M_positive_sign
;
871 size_t _M_positive_sign_size
;
872 const _CharT
* _M_negative_sign
;
873 size_t _M_negative_sign_size
;
875 money_base::pattern _M_pos_format
;
876 money_base::pattern _M_neg_format
;
878 // A list of valid numeric literals for input and output: in the standard
879 // "C" locale, this is "-0123456789". This array contains the chars after
880 // having been passed through the current locale's ctype<_CharT>.widen().
881 _CharT _M_atoms
[money_base::_S_end
];
885 __moneypunct_cache(size_t __refs
= 0) : facet(__refs
),
886 _M_grouping(0), _M_grouping_size(0), _M_use_grouping(false),
887 _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()),
888 _M_curr_symbol(0), _M_curr_symbol_size(0),
889 _M_positive_sign(0), _M_positive_sign_size(0),
890 _M_negative_sign(0), _M_negative_sign_size(0),
892 _M_pos_format(money_base::pattern()),
893 _M_neg_format(money_base::pattern()), _M_allocated(false)
896 ~__moneypunct_cache();
899 _M_cache(const locale
& __loc
);
903 operator=(const __moneypunct_cache
&);
906 __moneypunct_cache(const __moneypunct_cache
&);
909 template<typename _CharT
, bool _Intl
>
910 __moneypunct_cache
<_CharT
, _Intl
>::~__moneypunct_cache()
914 delete [] _M_grouping
;
915 delete [] _M_curr_symbol
;
916 delete [] _M_positive_sign
;
917 delete [] _M_negative_sign
;
922 * @brief Primary class template moneypunct.
925 * This facet encapsulates the punctuation, grouping and other formatting
926 * features of money amount string representations.
928 template<typename _CharT
, bool _Intl
>
929 class moneypunct
: public locale::facet
, public money_base
935 typedef _CharT char_type
;
936 typedef basic_string
<_CharT
> string_type
;
938 typedef __moneypunct_cache
<_CharT
, _Intl
> __cache_type
;
941 __cache_type
* _M_data
;
944 /// This value is provided by the standard, but no reason for its
946 static const bool intl
= _Intl
;
947 /// Numpunct facet id.
948 static locale::id id
;
951 * @brief Constructor performs initialization.
953 * This is the constructor provided by the standard.
955 * @param refs Passed to the base facet class.
958 moneypunct(size_t __refs
= 0)
959 : facet(__refs
), _M_data(0)
960 { _M_initialize_moneypunct(); }
963 * @brief Constructor performs initialization.
965 * This is an internal constructor.
967 * @param cache Cache for optimization.
968 * @param refs Passed to the base facet class.
971 moneypunct(__cache_type
* __cache
, size_t __refs
= 0)
972 : facet(__refs
), _M_data(__cache
)
973 { _M_initialize_moneypunct(); }
976 * @brief Internal constructor. Not for general use.
978 * This is a constructor for use by the library itself to set up new
981 * @param cloc The C locale.
982 * @param s The name of a locale.
983 * @param refs Passed to the base facet class.
986 moneypunct(__c_locale __cloc
, const char* __s
, size_t __refs
= 0)
987 : facet(__refs
), _M_data(0)
988 { _M_initialize_moneypunct(__cloc
, __s
); }
991 * @brief Return decimal point character.
993 * This function returns a char_type to use as a decimal point. It
994 * does so by returning returning
995 * moneypunct<char_type>::do_decimal_point().
997 * @return @a char_type representing a decimal point.
1000 decimal_point() const
1001 { return this->do_decimal_point(); }
1004 * @brief Return thousands separator character.
1006 * This function returns a char_type to use as a thousands
1007 * separator. It does so by returning returning
1008 * moneypunct<char_type>::do_thousands_sep().
1010 * @return char_type representing a thousands separator.
1013 thousands_sep() const
1014 { return this->do_thousands_sep(); }
1017 * @brief Return grouping specification.
1019 * This function returns a string representing groupings for the
1020 * integer part of an amount. Groupings indicate where thousands
1021 * separators should be inserted.
1023 * Each char in the return string is interpret as an integer rather
1024 * than a character. These numbers represent the number of digits in a
1025 * group. The first char in the string represents the number of digits
1026 * in the least significant group. If a char is negative, it indicates
1027 * an unlimited number of digits for the group. If more chars from the
1028 * string are required to group a number, the last char is used
1031 * For example, if the grouping() returns <code>\003\002</code>
1032 * and is applied to the number 123456789, this corresponds to
1033 * 12,34,56,789. Note that if the string was <code>32</code>, this would
1034 * put more than 50 digits into the least significant group if
1035 * the character set is ASCII.
1037 * The string is returned by calling
1038 * moneypunct<char_type>::do_grouping().
1040 * @return string representing grouping specification.
1044 { return this->do_grouping(); }
1047 * @brief Return currency symbol string.
1049 * This function returns a string_type to use as a currency symbol. It
1050 * does so by returning returning
1051 * moneypunct<char_type>::do_curr_symbol().
1053 * @return @a string_type representing a currency symbol.
1057 { return this->do_curr_symbol(); }
1060 * @brief Return positive sign string.
1062 * This function returns a string_type to use as a sign for positive
1063 * amounts. It does so by returning returning
1064 * moneypunct<char_type>::do_positive_sign().
1066 * If the return value contains more than one character, the first
1067 * character appears in the position indicated by pos_format() and the
1068 * remainder appear at the end of the formatted string.
1070 * @return @a string_type representing a positive sign.
1073 positive_sign() const
1074 { return this->do_positive_sign(); }
1077 * @brief Return negative sign string.
1079 * This function returns a string_type to use as a sign for negative
1080 * amounts. It does so by returning returning
1081 * moneypunct<char_type>::do_negative_sign().
1083 * If the return value contains more than one character, the first
1084 * character appears in the position indicated by neg_format() and the
1085 * remainder appear at the end of the formatted string.
1087 * @return @a string_type representing a negative sign.
1090 negative_sign() const
1091 { return this->do_negative_sign(); }
1094 * @brief Return number of digits in fraction.
1096 * This function returns the exact number of digits that make up the
1097 * fractional part of a money amount. It does so by returning
1098 * returning moneypunct<char_type>::do_frac_digits().
1100 * The fractional part of a money amount is optional. But if it is
1101 * present, there must be frac_digits() digits.
1103 * @return Number of digits in amount fraction.
1107 { return this->do_frac_digits(); }
1111 * @brief Return pattern for money values.
1113 * This function returns a pattern describing the formatting of a
1114 * positive or negative valued money amount. It does so by returning
1115 * returning moneypunct<char_type>::do_pos_format() or
1116 * moneypunct<char_type>::do_neg_format().
1118 * The pattern has 4 fields describing the ordering of symbol, sign,
1119 * value, and none or space. There must be one of each in the pattern.
1120 * The none and space enums may not appear in the first field and space
1121 * may not appear in the final field.
1123 * The parts of a money string must appear in the order indicated by
1124 * the fields of the pattern. The symbol field indicates that the
1125 * value of curr_symbol() may be present. The sign field indicates
1126 * that the value of positive_sign() or negative_sign() must be
1127 * present. The value field indicates that the absolute value of the
1128 * money amount is present. none indicates 0 or more whitespace
1129 * characters, except at the end, where it permits no whitespace.
1130 * space indicates that 1 or more whitespace characters must be
1133 * For example, for the US locale and pos_format() pattern
1134 * {symbol,sign,value,none}, curr_symbol() == '$'
1135 * positive_sign() == '+', and value 10.01, and
1136 * options set to force the symbol, the corresponding string is
1137 * <code>$+10.01</code>.
1139 * @return Pattern for money values.
1143 { return this->do_pos_format(); }
1147 { return this->do_neg_format(); }
1156 * @brief Return decimal point character.
1158 * Returns a char_type to use as a decimal point. This function is a
1159 * hook for derived classes to change the value returned.
1161 * @return @a char_type representing a decimal point.
1164 do_decimal_point() const
1165 { return _M_data
->_M_decimal_point
; }
1168 * @brief Return thousands separator character.
1170 * Returns a char_type to use as a thousands separator. This function
1171 * is a hook for derived classes to change the value returned.
1173 * @return @a char_type representing a thousands separator.
1176 do_thousands_sep() const
1177 { return _M_data
->_M_thousands_sep
; }
1180 * @brief Return grouping specification.
1182 * Returns a string representing groupings for the integer part of a
1183 * number. This function is a hook for derived classes to change the
1184 * value returned. @see grouping() for details.
1186 * @return String representing grouping specification.
1190 { return _M_data
->_M_grouping
; }
1193 * @brief Return currency symbol string.
1195 * This function returns a string_type to use as a currency symbol.
1196 * This function is a hook for derived classes to change the value
1197 * returned. @see curr_symbol() for details.
1199 * @return @a string_type representing a currency symbol.
1202 do_curr_symbol() const
1203 { return _M_data
->_M_curr_symbol
; }
1206 * @brief Return positive sign string.
1208 * This function returns a string_type to use as a sign for positive
1209 * amounts. This function is a hook for derived classes to change the
1210 * value returned. @see positive_sign() for details.
1212 * @return @a string_type representing a positive sign.
1215 do_positive_sign() const
1216 { return _M_data
->_M_positive_sign
; }
1219 * @brief Return negative sign string.
1221 * This function returns a string_type to use as a sign for negative
1222 * amounts. This function is a hook for derived classes to change the
1223 * value returned. @see negative_sign() for details.
1225 * @return @a string_type representing a negative sign.
1228 do_negative_sign() const
1229 { return _M_data
->_M_negative_sign
; }
1232 * @brief Return number of digits in fraction.
1234 * This function returns the exact number of digits that make up the
1235 * fractional part of a money amount. This function is a hook for
1236 * derived classes to change the value returned. @see frac_digits()
1239 * @return Number of digits in amount fraction.
1242 do_frac_digits() const
1243 { return _M_data
->_M_frac_digits
; }
1246 * @brief Return pattern for money values.
1248 * This function returns a pattern describing the formatting of a
1249 * positive valued money amount. This function is a hook for derived
1250 * classes to change the value returned. @see pos_format() for
1253 * @return Pattern for money values.
1256 do_pos_format() const
1257 { return _M_data
->_M_pos_format
; }
1260 * @brief Return pattern for money values.
1262 * This function returns a pattern describing the formatting of a
1263 * negative valued money amount. This function is a hook for derived
1264 * classes to change the value returned. @see neg_format() for
1267 * @return Pattern for money values.
1270 do_neg_format() const
1271 { return _M_data
->_M_neg_format
; }
1273 // For use at construction time only.
1275 _M_initialize_moneypunct(__c_locale __cloc
= 0,
1276 const char* __name
= 0);
1279 template<typename _CharT
, bool _Intl
>
1280 locale::id moneypunct
<_CharT
, _Intl
>::id
;
1282 template<typename _CharT
, bool _Intl
>
1283 const bool moneypunct
<_CharT
, _Intl
>::intl
;
1286 moneypunct
<char, true>::~moneypunct();
1289 moneypunct
<char, false>::~moneypunct();
1293 moneypunct
<char, true>::_M_initialize_moneypunct(__c_locale
, const char*);
1297 moneypunct
<char, false>::_M_initialize_moneypunct(__c_locale
, const char*);
1299 #ifdef _GLIBCXX_USE_WCHAR_T
1301 moneypunct
<wchar_t, true>::~moneypunct();
1304 moneypunct
<wchar_t, false>::~moneypunct();
1308 moneypunct
<wchar_t, true>::_M_initialize_moneypunct(__c_locale
,
1313 moneypunct
<wchar_t, false>::_M_initialize_moneypunct(__c_locale
,
1317 /// class moneypunct_byname [22.2.6.4].
1318 template<typename _CharT
, bool _Intl
>
1319 class moneypunct_byname
: public moneypunct
<_CharT
, _Intl
>
1322 typedef _CharT char_type
;
1323 typedef basic_string
<_CharT
> string_type
;
1325 static const bool intl
= _Intl
;
1328 moneypunct_byname(const char* __s
, size_t __refs
= 0)
1329 : moneypunct
<_CharT
, _Intl
>(__refs
)
1331 if (__builtin_strcmp(__s
, "C") != 0
1332 && __builtin_strcmp(__s
, "POSIX") != 0)
1335 this->_S_create_c_locale(__tmp
, __s
);
1336 this->_M_initialize_moneypunct(__tmp
);
1337 this->_S_destroy_c_locale(__tmp
);
1343 ~moneypunct_byname() { }
1346 template<typename _CharT
, bool _Intl
>
1347 const bool moneypunct_byname
<_CharT
, _Intl
>::intl
;
1349 _GLIBCXX_BEGIN_LDBL_NAMESPACE
1352 * @brief Primary class template money_get.
1355 * This facet encapsulates the code to parse and return a monetary
1356 * amount from a string.
1358 * The money_get template uses protected virtual functions to
1359 * provide the actual results. The public accessors forward the
1360 * call to the virtual functions. These virtual functions are
1361 * hooks for developers to implement the behavior they require from
1362 * the money_get facet.
1364 template<typename _CharT
, typename _InIter
>
1365 class money_get
: public locale::facet
1371 typedef _CharT char_type
;
1372 typedef _InIter iter_type
;
1373 typedef basic_string
<_CharT
> string_type
;
1376 /// Numpunct facet id.
1377 static locale::id id
;
1380 * @brief Constructor performs initialization.
1382 * This is the constructor provided by the standard.
1384 * @param refs Passed to the base facet class.
1387 money_get(size_t __refs
= 0) : facet(__refs
) { }
1390 * @brief Read and parse a monetary value.
1392 * This function reads characters from @a s, interprets them as a
1393 * monetary value according to moneypunct and ctype facets retrieved
1394 * from io.getloc(), and returns the result in @a units as an integral
1395 * value moneypunct::frac_digits() * the actual amount. For example,
1396 * the string $10.01 in a US locale would store 1001 in @a units.
1398 * Any characters not part of a valid money amount are not consumed.
1400 * If a money value cannot be parsed from the input stream, sets
1401 * err=(err|io.failbit). If the stream is consumed before finishing
1402 * parsing, sets err=(err|io.failbit|io.eofbit). @a units is
1403 * unchanged if parsing fails.
1405 * This function works by returning the result of do_get().
1407 * @param s Start of characters to parse.
1408 * @param end End of characters to parse.
1409 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
1410 * @param io Source of facets and io state.
1411 * @param err Error field to set if parsing fails.
1412 * @param units Place to store result of parsing.
1413 * @return Iterator referencing first character beyond valid money
1417 get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
1418 ios_base::iostate
& __err
, long double& __units
) const
1419 { return this->do_get(__s
, __end
, __intl
, __io
, __err
, __units
); }
1422 * @brief Read and parse a monetary value.
1424 * This function reads characters from @a s, interprets them as
1425 * a monetary value according to moneypunct and ctype facets
1426 * retrieved from io.getloc(), and returns the result in @a
1427 * digits. For example, the string $10.01 in a US locale would
1428 * store <code>1001</code> in @a digits.
1430 * Any characters not part of a valid money amount are not consumed.
1432 * If a money value cannot be parsed from the input stream, sets
1433 * err=(err|io.failbit). If the stream is consumed before finishing
1434 * parsing, sets err=(err|io.failbit|io.eofbit).
1436 * This function works by returning the result of do_get().
1438 * @param s Start of characters to parse.
1439 * @param end End of characters to parse.
1440 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
1441 * @param io Source of facets and io state.
1442 * @param err Error field to set if parsing fails.
1443 * @param digits Place to store result of parsing.
1444 * @return Iterator referencing first character beyond valid money
1448 get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
1449 ios_base::iostate
& __err
, string_type
& __digits
) const
1450 { return this->do_get(__s
, __end
, __intl
, __io
, __err
, __digits
); }
1458 * @brief Read and parse a monetary value.
1460 * This function reads and parses characters representing a monetary
1461 * value. This function is a hook for derived classes to change the
1462 * value returned. @see get() for details.
1464 // XXX GLIBCXX_ABI Deprecated
1465 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1467 __do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
1468 ios_base::iostate
& __err
, double& __units
) const;
1471 do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
1472 ios_base::iostate
& __err
, long double& __units
) const;
1476 * @brief Read and parse a monetary value.
1478 * This function reads and parses characters representing a monetary
1479 * value. This function is a hook for derived classes to change the
1480 * value returned. @see get() for details.
1483 do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
1484 ios_base::iostate
& __err
, string_type
& __digits
) const;
1486 // XXX GLIBCXX_ABI Deprecated
1487 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1489 do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
1490 ios_base::iostate
& __err
, long double& __units
) const;
1493 template<bool _Intl
>
1495 _M_extract(iter_type __s
, iter_type __end
, ios_base
& __io
,
1496 ios_base::iostate
& __err
, string
& __digits
) const;
1499 template<typename _CharT
, typename _InIter
>
1500 locale::id money_get
<_CharT
, _InIter
>::id
;
1503 * @brief Primary class template money_put.
1506 * This facet encapsulates the code to format and output a monetary
1509 * The money_put template uses protected virtual functions to
1510 * provide the actual results. The public accessors forward the
1511 * call to the virtual functions. These virtual functions are
1512 * hooks for developers to implement the behavior they require from
1513 * the money_put facet.
1515 template<typename _CharT
, typename _OutIter
>
1516 class money_put
: public locale::facet
1521 typedef _CharT char_type
;
1522 typedef _OutIter iter_type
;
1523 typedef basic_string
<_CharT
> string_type
;
1526 /// Numpunct facet id.
1527 static locale::id id
;
1530 * @brief Constructor performs initialization.
1532 * This is the constructor provided by the standard.
1534 * @param refs Passed to the base facet class.
1537 money_put(size_t __refs
= 0) : facet(__refs
) { }
1540 * @brief Format and output a monetary value.
1542 * This function formats @a units as a monetary value according to
1543 * moneypunct and ctype facets retrieved from io.getloc(), and writes
1544 * the resulting characters to @a s. For example, the value 1001 in a
1545 * US locale would write <code>$10.01</code> to @a s.
1547 * This function works by returning the result of do_put().
1549 * @param s The stream to write to.
1550 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
1551 * @param io Source of facets and io state.
1552 * @param fill char_type to use for padding.
1553 * @param units Place to store result of parsing.
1554 * @return Iterator after writing.
1557 put(iter_type __s
, bool __intl
, ios_base
& __io
,
1558 char_type __fill
, long double __units
) const
1559 { return this->do_put(__s
, __intl
, __io
, __fill
, __units
); }
1562 * @brief Format and output a monetary value.
1564 * This function formats @a digits as a monetary value
1565 * according to moneypunct and ctype facets retrieved from
1566 * io.getloc(), and writes the resulting characters to @a s.
1567 * For example, the string <code>1001</code> in a US locale
1568 * would write <code>$10.01</code> to @a s.
1570 * This function works by returning the result of do_put().
1572 * @param s The stream to write to.
1573 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
1574 * @param io Source of facets and io state.
1575 * @param fill char_type to use for padding.
1576 * @param units Place to store result of parsing.
1577 * @return Iterator after writing.
1580 put(iter_type __s
, bool __intl
, ios_base
& __io
,
1581 char_type __fill
, const string_type
& __digits
) const
1582 { return this->do_put(__s
, __intl
, __io
, __fill
, __digits
); }
1590 * @brief Format and output a monetary value.
1592 * This function formats @a units as a monetary value according to
1593 * moneypunct and ctype facets retrieved from io.getloc(), and writes
1594 * the resulting characters to @a s. For example, the value 1001 in a
1595 * US locale would write <code>$10.01</code> to @a s.
1597 * This function is a hook for derived classes to change the value
1598 * returned. @see put().
1600 * @param s The stream to write to.
1601 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
1602 * @param io Source of facets and io state.
1603 * @param fill char_type to use for padding.
1604 * @param units Place to store result of parsing.
1605 * @return Iterator after writing.
1607 // XXX GLIBCXX_ABI Deprecated
1608 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1610 __do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
1611 double __units
) const;
1614 do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
1615 long double __units
) const;
1619 * @brief Format and output a monetary value.
1621 * This function formats @a digits as a monetary value
1622 * according to moneypunct and ctype facets retrieved from
1623 * io.getloc(), and writes the resulting characters to @a s.
1624 * For example, the string <code>1001</code> in a US locale
1625 * would write <code>$10.01</code> to @a s.
1627 * This function is a hook for derived classes to change the value
1628 * returned. @see put().
1630 * @param s The stream to write to.
1631 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
1632 * @param io Source of facets and io state.
1633 * @param fill char_type to use for padding.
1634 * @param units Place to store result of parsing.
1635 * @return Iterator after writing.
1638 do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
1639 const string_type
& __digits
) const;
1641 // XXX GLIBCXX_ABI Deprecated
1642 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1644 do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
1645 long double __units
) const;
1648 template<bool _Intl
>
1650 _M_insert(iter_type __s
, ios_base
& __io
, char_type __fill
,
1651 const string_type
& __digits
) const;
1654 template<typename _CharT
, typename _OutIter
>
1655 locale::id money_put
<_CharT
, _OutIter
>::id
;
1657 _GLIBCXX_END_LDBL_NAMESPACE
1660 * @brief Messages facet base class providing catalog typedef.
1663 struct messages_base
1665 typedef int catalog
;
1669 * @brief Primary class template messages.
1672 * This facet encapsulates the code to retrieve messages from
1673 * message catalogs. The only thing defined by the standard for this facet
1674 * is the interface. All underlying functionality is
1675 * implementation-defined.
1677 * This library currently implements 3 versions of the message facet. The
1678 * first version (gnu) is a wrapper around gettext, provided by libintl.
1679 * The second version (ieee) is a wrapper around catgets. The final
1680 * version (default) does no actual translation. These implementations are
1681 * only provided for char and wchar_t instantiations.
1683 * The messages template uses protected virtual functions to
1684 * provide the actual results. The public accessors forward the
1685 * call to the virtual functions. These virtual functions are
1686 * hooks for developers to implement the behavior they require from
1687 * the messages facet.
1689 template<typename _CharT
>
1690 class messages
: public locale::facet
, public messages_base
1696 typedef _CharT char_type
;
1697 typedef basic_string
<_CharT
> string_type
;
1701 // Underlying "C" library locale information saved from
1702 // initialization, needed by messages_byname as well.
1703 __c_locale _M_c_locale_messages
;
1704 const char* _M_name_messages
;
1707 /// Numpunct facet id.
1708 static locale::id id
;
1711 * @brief Constructor performs initialization.
1713 * This is the constructor provided by the standard.
1715 * @param refs Passed to the base facet class.
1718 messages(size_t __refs
= 0);
1722 * @brief Internal constructor. Not for general use.
1724 * This is a constructor for use by the library itself to set up new
1727 * @param cloc The C locale.
1728 * @param s The name of a locale.
1729 * @param refs Refcount to pass to the base class.
1732 messages(__c_locale __cloc
, const char* __s
, size_t __refs
= 0);
1735 * @brief Open a message catalog.
1737 * This function opens and returns a handle to a message catalog by
1738 * returning do_open(s, loc).
1740 * @param s The catalog to open.
1741 * @param loc Locale to use for character set conversions.
1742 * @return Handle to the catalog or value < 0 if open fails.
1745 open(const basic_string
<char>& __s
, const locale
& __loc
) const
1746 { return this->do_open(__s
, __loc
); }
1748 // Non-standard and unorthodox, yet effective.
1750 * @brief Open a message catalog.
1752 * This non-standard function opens and returns a handle to a message
1753 * catalog by returning do_open(s, loc). The third argument provides a
1754 * message catalog root directory for gnu gettext and is ignored
1757 * @param s The catalog to open.
1758 * @param loc Locale to use for character set conversions.
1759 * @param dir Message catalog root directory.
1760 * @return Handle to the catalog or value < 0 if open fails.
1763 open(const basic_string
<char>&, const locale
&, const char*) const;
1766 * @brief Look up a string in a message catalog.
1768 * This function retrieves and returns a message from a catalog by
1769 * returning do_get(c, set, msgid, s).
1771 * For gnu, @a set and @a msgid are ignored. Returns gettext(s).
1772 * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
1774 * @param c The catalog to access.
1775 * @param set Implementation-defined.
1776 * @param msgid Implementation-defined.
1777 * @param s Default return value if retrieval fails.
1778 * @return Retrieved message or @a s if get fails.
1781 get(catalog __c
, int __set
, int __msgid
, const string_type
& __s
) const
1782 { return this->do_get(__c
, __set
, __msgid
, __s
); }
1785 * @brief Close a message catalog.
1787 * Closes catalog @a c by calling do_close(c).
1789 * @param c The catalog to close.
1792 close(catalog __c
) const
1793 { return this->do_close(__c
); }
1801 * @brief Open a message catalog.
1803 * This function opens and returns a handle to a message catalog in an
1804 * implementation-defined manner. This function is a hook for derived
1805 * classes to change the value returned.
1807 * @param s The catalog to open.
1808 * @param loc Locale to use for character set conversions.
1809 * @return Handle to the opened catalog, value < 0 if open failed.
1812 do_open(const basic_string
<char>&, const locale
&) const;
1815 * @brief Look up a string in a message catalog.
1817 * This function retrieves and returns a message from a catalog in an
1818 * implementation-defined manner. This function is a hook for derived
1819 * classes to change the value returned.
1821 * For gnu, @a set and @a msgid are ignored. Returns gettext(s).
1822 * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
1824 * @param c The catalog to access.
1825 * @param set Implementation-defined.
1826 * @param msgid Implementation-defined.
1827 * @param s Default return value if retrieval fails.
1828 * @return Retrieved message or @a s if get fails.
1831 do_get(catalog
, int, int, const string_type
& __dfault
) const;
1834 * @brief Close a message catalog.
1836 * @param c The catalog to close.
1839 do_close(catalog
) const;
1841 // Returns a locale and codeset-converted string, given a char* message.
1843 _M_convert_to_char(const string_type
& __msg
) const
1846 return reinterpret_cast<char*>(const_cast<_CharT
*>(__msg
.c_str()));
1849 // Returns a locale and codeset-converted string, given a char* message.
1851 _M_convert_from_char(char*) const
1854 // Length of message string without terminating null.
1855 size_t __len
= char_traits
<char>::length(__msg
) - 1;
1857 // "everybody can easily convert the string using
1858 // mbsrtowcs/wcsrtombs or with iconv()"
1860 // Convert char* to _CharT in locale used to open catalog.
1861 // XXX need additional template parameter on messages class for this..
1862 // typedef typename codecvt<char, _CharT, _StateT> __codecvt_type;
1863 typedef typename codecvt
<char, _CharT
, mbstate_t> __codecvt_type
;
1865 __codecvt_type::state_type __state
;
1866 // XXX may need to initialize state.
1867 //initialize_state(__state._M_init());
1870 // XXX what size for this string?
1871 _CharT
* __to
= static_cast<_CharT
*>(__builtin_alloca(__len
+ 1));
1872 const __codecvt_type
& __cvt
= use_facet
<__codecvt_type
>(_M_locale_conv
);
1873 __cvt
.out(__state
, __msg
, __msg
+ __len
, __from_next
,
1874 __to
, __to
+ __len
+ 1, __to_next
);
1875 return string_type(__to
);
1878 typedef ctype
<_CharT
> __ctype_type
;
1879 // const __ctype_type& __cvt = use_facet<__ctype_type>(_M_locale_msg);
1880 const __ctype_type
& __cvt
= use_facet
<__ctype_type
>(locale());
1881 // XXX Again, proper length of converted string an issue here.
1882 // For now, assume the converted length is not larger.
1883 _CharT
* __dest
= static_cast<_CharT
*>(__builtin_alloca(__len
+ 1));
1884 __cvt
.widen(__msg
, __msg
+ __len
, __dest
);
1885 return basic_string
<_CharT
>(__dest
);
1887 return string_type();
1891 template<typename _CharT
>
1892 locale::id messages
<_CharT
>::id
;
1894 /// Specializations for required instantiations.
1897 messages
<char>::do_get(catalog
, int, int, const string
&) const;
1899 #ifdef _GLIBCXX_USE_WCHAR_T
1902 messages
<wchar_t>::do_get(catalog
, int, int, const wstring
&) const;
1905 /// class messages_byname [22.2.7.2].
1906 template<typename _CharT
>
1907 class messages_byname
: public messages
<_CharT
>
1910 typedef _CharT char_type
;
1911 typedef basic_string
<_CharT
> string_type
;
1914 messages_byname(const char* __s
, size_t __refs
= 0);
1922 _GLIBCXX_END_NAMESPACE
1924 // Include host and configuration specific messages functions.
1925 #include <bits/messages_members.h>
1927 // 22.2.1.5 Template class codecvt
1928 #include <bits/codecvt.h>
1930 #ifndef _GLIBCXX_EXPORT_TEMPLATE
1931 # include <bits/locale_facets_nonio.tcc>