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