This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

num_get<>::do_get question



The implementations of num_get<>::do_get in bits/locfacets.tcc
use a local variable `__conv' for the format for sscanf.

It is of type `string', but this is not necessary.
It could be `const char*'.
This solution should be faster because no call of `new' and `delete'
occurs.


// sample of the modification
//
   export template<typename _CharT, typename _InIter>
     _InIter
     num_get<_CharT, _InIter>::
     do_get(iter_type __beg, iter_type __end, ios_base& __io,
            ios_base::iostate& __err, long& __v) const
     {
      // Stage 1: determine a conversion specifier.
      ios_base::fmtflags __flags = __io.flags();
      ios_base::fmtflags __basefield = __flags & ios_base::basefield;
      ios_base::fmtflags __uppercase = __flags & ios_base::uppercase;
      ios_base::fmtflags __boolalpha = __flags & ios_base::boolalpha;
      const char* __conv = 0;
//    string  __conv;

      if (__basefield == ios_base::oct)
        __conv = "%ol";
//      __conv = "%o";

      else if (__basefield == ios_base::hex)
        __conv = "%Xl";
//      __conv = "%X";

      else if (__basefield == 0)
        __conv = "%il";
//      __conv = "%i";

      // Add this in for each overloaded mf. Choices are:
      // = %d for signed ints
      // = %u for unsigned ints
      // = %g for floats
      // = %p for void*
      else
        __conv = "%dl";
//      __conv = "%d";

      // Add a length modifier, if necessary for this mf. Choices are:
      // short || unsigned short = h
      // long || unsigned long  = l
      // long double = L
//    __conv += 'l';

      // Stage 2: extract
      string __xtrc;
      _M_extract(__beg, __end, __io, __err, __xtrc);

      // Stage 3: store results.
      int __ok = sscanf(__xtrc.c_str(), __conv, &__v);
//    int __ok = sscanf(__xtrc.c_str(), __conv.c_str(), &__v);
      if (__ok && __ok != __traits_type::eof())
        __err = ios_base::goodbit;
      else
        __err |= ios_base::failbit;

      return __beg;
     }


Ryszard Kabatek
Martin-Luther University Halle-Wittenberg, Department of Physical Chemistry
Geusaer Str. 88, 06217 Merseburg, Germany
Tel. +49 3461 46 2487 Fax. +49 3461 46 2129



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]