• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/toolchains/hndtools-arm-linux-2.6.36-uclibc-4.5.3/arm-brcm-linux-uclibcgnueabi/include/c++/4.5.3/bits/
1// Locale support -*- C++ -*-
2
3// Copyright (C) 2007, 2008, 2009, 2010 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 locale_facets_nonio.h
26 *  This is an internal header file, included by other library headers.
27 *  You should not attempt to use it directly.
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_GLIBCXX_BEGIN_NAMESPACE(std)
42
43  /**
44   *  @brief  Time format ordering data.
45   *  @ingroup locales
46   *
47   *  This class provides an enum representing different orderings of
48   *  time: day, month, and year.
49  */
50  class time_base
51  {
52  public:
53    enum dateorder { no_order, dmy, mdy, ymd, ydm };
54  };
55
56  template<typename _CharT>
57    struct __timepunct_cache : public locale::facet
58    {
59      // List of all known timezones, with GMT first.
60      static const _CharT*		_S_timezones[14];
61
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;
68      const _CharT*			_M_am;
69      const _CharT*			_M_pm;
70      const _CharT*			_M_am_pm_format;
71
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;
80
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;
89
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;
103
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;
117
118      bool				_M_allocated;
119
120      __timepunct_cache(size_t __refs = 0) : facet(__refs),
121      _M_date_format(NULL), _M_date_era_format(NULL), _M_time_format(NULL),
122      _M_time_era_format(NULL), _M_date_time_format(NULL),
123      _M_date_time_era_format(NULL), _M_am(NULL), _M_pm(NULL),
124      _M_am_pm_format(NULL), _M_day1(NULL), _M_day2(NULL), _M_day3(NULL),
125      _M_day4(NULL), _M_day5(NULL), _M_day6(NULL), _M_day7(NULL),
126      _M_aday1(NULL), _M_aday2(NULL), _M_aday3(NULL), _M_aday4(NULL),
127      _M_aday5(NULL), _M_aday6(NULL), _M_aday7(NULL), _M_month01(NULL),
128      _M_month02(NULL), _M_month03(NULL), _M_month04(NULL), _M_month05(NULL),
129      _M_month06(NULL), _M_month07(NULL), _M_month08(NULL), _M_month09(NULL),
130      _M_month10(NULL), _M_month11(NULL), _M_month12(NULL), _M_amonth01(NULL),
131      _M_amonth02(NULL), _M_amonth03(NULL), _M_amonth04(NULL),
132      _M_amonth05(NULL), _M_amonth06(NULL), _M_amonth07(NULL),
133      _M_amonth08(NULL), _M_amonth09(NULL), _M_amonth10(NULL),
134      _M_amonth11(NULL), _M_amonth12(NULL), _M_allocated(false)
135      { }
136
137      ~__timepunct_cache();
138
139      void
140      _M_cache(const locale& __loc);
141
142    private:
143      __timepunct_cache&
144      operator=(const __timepunct_cache&);
145
146      explicit
147      __timepunct_cache(const __timepunct_cache&);
148    };
149
150  template<typename _CharT>
151    __timepunct_cache<_CharT>::~__timepunct_cache()
152    {
153      if (_M_allocated)
154	{
155	  // Unused.
156	}
157    }
158
159  // Specializations.
160  template<>
161    const char*
162    __timepunct_cache<char>::_S_timezones[14];
163
164#ifdef _GLIBCXX_USE_WCHAR_T
165  template<>
166    const wchar_t*
167    __timepunct_cache<wchar_t>::_S_timezones[14];
168#endif
169
170  // Generic.
171  template<typename _CharT>
172    const _CharT* __timepunct_cache<_CharT>::_S_timezones[14];
173
174  template<typename _CharT>
175    class __timepunct : public locale::facet
176    {
177    public:
178      // Types:
179      typedef _CharT			__char_type;
180      typedef basic_string<_CharT>	__string_type;
181      typedef __timepunct_cache<_CharT>	__cache_type;
182
183    protected:
184      __cache_type*			_M_data;
185      __c_locale			_M_c_locale_timepunct;
186      const char*			_M_name_timepunct;
187
188    public:
189      /// Numpunct facet id.
190      static locale::id			id;
191
192      explicit
193      __timepunct(size_t __refs = 0);
194
195      explicit
196      __timepunct(__cache_type* __cache, size_t __refs = 0);
197
198      /**
199       *  @brief  Internal constructor. Not for general use.
200       *
201       *  This is a constructor for use by the library itself to set up new
202       *  locales.
203       *
204       *  @param cloc  The C locale.
205       *  @param s  The name of a locale.
206       *  @param refs  Passed to the base facet class.
207      */
208      explicit
209      __timepunct(__c_locale __cloc, const char* __s, size_t __refs = 0);
210
211      // FIXME: for error checking purposes _M_put should return the return
212      // value of strftime/wcsftime.
213      void
214      _M_put(_CharT* __s, size_t __maxlen, const _CharT* __format,
215	     const tm* __tm) const throw ();
216
217      void
218      _M_date_formats(const _CharT** __date) const
219      {
220	// Always have default first.
221	__date[0] = _M_data->_M_date_format;
222	__date[1] = _M_data->_M_date_era_format;
223      }
224
225      void
226      _M_time_formats(const _CharT** __time) const
227      {
228	// Always have default first.
229	__time[0] = _M_data->_M_time_format;
230	__time[1] = _M_data->_M_time_era_format;
231      }
232
233      void
234      _M_date_time_formats(const _CharT** __dt) const
235      {
236	// Always have default first.
237	__dt[0] = _M_data->_M_date_time_format;
238	__dt[1] = _M_data->_M_date_time_era_format;
239      }
240
241      void
242      _M_am_pm_format(const _CharT* __ampm) const
243      { __ampm = _M_data->_M_am_pm_format; }
244
245      void
246      _M_am_pm(const _CharT** __ampm) const
247      {
248	__ampm[0] = _M_data->_M_am;
249	__ampm[1] = _M_data->_M_pm;
250      }
251
252      void
253      _M_days(const _CharT** __days) const
254      {
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;
262      }
263
264      void
265      _M_days_abbreviated(const _CharT** __days) const
266      {
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;
274      }
275
276      void
277      _M_months(const _CharT** __months) const
278      {
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;
291      }
292
293      void
294      _M_months_abbreviated(const _CharT** __months) const
295      {
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;
308      }
309
310    protected:
311      virtual
312      ~__timepunct();
313
314      // For use at construction time only.
315      void
316      _M_initialize_timepunct(__c_locale __cloc = NULL);
317    };
318
319  template<typename _CharT>
320    locale::id __timepunct<_CharT>::id;
321
322  // Specializations.
323  template<>
324    void
325    __timepunct<char>::_M_initialize_timepunct(__c_locale __cloc);
326
327  template<>
328    void
329    __timepunct<char>::_M_put(char*, size_t, const char*, const tm*) const throw ();
330
331#ifdef _GLIBCXX_USE_WCHAR_T
332  template<>
333    void
334    __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale __cloc);
335
336  template<>
337    void
338    __timepunct<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*,
339				 const tm*) const throw ();
340#endif
341
342_GLIBCXX_END_NAMESPACE
343
344  // Include host and configuration specific timepunct functions.
345  #include <bits/time_members.h>
346
347_GLIBCXX_BEGIN_NAMESPACE(std)
348
349  /**
350   *  @brief  Primary class template time_get.
351   *  @ingroup locales
352   *
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.
356   *
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.
361  */
362  template<typename _CharT, typename _InIter>
363    class time_get : public locale::facet, public time_base
364    {
365    public:
366      // Types:
367      //@{
368      /// Public typedefs
369      typedef _CharT			char_type;
370      typedef _InIter			iter_type;
371      //@}
372      typedef basic_string<_CharT>	__string_type;
373
374      /// Numpunct facet id.
375      static locale::id			id;
376
377      /**
378       *  @brief  Constructor performs initialization.
379       *
380       *  This is the constructor provided by the standard.
381       *
382       *  @param refs  Passed to the base facet class.
383      */
384      explicit
385      time_get(size_t __refs = 0)
386      : facet (__refs) { }
387
388      /**
389       *  @brief  Return preferred order of month, day, and year.
390       *
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.
396       *
397       *  NOTE: The library always returns noorder at the moment.
398       *
399       *  @return  A member of timebase::dateorder.
400      */
401      dateorder
402      date_order()  const
403      { return this->do_date_order(); }
404
405      /**
406       *  @brief  Parse input time string.
407       *
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().
411       *
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.
417       *
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.
424      */
425      iter_type
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); }
429
430      /**
431       *  @brief  Parse input date string.
432       *
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().
436       *
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.
442       *
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.
449      */
450      iter_type
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); }
454
455      /**
456       *  @brief  Parse input weekday string.
457       *
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().
461       *
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
466       *  abbreviated name.
467       *
468       *  If an error occurs before the end, err |= ios_base::failbit.  If
469       *  parsing reads all the characters, err |= ios_base::eofbit.
470       *
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.
477      */
478      iter_type
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); }
482
483      /**
484       *  @brief  Parse input month string.
485       *
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().
489       *
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
494       *  abbreviated name.
495       *
496       *  If an error occurs before the end, err |= ios_base::failbit.  If
497       *  parsing reads all the characters, err |=
498       *  ios_base::eofbit.
499       *
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.
506      */
507      iter_type
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); }
511
512      /**
513       *  @brief  Parse input year string.
514       *
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().
518       *
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.
522       *
523       *  If an error occurs before the end, err |= ios_base::failbit.  If
524       *  parsing reads all the characters, err |= ios_base::eofbit.
525       *
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.
532      */
533      iter_type
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); }
537
538    protected:
539      /// Destructor.
540      virtual
541      ~time_get() { }
542
543      /**
544       *  @brief  Return preferred order of month, day, and year.
545       *
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.
550       *
551       *  @return  A member of timebase::dateorder.
552      */
553      virtual dateorder
554      do_date_order() const;
555
556      /**
557       *  @brief  Parse input time string.
558       *
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
562       *  details.
563       *
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.
570      */
571      virtual iter_type
572      do_get_time(iter_type __beg, iter_type __end, ios_base& __io,
573		  ios_base::iostate& __err, tm* __tm) const;
574
575      /**
576       *  @brief  Parse input date string.
577       *
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
581       *  details.
582       *
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.
589      */
590      virtual iter_type
591      do_get_date(iter_type __beg, iter_type __end, ios_base& __io,
592		  ios_base::iostate& __err, tm* __tm) const;
593
594      /**
595       *  @brief  Parse input weekday string.
596       *
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
600       *  details.
601       *
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.
608      */
609      virtual iter_type
610      do_get_weekday(iter_type __beg, iter_type __end, ios_base&,
611		     ios_base::iostate& __err, tm* __tm) const;
612
613      /**
614       *  @brief  Parse input month string.
615       *
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
619       *  details.
620       *
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.
627      */
628      virtual iter_type
629      do_get_monthname(iter_type __beg, iter_type __end, ios_base&,
630		       ios_base::iostate& __err, tm* __tm) const;
631
632      /**
633       *  @brief  Parse input year string.
634       *
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.
639       *
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.
646      */
647      virtual iter_type
648      do_get_year(iter_type __beg, iter_type __end, ios_base& __io,
649		  ios_base::iostate& __err, tm* __tm) const;
650
651      // Extract numeric component of length __len.
652      iter_type
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;
656
657      // Extract any unique array of string literals in a const _CharT* array.
658      iter_type
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;
662
663      // Extract day or month name in a const _CharT* array.
664      iter_type
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;
668
669      // Extract on a component-by-component basis, via __format argument.
670      iter_type
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;
674    };
675
676  template<typename _CharT, typename _InIter>
677    locale::id time_get<_CharT, _InIter>::id;
678
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>
682    {
683    public:
684      // Types:
685      typedef _CharT			char_type;
686      typedef _InIter			iter_type;
687
688      explicit
689      time_get_byname(const char*, size_t __refs = 0)
690      : time_get<_CharT, _InIter>(__refs) { }
691
692    protected:
693      virtual
694      ~time_get_byname() { }
695    };
696
697  /**
698   *  @brief  Primary class template time_put.
699   *  @ingroup locales
700   *
701   *  This facet encapsulates the code to format and output dates and times
702   *  according to formats used by strftime().
703   *
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.
708  */
709  template<typename _CharT, typename _OutIter>
710    class time_put : public locale::facet
711    {
712    public:
713      // Types:
714      //@{
715      /// Public typedefs
716      typedef _CharT			char_type;
717      typedef _OutIter			iter_type;
718      //@}
719
720      /// Numpunct facet id.
721      static locale::id			id;
722
723      /**
724       *  @brief  Constructor performs initialization.
725       *
726       *  This is the constructor provided by the standard.
727       *
728       *  @param refs  Passed to the base facet class.
729      */
730      explicit
731      time_put(size_t __refs = 0)
732      : facet(__refs) { }
733
734      /**
735       *  @brief  Format and output a time or date.
736       *
737       *  This function formats the data in struct tm according to the
738       *  provided format string.  The format string is interpreted as by
739       *  strftime().
740       *
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.
748       */
749      iter_type
750      put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
751	  const _CharT* __beg, const _CharT* __end) const;
752
753      /**
754       *  @brief  Format and output a time or date.
755       *
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().
760       *
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.
768       */
769      iter_type
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); }
773
774    protected:
775      /// Destructor.
776      virtual
777      ~time_put()
778      { }
779
780      /**
781       *  @brief  Format and output a time or date.
782       *
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
786       *  more details.
787       *
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.
795       */
796      virtual iter_type
797      do_put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
798	     char __format, char __mod) const;
799    };
800
801  template<typename _CharT, typename _OutIter>
802    locale::id time_put<_CharT, _OutIter>::id;
803
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>
807    {
808    public:
809      // Types:
810      typedef _CharT			char_type;
811      typedef _OutIter			iter_type;
812
813      explicit
814      time_put_byname(const char*, size_t __refs = 0)
815      : time_put<_CharT, _OutIter>(__refs)
816      { };
817
818    protected:
819      virtual
820      ~time_put_byname() { }
821    };
822
823
824  /**
825   *  @brief  Money format ordering data.
826   *  @ingroup locales
827   *
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.
834  */
835  class money_base
836  {
837  public:
838    enum part { none, space, symbol, sign, value };
839    struct pattern { char field[4]; };
840
841    static const pattern _S_default_pattern;
842
843    enum
844    {
845      _S_minus,
846      _S_zero,
847      _S_end = 11
848    };
849
850    // String literal of acceptable (narrow) input/output, for
851    // money_get/money_put. "-0123456789"
852    static const char* _S_atoms;
853
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 ();
858  };
859
860  template<typename _CharT, bool _Intl>
861    struct __moneypunct_cache : public locale::facet
862    {
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;
874      int				_M_frac_digits;
875      money_base::pattern		_M_pos_format;
876      money_base::pattern	        _M_neg_format;
877
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];
882
883      bool				_M_allocated;
884
885      __moneypunct_cache(size_t __refs = 0) : facet(__refs),
886      _M_grouping(NULL), _M_grouping_size(0), _M_use_grouping(false),
887      _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()),
888      _M_curr_symbol(NULL), _M_curr_symbol_size(0),
889      _M_positive_sign(NULL), _M_positive_sign_size(0),
890      _M_negative_sign(NULL), _M_negative_sign_size(0),
891      _M_frac_digits(0),
892      _M_pos_format(money_base::pattern()),
893      _M_neg_format(money_base::pattern()), _M_allocated(false)
894      { }
895
896      ~__moneypunct_cache();
897
898      void
899      _M_cache(const locale& __loc);
900
901    private:
902      __moneypunct_cache&
903      operator=(const __moneypunct_cache&);
904
905      explicit
906      __moneypunct_cache(const __moneypunct_cache&);
907    };
908
909  template<typename _CharT, bool _Intl>
910    __moneypunct_cache<_CharT, _Intl>::~__moneypunct_cache()
911    {
912      if (_M_allocated)
913	{
914	  delete [] _M_grouping;
915	  delete [] _M_curr_symbol;
916	  delete [] _M_positive_sign;
917	  delete [] _M_negative_sign;
918	}
919    }
920
921  /**
922   *  @brief  Primary class template moneypunct.
923   *  @ingroup locales
924   *
925   *  This facet encapsulates the punctuation, grouping and other formatting
926   *  features of money amount string representations.
927  */
928  template<typename _CharT, bool _Intl>
929    class moneypunct : public locale::facet, public money_base
930    {
931    public:
932      // Types:
933      //@{
934      /// Public typedefs
935      typedef _CharT			char_type;
936      typedef basic_string<_CharT>	string_type;
937      //@}
938      typedef __moneypunct_cache<_CharT, _Intl>     __cache_type;
939
940    private:
941      __cache_type*			_M_data;
942
943    public:
944      /// This value is provided by the standard, but no reason for its
945      /// existence.
946      static const bool			intl = _Intl;
947      /// Numpunct facet id.
948      static locale::id			id;
949
950      /**
951       *  @brief  Constructor performs initialization.
952       *
953       *  This is the constructor provided by the standard.
954       *
955       *  @param refs  Passed to the base facet class.
956      */
957      explicit
958      moneypunct(size_t __refs = 0) : facet(__refs), _M_data(NULL)
959      { _M_initialize_moneypunct(); }
960
961      /**
962       *  @brief  Constructor performs initialization.
963       *
964       *  This is an internal constructor.
965       *
966       *  @param cache  Cache for optimization.
967       *  @param refs  Passed to the base facet class.
968      */
969      explicit
970      moneypunct(__cache_type* __cache, size_t __refs = 0)
971      : facet(__refs), _M_data(__cache)
972      { _M_initialize_moneypunct(); }
973
974      /**
975       *  @brief  Internal constructor. Not for general use.
976       *
977       *  This is a constructor for use by the library itself to set up new
978       *  locales.
979       *
980       *  @param cloc  The C locale.
981       *  @param s  The name of a locale.
982       *  @param refs  Passed to the base facet class.
983      */
984      explicit
985      moneypunct(__c_locale __cloc, const char* __s, size_t __refs = 0)
986      : facet(__refs), _M_data(NULL)
987      { _M_initialize_moneypunct(__cloc, __s); }
988
989      /**
990       *  @brief  Return decimal point character.
991       *
992       *  This function returns a char_type to use as a decimal point.  It
993       *  does so by returning returning
994       *  moneypunct<char_type>::do_decimal_point().
995       *
996       *  @return  @a char_type representing a decimal point.
997      */
998      char_type
999      decimal_point() const
1000      { return this->do_decimal_point(); }
1001
1002      /**
1003       *  @brief  Return thousands separator character.
1004       *
1005       *  This function returns a char_type to use as a thousands
1006       *  separator.  It does so by returning returning
1007       *  moneypunct<char_type>::do_thousands_sep().
1008       *
1009       *  @return  char_type representing a thousands separator.
1010      */
1011      char_type
1012      thousands_sep() const
1013      { return this->do_thousands_sep(); }
1014
1015      /**
1016       *  @brief  Return grouping specification.
1017       *
1018       *  This function returns a string representing groupings for the
1019       *  integer part of an amount.  Groupings indicate where thousands
1020       *  separators should be inserted.
1021       *
1022       *  Each char in the return string is interpret as an integer rather
1023       *  than a character.  These numbers represent the number of digits in a
1024       *  group.  The first char in the string represents the number of digits
1025       *  in the least significant group.  If a char is negative, it indicates
1026       *  an unlimited number of digits for the group.  If more chars from the
1027       *  string are required to group a number, the last char is used
1028       *  repeatedly.
1029       *
1030       *  For example, if the grouping() returns <code>\003\002</code>
1031       *  and is applied to the number 123456789, this corresponds to
1032       *  12,34,56,789.  Note that if the string was <code>32</code>, this would
1033       *  put more than 50 digits into the least significant group if
1034       *  the character set is ASCII.
1035       *
1036       *  The string is returned by calling
1037       *  moneypunct<char_type>::do_grouping().
1038       *
1039       *  @return  string representing grouping specification.
1040      */
1041      string
1042      grouping() const
1043      { return this->do_grouping(); }
1044
1045      /**
1046       *  @brief  Return currency symbol string.
1047       *
1048       *  This function returns a string_type to use as a currency symbol.  It
1049       *  does so by returning returning
1050       *  moneypunct<char_type>::do_curr_symbol().
1051       *
1052       *  @return  @a string_type representing a currency symbol.
1053      */
1054      string_type
1055      curr_symbol() const
1056      { return this->do_curr_symbol(); }
1057
1058      /**
1059       *  @brief  Return positive sign string.
1060       *
1061       *  This function returns a string_type to use as a sign for positive
1062       *  amounts.  It does so by returning returning
1063       *  moneypunct<char_type>::do_positive_sign().
1064       *
1065       *  If the return value contains more than one character, the first
1066       *  character appears in the position indicated by pos_format() and the
1067       *  remainder appear at the end of the formatted string.
1068       *
1069       *  @return  @a string_type representing a positive sign.
1070      */
1071      string_type
1072      positive_sign() const
1073      { return this->do_positive_sign(); }
1074
1075      /**
1076       *  @brief  Return negative sign string.
1077       *
1078       *  This function returns a string_type to use as a sign for negative
1079       *  amounts.  It does so by returning returning
1080       *  moneypunct<char_type>::do_negative_sign().
1081       *
1082       *  If the return value contains more than one character, the first
1083       *  character appears in the position indicated by neg_format() and the
1084       *  remainder appear at the end of the formatted string.
1085       *
1086       *  @return  @a string_type representing a negative sign.
1087      */
1088      string_type
1089      negative_sign() const
1090      { return this->do_negative_sign(); }
1091
1092      /**
1093       *  @brief  Return number of digits in fraction.
1094       *
1095       *  This function returns the exact number of digits that make up the
1096       *  fractional part of a money amount.  It does so by returning
1097       *  returning moneypunct<char_type>::do_frac_digits().
1098       *
1099       *  The fractional part of a money amount is optional.  But if it is
1100       *  present, there must be frac_digits() digits.
1101       *
1102       *  @return  Number of digits in amount fraction.
1103      */
1104      int
1105      frac_digits() const
1106      { return this->do_frac_digits(); }
1107
1108      //@{
1109      /**
1110       *  @brief  Return pattern for money values.
1111       *
1112       *  This function returns a pattern describing the formatting of a
1113       *  positive or negative valued money amount.  It does so by returning
1114       *  returning moneypunct<char_type>::do_pos_format() or
1115       *  moneypunct<char_type>::do_neg_format().
1116       *
1117       *  The pattern has 4 fields describing the ordering of symbol, sign,
1118       *  value, and none or space.  There must be one of each in the pattern.
1119       *  The none and space enums may not appear in the first field and space
1120       *  may not appear in the final field.
1121       *
1122       *  The parts of a money string must appear in the order indicated by
1123       *  the fields of the pattern.  The symbol field indicates that the
1124       *  value of curr_symbol() may be present.  The sign field indicates
1125       *  that the value of positive_sign() or negative_sign() must be
1126       *  present.  The value field indicates that the absolute value of the
1127       *  money amount is present.  none indicates 0 or more whitespace
1128       *  characters, except at the end, where it permits no whitespace.
1129       *  space indicates that 1 or more whitespace characters must be
1130       *  present.
1131       *
1132       *  For example, for the US locale and pos_format() pattern
1133       *  {symbol,sign,value,none}, curr_symbol() == &apos;$&apos;
1134       *  positive_sign() == &apos;+&apos;, and value 10.01, and
1135       *  options set to force the symbol, the corresponding string is
1136       *  <code>$+10.01</code>.
1137       *
1138       *  @return  Pattern for money values.
1139      */
1140      pattern
1141      pos_format() const
1142      { return this->do_pos_format(); }
1143
1144      pattern
1145      neg_format() const
1146      { return this->do_neg_format(); }
1147      //@}
1148
1149    protected:
1150      /// Destructor.
1151      virtual
1152      ~moneypunct();
1153
1154      /**
1155       *  @brief  Return decimal point character.
1156       *
1157       *  Returns a char_type to use as a decimal point.  This function is a
1158       *  hook for derived classes to change the value returned.
1159       *
1160       *  @return  @a char_type representing a decimal point.
1161      */
1162      virtual char_type
1163      do_decimal_point() const
1164      { return _M_data->_M_decimal_point; }
1165
1166      /**
1167       *  @brief  Return thousands separator character.
1168       *
1169       *  Returns a char_type to use as a thousands separator.  This function
1170       *  is a hook for derived classes to change the value returned.
1171       *
1172       *  @return  @a char_type representing a thousands separator.
1173      */
1174      virtual char_type
1175      do_thousands_sep() const
1176      { return _M_data->_M_thousands_sep; }
1177
1178      /**
1179       *  @brief  Return grouping specification.
1180       *
1181       *  Returns a string representing groupings for the integer part of a
1182       *  number.  This function is a hook for derived classes to change the
1183       *  value returned.  @see grouping() for details.
1184       *
1185       *  @return  String representing grouping specification.
1186      */
1187      virtual string
1188      do_grouping() const
1189      { return _M_data->_M_grouping; }
1190
1191      /**
1192       *  @brief  Return currency symbol string.
1193       *
1194       *  This function returns a string_type to use as a currency symbol.
1195       *  This function is a hook for derived classes to change the value
1196       *  returned.  @see curr_symbol() for details.
1197       *
1198       *  @return  @a string_type representing a currency symbol.
1199      */
1200      virtual string_type
1201      do_curr_symbol()   const
1202      { return _M_data->_M_curr_symbol; }
1203
1204      /**
1205       *  @brief  Return positive sign string.
1206       *
1207       *  This function returns a string_type to use as a sign for positive
1208       *  amounts.  This function is a hook for derived classes to change the
1209       *  value returned.  @see positive_sign() for details.
1210       *
1211       *  @return  @a string_type representing a positive sign.
1212      */
1213      virtual string_type
1214      do_positive_sign() const
1215      { return _M_data->_M_positive_sign; }
1216
1217      /**
1218       *  @brief  Return negative sign string.
1219       *
1220       *  This function returns a string_type to use as a sign for negative
1221       *  amounts.  This function is a hook for derived classes to change the
1222       *  value returned.  @see negative_sign() for details.
1223       *
1224       *  @return  @a string_type representing a negative sign.
1225      */
1226      virtual string_type
1227      do_negative_sign() const
1228      { return _M_data->_M_negative_sign; }
1229
1230      /**
1231       *  @brief  Return number of digits in fraction.
1232       *
1233       *  This function returns the exact number of digits that make up the
1234       *  fractional part of a money amount.  This function is a hook for
1235       *  derived classes to change the value returned.  @see frac_digits()
1236       *  for details.
1237       *
1238       *  @return  Number of digits in amount fraction.
1239      */
1240      virtual int
1241      do_frac_digits() const
1242      { return _M_data->_M_frac_digits; }
1243
1244      /**
1245       *  @brief  Return pattern for money values.
1246       *
1247       *  This function returns a pattern describing the formatting of a
1248       *  positive valued money amount.  This function is a hook for derived
1249       *  classes to change the value returned.  @see pos_format() for
1250       *  details.
1251       *
1252       *  @return  Pattern for money values.
1253      */
1254      virtual pattern
1255      do_pos_format() const
1256      { return _M_data->_M_pos_format; }
1257
1258      /**
1259       *  @brief  Return pattern for money values.
1260       *
1261       *  This function returns a pattern describing the formatting of a
1262       *  negative valued money amount.  This function is a hook for derived
1263       *  classes to change the value returned.  @see neg_format() for
1264       *  details.
1265       *
1266       *  @return  Pattern for money values.
1267      */
1268      virtual pattern
1269      do_neg_format() const
1270      { return _M_data->_M_neg_format; }
1271
1272      // For use at construction time only.
1273       void
1274       _M_initialize_moneypunct(__c_locale __cloc = NULL,
1275				const char* __name = NULL);
1276    };
1277
1278  template<typename _CharT, bool _Intl>
1279    locale::id moneypunct<_CharT, _Intl>::id;
1280
1281  template<typename _CharT, bool _Intl>
1282    const bool moneypunct<_CharT, _Intl>::intl;
1283
1284  template<>
1285    moneypunct<char, true>::~moneypunct();
1286
1287  template<>
1288    moneypunct<char, false>::~moneypunct();
1289
1290  template<>
1291    void
1292    moneypunct<char, true>::_M_initialize_moneypunct(__c_locale, const char*);
1293
1294  template<>
1295    void
1296    moneypunct<char, false>::_M_initialize_moneypunct(__c_locale, const char*);
1297
1298#ifdef _GLIBCXX_USE_WCHAR_T
1299  template<>
1300    moneypunct<wchar_t, true>::~moneypunct();
1301
1302  template<>
1303    moneypunct<wchar_t, false>::~moneypunct();
1304
1305  template<>
1306    void
1307    moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale,
1308							const char*);
1309
1310  template<>
1311    void
1312    moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale,
1313							 const char*);
1314#endif
1315
1316  /// class moneypunct_byname [22.2.6.4].
1317  template<typename _CharT, bool _Intl>
1318    class moneypunct_byname : public moneypunct<_CharT, _Intl>
1319    {
1320    public:
1321      typedef _CharT			char_type;
1322      typedef basic_string<_CharT>	string_type;
1323
1324      static const bool intl = _Intl;
1325
1326      explicit
1327      moneypunct_byname(const char* __s, size_t __refs = 0)
1328      : moneypunct<_CharT, _Intl>(__refs)
1329      {
1330	if (__builtin_strcmp(__s, "C") != 0
1331	    && __builtin_strcmp(__s, "POSIX") != 0)
1332	  {
1333	    __c_locale __tmp;
1334	    this->_S_create_c_locale(__tmp, __s);
1335	    this->_M_initialize_moneypunct(__tmp);
1336	    this->_S_destroy_c_locale(__tmp);
1337	  }
1338      }
1339
1340    protected:
1341      virtual
1342      ~moneypunct_byname() { }
1343    };
1344
1345  template<typename _CharT, bool _Intl>
1346    const bool moneypunct_byname<_CharT, _Intl>::intl;
1347
1348_GLIBCXX_BEGIN_LDBL_NAMESPACE
1349
1350  /**
1351   *  @brief  Primary class template money_get.
1352   *  @ingroup locales
1353   *
1354   *  This facet encapsulates the code to parse and return a monetary
1355   *  amount from a string.
1356   *
1357   *  The money_get template uses protected virtual functions to
1358   *  provide the actual results.  The public accessors forward the
1359   *  call to the virtual functions.  These virtual functions are
1360   *  hooks for developers to implement the behavior they require from
1361   *  the money_get facet.
1362  */
1363  template<typename _CharT, typename _InIter>
1364    class money_get : public locale::facet
1365    {
1366    public:
1367      // Types:
1368      //@{
1369      /// Public typedefs
1370      typedef _CharT			char_type;
1371      typedef _InIter			iter_type;
1372      typedef basic_string<_CharT>	string_type;
1373      //@}
1374
1375      /// Numpunct facet id.
1376      static locale::id			id;
1377
1378      /**
1379       *  @brief  Constructor performs initialization.
1380       *
1381       *  This is the constructor provided by the standard.
1382       *
1383       *  @param refs  Passed to the base facet class.
1384      */
1385      explicit
1386      money_get(size_t __refs = 0) : facet(__refs) { }
1387
1388      /**
1389       *  @brief  Read and parse a monetary value.
1390       *
1391       *  This function reads characters from @a s, interprets them as a
1392       *  monetary value according to moneypunct and ctype facets retrieved
1393       *  from io.getloc(), and returns the result in @a units as an integral
1394       *  value moneypunct::frac_digits() * the actual amount.  For example,
1395       *  the string $10.01 in a US locale would store 1001 in @a units.
1396       *
1397       *  Any characters not part of a valid money amount are not consumed.
1398       *
1399       *  If a money value cannot be parsed from the input stream, sets
1400       *  err=(err|io.failbit).  If the stream is consumed before finishing
1401       *  parsing,  sets err=(err|io.failbit|io.eofbit).  @a units is
1402       *  unchanged if parsing fails.
1403       *
1404       *  This function works by returning the result of do_get().
1405       *
1406       *  @param  s  Start of characters to parse.
1407       *  @param  end  End of characters to parse.
1408       *  @param  intl  Parameter to use_facet<moneypunct<CharT,intl> >.
1409       *  @param  io  Source of facets and io state.
1410       *  @param  err  Error field to set if parsing fails.
1411       *  @param  units  Place to store result of parsing.
1412       *  @return  Iterator referencing first character beyond valid money
1413       *	   amount.
1414       */
1415      iter_type
1416      get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1417	  ios_base::iostate& __err, long double& __units) const
1418      { return this->do_get(__s, __end, __intl, __io, __err, __units); }
1419
1420      /**
1421       *  @brief  Read and parse a monetary value.
1422       *
1423       *  This function reads characters from @a s, interprets them as
1424       *  a monetary value according to moneypunct and ctype facets
1425       *  retrieved from io.getloc(), and returns the result in @a
1426       *  digits.  For example, the string $10.01 in a US locale would
1427       *  store <code>1001</code> in @a digits.
1428       *
1429       *  Any characters not part of a valid money amount are not consumed.
1430       *
1431       *  If a money value cannot be parsed from the input stream, sets
1432       *  err=(err|io.failbit).  If the stream is consumed before finishing
1433       *  parsing,  sets err=(err|io.failbit|io.eofbit).
1434       *
1435       *  This function works by returning the result of do_get().
1436       *
1437       *  @param  s  Start of characters to parse.
1438       *  @param  end  End of characters to parse.
1439       *  @param  intl  Parameter to use_facet<moneypunct<CharT,intl> >.
1440       *  @param  io  Source of facets and io state.
1441       *  @param  err  Error field to set if parsing fails.
1442       *  @param  digits  Place to store result of parsing.
1443       *  @return  Iterator referencing first character beyond valid money
1444       *	   amount.
1445       */
1446      iter_type
1447      get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1448	  ios_base::iostate& __err, string_type& __digits) const
1449      { return this->do_get(__s, __end, __intl, __io, __err, __digits); }
1450
1451    protected:
1452      /// Destructor.
1453      virtual
1454      ~money_get() { }
1455
1456      /**
1457       *  @brief  Read and parse a monetary value.
1458       *
1459       *  This function reads and parses characters representing a monetary
1460       *  value.  This function is a hook for derived classes to change the
1461       *  value returned.  @see get() for details.
1462       */
1463      // XXX GLIBCXX_ABI Deprecated
1464#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1465      virtual iter_type
1466      __do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1467	       ios_base::iostate& __err, double& __units) const;
1468#else
1469      virtual iter_type
1470      do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1471	     ios_base::iostate& __err, long double& __units) const;
1472#endif
1473
1474      /**
1475       *  @brief  Read and parse a monetary value.
1476       *
1477       *  This function reads and parses characters representing a monetary
1478       *  value.  This function is a hook for derived classes to change the
1479       *  value returned.  @see get() for details.
1480       */
1481      virtual iter_type
1482      do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1483	     ios_base::iostate& __err, string_type& __digits) const;
1484
1485      // XXX GLIBCXX_ABI Deprecated
1486#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1487      virtual iter_type
1488      do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1489	     ios_base::iostate& __err, long double& __units) const;
1490#endif
1491
1492      template<bool _Intl>
1493        iter_type
1494        _M_extract(iter_type __s, iter_type __end, ios_base& __io,
1495		   ios_base::iostate& __err, string& __digits) const;
1496    };
1497
1498  template<typename _CharT, typename _InIter>
1499    locale::id money_get<_CharT, _InIter>::id;
1500
1501  /**
1502   *  @brief  Primary class template money_put.
1503   *  @ingroup locales
1504   *
1505   *  This facet encapsulates the code to format and output a monetary
1506   *  amount.
1507   *
1508   *  The money_put template uses protected virtual functions to
1509   *  provide the actual results.  The public accessors forward the
1510   *  call to the virtual functions.  These virtual functions are
1511   *  hooks for developers to implement the behavior they require from
1512   *  the money_put facet.
1513  */
1514  template<typename _CharT, typename _OutIter>
1515    class money_put : public locale::facet
1516    {
1517    public:
1518      //@{
1519      /// Public typedefs
1520      typedef _CharT			char_type;
1521      typedef _OutIter			iter_type;
1522      typedef basic_string<_CharT>	string_type;
1523      //@}
1524
1525      /// Numpunct facet id.
1526      static locale::id			id;
1527
1528      /**
1529       *  @brief  Constructor performs initialization.
1530       *
1531       *  This is the constructor provided by the standard.
1532       *
1533       *  @param refs  Passed to the base facet class.
1534      */
1535      explicit
1536      money_put(size_t __refs = 0) : facet(__refs) { }
1537
1538      /**
1539       *  @brief  Format and output a monetary value.
1540       *
1541       *  This function formats @a units as a monetary value according to
1542       *  moneypunct and ctype facets retrieved from io.getloc(), and writes
1543       *  the resulting characters to @a s.  For example, the value 1001 in a
1544       *  US locale would write <code>$10.01</code> to @a s.
1545       *
1546       *  This function works by returning the result of do_put().
1547       *
1548       *  @param  s  The stream to write to.
1549       *  @param  intl  Parameter to use_facet<moneypunct<CharT,intl> >.
1550       *  @param  io  Source of facets and io state.
1551       *  @param  fill  char_type to use for padding.
1552       *  @param  units  Place to store result of parsing.
1553       *  @return  Iterator after writing.
1554       */
1555      iter_type
1556      put(iter_type __s, bool __intl, ios_base& __io,
1557	  char_type __fill, long double __units) const
1558      { return this->do_put(__s, __intl, __io, __fill, __units); }
1559
1560      /**
1561       *  @brief  Format and output a monetary value.
1562       *
1563       *  This function formats @a digits as a monetary value
1564       *  according to moneypunct and ctype facets retrieved from
1565       *  io.getloc(), and writes the resulting characters to @a s.
1566       *  For example, the string <code>1001</code> in a US locale
1567       *  would write <code>$10.01</code> to @a s.
1568       *
1569       *  This function works by returning the result of do_put().
1570       *
1571       *  @param  s  The stream to write to.
1572       *  @param  intl  Parameter to use_facet<moneypunct<CharT,intl> >.
1573       *  @param  io  Source of facets and io state.
1574       *  @param  fill  char_type to use for padding.
1575       *  @param  units  Place to store result of parsing.
1576       *  @return  Iterator after writing.
1577       */
1578      iter_type
1579      put(iter_type __s, bool __intl, ios_base& __io,
1580	  char_type __fill, const string_type& __digits) const
1581      { return this->do_put(__s, __intl, __io, __fill, __digits); }
1582
1583    protected:
1584      /// Destructor.
1585      virtual
1586      ~money_put() { }
1587
1588      /**
1589       *  @brief  Format and output a monetary value.
1590       *
1591       *  This function formats @a units as a monetary value according to
1592       *  moneypunct and ctype facets retrieved from io.getloc(), and writes
1593       *  the resulting characters to @a s.  For example, the value 1001 in a
1594       *  US locale would write <code>$10.01</code> to @a s.
1595       *
1596       *  This function is a hook for derived classes to change the value
1597       *  returned.  @see put().
1598       *
1599       *  @param  s  The stream to write to.
1600       *  @param  intl  Parameter to use_facet<moneypunct<CharT,intl> >.
1601       *  @param  io  Source of facets and io state.
1602       *  @param  fill  char_type to use for padding.
1603       *  @param  units  Place to store result of parsing.
1604       *  @return  Iterator after writing.
1605       */
1606      // XXX GLIBCXX_ABI Deprecated
1607#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1608      virtual iter_type
1609      __do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1610	       double __units) const;
1611#else
1612      virtual iter_type
1613      do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1614	     long double __units) const;
1615#endif
1616
1617      /**
1618       *  @brief  Format and output a monetary value.
1619       *
1620       *  This function formats @a digits as a monetary value
1621       *  according to moneypunct and ctype facets retrieved from
1622       *  io.getloc(), and writes the resulting characters to @a s.
1623       *  For example, the string <code>1001</code> in a US locale
1624       *  would write <code>$10.01</code> to @a s.
1625       *
1626       *  This function is a hook for derived classes to change the value
1627       *  returned.  @see put().
1628       *
1629       *  @param  s  The stream to write to.
1630       *  @param  intl  Parameter to use_facet<moneypunct<CharT,intl> >.
1631       *  @param  io  Source of facets and io state.
1632       *  @param  fill  char_type to use for padding.
1633       *  @param  units  Place to store result of parsing.
1634       *  @return  Iterator after writing.
1635       */
1636      virtual iter_type
1637      do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1638	     const string_type& __digits) const;
1639
1640      // XXX GLIBCXX_ABI Deprecated
1641#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1642      virtual iter_type
1643      do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1644	     long double __units) const;
1645#endif
1646
1647      template<bool _Intl>
1648        iter_type
1649        _M_insert(iter_type __s, ios_base& __io, char_type __fill,
1650		  const string_type& __digits) const;
1651    };
1652
1653  template<typename _CharT, typename _OutIter>
1654    locale::id money_put<_CharT, _OutIter>::id;
1655
1656_GLIBCXX_END_LDBL_NAMESPACE
1657
1658  /**
1659   *  @brief  Messages facet base class providing catalog typedef.
1660   *  @ingroup locales
1661   */
1662  struct messages_base
1663  {
1664    typedef int catalog;
1665  };
1666
1667  /**
1668   *  @brief  Primary class template messages.
1669   *  @ingroup locales
1670   *
1671   *  This facet encapsulates the code to retrieve messages from
1672   *  message catalogs.  The only thing defined by the standard for this facet
1673   *  is the interface.  All underlying functionality is
1674   *  implementation-defined.
1675   *
1676   *  This library currently implements 3 versions of the message facet.  The
1677   *  first version (gnu) is a wrapper around gettext, provided by libintl.
1678   *  The second version (ieee) is a wrapper around catgets.  The final
1679   *  version (default) does no actual translation.  These implementations are
1680   *  only provided for char and wchar_t instantiations.
1681   *
1682   *  The messages template uses protected virtual functions to
1683   *  provide the actual results.  The public accessors forward the
1684   *  call to the virtual functions.  These virtual functions are
1685   *  hooks for developers to implement the behavior they require from
1686   *  the messages facet.
1687  */
1688  template<typename _CharT>
1689    class messages : public locale::facet, public messages_base
1690    {
1691    public:
1692      // Types:
1693      //@{
1694      /// Public typedefs
1695      typedef _CharT			char_type;
1696      typedef basic_string<_CharT>	string_type;
1697      //@}
1698
1699    protected:
1700      // Underlying "C" library locale information saved from
1701      // initialization, needed by messages_byname as well.
1702      __c_locale			_M_c_locale_messages;
1703      const char*			_M_name_messages;
1704
1705    public:
1706      /// Numpunct facet id.
1707      static locale::id			id;
1708
1709      /**
1710       *  @brief  Constructor performs initialization.
1711       *
1712       *  This is the constructor provided by the standard.
1713       *
1714       *  @param refs  Passed to the base facet class.
1715      */
1716      explicit
1717      messages(size_t __refs = 0);
1718
1719      // Non-standard.
1720      /**
1721       *  @brief  Internal constructor.  Not for general use.
1722       *
1723       *  This is a constructor for use by the library itself to set up new
1724       *  locales.
1725       *
1726       *  @param  cloc  The C locale.
1727       *  @param  s  The name of a locale.
1728       *  @param  refs  Refcount to pass to the base class.
1729       */
1730      explicit
1731      messages(__c_locale __cloc, const char* __s, size_t __refs = 0);
1732
1733      /*
1734       *  @brief  Open a message catalog.
1735       *
1736       *  This function opens and returns a handle to a message catalog by
1737       *  returning do_open(s, loc).
1738       *
1739       *  @param  s  The catalog to open.
1740       *  @param  loc  Locale to use for character set conversions.
1741       *  @return  Handle to the catalog or value < 0 if open fails.
1742      */
1743      catalog
1744      open(const basic_string<char>& __s, const locale& __loc) const
1745      { return this->do_open(__s, __loc); }
1746
1747      // Non-standard and unorthodox, yet effective.
1748      /*
1749       *  @brief  Open a message catalog.
1750       *
1751       *  This non-standard function opens and returns a handle to a message
1752       *  catalog by returning do_open(s, loc).  The third argument provides a
1753       *  message catalog root directory for gnu gettext and is ignored
1754       *  otherwise.
1755       *
1756       *  @param  s  The catalog to open.
1757       *  @param  loc  Locale to use for character set conversions.
1758       *  @param  dir  Message catalog root directory.
1759       *  @return  Handle to the catalog or value < 0 if open fails.
1760      */
1761      catalog
1762      open(const basic_string<char>&, const locale&, const char*) const;
1763
1764      /*
1765       *  @brief  Look up a string in a message catalog.
1766       *
1767       *  This function retrieves and returns a message from a catalog by
1768       *  returning do_get(c, set, msgid, s).
1769       *
1770       *  For gnu, @a set and @a msgid are ignored.  Returns gettext(s).
1771       *  For default, returns s. For ieee, returns catgets(c,set,msgid,s).
1772       *
1773       *  @param  c  The catalog to access.
1774       *  @param  set  Implementation-defined.
1775       *  @param  msgid  Implementation-defined.
1776       *  @param  s  Default return value if retrieval fails.
1777       *  @return  Retrieved message or @a s if get fails.
1778      */
1779      string_type
1780      get(catalog __c, int __set, int __msgid, const string_type& __s) const
1781      { return this->do_get(__c, __set, __msgid, __s); }
1782
1783      /*
1784       *  @brief  Close a message catalog.
1785       *
1786       *  Closes catalog @a c by calling do_close(c).
1787       *
1788       *  @param  c  The catalog to close.
1789      */
1790      void
1791      close(catalog __c) const
1792      { return this->do_close(__c); }
1793
1794    protected:
1795      /// Destructor.
1796      virtual
1797      ~messages();
1798
1799      /*
1800       *  @brief  Open a message catalog.
1801       *
1802       *  This function opens and returns a handle to a message catalog in an
1803       *  implementation-defined manner.  This function is a hook for derived
1804       *  classes to change the value returned.
1805       *
1806       *  @param  s  The catalog to open.
1807       *  @param  loc  Locale to use for character set conversions.
1808       *  @return  Handle to the opened catalog, value < 0 if open failed.
1809      */
1810      virtual catalog
1811      do_open(const basic_string<char>&, const locale&) const;
1812
1813      /*
1814       *  @brief  Look up a string in a message catalog.
1815       *
1816       *  This function retrieves and returns a message from a catalog in an
1817       *  implementation-defined manner.  This function is a hook for derived
1818       *  classes to change the value returned.
1819       *
1820       *  For gnu, @a set and @a msgid are ignored.  Returns gettext(s).
1821       *  For default, returns s. For ieee, returns catgets(c,set,msgid,s).
1822       *
1823       *  @param  c  The catalog to access.
1824       *  @param  set  Implementation-defined.
1825       *  @param  msgid  Implementation-defined.
1826       *  @param  s  Default return value if retrieval fails.
1827       *  @return  Retrieved message or @a s if get fails.
1828      */
1829      virtual string_type
1830      do_get(catalog, int, int, const string_type& __dfault) const;
1831
1832      /*
1833       *  @brief  Close a message catalog.
1834       *
1835       *  @param  c  The catalog to close.
1836      */
1837      virtual void
1838      do_close(catalog) const;
1839
1840      // Returns a locale and codeset-converted string, given a char* message.
1841      char*
1842      _M_convert_to_char(const string_type& __msg) const
1843      {
1844	// XXX
1845	return reinterpret_cast<char*>(const_cast<_CharT*>(__msg.c_str()));
1846      }
1847
1848      // Returns a locale and codeset-converted string, given a char* message.
1849      string_type
1850      _M_convert_from_char(char*) const
1851      {
1852#if 0
1853	// Length of message string without terminating null.
1854	size_t __len = char_traits<char>::length(__msg) - 1;
1855
1856	// "everybody can easily convert the string using
1857	// mbsrtowcs/wcsrtombs or with iconv()"
1858
1859	// Convert char* to _CharT in locale used to open catalog.
1860	// XXX need additional template parameter on messages class for this..
1861	// typedef typename codecvt<char, _CharT, _StateT> __codecvt_type;
1862	typedef typename codecvt<char, _CharT, mbstate_t> __codecvt_type;
1863
1864	__codecvt_type::state_type __state;
1865	// XXX may need to initialize state.
1866	//initialize_state(__state._M_init());
1867
1868	char* __from_next;
1869	// XXX what size for this string?
1870	_CharT* __to = static_cast<_CharT*>(__builtin_alloca(__len + 1));
1871	const __codecvt_type& __cvt = use_facet<__codecvt_type>(_M_locale_conv);
1872	__cvt.out(__state, __msg, __msg + __len, __from_next,
1873		  __to, __to + __len + 1, __to_next);
1874	return string_type(__to);
1875#endif
1876#if 0
1877	typedef ctype<_CharT> __ctype_type;
1878	// const __ctype_type& __cvt = use_facet<__ctype_type>(_M_locale_msg);
1879	const __ctype_type& __cvt = use_facet<__ctype_type>(locale());
1880	// XXX Again, proper length of converted string an issue here.
1881	// For now, assume the converted length is not larger.
1882	_CharT* __dest = static_cast<_CharT*>(__builtin_alloca(__len + 1));
1883	__cvt.widen(__msg, __msg + __len, __dest);
1884	return basic_string<_CharT>(__dest);
1885#endif
1886	return string_type();
1887      }
1888     };
1889
1890  template<typename _CharT>
1891    locale::id messages<_CharT>::id;
1892
1893  /// Specializations for required instantiations.
1894  template<>
1895    string
1896    messages<char>::do_get(catalog, int, int, const string&) const;
1897
1898#ifdef _GLIBCXX_USE_WCHAR_T
1899  template<>
1900    wstring
1901    messages<wchar_t>::do_get(catalog, int, int, const wstring&) const;
1902#endif
1903
1904   /// class messages_byname [22.2.7.2].
1905   template<typename _CharT>
1906    class messages_byname : public messages<_CharT>
1907    {
1908    public:
1909      typedef _CharT			char_type;
1910      typedef basic_string<_CharT>	string_type;
1911
1912      explicit
1913      messages_byname(const char* __s, size_t __refs = 0);
1914
1915    protected:
1916      virtual
1917      ~messages_byname()
1918      { }
1919    };
1920
1921_GLIBCXX_END_NAMESPACE
1922
1923// Include host and configuration specific messages functions.
1924#include <bits/messages_members.h>
1925
1926// 22.2.1.5  Template class codecvt
1927#include <bits/codecvt.h>
1928
1929#ifndef _GLIBCXX_EXPORT_TEMPLATE
1930# include <bits/locale_facets_nonio.tcc>
1931#endif
1932
1933#endif
1934