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