libstdc++
locale_facets_nonio.h
Go to the documentation of this file.
1 // Locale support -*- C++ -*-
2 
3 // Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 
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.
15 
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.
19 
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/>.
24 
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}
28  */
29 
30 //
31 // ISO C++ 14882: 22.1 Locales
32 //
33 
34 #ifndef _LOCALE_FACETS_NONIO_H
35 #define _LOCALE_FACETS_NONIO_H 1
36 
37 #pragma GCC system_header
38 
39 #include <ctime> // For struct tm
40 
41 namespace std _GLIBCXX_VISIBILITY(default)
42 {
43 _GLIBCXX_BEGIN_NAMESPACE_VERSION
44 
45  /**
46  * @brief Time format ordering data.
47  * @ingroup locales
48  *
49  * This class provides an enum representing different orderings of
50  * time: day, month, and year.
51  */
52  class time_base
53  {
54  public:
55  enum dateorder { no_order, dmy, mdy, ymd, ydm };
56  };
57 
58  template<typename _CharT>
59  struct __timepunct_cache : public locale::facet
60  {
61  // List of all known timezones, with GMT first.
62  static const _CharT* _S_timezones[14];
63 
64  const _CharT* _M_date_format;
65  const _CharT* _M_date_era_format;
66  const _CharT* _M_time_format;
67  const _CharT* _M_time_era_format;
68  const _CharT* _M_date_time_format;
69  const _CharT* _M_date_time_era_format;
70  const _CharT* _M_am;
71  const _CharT* _M_pm;
72  const _CharT* _M_am_pm_format;
73 
74  // Day names, starting with "C"'s Sunday.
75  const _CharT* _M_day1;
76  const _CharT* _M_day2;
77  const _CharT* _M_day3;
78  const _CharT* _M_day4;
79  const _CharT* _M_day5;
80  const _CharT* _M_day6;
81  const _CharT* _M_day7;
82 
83  // Abbreviated day names, starting with "C"'s Sun.
84  const _CharT* _M_aday1;
85  const _CharT* _M_aday2;
86  const _CharT* _M_aday3;
87  const _CharT* _M_aday4;
88  const _CharT* _M_aday5;
89  const _CharT* _M_aday6;
90  const _CharT* _M_aday7;
91 
92  // Month names, starting with "C"'s January.
93  const _CharT* _M_month01;
94  const _CharT* _M_month02;
95  const _CharT* _M_month03;
96  const _CharT* _M_month04;
97  const _CharT* _M_month05;
98  const _CharT* _M_month06;
99  const _CharT* _M_month07;
100  const _CharT* _M_month08;
101  const _CharT* _M_month09;
102  const _CharT* _M_month10;
103  const _CharT* _M_month11;
104  const _CharT* _M_month12;
105 
106  // Abbreviated month names, starting with "C"'s Jan.
107  const _CharT* _M_amonth01;
108  const _CharT* _M_amonth02;
109  const _CharT* _M_amonth03;
110  const _CharT* _M_amonth04;
111  const _CharT* _M_amonth05;
112  const _CharT* _M_amonth06;
113  const _CharT* _M_amonth07;
114  const _CharT* _M_amonth08;
115  const _CharT* _M_amonth09;
116  const _CharT* _M_amonth10;
117  const _CharT* _M_amonth11;
118  const _CharT* _M_amonth12;
119 
120  bool _M_allocated;
121 
122  __timepunct_cache(size_t __refs = 0) : facet(__refs),
123  _M_date_format(0), _M_date_era_format(0), _M_time_format(0),
124  _M_time_era_format(0), _M_date_time_format(0),
125  _M_date_time_era_format(0), _M_am(0), _M_pm(0),
126  _M_am_pm_format(0), _M_day1(0), _M_day2(0), _M_day3(0),
127  _M_day4(0), _M_day5(0), _M_day6(0), _M_day7(0),
128  _M_aday1(0), _M_aday2(0), _M_aday3(0), _M_aday4(0),
129  _M_aday5(0), _M_aday6(0), _M_aday7(0), _M_month01(0),
130  _M_month02(0), _M_month03(0), _M_month04(0), _M_month05(0),
131  _M_month06(0), _M_month07(0), _M_month08(0), _M_month09(0),
132  _M_month10(0), _M_month11(0), _M_month12(0), _M_amonth01(0),
133  _M_amonth02(0), _M_amonth03(0), _M_amonth04(0),
134  _M_amonth05(0), _M_amonth06(0), _M_amonth07(0),
135  _M_amonth08(0), _M_amonth09(0), _M_amonth10(0),
136  _M_amonth11(0), _M_amonth12(0), _M_allocated(false)
137  { }
138 
139  ~__timepunct_cache();
140 
141  void
142  _M_cache(const locale& __loc);
143 
144  private:
145  __timepunct_cache&
146  operator=(const __timepunct_cache&);
147 
148  explicit
149  __timepunct_cache(const __timepunct_cache&);
150  };
151 
152  template<typename _CharT>
153  __timepunct_cache<_CharT>::~__timepunct_cache()
154  {
155  if (_M_allocated)
156  {
157  // Unused.
158  }
159  }
160 
161  // Specializations.
162  template<>
163  const char*
164  __timepunct_cache<char>::_S_timezones[14];
165 
166 #ifdef _GLIBCXX_USE_WCHAR_T
167  template<>
168  const wchar_t*
169  __timepunct_cache<wchar_t>::_S_timezones[14];
170 #endif
171 
172  // Generic.
173  template<typename _CharT>
174  const _CharT* __timepunct_cache<_CharT>::_S_timezones[14];
175 
176  template<typename _CharT>
177  class __timepunct : public locale::facet
178  {
179  public:
180  // Types:
181  typedef _CharT __char_type;
182  typedef basic_string<_CharT> __string_type;
183  typedef __timepunct_cache<_CharT> __cache_type;
184 
185  protected:
186  __cache_type* _M_data;
187  __c_locale _M_c_locale_timepunct;
188  const char* _M_name_timepunct;
189 
190  public:
191  /// Numpunct facet id.
192  static locale::id id;
193 
194  explicit
195  __timepunct(size_t __refs = 0);
196 
197  explicit
198  __timepunct(__cache_type* __cache, size_t __refs = 0);
199 
200  /**
201  * @brief Internal constructor. Not for general use.
202  *
203  * This is a constructor for use by the library itself to set up new
204  * locales.
205  *
206  * @param __cloc The C locale.
207  * @param __s The name of a locale.
208  * @param refs Passed to the base facet class.
209  */
210  explicit
211  __timepunct(__c_locale __cloc, const char* __s, size_t __refs = 0);
212 
213  // FIXME: for error checking purposes _M_put should return the return
214  // value of strftime/wcsftime.
215  void
216  _M_put(_CharT* __s, size_t __maxlen, const _CharT* __format,
217  const tm* __tm) const throw ();
218 
219  void
220  _M_date_formats(const _CharT** __date) const
221  {
222  // Always have default first.
223  __date[0] = _M_data->_M_date_format;
224  __date[1] = _M_data->_M_date_era_format;
225  }
226 
227  void
228  _M_time_formats(const _CharT** __time) const
229  {
230  // Always have default first.
231  __time[0] = _M_data->_M_time_format;
232  __time[1] = _M_data->_M_time_era_format;
233  }
234 
235  void
236  _M_date_time_formats(const _CharT** __dt) const
237  {
238  // Always have default first.
239  __dt[0] = _M_data->_M_date_time_format;
240  __dt[1] = _M_data->_M_date_time_era_format;
241  }
242 
243  void
244  _M_am_pm_format(const _CharT* __ampm) const
245  { __ampm = _M_data->_M_am_pm_format; }
246 
247  void
248  _M_am_pm(const _CharT** __ampm) const
249  {
250  __ampm[0] = _M_data->_M_am;
251  __ampm[1] = _M_data->_M_pm;
252  }
253 
254  void
255  _M_days(const _CharT** __days) const
256  {
257  __days[0] = _M_data->_M_day1;
258  __days[1] = _M_data->_M_day2;
259  __days[2] = _M_data->_M_day3;
260  __days[3] = _M_data->_M_day4;
261  __days[4] = _M_data->_M_day5;
262  __days[5] = _M_data->_M_day6;
263  __days[6] = _M_data->_M_day7;
264  }
265 
266  void
267  _M_days_abbreviated(const _CharT** __days) const
268  {
269  __days[0] = _M_data->_M_aday1;
270  __days[1] = _M_data->_M_aday2;
271  __days[2] = _M_data->_M_aday3;
272  __days[3] = _M_data->_M_aday4;
273  __days[4] = _M_data->_M_aday5;
274  __days[5] = _M_data->_M_aday6;
275  __days[6] = _M_data->_M_aday7;
276  }
277 
278  void
279  _M_months(const _CharT** __months) const
280  {
281  __months[0] = _M_data->_M_month01;
282  __months[1] = _M_data->_M_month02;
283  __months[2] = _M_data->_M_month03;
284  __months[3] = _M_data->_M_month04;
285  __months[4] = _M_data->_M_month05;
286  __months[5] = _M_data->_M_month06;
287  __months[6] = _M_data->_M_month07;
288  __months[7] = _M_data->_M_month08;
289  __months[8] = _M_data->_M_month09;
290  __months[9] = _M_data->_M_month10;
291  __months[10] = _M_data->_M_month11;
292  __months[11] = _M_data->_M_month12;
293  }
294 
295  void
296  _M_months_abbreviated(const _CharT** __months) const
297  {
298  __months[0] = _M_data->_M_amonth01;
299  __months[1] = _M_data->_M_amonth02;
300  __months[2] = _M_data->_M_amonth03;
301  __months[3] = _M_data->_M_amonth04;
302  __months[4] = _M_data->_M_amonth05;
303  __months[5] = _M_data->_M_amonth06;
304  __months[6] = _M_data->_M_amonth07;
305  __months[7] = _M_data->_M_amonth08;
306  __months[8] = _M_data->_M_amonth09;
307  __months[9] = _M_data->_M_amonth10;
308  __months[10] = _M_data->_M_amonth11;
309  __months[11] = _M_data->_M_amonth12;
310  }
311 
312  protected:
313  virtual
314  ~__timepunct();
315 
316  // For use at construction time only.
317  void
318  _M_initialize_timepunct(__c_locale __cloc = 0);
319  };
320 
321  template<typename _CharT>
322  locale::id __timepunct<_CharT>::id;
323 
324  // Specializations.
325  template<>
326  void
327  __timepunct<char>::_M_initialize_timepunct(__c_locale __cloc);
328 
329  template<>
330  void
331  __timepunct<char>::_M_put(char*, size_t, const char*, const tm*) const throw ();
332 
333 #ifdef _GLIBCXX_USE_WCHAR_T
334  template<>
335  void
336  __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale __cloc);
337 
338  template<>
339  void
340  __timepunct<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*,
341  const tm*) const throw ();
342 #endif
343 
344 _GLIBCXX_END_NAMESPACE_VERSION
345 } // namespace
346 
347  // Include host and configuration specific timepunct functions.
348  #include <bits/time_members.h>
349 
350 namespace std _GLIBCXX_VISIBILITY(default)
351 {
352 _GLIBCXX_BEGIN_NAMESPACE_VERSION
353 
354  /**
355  * @brief Primary class template time_get.
356  * @ingroup locales
357  *
358  * This facet encapsulates the code to parse and return a date or
359  * time from a string. It is used by the istream numeric
360  * extraction operators.
361  *
362  * The time_get template uses protected virtual functions to provide the
363  * actual results. The public accessors forward the call to the virtual
364  * functions. These virtual functions are hooks for developers to
365  * implement the behavior they require from the time_get facet.
366  */
367  template<typename _CharT, typename _InIter>
368  class time_get : public locale::facet, public time_base
369  {
370  public:
371  // Types:
372  //@{
373  /// Public typedefs
374  typedef _CharT char_type;
375  typedef _InIter iter_type;
376  //@}
378 
379  /// Numpunct facet id.
380  static locale::id id;
381 
382  /**
383  * @brief Constructor performs initialization.
384  *
385  * This is the constructor provided by the standard.
386  *
387  * @param __refs Passed to the base facet class.
388  */
389  explicit
390  time_get(size_t __refs = 0)
391  : facet (__refs) { }
392 
393  /**
394  * @brief Return preferred order of month, day, and year.
395  *
396  * This function returns an enum from timebase::dateorder giving the
397  * preferred ordering if the format @a x given to time_put::put() only
398  * uses month, day, and year. If the format @a x for the associated
399  * locale uses other fields, this function returns
400  * timebase::dateorder::noorder.
401  *
402  * NOTE: The library always returns noorder at the moment.
403  *
404  * @return A member of timebase::dateorder.
405  */
406  dateorder
407  date_order() const
408  { return this->do_date_order(); }
409 
410  /**
411  * @brief Parse input time string.
412  *
413  * This function parses a time according to the format @a X and puts the
414  * results into a user-supplied struct tm. The result is returned by
415  * calling time_get::do_get_time().
416  *
417  * If there is a valid time string according to format @a X, @a tm will
418  * be filled in accordingly and the returned iterator will point to the
419  * first character beyond the time string. If an error occurs before
420  * the end, err |= ios_base::failbit. If parsing reads all the
421  * characters, err |= ios_base::eofbit.
422  *
423  * @param __beg Start of string to parse.
424  * @param __end End of string to parse.
425  * @param __io Source of the locale.
426  * @param __err Error flags to set.
427  * @param __tm Pointer to struct tm to fill in.
428  * @return Iterator to first char beyond time string.
429  */
430  iter_type
431  get_time(iter_type __beg, iter_type __end, ios_base& __io,
432  ios_base::iostate& __err, tm* __tm) const
433  { return this->do_get_time(__beg, __end, __io, __err, __tm); }
434 
435  /**
436  * @brief Parse input date string.
437  *
438  * This function parses a date according to the format @a x and puts the
439  * results into a user-supplied struct tm. The result is returned by
440  * calling time_get::do_get_date().
441  *
442  * If there is a valid date string according to format @a x, @a tm will
443  * be filled in accordingly and the returned iterator will point to the
444  * first character beyond the date string. If an error occurs before
445  * the end, err |= ios_base::failbit. If parsing reads all the
446  * characters, err |= ios_base::eofbit.
447  *
448  * @param __beg Start of string to parse.
449  * @param __end End of string to parse.
450  * @param __io Source of the locale.
451  * @param __err Error flags to set.
452  * @param __tm Pointer to struct tm to fill in.
453  * @return Iterator to first char beyond date string.
454  */
455  iter_type
456  get_date(iter_type __beg, iter_type __end, ios_base& __io,
457  ios_base::iostate& __err, tm* __tm) const
458  { return this->do_get_date(__beg, __end, __io, __err, __tm); }
459 
460  /**
461  * @brief Parse input weekday string.
462  *
463  * This function parses a weekday name and puts the results into a
464  * user-supplied struct tm. The result is returned by calling
465  * time_get::do_get_weekday().
466  *
467  * Parsing starts by parsing an abbreviated weekday name. If a valid
468  * abbreviation is followed by a character that would lead to the full
469  * weekday name, parsing continues until the full name is found or an
470  * error occurs. Otherwise parsing finishes at the end of the
471  * abbreviated name.
472  *
473  * If an error occurs before the end, err |= ios_base::failbit. If
474  * parsing reads all the characters, err |= ios_base::eofbit.
475  *
476  * @param __beg Start of string to parse.
477  * @param __end End of string to parse.
478  * @param __io Source of the locale.
479  * @param __err Error flags to set.
480  * @param __tm Pointer to struct tm to fill in.
481  * @return Iterator to first char beyond weekday name.
482  */
483  iter_type
485  ios_base::iostate& __err, tm* __tm) const
486  { return this->do_get_weekday(__beg, __end, __io, __err, __tm); }
487 
488  /**
489  * @brief Parse input month string.
490  *
491  * This function parses a month name and puts the results into a
492  * user-supplied struct tm. The result is returned by calling
493  * time_get::do_get_monthname().
494  *
495  * Parsing starts by parsing an abbreviated month name. If a valid
496  * abbreviation is followed by a character that would lead to the full
497  * month name, parsing continues until the full name is found or an
498  * error occurs. Otherwise parsing finishes at the end of the
499  * abbreviated name.
500  *
501  * If an error occurs before the end, err |= ios_base::failbit. If
502  * parsing reads all the characters, err |=
503  * ios_base::eofbit.
504  *
505  * @param __beg Start of string to parse.
506  * @param __end End of string to parse.
507  * @param __io Source of the locale.
508  * @param __err Error flags to set.
509  * @param __tm Pointer to struct tm to fill in.
510  * @return Iterator to first char beyond month name.
511  */
512  iter_type
514  ios_base::iostate& __err, tm* __tm) const
515  { return this->do_get_monthname(__beg, __end, __io, __err, __tm); }
516 
517  /**
518  * @brief Parse input year string.
519  *
520  * This function reads up to 4 characters to parse a year string and
521  * puts the results into a user-supplied struct tm. The result is
522  * returned by calling time_get::do_get_year().
523  *
524  * 4 consecutive digits are interpreted as a full year. If there are
525  * exactly 2 consecutive digits, the library interprets this as the
526  * number of years since 1900.
527  *
528  * If an error occurs before the end, err |= ios_base::failbit. If
529  * parsing reads all the characters, err |= ios_base::eofbit.
530  *
531  * @param __beg Start of string to parse.
532  * @param __end End of string to parse.
533  * @param __io Source of the locale.
534  * @param __err Error flags to set.
535  * @param __tm Pointer to struct tm to fill in.
536  * @return Iterator to first char beyond year.
537  */
538  iter_type
539  get_year(iter_type __beg, iter_type __end, ios_base& __io,
540  ios_base::iostate& __err, tm* __tm) const
541  { return this->do_get_year(__beg, __end, __io, __err, __tm); }
542 
543  protected:
544  /// Destructor.
545  virtual
546  ~time_get() { }
547 
548  /**
549  * @brief Return preferred order of month, day, and year.
550  *
551  * This function returns an enum from timebase::dateorder giving the
552  * preferred ordering if the format @a x given to time_put::put() only
553  * uses month, day, and year. This function is a hook for derived
554  * classes to change the value returned.
555  *
556  * @return A member of timebase::dateorder.
557  */
558  virtual dateorder
559  do_date_order() const;
560 
561  /**
562  * @brief Parse input time string.
563  *
564  * This function parses a time according to the format @a x and puts the
565  * results into a user-supplied struct tm. This function is a hook for
566  * derived classes to change the value returned. @see get_time() for
567  * details.
568  *
569  * @param __beg Start of string to parse.
570  * @param __end End of string to parse.
571  * @param __io Source of the locale.
572  * @param __err Error flags to set.
573  * @param __tm Pointer to struct tm to fill in.
574  * @return Iterator to first char beyond time string.
575  */
576  virtual iter_type
577  do_get_time(iter_type __beg, iter_type __end, ios_base& __io,
578  ios_base::iostate& __err, tm* __tm) const;
579 
580  /**
581  * @brief Parse input date string.
582  *
583  * This function parses a date according to the format @a X and puts the
584  * results into a user-supplied struct tm. This function is a hook for
585  * derived classes to change the value returned. @see get_date() for
586  * details.
587  *
588  * @param __beg Start of string to parse.
589  * @param __end End of string to parse.
590  * @param __io Source of the locale.
591  * @param __err Error flags to set.
592  * @param __tm Pointer to struct tm to fill in.
593  * @return Iterator to first char beyond date string.
594  */
595  virtual iter_type
596  do_get_date(iter_type __beg, iter_type __end, ios_base& __io,
597  ios_base::iostate& __err, tm* __tm) const;
598 
599  /**
600  * @brief Parse input weekday string.
601  *
602  * This function parses a weekday name and puts the results into a
603  * user-supplied struct tm. This function is a hook for derived
604  * classes to change the value returned. @see get_weekday() for
605  * details.
606  *
607  * @param __beg Start of string to parse.
608  * @param __end End of string to parse.
609  * @param __io Source of the locale.
610  * @param __err Error flags to set.
611  * @param __tm Pointer to struct tm to fill in.
612  * @return Iterator to first char beyond weekday name.
613  */
614  virtual iter_type
616  ios_base::iostate& __err, tm* __tm) const;
617 
618  /**
619  * @brief Parse input month string.
620  *
621  * This function parses a month name and puts the results into a
622  * user-supplied struct tm. This function is a hook for derived
623  * classes to change the value returned. @see get_monthname() for
624  * details.
625  *
626  * @param __beg Start of string to parse.
627  * @param __end End of string to parse.
628  * @param __io Source of the locale.
629  * @param __err Error flags to set.
630  * @param __tm Pointer to struct tm to fill in.
631  * @return Iterator to first char beyond month name.
632  */
633  virtual iter_type
635  ios_base::iostate& __err, tm* __tm) const;
636 
637  /**
638  * @brief Parse input year string.
639  *
640  * This function reads up to 4 characters to parse a year string and
641  * puts the results into a user-supplied struct tm. This function is a
642  * hook for derived classes to change the value returned. @see
643  * get_year() for details.
644  *
645  * @param __beg Start of string to parse.
646  * @param __end End of string to parse.
647  * @param __io Source of the locale.
648  * @param __err Error flags to set.
649  * @param __tm Pointer to struct tm to fill in.
650  * @return Iterator to first char beyond year.
651  */
652  virtual iter_type
653  do_get_year(iter_type __beg, iter_type __end, ios_base& __io,
654  ios_base::iostate& __err, tm* __tm) const;
655 
656  // Extract numeric component of length __len.
657  iter_type
658  _M_extract_num(iter_type __beg, iter_type __end, int& __member,
659  int __min, int __max, size_t __len,
660  ios_base& __io, ios_base::iostate& __err) const;
661 
662  // Extract any unique array of string literals in a const _CharT* array.
663  iter_type
664  _M_extract_name(iter_type __beg, iter_type __end, int& __member,
665  const _CharT** __names, size_t __indexlen,
666  ios_base& __io, ios_base::iostate& __err) const;
667 
668  // Extract day or month name in a const _CharT* array.
669  iter_type
670  _M_extract_wday_or_month(iter_type __beg, iter_type __end, int& __member,
671  const _CharT** __names, size_t __indexlen,
672  ios_base& __io, ios_base::iostate& __err) const;
673 
674  // Extract on a component-by-component basis, via __format argument.
675  iter_type
676  _M_extract_via_format(iter_type __beg, iter_type __end, ios_base& __io,
677  ios_base::iostate& __err, tm* __tm,
678  const _CharT* __format) const;
679  };
680 
681  template<typename _CharT, typename _InIter>
682  locale::id time_get<_CharT, _InIter>::id;
683 
684  /// class time_get_byname [22.2.5.2].
685  template<typename _CharT, typename _InIter>
686  class time_get_byname : public time_get<_CharT, _InIter>
687  {
688  public:
689  // Types:
690  typedef _CharT char_type;
691  typedef _InIter iter_type;
692 
693  explicit
694  time_get_byname(const char*, size_t __refs = 0)
695  : time_get<_CharT, _InIter>(__refs) { }
696 
697  protected:
698  virtual
699  ~time_get_byname() { }
700  };
701 
702  /**
703  * @brief Primary class template time_put.
704  * @ingroup locales
705  *
706  * This facet encapsulates the code to format and output dates and times
707  * according to formats used by strftime().
708  *
709  * The time_put template uses protected virtual functions to provide the
710  * actual results. The public accessors forward the call to the virtual
711  * functions. These virtual functions are hooks for developers to
712  * implement the behavior they require from the time_put facet.
713  */
714  template<typename _CharT, typename _OutIter>
715  class time_put : public locale::facet
716  {
717  public:
718  // Types:
719  //@{
720  /// Public typedefs
721  typedef _CharT char_type;
722  typedef _OutIter iter_type;
723  //@}
724 
725  /// Numpunct facet id.
726  static locale::id id;
727 
728  /**
729  * @brief Constructor performs initialization.
730  *
731  * This is the constructor provided by the standard.
732  *
733  * @param __refs Passed to the base facet class.
734  */
735  explicit
736  time_put(size_t __refs = 0)
737  : facet(__refs) { }
738 
739  /**
740  * @brief Format and output a time or date.
741  *
742  * This function formats the data in struct tm according to the
743  * provided format string. The format string is interpreted as by
744  * strftime().
745  *
746  * @param __s The stream to write to.
747  * @param __io Source of locale.
748  * @param __fill char_type to use for padding.
749  * @param __tm Struct tm with date and time info to format.
750  * @param __beg Start of format string.
751  * @param __end End of format string.
752  * @return Iterator after writing.
753  */
754  iter_type
755  put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
756  const _CharT* __beg, const _CharT* __end) const;
757 
758  /**
759  * @brief Format and output a time or date.
760  *
761  * This function formats the data in struct tm according to the
762  * provided format char and optional modifier. The format and modifier
763  * are interpreted as by strftime(). It does so by returning
764  * time_put::do_put().
765  *
766  * @param __s The stream to write to.
767  * @param __io Source of locale.
768  * @param __fill char_type to use for padding.
769  * @param __tm Struct tm with date and time info to format.
770  * @param __format Format char.
771  * @param __mod Optional modifier char.
772  * @return Iterator after writing.
773  */
774  iter_type
775  put(iter_type __s, ios_base& __io, char_type __fill,
776  const tm* __tm, char __format, char __mod = 0) const
777  { return this->do_put(__s, __io, __fill, __tm, __format, __mod); }
778 
779  protected:
780  /// Destructor.
781  virtual
783  { }
784 
785  /**
786  * @brief Format and output a time or date.
787  *
788  * This function formats the data in struct tm according to the
789  * provided format char and optional modifier. This function is a hook
790  * for derived classes to change the value returned. @see put() for
791  * more details.
792  *
793  * @param __s The stream to write to.
794  * @param __io Source of locale.
795  * @param __fill char_type to use for padding.
796  * @param __tm Struct tm with date and time info to format.
797  * @param __format Format char.
798  * @param __mod Optional modifier char.
799  * @return Iterator after writing.
800  */
801  virtual iter_type
802  do_put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
803  char __format, char __mod) const;
804  };
805 
806  template<typename _CharT, typename _OutIter>
807  locale::id time_put<_CharT, _OutIter>::id;
808 
809  /// class time_put_byname [22.2.5.4].
810  template<typename _CharT, typename _OutIter>
811  class time_put_byname : public time_put<_CharT, _OutIter>
812  {
813  public:
814  // Types:
815  typedef _CharT char_type;
816  typedef _OutIter iter_type;
817 
818  explicit
819  time_put_byname(const char*, size_t __refs = 0)
820  : time_put<_CharT, _OutIter>(__refs)
821  { };
822 
823  protected:
824  virtual
825  ~time_put_byname() { }
826  };
827 
828 
829  /**
830  * @brief Money format ordering data.
831  * @ingroup locales
832  *
833  * This class contains an ordered array of 4 fields to represent the
834  * pattern for formatting a money amount. Each field may contain one entry
835  * from the part enum. symbol, sign, and value must be present and the
836  * remaining field must contain either none or space. @see
837  * moneypunct::pos_format() and moneypunct::neg_format() for details of how
838  * these fields are interpreted.
839  */
841  {
842  public:
843  enum part { none, space, symbol, sign, value };
844  struct pattern { char field[4]; };
845 
846  static const pattern _S_default_pattern;
847 
848  enum
849  {
850  _S_minus,
851  _S_zero,
852  _S_end = 11
853  };
854 
855  // String literal of acceptable (narrow) input/output, for
856  // money_get/money_put. "-0123456789"
857  static const char* _S_atoms;
858 
859  // Construct and return valid pattern consisting of some combination of:
860  // space none symbol sign value
861  _GLIBCXX_CONST static pattern
862  _S_construct_pattern(char __precedes, char __space, char __posn) throw ();
863  };
864 
865  template<typename _CharT, bool _Intl>
866  struct __moneypunct_cache : public locale::facet
867  {
868  const char* _M_grouping;
869  size_t _M_grouping_size;
870  bool _M_use_grouping;
871  _CharT _M_decimal_point;
872  _CharT _M_thousands_sep;
873  const _CharT* _M_curr_symbol;
874  size_t _M_curr_symbol_size;
875  const _CharT* _M_positive_sign;
876  size_t _M_positive_sign_size;
877  const _CharT* _M_negative_sign;
878  size_t _M_negative_sign_size;
879  int _M_frac_digits;
880  money_base::pattern _M_pos_format;
881  money_base::pattern _M_neg_format;
882 
883  // A list of valid numeric literals for input and output: in the standard
884  // "C" locale, this is "-0123456789". This array contains the chars after
885  // having been passed through the current locale's ctype<_CharT>.widen().
886  _CharT _M_atoms[money_base::_S_end];
887 
888  bool _M_allocated;
889 
890  __moneypunct_cache(size_t __refs = 0) : facet(__refs),
891  _M_grouping(0), _M_grouping_size(0), _M_use_grouping(false),
892  _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()),
893  _M_curr_symbol(0), _M_curr_symbol_size(0),
894  _M_positive_sign(0), _M_positive_sign_size(0),
895  _M_negative_sign(0), _M_negative_sign_size(0),
896  _M_frac_digits(0),
897  _M_pos_format(money_base::pattern()),
898  _M_neg_format(money_base::pattern()), _M_allocated(false)
899  { }
900 
901  ~__moneypunct_cache();
902 
903  void
904  _M_cache(const locale& __loc);
905 
906  private:
907  __moneypunct_cache&
908  operator=(const __moneypunct_cache&);
909 
910  explicit
911  __moneypunct_cache(const __moneypunct_cache&);
912  };
913 
914  template<typename _CharT, bool _Intl>
915  __moneypunct_cache<_CharT, _Intl>::~__moneypunct_cache()
916  {
917  if (_M_allocated)
918  {
919  delete [] _M_grouping;
920  delete [] _M_curr_symbol;
921  delete [] _M_positive_sign;
922  delete [] _M_negative_sign;
923  }
924  }
925 
926  /**
927  * @brief Primary class template moneypunct.
928  * @ingroup locales
929  *
930  * This facet encapsulates the punctuation, grouping and other formatting
931  * features of money amount string representations.
932  */
933  template<typename _CharT, bool _Intl>
934  class moneypunct : public locale::facet, public money_base
935  {
936  public:
937  // Types:
938  //@{
939  /// Public typedefs
940  typedef _CharT char_type;
942  //@}
943  typedef __moneypunct_cache<_CharT, _Intl> __cache_type;
944 
945  private:
946  __cache_type* _M_data;
947 
948  public:
949  /// This value is provided by the standard, but no reason for its
950  /// existence.
951  static const bool intl = _Intl;
952  /// Numpunct facet id.
953  static locale::id id;
954 
955  /**
956  * @brief Constructor performs initialization.
957  *
958  * This is the constructor provided by the standard.
959  *
960  * @param __refs Passed to the base facet class.
961  */
962  explicit
963  moneypunct(size_t __refs = 0)
964  : facet(__refs), _M_data(0)
965  { _M_initialize_moneypunct(); }
966 
967  /**
968  * @brief Constructor performs initialization.
969  *
970  * This is an internal constructor.
971  *
972  * @param __cache Cache for optimization.
973  * @param __refs Passed to the base facet class.
974  */
975  explicit
976  moneypunct(__cache_type* __cache, size_t __refs = 0)
977  : facet(__refs), _M_data(__cache)
978  { _M_initialize_moneypunct(); }
979 
980  /**
981  * @brief Internal constructor. Not for general use.
982  *
983  * This is a constructor for use by the library itself to set up new
984  * locales.
985  *
986  * @param __cloc The C locale.
987  * @param __s The name of a locale.
988  * @param __refs Passed to the base facet class.
989  */
990  explicit
991  moneypunct(__c_locale __cloc, const char* __s, size_t __refs = 0)
992  : facet(__refs), _M_data(0)
993  { _M_initialize_moneypunct(__cloc, __s); }
994 
995  /**
996  * @brief Return decimal point character.
997  *
998  * This function returns a char_type to use as a decimal point. It
999  * does so by returning returning
1000  * moneypunct<char_type>::do_decimal_point().
1001  *
1002  * @return @a char_type representing a decimal point.
1003  */
1004  char_type
1006  { return this->do_decimal_point(); }
1007 
1008  /**
1009  * @brief Return thousands separator character.
1010  *
1011  * This function returns a char_type to use as a thousands
1012  * separator. It does so by returning returning
1013  * moneypunct<char_type>::do_thousands_sep().
1014  *
1015  * @return char_type representing a thousands separator.
1016  */
1017  char_type
1019  { return this->do_thousands_sep(); }
1020 
1021  /**
1022  * @brief Return grouping specification.
1023  *
1024  * This function returns a string representing groupings for the
1025  * integer part of an amount. Groupings indicate where thousands
1026  * separators should be inserted.
1027  *
1028  * Each char in the return string is interpret as an integer rather
1029  * than a character. These numbers represent the number of digits in a
1030  * group. The first char in the string represents the number of digits
1031  * in the least significant group. If a char is negative, it indicates
1032  * an unlimited number of digits for the group. If more chars from the
1033  * string are required to group a number, the last char is used
1034  * repeatedly.
1035  *
1036  * For example, if the grouping() returns <code>\003\002</code>
1037  * and is applied to the number 123456789, this corresponds to
1038  * 12,34,56,789. Note that if the string was <code>32</code>, this would
1039  * put more than 50 digits into the least significant group if
1040  * the character set is ASCII.
1041  *
1042  * The string is returned by calling
1043  * moneypunct<char_type>::do_grouping().
1044  *
1045  * @return string representing grouping specification.
1046  */
1047  string
1048  grouping() const
1049  { return this->do_grouping(); }
1050 
1051  /**
1052  * @brief Return currency symbol string.
1053  *
1054  * This function returns a string_type to use as a currency symbol. It
1055  * does so by returning returning
1056  * moneypunct<char_type>::do_curr_symbol().
1057  *
1058  * @return @a string_type representing a currency symbol.
1059  */
1060  string_type
1061  curr_symbol() const
1062  { return this->do_curr_symbol(); }
1063 
1064  /**
1065  * @brief Return positive sign string.
1066  *
1067  * This function returns a string_type to use as a sign for positive
1068  * amounts. It does so by returning returning
1069  * moneypunct<char_type>::do_positive_sign().
1070  *
1071  * If the return value contains more than one character, the first
1072  * character appears in the position indicated by pos_format() and the
1073  * remainder appear at the end of the formatted string.
1074  *
1075  * @return @a string_type representing a positive sign.
1076  */
1077  string_type
1079  { return this->do_positive_sign(); }
1080 
1081  /**
1082  * @brief Return negative sign string.
1083  *
1084  * This function returns a string_type to use as a sign for negative
1085  * amounts. It does so by returning returning
1086  * moneypunct<char_type>::do_negative_sign().
1087  *
1088  * If the return value contains more than one character, the first
1089  * character appears in the position indicated by neg_format() and the
1090  * remainder appear at the end of the formatted string.
1091  *
1092  * @return @a string_type representing a negative sign.
1093  */
1094  string_type
1096  { return this->do_negative_sign(); }
1097 
1098  /**
1099  * @brief Return number of digits in fraction.
1100  *
1101  * This function returns the exact number of digits that make up the
1102  * fractional part of a money amount. It does so by returning
1103  * returning moneypunct<char_type>::do_frac_digits().
1104  *
1105  * The fractional part of a money amount is optional. But if it is
1106  * present, there must be frac_digits() digits.
1107  *
1108  * @return Number of digits in amount fraction.
1109  */
1110  int
1111  frac_digits() const
1112  { return this->do_frac_digits(); }
1113 
1114  //@{
1115  /**
1116  * @brief Return pattern for money values.
1117  *
1118  * This function returns a pattern describing the formatting of a
1119  * positive or negative valued money amount. It does so by returning
1120  * returning moneypunct<char_type>::do_pos_format() or
1121  * moneypunct<char_type>::do_neg_format().
1122  *
1123  * The pattern has 4 fields describing the ordering of symbol, sign,
1124  * value, and none or space. There must be one of each in the pattern.
1125  * The none and space enums may not appear in the first field and space
1126  * may not appear in the final field.
1127  *
1128  * The parts of a money string must appear in the order indicated by
1129  * the fields of the pattern. The symbol field indicates that the
1130  * value of curr_symbol() may be present. The sign field indicates
1131  * that the value of positive_sign() or negative_sign() must be
1132  * present. The value field indicates that the absolute value of the
1133  * money amount is present. none indicates 0 or more whitespace
1134  * characters, except at the end, where it permits no whitespace.
1135  * space indicates that 1 or more whitespace characters must be
1136  * present.
1137  *
1138  * For example, for the US locale and pos_format() pattern
1139  * {symbol,sign,value,none}, curr_symbol() == &apos;$&apos;
1140  * positive_sign() == &apos;+&apos;, and value 10.01, and
1141  * options set to force the symbol, the corresponding string is
1142  * <code>$+10.01</code>.
1143  *
1144  * @return Pattern for money values.
1145  */
1146  pattern
1147  pos_format() const
1148  { return this->do_pos_format(); }
1149 
1150  pattern
1151  neg_format() const
1152  { return this->do_neg_format(); }
1153  //@}
1154 
1155  protected:
1156  /// Destructor.
1157  virtual
1158  ~moneypunct();
1159 
1160  /**
1161  * @brief Return decimal point character.
1162  *
1163  * Returns a char_type to use as a decimal point. This function is a
1164  * hook for derived classes to change the value returned.
1165  *
1166  * @return @a char_type representing a decimal point.
1167  */
1168  virtual char_type
1170  { return _M_data->_M_decimal_point; }
1171 
1172  /**
1173  * @brief Return thousands separator character.
1174  *
1175  * Returns a char_type to use as a thousands separator. This function
1176  * is a hook for derived classes to change the value returned.
1177  *
1178  * @return @a char_type representing a thousands separator.
1179  */
1180  virtual char_type
1182  { return _M_data->_M_thousands_sep; }
1183 
1184  /**
1185  * @brief Return grouping specification.
1186  *
1187  * Returns a string representing groupings for the integer part of a
1188  * number. This function is a hook for derived classes to change the
1189  * value returned. @see grouping() for details.
1190  *
1191  * @return String representing grouping specification.
1192  */
1193  virtual string
1194  do_grouping() const
1195  { return _M_data->_M_grouping; }
1196 
1197  /**
1198  * @brief Return currency symbol string.
1199  *
1200  * This function returns a string_type to use as a currency symbol.
1201  * This function is a hook for derived classes to change the value
1202  * returned. @see curr_symbol() for details.
1203  *
1204  * @return @a string_type representing a currency symbol.
1205  */
1206  virtual string_type
1208  { return _M_data->_M_curr_symbol; }
1209 
1210  /**
1211  * @brief Return positive sign string.
1212  *
1213  * This function returns a string_type to use as a sign for positive
1214  * amounts. This function is a hook for derived classes to change the
1215  * value returned. @see positive_sign() for details.
1216  *
1217  * @return @a string_type representing a positive sign.
1218  */
1219  virtual string_type
1221  { return _M_data->_M_positive_sign; }
1222 
1223  /**
1224  * @brief Return negative sign string.
1225  *
1226  * This function returns a string_type to use as a sign for negative
1227  * amounts. This function is a hook for derived classes to change the
1228  * value returned. @see negative_sign() for details.
1229  *
1230  * @return @a string_type representing a negative sign.
1231  */
1232  virtual string_type
1234  { return _M_data->_M_negative_sign; }
1235 
1236  /**
1237  * @brief Return number of digits in fraction.
1238  *
1239  * This function returns the exact number of digits that make up the
1240  * fractional part of a money amount. This function is a hook for
1241  * derived classes to change the value returned. @see frac_digits()
1242  * for details.
1243  *
1244  * @return Number of digits in amount fraction.
1245  */
1246  virtual int
1248  { return _M_data->_M_frac_digits; }
1249 
1250  /**
1251  * @brief Return pattern for money values.
1252  *
1253  * This function returns a pattern describing the formatting of a
1254  * positive valued money amount. This function is a hook for derived
1255  * classes to change the value returned. @see pos_format() for
1256  * details.
1257  *
1258  * @return Pattern for money values.
1259  */
1260  virtual pattern
1262  { return _M_data->_M_pos_format; }
1263 
1264  /**
1265  * @brief Return pattern for money values.
1266  *
1267  * This function returns a pattern describing the formatting of a
1268  * negative valued money amount. This function is a hook for derived
1269  * classes to change the value returned. @see neg_format() for
1270  * details.
1271  *
1272  * @return Pattern for money values.
1273  */
1274  virtual pattern
1276  { return _M_data->_M_neg_format; }
1277 
1278  // For use at construction time only.
1279  void
1280  _M_initialize_moneypunct(__c_locale __cloc = 0,
1281  const char* __name = 0);
1282  };
1283 
1284  template<typename _CharT, bool _Intl>
1285  locale::id moneypunct<_CharT, _Intl>::id;
1286 
1287  template<typename _CharT, bool _Intl>
1288  const bool moneypunct<_CharT, _Intl>::intl;
1289 
1290  template<>
1292 
1293  template<>
1295 
1296  template<>
1297  void
1298  moneypunct<char, true>::_M_initialize_moneypunct(__c_locale, const char*);
1299 
1300  template<>
1301  void
1302  moneypunct<char, false>::_M_initialize_moneypunct(__c_locale, const char*);
1303 
1304 #ifdef _GLIBCXX_USE_WCHAR_T
1305  template<>
1307 
1308  template<>
1310 
1311  template<>
1312  void
1313  moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale,
1314  const char*);
1315 
1316  template<>
1317  void
1318  moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale,
1319  const char*);
1320 #endif
1321 
1322  /// class moneypunct_byname [22.2.6.4].
1323  template<typename _CharT, bool _Intl>
1324  class moneypunct_byname : public moneypunct<_CharT, _Intl>
1325  {
1326  public:
1327  typedef _CharT char_type;
1329 
1330  static const bool intl = _Intl;
1331 
1332  explicit
1333  moneypunct_byname(const char* __s, size_t __refs = 0)
1334  : moneypunct<_CharT, _Intl>(__refs)
1335  {
1336  if (__builtin_strcmp(__s, "C") != 0
1337  && __builtin_strcmp(__s, "POSIX") != 0)
1338  {
1339  __c_locale __tmp;
1340  this->_S_create_c_locale(__tmp, __s);
1341  this->_M_initialize_moneypunct(__tmp);
1342  this->_S_destroy_c_locale(__tmp);
1343  }
1344  }
1345 
1346  protected:
1347  virtual
1348  ~moneypunct_byname() { }
1349  };
1350 
1351  template<typename _CharT, bool _Intl>
1352  const bool moneypunct_byname<_CharT, _Intl>::intl;
1353 
1354 _GLIBCXX_BEGIN_NAMESPACE_LDBL
1355 
1356  /**
1357  * @brief Primary class template money_get.
1358  * @ingroup locales
1359  *
1360  * This facet encapsulates the code to parse and return a monetary
1361  * amount from a string.
1362  *
1363  * The money_get template uses protected virtual functions to
1364  * provide the actual results. The public accessors forward the
1365  * call to the virtual functions. These virtual functions are
1366  * hooks for developers to implement the behavior they require from
1367  * the money_get facet.
1368  */
1369  template<typename _CharT, typename _InIter>
1370  class money_get : public locale::facet
1371  {
1372  public:
1373  // Types:
1374  //@{
1375  /// Public typedefs
1376  typedef _CharT char_type;
1377  typedef _InIter iter_type;
1379  //@}
1380 
1381  /// Numpunct facet id.
1382  static locale::id id;
1383 
1384  /**
1385  * @brief Constructor performs initialization.
1386  *
1387  * This is the constructor provided by the standard.
1388  *
1389  * @param __refs Passed to the base facet class.
1390  */
1391  explicit
1392  money_get(size_t __refs = 0) : facet(__refs) { }
1393 
1394  /**
1395  * @brief Read and parse a monetary value.
1396  *
1397  * This function reads characters from @a __s, interprets them as a
1398  * monetary value according to moneypunct and ctype facets retrieved
1399  * from io.getloc(), and returns the result in @a units as an integral
1400  * value moneypunct::frac_digits() * the actual amount. For example,
1401  * the string $10.01 in a US locale would store 1001 in @a units.
1402  *
1403  * Any characters not part of a valid money amount are not consumed.
1404  *
1405  * If a money value cannot be parsed from the input stream, sets
1406  * err=(err|io.failbit). If the stream is consumed before finishing
1407  * parsing, sets err=(err|io.failbit|io.eofbit). @a units is
1408  * unchanged if parsing fails.
1409  *
1410  * This function works by returning the result of do_get().
1411  *
1412  * @param __s Start of characters to parse.
1413  * @param __end End of characters to parse.
1414  * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
1415  * @param __io Source of facets and io state.
1416  * @param __err Error field to set if parsing fails.
1417  * @param __units Place to store result of parsing.
1418  * @return Iterator referencing first character beyond valid money
1419  * amount.
1420  */
1421  iter_type
1422  get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1423  ios_base::iostate& __err, long double& __units) const
1424  { return this->do_get(__s, __end, __intl, __io, __err, __units); }
1425 
1426  /**
1427  * @brief Read and parse a monetary value.
1428  *
1429  * This function reads characters from @a __s, interprets them as
1430  * a monetary value according to moneypunct and ctype facets
1431  * retrieved from io.getloc(), and returns the result in @a
1432  * digits. For example, the string $10.01 in a US locale would
1433  * store <code>1001</code> in @a digits.
1434  *
1435  * Any characters not part of a valid money amount are not consumed.
1436  *
1437  * If a money value cannot be parsed from the input stream, sets
1438  * err=(err|io.failbit). If the stream is consumed before finishing
1439  * parsing, sets err=(err|io.failbit|io.eofbit).
1440  *
1441  * This function works by returning the result of do_get().
1442  *
1443  * @param __s Start of characters to parse.
1444  * @param __end End of characters to parse.
1445  * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
1446  * @param __io Source of facets and io state.
1447  * @param __err Error field to set if parsing fails.
1448  * @param __digits Place to store result of parsing.
1449  * @return Iterator referencing first character beyond valid money
1450  * amount.
1451  */
1452  iter_type
1453  get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1454  ios_base::iostate& __err, string_type& __digits) const
1455  { return this->do_get(__s, __end, __intl, __io, __err, __digits); }
1456 
1457  protected:
1458  /// Destructor.
1459  virtual
1461 
1462  /**
1463  * @brief Read and parse a monetary value.
1464  *
1465  * This function reads and parses characters representing a monetary
1466  * value. This function is a hook for derived classes to change the
1467  * value returned. @see get() for details.
1468  */
1469  // XXX GLIBCXX_ABI Deprecated
1470 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1471  virtual iter_type
1472  __do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1473  ios_base::iostate& __err, double& __units) const;
1474 #else
1475  virtual iter_type
1476  do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1477  ios_base::iostate& __err, long double& __units) const;
1478 #endif
1479 
1480  /**
1481  * @brief Read and parse a monetary value.
1482  *
1483  * This function reads and parses characters representing a monetary
1484  * value. This function is a hook for derived classes to change the
1485  * value returned. @see get() for details.
1486  */
1487  virtual iter_type
1488  do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1489  ios_base::iostate& __err, string_type& __digits) const;
1490 
1491  // XXX GLIBCXX_ABI Deprecated
1492 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1493  virtual iter_type
1494  do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1495  ios_base::iostate& __err, long double& __units) const;
1496 #endif
1497 
1498  template<bool _Intl>
1499  iter_type
1500  _M_extract(iter_type __s, iter_type __end, ios_base& __io,
1501  ios_base::iostate& __err, string& __digits) const;
1502  };
1503 
1504  template<typename _CharT, typename _InIter>
1505  locale::id money_get<_CharT, _InIter>::id;
1506 
1507  /**
1508  * @brief Primary class template money_put.
1509  * @ingroup locales
1510  *
1511  * This facet encapsulates the code to format and output a monetary
1512  * amount.
1513  *
1514  * The money_put template uses protected virtual functions to
1515  * provide the actual results. The public accessors forward the
1516  * call to the virtual functions. These virtual functions are
1517  * hooks for developers to implement the behavior they require from
1518  * the money_put facet.
1519  */
1520  template<typename _CharT, typename _OutIter>
1521  class money_put : public locale::facet
1522  {
1523  public:
1524  //@{
1525  /// Public typedefs
1526  typedef _CharT char_type;
1527  typedef _OutIter iter_type;
1529  //@}
1530 
1531  /// Numpunct facet id.
1532  static locale::id id;
1533 
1534  /**
1535  * @brief Constructor performs initialization.
1536  *
1537  * This is the constructor provided by the standard.
1538  *
1539  * @param __refs Passed to the base facet class.
1540  */
1541  explicit
1542  money_put(size_t __refs = 0) : facet(__refs) { }
1543 
1544  /**
1545  * @brief Format and output a monetary value.
1546  *
1547  * This function formats @a units as a monetary value according to
1548  * moneypunct and ctype facets retrieved from io.getloc(), and writes
1549  * the resulting characters to @a __s. For example, the value 1001 in a
1550  * US locale would write <code>$10.01</code> to @a __s.
1551  *
1552  * This function works by returning the result of do_put().
1553  *
1554  * @param __s The stream to write to.
1555  * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
1556  * @param __io Source of facets and io state.
1557  * @param __fill char_type to use for padding.
1558  * @param __units Place to store result of parsing.
1559  * @return Iterator after writing.
1560  */
1561  iter_type
1562  put(iter_type __s, bool __intl, ios_base& __io,
1563  char_type __fill, long double __units) const
1564  { return this->do_put(__s, __intl, __io, __fill, __units); }
1565 
1566  /**
1567  * @brief Format and output a monetary value.
1568  *
1569  * This function formats @a digits as a monetary value
1570  * according to moneypunct and ctype facets retrieved from
1571  * io.getloc(), and writes the resulting characters to @a __s.
1572  * For example, the string <code>1001</code> in a US locale
1573  * would write <code>$10.01</code> to @a __s.
1574  *
1575  * This function works by returning the result of do_put().
1576  *
1577  * @param __s The stream to write to.
1578  * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
1579  * @param __io Source of facets and io state.
1580  * @param __fill char_type to use for padding.
1581  * @param __digits Place to store result of parsing.
1582  * @return Iterator after writing.
1583  */
1584  iter_type
1585  put(iter_type __s, bool __intl, ios_base& __io,
1586  char_type __fill, const string_type& __digits) const
1587  { return this->do_put(__s, __intl, __io, __fill, __digits); }
1588 
1589  protected:
1590  /// Destructor.
1591  virtual
1593 
1594  /**
1595  * @brief Format and output a monetary value.
1596  *
1597  * This function formats @a units as a monetary value according to
1598  * moneypunct and ctype facets retrieved from io.getloc(), and writes
1599  * the resulting characters to @a __s. For example, the value 1001 in a
1600  * US locale would write <code>$10.01</code> to @a __s.
1601  *
1602  * This function is a hook for derived classes to change the value
1603  * returned. @see put().
1604  *
1605  * @param __s The stream to write to.
1606  * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
1607  * @param __io Source of facets and io state.
1608  * @param __fill char_type to use for padding.
1609  * @param __units Place to store result of parsing.
1610  * @return Iterator after writing.
1611  */
1612  // XXX GLIBCXX_ABI Deprecated
1613 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1614  virtual iter_type
1615  __do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1616  double __units) const;
1617 #else
1618  virtual iter_type
1619  do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1620  long double __units) const;
1621 #endif
1622 
1623  /**
1624  * @brief Format and output a monetary value.
1625  *
1626  * This function formats @a digits as a monetary value
1627  * according to moneypunct and ctype facets retrieved from
1628  * io.getloc(), and writes the resulting characters to @a __s.
1629  * For example, the string <code>1001</code> in a US locale
1630  * would write <code>$10.01</code> to @a __s.
1631  *
1632  * This function is a hook for derived classes to change the value
1633  * returned. @see put().
1634  *
1635  * @param __s The stream to write to.
1636  * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
1637  * @param __io Source of facets and io state.
1638  * @param __fill char_type to use for padding.
1639  * @param __digits Place to store result of parsing.
1640  * @return Iterator after writing.
1641  */
1642  virtual iter_type
1643  do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1644  const string_type& __digits) const;
1645 
1646  // XXX GLIBCXX_ABI Deprecated
1647 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1648  virtual iter_type
1649  do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1650  long double __units) const;
1651 #endif
1652 
1653  template<bool _Intl>
1654  iter_type
1655  _M_insert(iter_type __s, ios_base& __io, char_type __fill,
1656  const string_type& __digits) const;
1657  };
1658 
1659  template<typename _CharT, typename _OutIter>
1660  locale::id money_put<_CharT, _OutIter>::id;
1661 
1662 _GLIBCXX_END_NAMESPACE_LDBL
1663 
1664  /**
1665  * @brief Messages facet base class providing catalog typedef.
1666  * @ingroup locales
1667  */
1669  {
1670  typedef int catalog;
1671  };
1672 
1673  /**
1674  * @brief Primary class template messages.
1675  * @ingroup locales
1676  *
1677  * This facet encapsulates the code to retrieve messages from
1678  * message catalogs. The only thing defined by the standard for this facet
1679  * is the interface. All underlying functionality is
1680  * implementation-defined.
1681  *
1682  * This library currently implements 3 versions of the message facet. The
1683  * first version (gnu) is a wrapper around gettext, provided by libintl.
1684  * The second version (ieee) is a wrapper around catgets. The final
1685  * version (default) does no actual translation. These implementations are
1686  * only provided for char and wchar_t instantiations.
1687  *
1688  * The messages template uses protected virtual functions to
1689  * provide the actual results. The public accessors forward the
1690  * call to the virtual functions. These virtual functions are
1691  * hooks for developers to implement the behavior they require from
1692  * the messages facet.
1693  */
1694  template<typename _CharT>
1695  class messages : public locale::facet, public messages_base
1696  {
1697  public:
1698  // Types:
1699  //@{
1700  /// Public typedefs
1701  typedef _CharT char_type;
1703  //@}
1704 
1705  protected:
1706  // Underlying "C" library locale information saved from
1707  // initialization, needed by messages_byname as well.
1708  __c_locale _M_c_locale_messages;
1709  const char* _M_name_messages;
1710 
1711  public:
1712  /// Numpunct facet id.
1713  static locale::id id;
1714 
1715  /**
1716  * @brief Constructor performs initialization.
1717  *
1718  * This is the constructor provided by the standard.
1719  *
1720  * @param __refs Passed to the base facet class.
1721  */
1722  explicit
1723  messages(size_t __refs = 0);
1724 
1725  // Non-standard.
1726  /**
1727  * @brief Internal constructor. Not for general use.
1728  *
1729  * This is a constructor for use by the library itself to set up new
1730  * locales.
1731  *
1732  * @param __cloc The C locale.
1733  * @param __s The name of a locale.
1734  * @param __refs Refcount to pass to the base class.
1735  */
1736  explicit
1737  messages(__c_locale __cloc, const char* __s, size_t __refs = 0);
1738 
1739  /*
1740  * @brief Open a message catalog.
1741  *
1742  * This function opens and returns a handle to a message catalog by
1743  * returning do_open(__s, __loc).
1744  *
1745  * @param __s The catalog to open.
1746  * @param __loc Locale to use for character set conversions.
1747  * @return Handle to the catalog or value < 0 if open fails.
1748  */
1749  catalog
1750  open(const basic_string<char>& __s, const locale& __loc) const
1751  { return this->do_open(__s, __loc); }
1752 
1753  // Non-standard and unorthodox, yet effective.
1754  /*
1755  * @brief Open a message catalog.
1756  *
1757  * This non-standard function opens and returns a handle to a message
1758  * catalog by returning do_open(s, loc). The third argument provides a
1759  * message catalog root directory for gnu gettext and is ignored
1760  * otherwise.
1761  *
1762  * @param __s The catalog to open.
1763  * @param __loc Locale to use for character set conversions.
1764  * @param __dir Message catalog root directory.
1765  * @return Handle to the catalog or value < 0 if open fails.
1766  */
1767  catalog
1768  open(const basic_string<char>&, const locale&, const char*) const;
1769 
1770  /*
1771  * @brief Look up a string in a message catalog.
1772  *
1773  * This function retrieves and returns a message from a catalog by
1774  * returning do_get(c, set, msgid, s).
1775  *
1776  * For gnu, @a __set and @a msgid are ignored. Returns gettext(s).
1777  * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
1778  *
1779  * @param __c The catalog to access.
1780  * @param __set Implementation-defined.
1781  * @param __msgid Implementation-defined.
1782  * @param __s Default return value if retrieval fails.
1783  * @return Retrieved message or @a __s if get fails.
1784  */
1785  string_type
1786  get(catalog __c, int __set, int __msgid, const string_type& __s) const
1787  { return this->do_get(__c, __set, __msgid, __s); }
1788 
1789  /*
1790  * @brief Close a message catalog.
1791  *
1792  * Closes catalog @a c by calling do_close(c).
1793  *
1794  * @param __c The catalog to close.
1795  */
1796  void
1797  close(catalog __c) const
1798  { return this->do_close(__c); }
1799 
1800  protected:
1801  /// Destructor.
1802  virtual
1803  ~messages();
1804 
1805  /*
1806  * @brief Open a message catalog.
1807  *
1808  * This function opens and returns a handle to a message catalog in an
1809  * implementation-defined manner. This function is a hook for derived
1810  * classes to change the value returned.
1811  *
1812  * @param __s The catalog to open.
1813  * @param __loc Locale to use for character set conversions.
1814  * @return Handle to the opened catalog, value < 0 if open failed.
1815  */
1816  virtual catalog
1817  do_open(const basic_string<char>&, const locale&) const;
1818 
1819  /*
1820  * @brief Look up a string in a message catalog.
1821  *
1822  * This function retrieves and returns a message from a catalog in an
1823  * implementation-defined manner. This function is a hook for derived
1824  * classes to change the value returned.
1825  *
1826  * For gnu, @a __set and @a __msgid are ignored. Returns gettext(s).
1827  * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
1828  *
1829  * @param __c The catalog to access.
1830  * @param __set Implementation-defined.
1831  * @param __msgid Implementation-defined.
1832  * @param __s Default return value if retrieval fails.
1833  * @return Retrieved message or @a __s if get fails.
1834  */
1835  virtual string_type
1836  do_get(catalog, int, int, const string_type& __dfault) const;
1837 
1838  /*
1839  * @brief Close a message catalog.
1840  *
1841  * @param __c The catalog to close.
1842  */
1843  virtual void
1844  do_close(catalog) const;
1845 
1846  // Returns a locale and codeset-converted string, given a char* message.
1847  char*
1848  _M_convert_to_char(const string_type& __msg) const
1849  {
1850  // XXX
1851  return reinterpret_cast<char*>(const_cast<_CharT*>(__msg.c_str()));
1852  }
1853 
1854  // Returns a locale and codeset-converted string, given a char* message.
1855  string_type
1856  _M_convert_from_char(char*) const
1857  {
1858  // XXX
1859  return string_type();
1860  }
1861  };
1862 
1863  template<typename _CharT>
1864  locale::id messages<_CharT>::id;
1865 
1866  /// Specializations for required instantiations.
1867  template<>
1868  string
1869  messages<char>::do_get(catalog, int, int, const string&) const;
1870 
1871 #ifdef _GLIBCXX_USE_WCHAR_T
1872  template<>
1873  wstring
1874  messages<wchar_t>::do_get(catalog, int, int, const wstring&) const;
1875 #endif
1876 
1877  /// class messages_byname [22.2.7.2].
1878  template<typename _CharT>
1879  class messages_byname : public messages<_CharT>
1880  {
1881  public:
1882  typedef _CharT char_type;
1884 
1885  explicit
1886  messages_byname(const char* __s, size_t __refs = 0);
1887 
1888  protected:
1889  virtual
1890  ~messages_byname()
1891  { }
1892  };
1893 
1894 _GLIBCXX_END_NAMESPACE_VERSION
1895 } // namespace
1896 
1897 // Include host and configuration specific messages functions.
1898 #include <bits/messages_members.h>
1899 
1900 // 22.2.1.5 Template class codecvt
1901 #include <bits/codecvt.h>
1902 
1904 
1905 #endif