OSDN Git Service

2004-03-23 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / bits / locale_facets.h
index 889c778..453ba78 100644 (file)
@@ -1451,14 +1451,15 @@ namespace std
       /**
        *  @brief  Narrow wchar_t to char
        *
-       *  This virtual function converts the argument to char using the
-       *  simplest reasonable transformation.  If the conversion fails, dfault
-       *  is returned instead.  For an underived ctype<wchar_t> facet, @a c will
-       *  be cast to char and returned.
+       *  This virtual function converts the argument to char using
+       *  the simplest reasonable transformation.  If the conversion
+       *  fails, dfault is returned instead.  For an underived
+       *  ctype<wchar_t> facet, @a c will be cast to char and
+       *  returned.
        *
-       *  do_narrow() is a hook for a derived facet to change the behavior of
-       *  narrowing.  do_narrow() must always return the same result for the
-       *  same input.
+       *  do_narrow() is a hook for a derived facet to change the
+       *  behavior of narrowing.  do_narrow() must always return the
+       *  same result for the same input.
        *
        *  Note: this is not what you want for codepage conversions.  See
        *  codecvt for that.
@@ -1626,40 +1627,6 @@ namespace std
     };
 
   template<typename _CharT>
-    void
-    __numpunct_cache<_CharT>::_M_cache(const locale& __loc)
-    {
-      _M_allocated = true;
-
-      const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
-
-      _M_grouping_size = __np.grouping().size();
-      char* __grouping = new char[_M_grouping_size];
-      __np.grouping().copy(__grouping, _M_grouping_size);
-      _M_grouping = __grouping;
-      _M_use_grouping = _M_grouping_size && __np.grouping()[0] != 0;
-
-      _M_truename_size = __np.truename().size();
-      _CharT* __truename = new _CharT[_M_truename_size];
-      __np.truename().copy(__truename, _M_truename_size);
-      _M_truename = __truename;
-
-      _M_falsename_size = __np.falsename().size();
-      _CharT* __falsename = new _CharT[_M_falsename_size];
-      __np.falsename().copy(__falsename, _M_falsename_size);
-      _M_falsename = __falsename;
-
-      _M_decimal_point = __np.decimal_point();
-      _M_thousands_sep = __np.thousands_sep();
-
-      const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__loc);
-      __ct.widen(__num_base::_S_atoms_out,
-                __num_base::_S_atoms_out + __num_base::_S_oend, _M_atoms_out);
-      __ct.widen(__num_base::_S_atoms_in,
-                __num_base::_S_atoms_in + __num_base::_S_iend, _M_atoms_in);
-    }
-
-  template<typename _CharT>
     __numpunct_cache<_CharT>::~__numpunct_cache()
     {
       if (_M_allocated)
@@ -1755,8 +1722,8 @@ namespace std
       /**
        *  @brief  Return thousands separator character.
        *
-       *  This function returns a char_type to use as a thousands separator.  It
-       *  does so by returning returning
+       *  This function returns a char_type to use as a thousands
+       *  separator.  It does so by returning returning
        *  numpunct<char_type>::do_thousands_sep().
        *
        *  @return  char_type representing a thousands separator.
@@ -1772,18 +1739,20 @@ namespace std
        *  integer part of a number.  Groupings indicate where thousands
        *  separators should be inserted in the integer part of a number.
        *
-       *  Each char in the return string is interpret as an integer rather
-       *  than a character.  These numbers represent the number of digits in a
-       *  group.  The first char in the string represents the number of digits
-       *  in the least significant group.  If a char is negative, it indicates
-       *  an unlimited number of digits for the group.  If more chars from the
+       *  Each char in the return string is interpret as an integer
+       *  rather than a character.  These numbers represent the number
+       *  of digits in a group.  The first char in the string
+       *  represents the number of digits in the least significant
+       *  group.  If a char is negative, it indicates an unlimited
+       *  number of digits for the group.  If more chars from the
        *  string are required to group a number, the last char is used
        *  repeatedly.
        *
-       *  For example, if the grouping() returns "\003\002" and is applied to
-       *  the number 123456789, this corresponds to 12,34,56,789.  Note that
-       *  if the string was "32", this would put more than 50 digits into the
-       *  least significant group if the character set is ASCII.
+       *  For example, if the grouping() returns "\003\002" and is
+       *  applied to the number 123456789, this corresponds to
+       *  12,34,56,789.  Note that if the string was "32", this would
+       *  put more than 50 digits into the least significant group if
+       *  the character set is ASCII.
        *
        *  The string is returned by calling
        *  numpunct<char_type>::do_grouping().
@@ -1950,7 +1919,7 @@ namespace std
    *  implement the behavior they require from the num_get facet.
   */
   template<typename _CharT, typename _InIter>
