locale_facets_nonio.h

Go to the documentation of this file.
00001 // Locale support -*- C++ -*-
00002 
00003 // Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /** @file locale_facets_nonio.h
00026  *  This is an internal header file, included by other library headers.
00027  *  You should not attempt to use it directly.
00028  */
00029 
00030 //
00031 // ISO C++ 14882: 22.1  Locales
00032 //
00033 
00034 #ifndef _LOCALE_FACETS_NONIO_H
00035 #define _LOCALE_FACETS_NONIO_H 1
00036 
00037 #pragma GCC system_header
00038 
00039 #include <ctime>    // For struct tm
00040 
00041 _GLIBCXX_BEGIN_NAMESPACE(std)
00042 
00043   /**
00044    *  @brief  Time format ordering data.
00045    *  @ingroup locales
00046    *
00047    *  This class provides an enum representing different orderings of
00048    *  time: day, month, and year.
00049   */
00050   class time_base
00051   {
00052   public:
00053     enum dateorder { no_order, dmy, mdy, ymd, ydm };
00054   };
00055 
00056   template<typename _CharT>
00057     struct __timepunct_cache : public locale::facet
00058     {
00059       // List of all known timezones, with GMT first.
00060       static const _CharT*      _S_timezones[14];
00061 
00062       const _CharT*         _M_date_format;
00063       const _CharT*         _M_date_era_format;
00064       const _CharT*         _M_time_format;
00065       const _CharT*         _M_time_era_format;
00066       const _CharT*         _M_date_time_format;
00067       const _CharT*         _M_date_time_era_format;
00068       const _CharT*         _M_am;
00069       const _CharT*         _M_pm;
00070       const _CharT*         _M_am_pm_format;
00071 
00072       // Day names, starting with "C"'s Sunday.
00073       const _CharT*         _M_day1;
00074       const _CharT*         _M_day2;
00075       const _CharT*         _M_day3;
00076       const _CharT*         _M_day4;
00077       const _CharT*         _M_day5;
00078       const _CharT*         _M_day6;
00079       const _CharT*         _M_day7;
00080 
00081       // Abbreviated day names, starting with "C"'s Sun.
00082       const _CharT*         _M_aday1;
00083       const _CharT*         _M_aday2;
00084       const _CharT*         _M_aday3;
00085       const _CharT*         _M_aday4;
00086       const _CharT*         _M_aday5;
00087       const _CharT*         _M_aday6;
00088       const _CharT*         _M_aday7;
00089 
00090       // Month names, starting with "C"'s January.
00091       const _CharT*         _M_month01;
00092       const _CharT*         _M_month02;
00093       const _CharT*         _M_month03;
00094       const _CharT*         _M_month04;
00095       const _CharT*         _M_month05;
00096       const _CharT*         _M_month06;
00097       const _CharT*         _M_month07;
00098       const _CharT*         _M_month08;
00099       const _CharT*         _M_month09;
00100       const _CharT*         _M_month10;
00101       const _CharT*         _M_month11;
00102       const _CharT*         _M_month12;
00103 
00104       // Abbreviated month names, starting with "C"'s Jan.
00105       const _CharT*         _M_amonth01;
00106       const _CharT*         _M_amonth02;
00107       const _CharT*         _M_amonth03;
00108       const _CharT*         _M_amonth04;
00109       const _CharT*         _M_amonth05;
00110       const _CharT*         _M_amonth06;
00111       const _CharT*         _M_amonth07;
00112       const _CharT*         _M_amonth08;
00113       const _CharT*         _M_amonth09;
00114       const _CharT*         _M_amonth10;
00115       const _CharT*         _M_amonth11;
00116       const _CharT*         _M_amonth12;
00117 
00118       bool              _M_allocated;
00119 
00120       __timepunct_cache(size_t __refs = 0) : facet(__refs),
00121       _M_date_format(NULL), _M_date_era_format(NULL), _M_time_format(NULL),
00122       _M_time_era_format(NULL), _M_date_time_format(NULL),
00123       _M_date_time_era_format(NULL), _M_am(NULL), _M_pm(NULL),
00124       _M_am_pm_format(NULL), _M_day1(NULL), _M_day2(NULL), _M_day3(NULL),
00125       _M_day4(NULL), _M_day5(NULL), _M_day6(NULL), _M_day7(NULL),
00126       _M_aday1(NULL), _M_aday2(NULL), _M_aday3(NULL), _M_aday4(NULL),
00127       _M_aday5(NULL), _M_aday6(NULL), _M_aday7(NULL), _M_month01(NULL),
00128       _M_month02(NULL), _M_month03(NULL), _M_month04(NULL), _M_month05(NULL),
00129       _M_month06(NULL), _M_month07(NULL), _M_month08(NULL), _M_month09(NULL),
00130       _M_month10(NULL), _M_month11(NULL), _M_month12(NULL), _M_amonth01(NULL),
00131       _M_amonth02(NULL), _M_amonth03(NULL), _M_amonth04(NULL),
00132       _M_amonth05(NULL), _M_amonth06(NULL), _M_amonth07(NULL),
00133       _M_amonth08(NULL), _M_amonth09(NULL), _M_amonth10(NULL),
00134       _M_amonth11(NULL), _M_amonth12(NULL), _M_allocated(false)
00135       { }
00136 
00137       ~__timepunct_cache();
00138 
00139       void
00140       _M_cache(const locale& __loc);
00141 
00142     private:
00143       __timepunct_cache&
00144       operator=(const __timepunct_cache&);
00145       
00146       explicit
00147       __timepunct_cache(const __timepunct_cache&);
00148     };
00149 
00150   template<typename _CharT>
00151     __timepunct_cache<_CharT>::~__timepunct_cache()
00152     {
00153       if (_M_allocated)
00154     {
00155       // Unused.
00156     }
00157     }
00158 
00159   // Specializations.
00160   template<>
00161     const char*
00162     __timepunct_cache<char>::_S_timezones[14];
00163 
00164 #ifdef _GLIBCXX_USE_WCHAR_T
00165   template<>
00166     const wchar_t*
00167     __timepunct_cache<wchar_t>::_S_timezones[14];
00168 #endif
00169 
00170   // Generic.
00171   template<typename _CharT>
00172     const _CharT* __timepunct_cache<_CharT>::_S_timezones[14];
00173 
00174   template<typename _CharT>
00175     class __timepunct : public locale::facet
00176     {
00177     public:
00178       // Types:
00179       typedef _CharT            __char_type;
00180       typedef basic_string<_CharT>  __string_type;
00181       typedef __timepunct_cache<_CharT> __cache_type;
00182 
00183     protected:
00184       __cache_type*         _M_data;
00185       __c_locale            _M_c_locale_timepunct;
00186       const char*           _M_name_timepunct;
00187 
00188     public:
00189       /// Numpunct facet id.
00190       static locale::id         id;
00191 
00192       explicit
00193       __timepunct(size_t __refs = 0);
00194 
00195       explicit
00196       __timepunct(__cache_type* __cache, size_t __refs = 0);
00197 
00198       /**
00199        *  @brief  Internal constructor. Not for general use.
00200        *
00201        *  This is a constructor for use by the library itself to set up new
00202        *  locales.
00203        *
00204        *  @param cloc  The C locale.
00205        *  @param s  The name of a locale.
00206        *  @param refs  Passed to the base facet class.
00207       */
00208       explicit
00209       __timepunct(__c_locale __cloc, const char* __s, size_t __refs = 0);
00210 
00211       // FIXME: for error checking purposes _M_put should return the return
00212       // value of strftime/wcsftime.
00213       void
00214       _M_put(_CharT* __s, size_t __maxlen, const _CharT* __format,
00215          const tm* __tm) const throw ();
00216 
00217       void
00218       _M_date_formats(const _CharT** __date) const
00219       {
00220     // Always have default first.
00221     __date[0] = _M_data->_M_date_format;
00222     __date[1] = _M_data->_M_date_era_format;
00223       }
00224 
00225       void
00226       _M_time_formats(const _CharT** __time) const
00227       {
00228     // Always have default first.
00229     __time[0] = _M_data->_M_time_format;
00230     __time[1] = _M_data->_M_time_era_format;
00231       }
00232 
00233       void
00234       _M_date_time_formats(const _CharT** __dt) const
00235       {
00236     // Always have default first.
00237     __dt[0] = _M_data->_M_date_time_format;
00238     __dt[1] = _M_data->_M_date_time_era_format;
00239       }
00240 
00241       void
00242       _M_am_pm_format(const _CharT* __ampm) const
00243       { __ampm = _M_data->_M_am_pm_format; }
00244 
00245       void
00246       _M_am_pm(const _CharT** __ampm) const
00247       {
00248     __ampm[0] = _M_data->_M_am;
00249     __ampm[1] = _M_data->_M_pm;
00250       }
00251 
00252       void
00253       _M_days(const _CharT** __days) const
00254       {
00255     __days[0] = _M_data->_M_day1;
00256     __days[1] = _M_data->_M_day2;
00257     __days[2] = _M_data->_M_day3;
00258     __days[3] = _M_data->_M_day4;
00259     __days[4] = _M_data->_M_day5;
00260     __days[5] = _M_data->_M_day6;
00261     __days[6] = _M_data->_M_day7;
00262       }
00263 
00264       void
00265       _M_days_abbreviated(const _CharT** __days) const
00266       {
00267     __days[0] = _M_data->_M_aday1;
00268     __days[1] = _M_data->_M_aday2;
00269     __days[2] = _M_data->_M_aday3;
00270     __days[3] = _M_data->_M_aday4;
00271     __days[4] = _M_data->_M_aday5;
00272     __days[5] = _M_data->_M_aday6;
00273     __days[6] = _M_data->_M_aday7;
00274       }
00275 
00276       void
00277       _M_months(const _CharT** __months) const
00278       {
00279     __months[0] = _M_data->_M_month01;
00280     __months[1] = _M_data->_M_month02;
00281     __months[2] = _M_data->_M_month03;
00282     __months[3] = _M_data->_M_month04;
00283     __months[4] = _M_data->_M_month05;
00284     __months[5] = _M_data->_M_month06;
00285     __months[6] = _M_data->_M_month07;
00286     __months[7] = _M_data->_M_month08;
00287     __months[8] = _M_data->_M_month09;
00288     __months[9] = _M_data->_M_month10;
00289     __months[10] = _M_data->_M_month11;
00290     __months[11] = _M_data->_M_month12;
00291       }
00292 
00293       void
00294       _M_months_abbreviated(const _CharT** __months) const
00295       {
00296     __months[0] = _M_data->_M_amonth01;
00297     __months[1] = _M_data->_M_amonth02;
00298     __months[2] = _M_data->_M_amonth03;
00299     __months[3] = _M_data->_M_amonth04;
00300     __months[4] = _M_data->_M_amonth05;
00301     __months[5] = _M_data->_M_amonth06;
00302     __months[6] = _M_data->_M_amonth07;
00303     __months[7] = _M_data->_M_amonth08;
00304     __months[8] = _M_data->_M_amonth09;
00305     __months[9] = _M_data->_M_amonth10;
00306     __months[10] = _M_data->_M_amonth11;
00307     __months[11] = _M_data->_M_amonth12;
00308       }
00309 
00310     protected:
00311       virtual
00312       ~__timepunct();
00313 
00314       // For use at construction time only.
00315       void
00316       _M_initialize_timepunct(__c_locale __cloc = NULL);
00317     };
00318 
00319   template<typename _CharT>
00320     locale::id __timepunct<_CharT>::id;
00321 
00322   // Specializations.
00323   template<>
00324     void
00325     __timepunct<char>::_M_initialize_timepunct(__c_locale __cloc);
00326 
00327   template<>
00328     void
00329     __timepunct<char>::_M_put(char*, size_t, const char*, const tm*) const throw ();
00330 
00331 #ifdef _GLIBCXX_USE_WCHAR_T
00332   template<>
00333     void
00334     __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale __cloc);
00335 
00336   template<>
00337     void
00338     __timepunct<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*,
00339                  const tm*) const throw ();
00340 #endif
00341 
00342 _GLIBCXX_END_NAMESPACE
00343 
00344   // Include host and configuration specific timepunct functions.
00345   #include <bits/time_members.h>
00346 
00347 _GLIBCXX_BEGIN_NAMESPACE(std)
00348 
00349   /**
00350    *  @brief  Primary class template time_get.
00351    *  @ingroup locales
00352    *
00353    *  This facet encapsulates the code to parse and return a date or
00354    *  time from a string.  It is used by the istream numeric
00355    *  extraction operators.
00356    *
00357    *  The time_get template uses protected virtual functions to provide the
00358    *  actual results.  The public accessors forward the call to the virtual
00359    *  functions.  These virtual functions are hooks for developers to
00360    *  implement the behavior they require from the time_get facet.
00361   */
00362   template<typename _CharT, typename _InIter>
00363     class time_get : public locale::facet, public time_base
00364     {
00365     public:
00366       // Types:
00367       //@{
00368       /// Public typedefs
00369       typedef _CharT            char_type;
00370       typedef _InIter           iter_type;
00371       //@}
00372       typedef basic_string<_CharT>  __string_type;
00373 
00374       /// Numpunct facet id.
00375       static locale::id         id;
00376 
00377       /**
00378        *  @brief  Constructor performs initialization.
00379        *
00380        *  This is the constructor provided by the standard.
00381        *
00382        *  @param refs  Passed to the base facet class.
00383       */
00384       explicit
00385       time_get(size_t __refs = 0)
00386       : facet (__refs) { }
00387 
00388       /**
00389        *  @brief  Return preferred order of month, day, and year.
00390        *
00391        *  This function returns an enum from timebase::dateorder giving the
00392        *  preferred ordering if the format @a x given to time_put::put() only
00393        *  uses month, day, and year.  If the format @a x for the associated
00394        *  locale uses other fields, this function returns
00395        *  timebase::dateorder::noorder.
00396        *
00397        *  NOTE: The library always returns noorder at the moment.
00398        *
00399        *  @return  A member of timebase::dateorder.
00400       */
00401       dateorder
00402       date_order()  const
00403       { return this->do_date_order(); }
00404 
00405       /**
00406        *  @brief  Parse input time string.
00407        *
00408        *  This function parses a time according to the format @a x and puts the
00409        *  results into a user-supplied struct tm.  The result is returned by
00410        *  calling time_get::do_get_time().
00411        *
00412        *  If there is a valid time string according to format @a x, @a tm will
00413        *  be filled in accordingly and the returned iterator will point to the
00414        *  first character beyond the time string.  If an error occurs before
00415        *  the end, err |= ios_base::failbit.  If parsing reads all the
00416        *  characters, err |= ios_base::eofbit.
00417        *
00418        *  @param  beg  Start of string to parse.
00419        *  @param  end  End of string to parse.
00420        *  @param  io  Source of the locale.
00421        *  @param  err  Error flags to set.
00422        *  @param  tm  Pointer to struct tm to fill in.
00423        *  @return  Iterator to first char beyond time string.
00424       */
00425       iter_type
00426       get_time(iter_type __beg, iter_type __end, ios_base& __io,
00427            ios_base::iostate& __err, tm* __tm)  const
00428       { return this->do_get_time(__beg, __end, __io, __err, __tm); }
00429 
00430       /**
00431        *  @brief  Parse input date string.
00432        *
00433        *  This function parses a date according to the format @a X and puts the
00434        *  results into a user-supplied struct tm.  The result is returned by
00435        *  calling time_get::do_get_date().
00436        *
00437        *  If there is a valid date string according to format @a X, @a tm will
00438        *  be filled in accordingly and the returned iterator will point to the
00439        *  first character beyond the date string.  If an error occurs before
00440        *  the end, err |= ios_base::failbit.  If parsing reads all the
00441        *  characters, err |= ios_base::eofbit.
00442        *
00443        *  @param  beg  Start of string to parse.
00444        *  @param  end  End of string to parse.
00445        *  @param  io  Source of the locale.
00446        *  @param  err  Error flags to set.
00447        *  @param  tm  Pointer to struct tm to fill in.
00448        *  @return  Iterator to first char beyond date string.
00449       */
00450       iter_type
00451       get_date(iter_type __beg, iter_type __end, ios_base& __io,
00452            ios_base::iostate& __err, tm* __tm)  const
00453       { return this->do_get_date(__beg, __end, __io, __err, __tm); }
00454 
00455       /**
00456        *  @brief  Parse input weekday string.
00457        *
00458        *  This function parses a weekday name and puts the results into a
00459        *  user-supplied struct tm.  The result is returned by calling
00460        *  time_get::do_get_weekday().
00461        *
00462        *  Parsing starts by parsing an abbreviated weekday name.  If a valid
00463        *  abbreviation is followed by a character that would lead to the full
00464        *  weekday name, parsing continues until the full name is found or an
00465        *  error occurs.  Otherwise parsing finishes at the end of the
00466        *  abbreviated name.
00467        *
00468        *  If an error occurs before the end, err |= ios_base::failbit.  If
00469        *  parsing reads all the characters, err |= ios_base::eofbit.
00470        *
00471        *  @param  beg  Start of string to parse.
00472        *  @param  end  End of string to parse.
00473        *  @param  io  Source of the locale.
00474        *  @param  err  Error flags to set.
00475        *  @param  tm  Pointer to struct tm to fill in.
00476        *  @return  Iterator to first char beyond weekday name.
00477       */
00478       iter_type
00479       get_weekday(iter_type __beg, iter_type __end, ios_base& __io,
00480           ios_base::iostate& __err, tm* __tm) const
00481       { return this->do_get_weekday(__beg, __end, __io, __err, __tm); }
00482 
00483       /**
00484        *  @brief  Parse input month string.
00485        *
00486        *  This function parses a month name and puts the results into a
00487        *  user-supplied struct tm.  The result is returned by calling
00488        *  time_get::do_get_monthname().
00489        *
00490        *  Parsing starts by parsing an abbreviated month name.  If a valid
00491        *  abbreviation is followed by a character that would lead to the full
00492        *  month name, parsing continues until the full name is found or an
00493        *  error occurs.  Otherwise parsing finishes at the end of the
00494        *  abbreviated name.
00495        *
00496        *  If an error occurs before the end, err |= ios_base::failbit.  If
00497        *  parsing reads all the characters, err |=
00498        *  ios_base::eofbit.
00499        *
00500        *  @param  beg  Start of string to parse.
00501        *  @param  end  End of string to parse.
00502        *  @param  io  Source of the locale.
00503        *  @param  err  Error flags to set.
00504        *  @param  tm  Pointer to struct tm to fill in.
00505        *  @return  Iterator to first char beyond month name.
00506       */
00507       iter_type
00508       get_monthname(iter_type __beg, iter_type __end, ios_base& __io,
00509             ios_base::iostate& __err, tm* __tm) const
00510       { return this->do_get_monthname(__beg, __end, __io, __err, __tm); }
00511 
00512       /**
00513        *  @brief  Parse input year string.
00514        *
00515        *  This function reads up to 4 characters to parse a year string and
00516        *  puts the results into a user-supplied struct tm.  The result is
00517        *  returned by calling time_get::do_get_year().
00518        *
00519        *  4 consecutive digits are interpreted as a full year.  If there are
00520        *  exactly 2 consecutive digits, the library interprets this as the
00521        *  number of years since 1900.
00522        *
00523        *  If an error occurs before the end, err |= ios_base::failbit.  If
00524        *  parsing reads all the characters, err |= ios_base::eofbit.
00525        *
00526        *  @param  beg  Start of string to parse.
00527        *  @param  end  End of string to parse.
00528        *  @param  io  Source of the locale.
00529        *  @param  err  Error flags to set.
00530        *  @param  tm  Pointer to struct tm to fill in.
00531        *  @return  Iterator to first char beyond year.
00532       */
00533       iter_type
00534       get_year(iter_type __beg, iter_type __end, ios_base& __io,
00535            ios_base::iostate& __err, tm* __tm) const
00536       { return this->do_get_year(__beg, __end, __io, __err, __tm); }
00537 
00538     protected:
00539       /// Destructor.
00540       virtual
00541       ~time_get() { }
00542 
00543       /**
00544        *  @brief  Return preferred order of month, day, and year.
00545        *
00546        *  This function returns an enum from timebase::dateorder giving the
00547        *  preferred ordering if the format @a x given to time_put::put() only
00548        *  uses month, day, and year.  This function is a hook for derived
00549        *  classes to change the value returned.
00550        *
00551        *  @return  A member of timebase::dateorder.
00552       */
00553       virtual dateorder
00554       do_date_order() const;
00555 
00556       /**
00557        *  @brief  Parse input time string.
00558        *
00559        *  This function parses a time according to the format @a x and puts the
00560        *  results into a user-supplied struct tm.  This function is a hook for
00561        *  derived classes to change the value returned.  @see get_time() for
00562        *  details.
00563        *
00564        *  @param  beg  Start of string to parse.
00565        *  @param  end  End of string to parse.
00566        *  @param  io  Source of the locale.
00567        *  @param  err  Error flags to set.
00568        *  @param  tm  Pointer to struct tm to fill in.
00569        *  @return  Iterator to first char beyond time string.
00570       */
00571       virtual iter_type
00572       do_get_time(iter_type __beg, iter_type __end, ios_base& __io,
00573           ios_base::iostate& __err, tm* __tm) const;
00574 
00575       /**
00576        *  @brief  Parse input date string.
00577        *
00578        *  This function parses a date according to the format @a X and puts the
00579        *  results into a user-supplied struct tm.  This function is a hook for
00580        *  derived classes to change the value returned.  @see get_date() for
00581        *  details.
00582        *
00583        *  @param  beg  Start of string to parse.
00584        *  @param  end  End of string to parse.
00585        *  @param  io  Source of the locale.
00586        *  @param  err  Error flags to set.
00587        *  @param  tm  Pointer to struct tm to fill in.
00588        *  @return  Iterator to first char beyond date string.
00589       */
00590       virtual iter_type
00591       do_get_date(iter_type __beg, iter_type __end, ios_base& __io,
00592           ios_base::iostate& __err, tm* __tm) const;
00593 
00594       /**
00595        *  @brief  Parse input weekday string.
00596        *
00597        *  This function parses a weekday name and puts the results into a
00598        *  user-supplied struct tm.  This function is a hook for derived
00599        *  classes to change the value returned.  @see get_weekday() for
00600        *  details.
00601        *
00602        *  @param  beg  Start of string to parse.
00603        *  @param  end  End of string to parse.
00604        *  @param  io  Source of the locale.
00605        *  @param  err  Error flags to set.
00606        *  @param  tm  Pointer to struct tm to fill in.
00607        *  @return  Iterator to first char beyond weekday name.
00608       */
00609       virtual iter_type
00610       do_get_weekday(iter_type __beg, iter_type __end, ios_base&,
00611              ios_base::iostate& __err, tm* __tm) const;
00612 
00613       /**
00614        *  @brief  Parse input month string.
00615        *
00616        *  This function parses a month name and puts the results into a
00617        *  user-supplied struct tm.  This function is a hook for derived
00618        *  classes to change the value returned.  @see get_monthname() for
00619        *  details.
00620        *
00621        *  @param  beg  Start of string to parse.
00622        *  @param  end  End of string to parse.
00623        *  @param  io  Source of the locale.
00624        *  @param  err  Error flags to set.
00625        *  @param  tm  Pointer to struct tm to fill in.
00626        *  @return  Iterator to first char beyond month name.
00627       */
00628       virtual iter_type
00629       do_get_monthname(iter_type __beg, iter_type __end, ios_base&,
00630                ios_base::iostate& __err, tm* __tm) const;
00631 
00632       /**
00633        *  @brief  Parse input year string.
00634        *
00635        *  This function reads up to 4 characters to parse a year string and
00636        *  puts the results into a user-supplied struct tm.  This function is a
00637        *  hook for derived classes to change the value returned.  @see
00638        *  get_year() for details.
00639        *
00640        *  @param  beg  Start of string to parse.
00641        *  @param  end  End of string to parse.
00642        *  @param  io  Source of the locale.
00643        *  @param  err  Error flags to set.
00644        *  @param  tm  Pointer to struct tm to fill in.
00645        *  @return  Iterator to first char beyond year.
00646       */
00647       virtual iter_type
00648       do_get_year(iter_type __beg, iter_type __end, ios_base& __io,
00649           ios_base::iostate& __err, tm* __tm) const;
00650 
00651       // Extract numeric component of length __len.
00652       iter_type
00653       _M_extract_num(iter_type __beg, iter_type __end, int& __member,
00654              int __min, int __max, size_t __len,
00655              ios_base& __io, ios_base::iostate& __err) const;
00656 
00657       // Extract any unique array of string literals in a const _CharT* array.
00658       iter_type
00659       _M_extract_name(iter_type __beg, iter_type __end, int& __member,
00660               const _CharT** __names, size_t __indexlen,
00661               ios_base& __io, ios_base::iostate& __err) const;
00662 
00663       // Extract day or month name in a const _CharT* array.
00664       iter_type
00665       _M_extract_wday_or_month(iter_type __beg, iter_type __end, int& __member,
00666                    const _CharT** __names, size_t __indexlen,
00667                    ios_base& __io, ios_base::iostate& __err) const;
00668 
00669       // Extract on a component-by-component basis, via __format argument.
00670       iter_type
00671       _M_extract_via_format(iter_type __beg, iter_type __end, ios_base& __io,
00672                 ios_base::iostate& __err, tm* __tm,
00673                 const _CharT* __format) const;
00674     };
00675 
00676   template<typename _CharT, typename _InIter>
00677     locale::id time_get<_CharT, _InIter>::id;
00678 
00679   /// class time_get_byname [22.2.5.2].
00680   template<typename _CharT, typename _InIter>
00681     class time_get_byname : public time_get<_CharT, _InIter>
00682     {
00683     public:
00684       // Types:
00685       typedef _CharT            char_type;
00686       typedef _InIter           iter_type;
00687 
00688       explicit
00689       time_get_byname(const char*, size_t __refs = 0)
00690       : time_get<_CharT, _InIter>(__refs) { }
00691 
00692     protected:
00693       virtual
00694       ~time_get_byname() { }
00695     };
00696 
00697   /**
00698    *  @brief  Primary class template time_put.
00699    *  @ingroup locales
00700    *
00701    *  This facet encapsulates the code to format and output dates and times
00702    *  according to formats used by strftime().
00703    *
00704    *  The time_put template uses protected virtual functions to provide the
00705    *  actual results.  The public accessors forward the call to the virtual
00706    *  functions.  These virtual functions are hooks for developers to
00707    *  implement the behavior they require from the time_put facet.
00708   */
00709   template<typename _CharT, typename _OutIter>
00710     class time_put : public locale::facet
00711     {
00712     public:
00713       // Types:
00714       //@{
00715       /// Public typedefs
00716       typedef _CharT            char_type;
00717       typedef _OutIter          iter_type;
00718       //@}
00719 
00720       /// Numpunct facet id.
00721       static locale::id         id;
00722 
00723       /**
00724        *  @brief  Constructor performs initialization.
00725        *
00726        *  This is the constructor provided by the standard.
00727        *
00728        *  @param refs  Passed to the base facet class.
00729       */
00730       explicit
00731       time_put(size_t __refs = 0)
00732       : facet(__refs) { }
00733 
00734       /**
00735        *  @brief  Format and output a time or date.
00736        *
00737        *  This function formats the data in struct tm according to the
00738        *  provided format string.  The format string is interpreted as by
00739        *  strftime().
00740        *
00741        *  @param  s  The stream to write to.
00742        *  @param  io  Source of locale.
00743        *  @param  fill  char_type to use for padding.
00744        *  @param  tm  Struct tm with date and time info to format.
00745        *  @param  beg  Start of format string.
00746        *  @param  end  End of format string.
00747        *  @return  Iterator after writing.
00748        */
00749       iter_type
00750       put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
00751       const _CharT* __beg, const _CharT* __end) const;
00752 
00753       /**
00754        *  @brief  Format and output a time or date.
00755        *
00756        *  This function formats the data in struct tm according to the
00757        *  provided format char and optional modifier.  The format and modifier
00758        *  are interpreted as by strftime().  It does so by returning
00759        *  time_put::do_put().
00760        *
00761        *  @param  s  The stream to write to.
00762        *  @param  io  Source of locale.
00763        *  @param  fill  char_type to use for padding.
00764        *  @param  tm  Struct tm with date and time info to format.
00765        *  @param  format  Format char.
00766        *  @param  mod  Optional modifier char.
00767        *  @return  Iterator after writing.
00768        */
00769       iter_type
00770       put(iter_type __s, ios_base& __io, char_type __fill,
00771       const tm* __tm, char __format, char __mod = 0) const
00772       { return this->do_put(__s, __io, __fill, __tm, __format, __mod); }
00773 
00774     protected:
00775       /// Destructor.
00776       virtual
00777       ~time_put()
00778       { }
00779 
00780       /**
00781        *  @brief  Format and output a time or date.
00782        *
00783        *  This function formats the data in struct tm according to the
00784        *  provided format char and optional modifier.  This function is a hook
00785        *  for derived classes to change the value returned.  @see put() for
00786        *  more details.
00787        *
00788        *  @param  s  The stream to write to.
00789        *  @param  io  Source of locale.
00790        *  @param  fill  char_type to use for padding.
00791        *  @param  tm  Struct tm with date and time info to format.
00792        *  @param  format  Format char.
00793        *  @param  mod  Optional modifier char.
00794        *  @return  Iterator after writing.
00795        */
00796       virtual iter_type
00797       do_put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
00798          char __format, char __mod) const;
00799     };
00800 
00801   template<typename _CharT, typename _OutIter>
00802     locale::id time_put<_CharT, _OutIter>::id;
00803 
00804   /// class time_put_byname [22.2.5.4].
00805   template<typename _CharT, typename _OutIter>
00806     class time_put_byname : public time_put<_CharT, _OutIter>
00807     {
00808     public:
00809       // Types:
00810       typedef _CharT            char_type;
00811       typedef _OutIter          iter_type;
00812 
00813       explicit
00814       time_put_byname(const char*, size_t __refs = 0)
00815       : time_put<_CharT, _OutIter>(__refs)
00816       { };
00817 
00818     protected:
00819       virtual
00820       ~time_put_byname() { }
00821     };
00822 
00823 
00824   /**
00825    *  @brief  Money format ordering data.
00826    *  @ingroup locales
00827    *
00828    *  This class contains an ordered array of 4 fields to represent the
00829    *  pattern for formatting a money amount.  Each field may contain one entry
00830    *  from the part enum.  symbol, sign, and value must be present and the
00831    *  remaining field must contain either none or space.  @see
00832    *  moneypunct::pos_format() and moneypunct::neg_format() for details of how
00833    *  these fields are interpreted.
00834   */
00835   class money_base
00836   {
00837   public:
00838     enum part { none, space, symbol, sign, value };
00839     struct pattern { char field[4]; };
00840 
00841     static const pattern _S_default_pattern;
00842 
00843     enum
00844     {
00845       _S_minus,
00846       _S_zero,
00847       _S_end = 11
00848     };
00849 
00850     // String literal of acceptable (narrow) input/output, for
00851     // money_get/money_put. "-0123456789"
00852     static const char* _S_atoms;
00853 
00854     // Construct and return valid pattern consisting of some combination of:
00855     // space none symbol sign value
00856     _GLIBCXX_CONST static pattern
00857     _S_construct_pattern(char __precedes, char __space, char __posn) throw ();
00858   };
00859 
00860   template<typename _CharT, bool _Intl>
00861     struct __moneypunct_cache : public locale::facet
00862     {
00863       const char*           _M_grouping;
00864       size_t                            _M_grouping_size;
00865       bool              _M_use_grouping;
00866       _CharT                _M_decimal_point;
00867       _CharT                _M_thousands_sep;
00868       const _CharT*         _M_curr_symbol;
00869       size_t                            _M_curr_symbol_size;
00870       const _CharT*         _M_positive_sign;
00871       size_t                            _M_positive_sign_size;
00872       const _CharT*         _M_negative_sign;
00873       size_t                            _M_negative_sign_size;
00874       int               _M_frac_digits;
00875       money_base::pattern       _M_pos_format;
00876       money_base::pattern           _M_neg_format;
00877 
00878       // A list of valid numeric literals for input and output: in the standard
00879       // "C" locale, this is "-0123456789". This array contains the chars after
00880       // having been passed through the current locale's ctype<_CharT>.widen().
00881       _CharT                _M_atoms[money_base::_S_end];
00882 
00883       bool              _M_allocated;
00884 
00885       __moneypunct_cache(size_t __refs = 0) : facet(__refs),
00886       _M_grouping(NULL), _M_grouping_size(0), _M_use_grouping(false),
00887       _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()),
00888       _M_curr_symbol(NULL), _M_curr_symbol_size(0),
00889       _M_positive_sign(NULL), _M_positive_sign_size(0),
00890       _M_negative_sign(NULL), _M_negative_sign_size(0),
00891       _M_frac_digits(0),
00892       _M_pos_format(money_base::pattern()),
00893       _M_neg_format(money_base::pattern()), _M_allocated(false)
00894       { }
00895 
00896       ~__moneypunct_cache();
00897 
00898       void
00899       _M_cache(const locale& __loc);
00900 
00901     private:
00902       __moneypunct_cache&
00903       operator=(const __moneypunct_cache&);
00904       
00905       explicit
00906       __moneypunct_cache(const __moneypunct_cache&);
00907     };
00908 
00909   template<typename _CharT, bool _Intl>
00910     __moneypunct_cache<_CharT, _Intl>::~__moneypunct_cache()
00911     {
00912       if (_M_allocated)
00913     {
00914       delete [] _M_grouping;
00915       delete [] _M_curr_symbol;
00916       delete [] _M_positive_sign;
00917       delete [] _M_negative_sign;
00918     }
00919     }
00920 
00921   /**
00922    *  @brief  Primary class template moneypunct.
00923    *  @ingroup locales
00924    *
00925    *  This facet encapsulates the punctuation, grouping and other formatting
00926    *  features of money amount string representations.
00927   */
00928   template<typename _CharT, bool _Intl>
00929     class moneypunct : public locale::facet, public money_base
00930     {
00931     public:
00932       // Types:
00933       //@{
00934       /// Public typedefs
00935       typedef _CharT            char_type;
00936       typedef basic_string<_CharT>  string_type;
00937       //@}
00938       typedef __moneypunct_cache<_CharT, _Intl>     __cache_type;
00939 
00940     private:
00941       __cache_type*         _M_data;
00942 
00943     public:
00944       /// This value is provided by the standard, but no reason for its
00945       /// existence.
00946       static const bool         intl = _Intl;
00947       /// Numpunct facet id.
00948       static locale::id         id;
00949 
00950       /**
00951        *  @brief  Constructor performs initialization.
00952        *
00953        *  This is the constructor provided by the standard.
00954        *
00955        *  @param refs  Passed to the base facet class.
00956       */
00957       explicit
00958       moneypunct(size_t __refs = 0) : facet(__refs), _M_data(NULL)
00959       { _M_initialize_moneypunct(); }
00960 
00961       /**
00962        *  @brief  Constructor performs initialization.
00963        *
00964        *  This is an internal constructor.
00965        *
00966        *  @param cache  Cache for optimization.
00967        *  @param refs  Passed to the base facet class.
00968       */
00969       explicit
00970       moneypunct(__cache_type* __cache, size_t __refs = 0)
00971       : facet(__refs), _M_data(__cache)
00972       { _M_initialize_moneypunct(); }
00973 
00974       /**
00975        *  @brief  Internal constructor. Not for general use.
00976        *
00977        *  This is a constructor for use by the library itself to set up new
00978        *  locales.
00979        *
00980        *  @param cloc  The C locale.
00981        *  @param s  The name of a locale.
00982        *  @param refs  Passed to the base facet class.
00983       */
00984       explicit
00985       moneypunct(__c_locale __cloc, const char* __s, size_t __refs = 0)
00986       : facet(__refs), _M_data(NULL)
00987       { _M_initialize_moneypunct(__cloc, __s); }
00988 
00989       /**
00990        *  @brief  Return decimal point character.
00991        *
00992        *  This function returns a char_type to use as a decimal point.  It
00993        *  does so by returning returning
00994        *  moneypunct<char_type>::do_decimal_point().
00995        *
00996        *  @return  @a char_type representing a decimal point.
00997       */
00998       char_type
00999       decimal_point() const
01000       { return this->do_decimal_point(); }
01001 
01002       /**
01003        *  @brief  Return thousands separator character.
01004        *
01005        *  This function returns a char_type to use as a thousands
01006        *  separator.  It does so by returning returning
01007        *  moneypunct<char_type>::do_thousands_sep().
01008        *
01009        *  @return  char_type representing a thousands separator.
01010       */
01011       char_type
01012       thousands_sep() const
01013       { return this->do_thousands_sep(); }
01014 
01015       /**
01016        *  @brief  Return grouping specification.
01017        *
01018        *  This function returns a string representing groupings for the
01019        *  integer part of an amount.  Groupings indicate where thousands
01020        *  separators should be inserted.
01021        *
01022        *  Each char in the return string is interpret as an integer rather
01023        *  than a character.  These numbers represent the number of digits in a
01024        *  group.  The first char in the string represents the number of digits
01025        *  in the least significant group.  If a char is negative, it indicates
01026        *  an unlimited number of digits for the group.  If more chars from the
01027        *  string are required to group a number, the last char is used
01028        *  repeatedly.
01029        *
01030        *  For example, if the grouping() returns <code>\003\002</code>
01031        *  and is applied to the number 123456789, this corresponds to
01032        *  12,34,56,789.  Note that if the string was <code>32</code>, this would
01033        *  put more than 50 digits into the least significant group if
01034        *  the character set is ASCII.
01035        *
01036        *  The string is returned by calling
01037        *  moneypunct<char_type>::do_grouping().
01038        *
01039        *  @return  string representing grouping specification.
01040       */
01041       string
01042       grouping() const
01043       { return this->do_grouping(); }
01044 
01045       /**
01046        *  @brief  Return currency symbol string.
01047        *
01048        *  This function returns a string_type to use as a currency symbol.  It
01049        *  does so by returning returning
01050        *  moneypunct<char_type>::do_curr_symbol().
01051        *
01052        *  @return  @a string_type representing a currency symbol.
01053       */
01054       string_type
01055       curr_symbol() const
01056       { return this->do_curr_symbol(); }
01057 
01058       /**
01059        *  @brief  Return positive sign string.
01060        *
01061        *  This function returns a string_type to use as a sign for positive
01062        *  amounts.  It does so by returning returning
01063        *  moneypunct<char_type>::do_positive_sign().
01064        *
01065        *  If the return value contains more than one character, the first
01066        *  character appears in the position indicated by pos_format() and the
01067        *  remainder appear at the end of the formatted string.
01068        *
01069        *  @return  @a string_type representing a positive sign.
01070       */
01071       string_type
01072       positive_sign() const
01073       { return this->do_positive_sign(); }
01074 
01075       /**
01076        *  @brief  Return negative sign string.
01077        *
01078        *  This function returns a string_type to use as a sign for negative
01079        *  amounts.  It does so by returning returning
01080        *  moneypunct<char_type>::do_negative_sign().
01081        *
01082        *  If the return value contains more than one character, the first
01083        *  character appears in the position indicated by neg_format() and the
01084        *  remainder appear at the end of the formatted string.
01085        *
01086        *  @return  @a string_type representing a negative sign.
01087       */
01088       string_type
01089       negative_sign() const
01090       { return this->do_negative_sign(); }
01091 
01092       /**
01093        *  @brief  Return number of digits in fraction.
01094        *
01095        *  This function returns the exact number of digits that make up the
01096        *  fractional part of a money amount.  It does so by returning
01097        *  returning moneypunct<char_type>::do_frac_digits().
01098        *
01099        *  The fractional part of a money amount is optional.  But if it is
01100        *  present, there must be frac_digits() digits.
01101        *
01102        *  @return  Number of digits in amount fraction.
01103       */
01104       int
01105       frac_digits() const
01106       { return this->do_frac_digits(); }
01107 
01108       //@{
01109       /**
01110        *  @brief  Return pattern for money values.
01111        *
01112        *  This function returns a pattern describing the formatting of a
01113        *  positive or negative valued money amount.  It does so by returning
01114        *  returning moneypunct<char_type>::do_pos_format() or
01115        *  moneypunct<char_type>::do_neg_format().
01116        *
01117        *  The pattern has 4 fields describing the ordering of symbol, sign,
01118        *  value, and none or space.  There must be one of each in the pattern.
01119        *  The none and space enums may not appear in the first field and space
01120        *  may not appear in the final field.
01121        *
01122        *  The parts of a money string must appear in the order indicated by
01123        *  the fields of the pattern.  The symbol field indicates that the
01124        *  value of curr_symbol() may be present.  The sign field indicates
01125        *  that the value of positive_sign() or negative_sign() must be
01126        *  present.  The value field indicates that the absolute value of the
01127        *  money amount is present.  none indicates 0 or more whitespace
01128        *  characters, except at the end, where it permits no whitespace.
01129        *  space indicates that 1 or more whitespace characters must be
01130        *  present.
01131        *
01132        *  For example, for the US locale and pos_format() pattern
01133        *  {symbol,sign,value,none}, curr_symbol() == &apos;$&apos;
01134        *  positive_sign() == &apos;+&apos;, and value 10.01, and
01135        *  options set to force the symbol, the corresponding string is
01136        *  <code>$+10.01</code>.
01137        *
01138        *  @return  Pattern for money values.
01139       */
01140       pattern
01141       pos_format() const
01142       { return this->do_pos_format(); }
01143 
01144       pattern
01145       neg_format() const
01146       { return this->do_neg_format(); }
01147       //@}
01148 
01149     protected:
01150       /// Destructor.
01151       virtual
01152       ~moneypunct();
01153 
01154       /**
01155        *  @brief  Return decimal point character.
01156        *
01157        *  Returns a char_type to use as a decimal point.  This function is a
01158        *  hook for derived classes to change the value returned.
01159        *
01160        *  @return  @a char_type representing a decimal point.
01161       */
01162       virtual char_type
01163       do_decimal_point() const
01164       { return _M_data->_M_decimal_point; }
01165 
01166       /**
01167        *  @brief  Return thousands separator character.
01168        *
01169        *  Returns a char_type to use as a thousands separator.  This function
01170        *  is a hook for derived classes to change the value returned.
01171        *
01172        *  @return  @a char_type representing a thousands separator.
01173       */
01174       virtual char_type
01175       do_thousands_sep() const
01176       { return _M_data->_M_thousands_sep; }
01177 
01178       /**
01179        *  @brief  Return grouping specification.
01180        *
01181        *  Returns a string representing groupings for the integer part of a
01182        *  number.  This function is a hook for derived classes to change the
01183        *  value returned.  @see grouping() for details.
01184        *
01185        *  @return  String representing grouping specification.
01186       */
01187       virtual string
01188       do_grouping() const
01189       { return _M_data->_M_grouping; }
01190 
01191       /**
01192        *  @brief  Return currency symbol string.
01193        *
01194        *  This function returns a string_type to use as a currency symbol.
01195        *  This function is a hook for derived classes to change the value
01196        *  returned.  @see curr_symbol() for details.
01197        *
01198        *  @return  @a string_type representing a currency symbol.
01199       */
01200       virtual string_type
01201       do_curr_symbol()   const
01202       { return _M_data->_M_curr_symbol; }
01203 
01204       /**
01205        *  @brief  Return positive sign string.
01206        *
01207        *  This function returns a string_type to use as a sign for positive
01208        *  amounts.  This function is a hook for derived classes to change the
01209        *  value returned.  @see positive_sign() for details.
01210        *
01211        *  @return  @a string_type representing a positive sign.
01212       */
01213       virtual string_type
01214       do_positive_sign() const
01215       { return _M_data->_M_positive_sign; }
01216 
01217       /**
01218        *  @brief  Return negative sign string.
01219        *
01220        *  This function returns a string_type to use as a sign for negative
01221        *  amounts.  This function is a hook for derived classes to change the
01222        *  value returned.  @see negative_sign() for details.
01223        *
01224        *  @return  @a string_type representing a negative sign.
01225       */
01226       virtual string_type
01227       do_negative_sign() const
01228       { return _M_data->_M_negative_sign; }
01229 
01230       /**
01231        *  @brief  Return number of digits in fraction.
01232        *
01233        *  This function returns the exact number of digits that make up the
01234        *  fractional part of a money amount.  This function is a hook for
01235        *  derived classes to change the value returned.  @see frac_digits()
01236        *  for details.
01237        *
01238        *  @return  Number of digits in amount fraction.
01239       */
01240       virtual int
01241       do_frac_digits() const
01242       { return _M_data->_M_frac_digits; }
01243 
01244       /**
01245        *  @brief  Return pattern for money values.
01246        *
01247        *  This function returns a pattern describing the formatting of a
01248        *  positive valued money amount.  This function is a hook for derived
01249        *  classes to change the value returned.  @see pos_format() for
01250        *  details.
01251        *
01252        *  @return  Pattern for money values.
01253       */
01254       virtual pattern
01255       do_pos_format() const
01256       { return _M_data->_M_pos_format; }
01257 
01258       /**
01259        *  @brief  Return pattern for money values.
01260        *
01261        *  This function returns a pattern describing the formatting of a
01262        *  negative valued money amount.  This function is a hook for derived
01263        *  classes to change the value returned.  @see neg_format() for
01264        *  details.
01265        *
01266        *  @return  Pattern for money values.
01267       */
01268       virtual pattern
01269       do_neg_format() const
01270       { return _M_data->_M_neg_format; }
01271 
01272       // For use at construction time only.
01273        void
01274        _M_initialize_moneypunct(__c_locale __cloc = NULL,
01275                 const char* __name = NULL);
01276     };
01277 
01278   template<typename _CharT, bool _Intl>
01279     locale::id moneypunct<_CharT, _Intl>::id;
01280 
01281   template<typename _CharT, bool _Intl>
01282     const bool moneypunct<_CharT, _Intl>::intl;
01283 
01284   template<>
01285     moneypunct<char, true>::~moneypunct();
01286 
01287   template<>
01288     moneypunct<char, false>::~moneypunct();
01289 
01290   template<>
01291     void
01292     moneypunct<char, true>::_M_initialize_moneypunct(__c_locale, const char*);
01293 
01294   template<>
01295     void
01296     moneypunct<char, false>::_M_initialize_moneypunct(__c_locale, const char*);
01297 
01298 #ifdef _GLIBCXX_USE_WCHAR_T
01299   template<>
01300     moneypunct<wchar_t, true>::~moneypunct();
01301 
01302   template<>
01303     moneypunct<wchar_t, false>::~moneypunct();
01304 
01305   template<>
01306     void
01307     moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale,
01308                             const char*);
01309 
01310   template<>
01311     void
01312     moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale,
01313                              const char*);
01314 #endif
01315 
01316   /// class moneypunct_byname [22.2.6.4].
01317   template<typename _CharT, bool _Intl>
01318     class moneypunct_byname : public moneypunct<_CharT, _Intl>
01319     {
01320     public:
01321       typedef _CharT            char_type;
01322       typedef basic_string<_CharT>  string_type;
01323 
01324       static const bool intl = _Intl;
01325 
01326       explicit
01327       moneypunct_byname(const char* __s, size_t __refs = 0)
01328       : moneypunct<_CharT, _Intl>(__refs)
01329       {
01330     if (__builtin_strcmp(__s, "C") != 0
01331         && __builtin_strcmp(__s, "POSIX") != 0)
01332       {
01333         __c_locale __tmp;
01334         this->_S_create_c_locale(__tmp, __s);
01335         this->_M_initialize_moneypunct(__tmp);
01336         this->_S_destroy_c_locale(__tmp);
01337       }
01338       }
01339 
01340     protected:
01341       virtual
01342       ~moneypunct_byname() { }
01343     };
01344 
01345   template<typename _CharT, bool _Intl>
01346     const bool moneypunct_byname<_CharT, _Intl>::intl;
01347 
01348 _GLIBCXX_BEGIN_LDBL_NAMESPACE
01349 
01350   /**
01351    *  @brief  Primary class template money_get.
01352    *  @ingroup locales
01353    *
01354    *  This facet encapsulates the code to parse and return a monetary
01355    *  amount from a string.
01356    *
01357    *  The money_get template uses protected virtual functions to
01358    *  provide the actual results.  The public accessors forward the
01359    *  call to the virtual functions.  These virtual functions are
01360    *  hooks for developers to implement the behavior they require from
01361    *  the money_get facet.
01362   */
01363   template<typename _CharT, typename _InIter>
01364     class money_get : public locale::facet
01365     {
01366     public:
01367       // Types:
01368       //@{
01369       /// Public typedefs
01370       typedef _CharT            char_type;
01371       typedef _InIter           iter_type;
01372       typedef basic_string<_CharT>  string_type;
01373       //@}
01374 
01375       /// Numpunct facet id.
01376       static locale::id         id;
01377 
01378       /**
01379        *  @brief  Constructor performs initialization.
01380        *
01381        *  This is the constructor provided by the standard.
01382        *
01383        *  @param refs  Passed to the base facet class.
01384       */
01385       explicit
01386       money_get(size_t __refs = 0) : facet(__refs) { }
01387 
01388       /**
01389        *  @brief  Read and parse a monetary value.
01390        *
01391        *  This function reads characters from @a s, interprets them as a
01392        *  monetary value according to moneypunct and ctype facets retrieved
01393        *  from io.getloc(), and returns the result in @a units as an integral
01394        *  value moneypunct::frac_digits() * the actual amount.  For example,
01395        *  the string $10.01 in a US locale would store 1001 in @a units.
01396        *
01397        *  Any characters not part of a valid money amount are not consumed.
01398        *
01399        *  If a money value cannot be parsed from the input stream, sets
01400        *  err=(err|io.failbit).  If the stream is consumed before finishing
01401        *  parsing,  sets err=(err|io.failbit|io.eofbit).  @a units is
01402        *  unchanged if parsing fails.
01403        *
01404        *  This function works by returning the result of do_get().
01405        *
01406        *  @param  s  Start of characters to parse.
01407        *  @param  end  End of characters to parse.
01408        *  @param  intl  Parameter to use_facet<moneypunct<CharT,intl> >.
01409        *  @param  io  Source of facets and io state.
01410        *  @param  err  Error field to set if parsing fails.
01411        *  @param  units  Place to store result of parsing.
01412        *  @return  Iterator referencing first character beyond valid money
01413        *       amount.
01414        */
01415       iter_type
01416       get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
01417       ios_base::iostate& __err, long double& __units) const
01418       { return this->do_get(__s, __end, __intl, __io, __err, __units); }
01419 
01420       /**
01421        *  @brief  Read and parse a monetary value.
01422        *
01423        *  This function reads characters from @a s, interprets them as
01424        *  a monetary value according to moneypunct and ctype facets
01425        *  retrieved from io.getloc(), and returns the result in @a
01426        *  digits.  For example, the string $10.01 in a US locale would
01427        *  store <code>1001</code> in @a digits.
01428        *
01429        *  Any characters not part of a valid money amount are not consumed.
01430        *
01431        *  If a money value cannot be parsed from the input stream, sets
01432        *  err=(err|io.failbit).  If the stream is consumed before finishing
01433        *  parsing,  sets err=(err|io.failbit|io.eofbit).
01434        *
01435        *  This function works by returning the result of do_get().
01436        *
01437        *  @param  s  Start of characters to parse.
01438        *  @param  end  End of characters to parse.
01439        *  @param  intl  Parameter to use_facet<moneypunct<CharT,intl> >.
01440        *  @param  io  Source of facets and io state.
01441        *  @param  err  Error field to set if parsing fails.
01442        *  @param  digits  Place to store result of parsing.
01443        *  @return  Iterator referencing first character beyond valid money
01444        *       amount.
01445        */
01446       iter_type
01447       get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
01448       ios_base::iostate& __err, string_type& __digits) const
01449       { return this->do_get(__s, __end, __intl, __io, __err, __digits); }
01450 
01451     protected:
01452       /// Destructor.
01453       virtual
01454       ~money_get() { }
01455 
01456       /**
01457        *  @brief  Read and parse a monetary value.
01458        *
01459        *  This function reads and parses characters representing a monetary
01460        *  value.  This function is a hook for derived classes to change the
01461        *  value returned.  @see get() for details.
01462        */
01463       // XXX GLIBCXX_ABI Deprecated
01464 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
01465       virtual iter_type
01466       __do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
01467            ios_base::iostate& __err, double& __units) const;
01468 #else
01469       virtual iter_type
01470       do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
01471          ios_base::iostate& __err, long double& __units) const;
01472 #endif
01473 
01474       /**
01475        *  @brief  Read and parse a monetary value.
01476        *
01477        *  This function reads and parses characters representing a monetary
01478        *  value.  This function is a hook for derived classes to change the
01479        *  value returned.  @see get() for details.
01480        */
01481       virtual iter_type
01482       do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
01483          ios_base::iostate& __err, string_type& __digits) const;
01484 
01485       // XXX GLIBCXX_ABI Deprecated
01486 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
01487       virtual iter_type
01488       do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
01489          ios_base::iostate& __err, long double& __units) const;
01490 #endif
01491 
01492       template<bool _Intl>
01493         iter_type
01494         _M_extract(iter_type __s, iter_type __end, ios_base& __io,
01495            ios_base::iostate& __err, string& __digits) const;     
01496     };
01497 
01498   template<typename _CharT, typename _InIter>
01499     locale::id money_get<_CharT, _InIter>::id;
01500 
01501   /**
01502    *  @brief  Primary class template money_put.
01503    *  @ingroup locales
01504    *
01505    *  This facet encapsulates the code to format and output a monetary
01506    *  amount.
01507    *
01508    *  The money_put template uses protected virtual functions to
01509    *  provide the actual results.  The public accessors forward the
01510    *  call to the virtual functions.  These virtual functions are
01511    *  hooks for developers to implement the behavior they require from
01512    *  the money_put facet.
01513   */
01514   template<typename _CharT, typename _OutIter>
01515     class money_put : public locale::facet
01516     {
01517     public:
01518       //@{
01519       /// Public typedefs
01520       typedef _CharT            char_type;
01521       typedef _OutIter          iter_type;
01522       typedef basic_string<_CharT>  string_type;
01523       //@}
01524 
01525       /// Numpunct facet id.
01526       static locale::id         id;
01527 
01528       /**
01529        *  @brief  Constructor performs initialization.
01530        *
01531        *  This is the constructor provided by the standard.
01532        *
01533        *  @param refs  Passed to the base facet class.
01534       */
01535       explicit
01536       money_put(size_t __refs = 0) : facet(__refs) { }
01537 
01538       /**
01539        *  @brief  Format and output a monetary value.
01540        *
01541        *  This function formats @a units as a monetary value according to
01542        *  moneypunct and ctype facets retrieved from io.getloc(), and writes
01543        *  the resulting characters to @a s.  For example, the value 1001 in a
01544        *  US locale would write <code>$10.01</code> to @a s.
01545        *
01546        *  This function works by returning the result of do_put().
01547        *
01548        *  @param  s  The stream to write to.
01549        *  @param  intl  Parameter to use_facet<moneypunct<CharT,intl> >.
01550        *  @param  io  Source of facets and io state.
01551        *  @param  fill  char_type to use for padding.
01552        *  @param  units  Place to store result of parsing.
01553        *  @return  Iterator after writing.
01554        */
01555       iter_type
01556       put(iter_type __s, bool __intl, ios_base& __io,
01557       char_type __fill, long double __units) const
01558       { return this->do_put(__s, __intl, __io, __fill, __units); }
01559 
01560       /**
01561        *  @brief  Format and output a monetary value.
01562        *
01563        *  This function formats @a digits as a monetary value
01564        *  according to moneypunct and ctype facets retrieved from
01565        *  io.getloc(), and writes the resulting characters to @a s.
01566        *  For example, the string <code>1001</code> in a US locale
01567        *  would write <code>$10.01</code> to @a s.
01568        *
01569        *  This function works by returning the result of do_put().
01570        *
01571        *  @param  s  The stream to write to.
01572        *  @param  intl  Parameter to use_facet<moneypunct<CharT,intl> >.
01573        *  @param  io  Source of facets and io state.
01574        *  @param  fill  char_type to use for padding.
01575        *  @param  units  Place to store result of parsing.
01576        *  @return  Iterator after writing.
01577        */
01578       iter_type
01579       put(iter_type __s, bool __intl, ios_base& __io,
01580       char_type __fill, const string_type& __digits) const
01581       { return this->do_put(__s, __intl, __io, __fill, __digits); }
01582 
01583     protected:
01584       /// Destructor.
01585       virtual
01586       ~money_put() { }
01587 
01588       /**
01589        *  @brief  Format and output a monetary value.
01590        *
01591        *  This function formats @a units as a monetary value according to
01592        *  moneypunct and ctype facets retrieved from io.getloc(), and writes
01593        *  the resulting characters to @a s.  For example, the value 1001 in a
01594        *  US locale would write <code>$10.01</code> to @a s.
01595        *
01596        *  This function is a hook for derived classes to change the value
01597        *  returned.  @see put().
01598        *
01599        *  @param  s  The stream to write to.
01600        *  @param  intl  Parameter to use_facet<moneypunct<CharT,intl> >.
01601        *  @param  io  Source of facets and io state.
01602        *  @param  fill  char_type to use for padding.
01603        *  @param  units  Place to store result of parsing.
01604        *  @return  Iterator after writing.
01605        */
01606       // XXX GLIBCXX_ABI Deprecated
01607 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
01608       virtual iter_type
01609       __do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
01610            double __units) const;
01611 #else
01612       virtual iter_type
01613       do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
01614          long double __units) const;
01615 #endif
01616 
01617       /**
01618        *  @brief  Format and output a monetary value.
01619        *
01620        *  This function formats @a digits as a monetary value
01621        *  according to moneypunct and ctype facets retrieved from
01622        *  io.getloc(), and writes the resulting characters to @a s.
01623        *  For example, the string <code>1001</code> in a US locale
01624        *  would write <code>$10.01</code> to @a s.
01625        *
01626        *  This function is a hook for derived classes to change the value
01627        *  returned.  @see put().
01628        *
01629        *  @param  s  The stream to write to.
01630        *  @param  intl  Parameter to use_facet<moneypunct<CharT,intl> >.
01631        *  @param  io  Source of facets and io state.
01632        *  @param  fill  char_type to use for padding.
01633        *  @param  units  Place to store result of parsing.
01634        *  @return  Iterator after writing.
01635        */
01636       virtual iter_type
01637       do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
01638          const string_type& __digits) const;
01639 
01640       // XXX GLIBCXX_ABI Deprecated
01641 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
01642       virtual iter_type
01643       do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
01644          long double __units) const;
01645 #endif
01646 
01647       template<bool _Intl>
01648         iter_type
01649         _M_insert(iter_type __s, ios_base& __io, char_type __fill,
01650           const string_type& __digits) const;
01651     };
01652 
01653   template<typename _CharT, typename _OutIter>
01654     locale::id money_put<_CharT, _OutIter>::id;
01655 
01656 _GLIBCXX_END_LDBL_NAMESPACE
01657 
01658   /**
01659    *  @brief  Messages facet base class providing catalog typedef.
01660    *  @ingroup locales
01661    */
01662   struct messages_base
01663   {
01664     typedef int catalog;
01665   };
01666 
01667   /**
01668    *  @brief  Primary class template messages.
01669    *  @ingroup locales
01670    *
01671    *  This facet encapsulates the code to retrieve messages from
01672    *  message catalogs.  The only thing defined by the standard for this facet
01673    *  is the interface.  All underlying functionality is
01674    *  implementation-defined.
01675    *
01676    *  This library currently implements 3 versions of the message facet.  The
01677    *  first version (gnu) is a wrapper around gettext, provided by libintl.
01678    *  The second version (ieee) is a wrapper around catgets.  The final
01679    *  version (default) does no actual translation.  These implementations are
01680    *  only provided for char and wchar_t instantiations.
01681    *
01682    *  The messages template uses protected virtual functions to
01683    *  provide the actual results.  The public accessors forward the
01684    *  call to the virtual functions.  These virtual functions are
01685    *  hooks for developers to implement the behavior they require from
01686    *  the messages facet.
01687   */
01688   template<typename _CharT>
01689     class messages : public locale::facet, public messages_base
01690     {
01691     public:
01692       // Types:
01693       //@{
01694       /// Public typedefs
01695       typedef _CharT            char_type;
01696       typedef basic_string<_CharT>  string_type;
01697       //@}
01698 
01699     protected:
01700       // Underlying "C" library locale information saved from
01701       // initialization, needed by messages_byname as well.
01702       __c_locale            _M_c_locale_messages;
01703       const char*           _M_name_messages;
01704 
01705     public:
01706       /// Numpunct facet id.
01707       static locale::id         id;
01708 
01709       /**
01710        *  @brief  Constructor performs initialization.
01711        *
01712        *  This is the constructor provided by the standard.
01713        *
01714        *  @param refs  Passed to the base facet class.
01715       */
01716       explicit
01717       messages(size_t __refs = 0);
01718 
01719       // Non-standard.
01720       /**
01721        *  @brief  Internal constructor.  Not for general use.
01722        *
01723        *  This is a constructor for use by the library itself to set up new
01724        *  locales.
01725        *
01726        *  @param  cloc  The C locale.
01727        *  @param  s  The name of a locale.
01728        *  @param  refs  Refcount to pass to the base class.
01729        */
01730       explicit
01731       messages(__c_locale __cloc, const char* __s, size_t __refs = 0);
01732 
01733       /*
01734        *  @brief  Open a message catalog.
01735        *
01736        *  This function opens and returns a handle to a message catalog by
01737        *  returning do_open(s, loc).
01738        *
01739        *  @param  s  The catalog to open.
01740        *  @param  loc  Locale to use for character set conversions.
01741        *  @return  Handle to the catalog or value < 0 if open fails.
01742       */
01743       catalog
01744       open(const basic_string<char>& __s, const locale& __loc) const
01745       { return this->do_open(__s, __loc); }
01746 
01747       // Non-standard and unorthodox, yet effective.
01748       /*
01749        *  @brief  Open a message catalog.
01750        *
01751        *  This non-standard function opens and returns a handle to a message
01752        *  catalog by returning do_open(s, loc).  The third argument provides a
01753        *  message catalog root directory for gnu gettext and is ignored
01754        *  otherwise.
01755        *
01756        *  @param  s  The catalog to open.
01757        *  @param  loc  Locale to use for character set conversions.
01758        *  @param  dir  Message catalog root directory.
01759        *  @return  Handle to the catalog or value < 0 if open fails.
01760       */
01761       catalog
01762       open(const basic_string<char>&, const locale&, const char*) const;
01763 
01764       /*
01765        *  @brief  Look up a string in a message catalog.
01766        *
01767        *  This function retrieves and returns a message from a catalog by
01768        *  returning do_get(c, set, msgid, s).
01769        *
01770        *  For gnu, @a set and @a msgid are ignored.  Returns gettext(s).
01771        *  For default, returns s. For ieee, returns catgets(c,set,msgid,s).
01772        *
01773        *  @param  c  The catalog to access.
01774        *  @param  set  Implementation-defined.
01775        *  @param  msgid  Implementation-defined.
01776        *  @param  s  Default return value if retrieval fails.
01777        *  @return  Retrieved message or @a s if get fails.
01778       */
01779       string_type
01780       get(catalog __c, int __set, int __msgid, const string_type& __s) const
01781       { return this->do_get(__c, __set, __msgid, __s); }
01782 
01783       /*
01784        *  @brief  Close a message catalog.
01785        *
01786        *  Closes catalog @a c by calling do_close(c).
01787        *
01788        *  @param  c  The catalog to close.
01789       */
01790       void
01791       close(catalog __c) const
01792       { return this->do_close(__c); }
01793 
01794     protected:
01795       /// Destructor.
01796       virtual
01797       ~messages();
01798 
01799       /*
01800        *  @brief  Open a message catalog.
01801        *
01802        *  This function opens and returns a handle to a message catalog in an
01803        *  implementation-defined manner.  This function is a hook for derived
01804        *  classes to change the value returned.
01805        *
01806        *  @param  s  The catalog to open.
01807        *  @param  loc  Locale to use for character set conversions.
01808        *  @return  Handle to the opened catalog, value < 0 if open failed.
01809       */
01810       virtual catalog
01811       do_open(const basic_string<char>&, const locale&) const;
01812 
01813       /*
01814        *  @brief  Look up a string in a message catalog.
01815        *
01816        *  This function retrieves and returns a message from a catalog in an
01817        *  implementation-defined manner.  This function is a hook for derived
01818        *  classes to change the value returned.
01819        *
01820        *  For gnu, @a set and @a msgid are ignored.  Returns gettext(s).
01821        *  For default, returns s. For ieee, returns catgets(c,set,msgid,s).
01822        *
01823        *  @param  c  The catalog to access.
01824        *  @param  set  Implementation-defined.
01825        *  @param  msgid  Implementation-defined.
01826        *  @param  s  Default return value if retrieval fails.
01827        *  @return  Retrieved message or @a s if get fails.
01828       */
01829       virtual string_type
01830       do_get(catalog, int, int, const string_type& __dfault) const;
01831 
01832       /*
01833        *  @brief  Close a message catalog.
01834        *
01835        *  @param  c  The catalog to close.
01836       */
01837       virtual void
01838       do_close(catalog) const;
01839 
01840       // Returns a locale and codeset-converted string, given a char* message.
01841       char*
01842       _M_convert_to_char(const string_type& __msg) const
01843       {
01844     // XXX
01845     return reinterpret_cast<char*>(const_cast<_CharT*>(__msg.c_str()));
01846       }
01847 
01848       // Returns a locale and codeset-converted string, given a char* message.
01849       string_type
01850       _M_convert_from_char(char*) const
01851       {
01852 #if 0
01853     // Length of message string without terminating null.
01854     size_t __len = char_traits<char>::length(__msg) - 1;
01855 
01856     // "everybody can easily convert the string using
01857     // mbsrtowcs/wcsrtombs or with iconv()"
01858 
01859     // Convert char* to _CharT in locale used to open catalog.
01860     // XXX need additional template parameter on messages class for this..
01861     // typedef typename codecvt<char, _CharT, _StateT> __codecvt_type;
01862     typedef typename codecvt<char, _CharT, mbstate_t> __codecvt_type;
01863 
01864     __codecvt_type::state_type __state;
01865     // XXX may need to initialize state.
01866     //initialize_state(__state._M_init());
01867 
01868     char* __from_next;
01869     // XXX what size for this string?
01870     _CharT* __to = static_cast<_CharT*>(__builtin_alloca(__len + 1));
01871     const __codecvt_type& __cvt = use_facet<__codecvt_type>(_M_locale_conv);
01872     __cvt.out(__state, __msg, __msg + __len, __from_next,
01873           __to, __to + __len + 1, __to_next);
01874     return string_type(__to);
01875 #endif
01876 #if 0
01877     typedef ctype<_CharT> __ctype_type;
01878     // const __ctype_type& __cvt = use_facet<__ctype_type>(_M_locale_msg);
01879     const __ctype_type& __cvt = use_facet<__ctype_type>(locale());
01880     // XXX Again, proper length of converted string an issue here.
01881     // For now, assume the converted length is not larger.
01882     _CharT* __dest = static_cast<_CharT*>(__builtin_alloca(__len + 1));
01883     __cvt.widen(__msg, __msg + __len, __dest);
01884     return basic_string<_CharT>(__dest);
01885 #endif
01886     return string_type();
01887       }
01888      };
01889 
01890   template<typename _CharT>
01891     locale::id messages<_CharT>::id;
01892 
01893   /// Specializations for required instantiations.
01894   template<>
01895     string
01896     messages<char>::do_get(catalog, int, int, const string&) const;
01897 
01898 #ifdef _GLIBCXX_USE_WCHAR_T
01899   template<>
01900     wstring
01901     messages<wchar_t>::do_get(catalog, int, int, const wstring&) const;
01902 #endif
01903 
01904    /// class messages_byname [22.2.7.2].
01905    template<typename _CharT>
01906     class messages_byname : public messages<_CharT>
01907     {
01908     public:
01909       typedef _CharT            char_type;
01910       typedef basic_string<_CharT>  string_type;
01911 
01912       explicit
01913       messages_byname(const char* __s, size_t __refs = 0);
01914 
01915     protected:
01916       virtual
01917       ~messages_byname()
01918       { }
01919     };
01920 
01921 _GLIBCXX_END_NAMESPACE
01922 
01923 // Include host and configuration specific messages functions.
01924 #include <bits/messages_members.h>
01925 
01926 // 22.2.1.5  Template class codecvt
01927 #include <bits/codecvt.h>
01928 
01929 #ifndef _GLIBCXX_EXPORT_TEMPLATE
01930 # include <bits/locale_facets_nonio.tcc>
01931 #endif
01932 
01933 #endif