-    class num_get : public locale::facet, public __num_base
+    class num_get : public locale::facet
     {
     public:
       // Types:
@@ -1979,10 +1948,11 @@ namespace std
        *  Parses the input stream into the bool @a v.  It does so by calling
        *  num_put::do_put().
        *
-       *  If ios_base::boolalpha is set, attempts to read ctype<CharT>::truename() or
-       *  ctype<CharT>::falsename().  Sets @a v to true or false if
-       *  successful.  Sets err to ios_base::failbit if reading the string
-       *  fails.  Sets err to ios_base::eofbit if the stream is emptied.
+       *  If ios_base::boolalpha is set, attempts to read
+       *  ctype<CharT>::truename() or ctype<CharT>::falsename().  Sets
+       *  @a v to true or false if successful.  Sets err to
+       *  ios_base::failbit if reading the string fails.  Sets err to
+       *  ios_base::eofbit if the stream is emptied.
        *
        *  If ios_base::boolalpha is not set, proceeds as with reading a long,
        *  except if the value is 1, sets @a v to true, if the value is 0, sets
@@ -2228,7 +2198,7 @@ namespace std
    *  implement the behavior they require from the num_put facet.
   */
   template<typename _CharT, typename _OutIter>
-    class num_put : public locale::facet, public __num_base
+    class num_put : public locale::facet
     {
     public:
       // Types:
@@ -2274,8 +2244,8 @@ namespace std
       /**
        *  @brief  Numeric formatting.
        *
-       *  Formats the integral value @a v and inserts it into a stream.  It does so
-       *  by calling num_put::do_put().
+       *  Formats the integral value @a v and inserts it into a
+       *  stream.  It does so by calling num_put::do_put().
        *
        *  Formatting is affected by the flag settings in @a io.
        *
@@ -2794,7 +2764,7 @@ namespace std
     {
       if (_M_allocated)
        {
-         // XXX.
+         // Unused.
        }
     }
 
@@ -2871,13 +2841,6 @@ namespace std
       }
 
       void
-      _M_ampm(const _CharT** __ampm) const
-      {
-       __ampm[0] = _M_data->_M_am;
-       __ampm[1] = _M_data->_M_pm;
-      }
-
-      void
       _M_date_time_formats(const _CharT** __dt) const
       {
        // Always have default first.
@@ -2886,6 +2849,17 @@ namespace std
       }
 
       void
+      _M_am_pm_format(const _CharT* __ampm) const
+      { __ampm = _M_data->_M_am_pm_format; }
+
+      void
+      _M_am_pm(const _CharT** __ampm) const
+      {
+       __ampm[0] = _M_data->_M_am;
+       __ampm[1] = _M_data->_M_pm;
+      }
+
+      void
       _M_days(const _CharT** __days) const
       {
        __days[0] = _M_data->_M_day1;
@@ -3280,23 +3254,21 @@ namespace std
                  ios_base::iostate& __err, tm* __tm) const;
 
       // Extract numeric component of length __len.
-      void
-      _M_extract_num(iter_type& __beg, iter_type& __end, int& __member,
+      iter_type
+      _M_extract_num(iter_type __beg, iter_type __end, int& __member,
                     int __min, int __max, size_t __len,
-                    const ctype<_CharT>& __ctype,
-                    ios_base::iostate& __err) const;
+                    ios_base& __io, ios_base::iostate& __err) const;
 
       // Extract day or month name, or any unique array of string
       // literals in a const _CharT* array.
-      void
-      _M_extract_name(iter_type& __beg, iter_type& __end, int& __member,
+      iter_type
+      _M_extract_name(iter_type __beg, iter_type __end, int& __member,
                      const _CharT** __names, size_t __indexlen,
-                     const ctype<_CharT>& __ctype,
-                     ios_base::iostate& __err) const;
+                     ios_base& __io, ios_base::iostate& __err) const;
 
       // Extract on a component-by-component basis, via __format argument.
-      void
-      _M_extract_via_format(iter_type& __beg, iter_type& __end, ios_base& __io,
+      iter_type
+      _M_extract_via_format(iter_type __beg, iter_type __end, ios_base& __io,
                            ios_base::iostate& __err, tm* __tm,
                            const _CharT* __format) const;
     };
@@ -3333,7 +3305,7 @@ namespace std
    *  implement the behavior they require from the time_put facet.
   */
   template<typename _CharT, typename _OutIter>
-    class time_put : public locale::facet, public time_base
+    class time_put : public locale::facet
     {
     public:
       // Types:
@@ -3464,32 +3436,55 @@ namespace std
 
     static const pattern _S_default_pattern;
 
+    enum
+    {
+      _S_minus,
+      _S_zero,
+      _S_end = 11
+    };
+
+    // String literal of acceptable (narrow) input/output, for
+    // money_get/money_put. "-0123456789"
+    static const char* _S_atoms;
+
     // Construct and return valid pattern consisting of some combination of:
     // space none symbol sign value
     static pattern
     _S_construct_pattern(char __precedes, char __space, char __posn);
   };
 
-  template<typename _CharT>
+  template<typename _CharT, bool _Intl>
     struct __moneypunct_cache : public locale::facet
     {
       const char*                      _M_grouping;
+      size_t                            _M_grouping_size;
       bool                             _M_use_grouping;
       _CharT                           _M_decimal_point;
       _CharT                           _M_thousands_sep;
       const _CharT*                    _M_curr_symbol;
+      size_t                            _M_curr_symbol_size;
       const _CharT*                    _M_positive_sign;
+      size_t                            _M_positive_sign_size;
       const _CharT*                    _M_negative_sign;
+      size_t                            _M_negative_sign_size;
       int                              _M_frac_digits;
       money_base::pattern              _M_pos_format;
       money_base::pattern              _M_neg_format;
 
+      // A list of valid numeric literals for input and output: in the standard
+      // "C" locale, this is "-0123456789". This array contains the chars after
+      // having been passed through the current locale's ctype<_CharT>.widen().
+      _CharT                           _M_atoms[money_base::_S_end];
+
       bool                             _M_allocated;
 
       __moneypunct_cache(size_t __refs = 0) : facet(__refs),
-      _M_grouping(NULL), _M_use_grouping(false), _M_decimal_point(_CharT()),
-      _M_thousands_sep(_CharT()), _M_curr_symbol(NULL), _M_positive_sign(NULL),
-      _M_negative_sign(NULL), _M_frac_digits(0),
+      _M_grouping(NULL), _M_grouping_size(0), _M_use_grouping(false),
+      _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()),
+      _M_curr_symbol(NULL), _M_curr_symbol_size(0),
+      _M_positive_sign(NULL), _M_positive_sign_size(0),
+      _M_negative_sign(NULL), _M_negative_sign_size(0),
+      _M_frac_digits(0),
       _M_pos_format(money_base::pattern()),
       _M_neg_format(money_base::pattern()), _M_allocated(false)
       { }
@@ -3500,12 +3495,15 @@ namespace std
       _M_cache(const locale& __loc);
     };
 
-  template<typename _CharT>
-    __moneypunct_cache<_CharT>::~__moneypunct_cache()
+  template<typename _CharT, bool _Intl>
+    __moneypunct_cache<_CharT, _Intl>::~__moneypunct_cache()
     {
       if (_M_allocated)
        {
-         // XXX.
+         delete [] _M_grouping;
+         delete [] _M_curr_symbol;
+         delete [] _M_positive_sign;
+         delete [] _M_negative_sign;
        }
     }
 
@@ -3525,7 +3523,7 @@ namespace std
       typedef _CharT                   char_type;
       typedef basic_string<_CharT>     string_type;
       //@}
-      typedef __moneypunct_cache<_CharT>       __cache_type;
+      typedef __moneypunct_cache<_CharT, _Intl>     __cache_type;
 
     private:
       __cache_type*                    _M_data;
@@ -3592,8 +3590,8 @@ namespace std
       /**
        *  @brief  Return thousands separator character.
        *
-       *  This function returns a char_type to use as a thousands separator.  It
-       *  does so by returning returning
+       *  This function returns a char_type to use as a thousands
+       *  separator.  It does so by returning returning
        *  moneypunct<char_type>::do_thousands_sep().
        *
        *  @return  char_type representing a thousands separator.
@@ -4057,9 +4055,10 @@ namespace std
       do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
             ios_base::iostate& __err, string_type& __digits) const;
 
-      iter_type
-      _M_extract(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
-                ios_base::iostate& __err, string_type& __digits) const;     
+      template<bool _Intl>
+        iter_type
+        _M_extract(iter_type __s, iter_type __end, ios_base& __io,
+                  ios_base::iostate& __err, string& __digits) const;     
     };
 
   template<typename _CharT, typename _InIter>
@@ -4194,9 +4193,10 @@ namespace std
       do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
             const string_type& __digits) const;
 
-      iter_type
-      _M_insert(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
-               const string_type& __digits) const;
+      template<bool _Intl>
+        iter_type
+        _M_insert(iter_type __s, ios_base& __io, char_type __fill,
+                 const string_type& __digits) const;
     };
 
   template<typename _CharT, typename _OutIter>