Пример #1
0
void callback(std::ios_base::event ev, std::ios_base& strm, int idx)
    {
    if (ev == std::ios_base::erase_event)
        {
        try
            {
            delete static_cast<NewFormat*>(strm.pword(idx));

            strm.pword(idx) = 0;
            }
        catch (...)
            { }
        }
    else if (ev == std::ios_base::copyfmt_event)
        {
        NewFormat* old(static_cast<NewFormat*>(strm.pword(idx)));

        if (old != 0)
            {
            try
                {
                strm.pword(idx) = new NewFormat(*old);
                }
            catch (std::bad_alloc&)
                { }
            }
        }
    }
Пример #2
0
void replace_pword(std::ios_base& iob, int idx, const T& x) {
    iob.register_callback(callback<NewFormat>, idx);

    NewFormat* new_format(new NewFormat(x));
    OldFormat* old_format(static_cast<OldFormat*>(iob.pword(idx)));
    iob.pword(idx) = new_format;
    delete old_format;
}
Пример #3
0
// Stream format gets copied or destroyed
static void my_ios_callback(std::ios_base::event ev, std::ios_base & s, int i)
{
	print_context *p = static_cast<print_context *>(s.pword(i));
	if (ev == std::ios_base::erase_event) {
		delete p;
		s.pword(i) = nullptr;
	} else if (ev == std::ios_base::copyfmt_event && p != nullptr)
		s.pword(i) = p->duplicate();
}
Пример #4
0
void cleanup(std::ios_base::event evt, std::ios_base& str, int idx)
{
    if (str.iword(separatorEnabled()) && evt == std::ios_base::erase_event)
    {
        void*& p = str.pword(idx);
        delete static_cast<std::string*>(p);
        str.iword(separatorEnabled()) = false; 
    }
}
Пример #5
0
    OutItrT put(OutItrT a_next, 
                std::ios_base& a_ios, 
                char_type a_fill, 
                const time_type& a_time) const 
    {
      if (a_time.is_special()) { 
        return do_put_special(a_next, a_ios, a_fill, 
                              a_time.date().as_special());
      }
      string_type format(m_format);
      string_type frac_str;
      if (format.find(seconds_with_fractional_seconds_format)) {
        // replace %s with %S.nnn 
        frac_str = 
          fractional_seconds_as_string(a_time.time_of_day(), false);
        char_type sep = std::use_facet<std::numpunct<char_type> >(a_ios.getloc()).decimal_point();
        
        string_type replace_string(seconds_format);
        replace_string += sep;
        replace_string += frac_str;
        boost::algorithm::replace_all(format, 
                                      seconds_with_fractional_seconds_format, 
                                      replace_string);
      }
      if (format.find(fractional_seconds_format)) {
        // replace %f with nnnnnnn
        if (!frac_str.size()) {
          frac_str = fractional_seconds_as_string(a_time.time_of_day(), false);
        }
        boost::algorithm::replace_all(format,
                                      fractional_seconds_format, 
                                      frac_str);
      }

      if (format.find(fractional_seconds_or_none_format)) {
        // replace %F with nnnnnnn or nothing if fs == 0
        frac_str = 
          fractional_seconds_as_string(a_time.time_of_day(), true);
        if (frac_str.size()) {
          char_type sep = std::use_facet<std::numpunct<char_type> >(a_ios.getloc()).decimal_point();
          string_type replace_string;
          replace_string += sep;
          replace_string += frac_str;
          boost::algorithm::replace_all(format,
                                        fractional_seconds_or_none_format, 
                                        replace_string);
        }
        else {
          boost::algorithm::erase_all(format,
                                      fractional_seconds_or_none_format);
        }
      }

      return do_put_tm(a_next, a_ios, a_fill, 
                       to_tm(a_time), format);
    }
Пример #6
0
 format_parser::format_parser(std::ios_base &ios,void *cookie,void (*imbuer)(void *,std::locale const &)) : 
     ios_(ios),
     d(new data)
 {
     d->position=std::numeric_limits<unsigned>::max();
     d->precision=ios.precision();
     d->flags = ios.flags();
     d->info=ios_info::get(ios);
     d->saved_locale = ios.getloc();
     d->restore_locale=false;
     d->cookie = cookie;
     d->imbuer = imbuer;
 }
Пример #7
0
 iter_type put_duration(iter_type i, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const
 {
   if (std::has_facet<duration_put<CharT> >(ios.getloc()))
   {
     duration_put<CharT> const &facet = std::use_facet<duration_put<CharT> >(ios.getloc());
     return facet.put(i, ios, fill, d);
   }
   else
   {
     duration_put<CharT> facet;
     return facet.put(i, ios, fill, d);
   }
 }
Пример #8
0
bool logstream_base::set_stream_state(std::ios_base& dest, int& dstchar) {
     std::ios_base::fmtflags setval = initset.flags();
     std::ios_base::fmtflags clrval = initclear.flags();
     std::ios_base::fmtflags mask = setval ^ (~clrval);
     dest.setf(clrval, mask);
     if (initset.precision() == initclear.precision()) {
         dest.precision(initset.precision());
     }
     if (initset.width() == initclear.width()) {
         dest.width(initset.width());
     }
     dstchar = fillchar;
     return fillset;
}
 iter_type get_duration(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err,
     duration<Rep, Period>& d) const
 {
   if (std::has_facet<duration_get<CharT> >(is.getloc()))
   {
     duration_get<CharT> const &facet = std::use_facet<duration_get<CharT> >(is.getloc());
     return get_duration(facet, i, e, is, err, d);
   }
   else
   {
     duration_get<CharT> facet;
     return get_duration(facet, i, e, is, err, d);
   }
 }
Пример #10
0
 iter_type put_unit(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const
 {
   if (std::has_facet<duration_units<CharT> >(ios.getloc()))
   {
     duration_units<CharT> const&facet = std::use_facet<duration_units<CharT> >(
         ios.getloc());
     return put_unit(facet, s, ios, fill, d);
   }
   else
   {
     duration_units_default<CharT> facet;
     return put_unit(facet, s, ios, fill, d);
   }
 }
Пример #11
0
 iter_type put(iter_type i, std::ios_base& ios, char_type fill, time_point<Clock, Duration> const& tp, const CharT* pattern,
     const CharT* pat_end) const
 {
   if (std::has_facet<time_point_units<CharT> >(ios.getloc()))
   {
     time_point_units<CharT> const &facet =
         std::use_facet<time_point_units<CharT> >(ios.getloc());
     return put(facet, i, ios, fill, tp, pattern, pat_end);
   }
   else
   {
     time_point_units_default<CharT> facet;
     return put(facet, i, ios, fill, tp, pattern, pat_end);
   }
 }
Пример #12
0
// Set print_context associated with stream, retain options
static void set_print_context(std::ios_base & s, const print_context & c)
{
	int i = my_ios_index();
	long flags = s.iword(i);
	if (!(flags & callback_registered)) {
		s.register_callback(my_ios_callback, i);
		s.iword(i) = flags | callback_registered;
	}
	print_context *p = static_cast<print_context *>(s.pword(i));
	unsigned options = p ? p->options : c.options;
	delete p;
	p = c.duplicate();
	p->options = options;
	s.pword(i) = p;
}
Пример #13
0
void LocaleUtils::CLocaleScope::set(std::ios_base &baseStream) {
	assert(orgLocale_ == NULL);

	orgLocale_ = new (static_cast<void*>(&orgLocaleStorage_)) std::locale(
			baseStream.imbue(getCLocale()));
	baseStream_ = &baseStream;
}
Пример #14
0
 iter_type put(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const
 {
   if (std::has_facet<duration_units<CharT> >(ios.getloc()))
   {
     duration_units<CharT> const&facet = std::use_facet<duration_units<CharT> >(
         ios.getloc());
     std::basic_string<CharT> str = facet.get_pattern();
     return put(facet, s, ios, fill, d, str.data(), str.data() + str.size());
   }
   else
   {
     duration_units_default<CharT> facet;
     std::basic_string<CharT> str = facet.get_pattern();
     return put(facet, s, ios, fill, d, str.data(), str.data() + str.size());
   }
 }
Пример #15
0
 iter_type put(iter_type i, std::ios_base& ios, char_type fill, time_point<Clock, Duration> const& tp) const
 {
   if (std::has_facet<time_point_units<CharT> >(ios.getloc()))
   {
     time_point_units<CharT> const &facet =
         std::use_facet<time_point_units<CharT> >(ios.getloc());
     std::basic_string<CharT> str = facet.get_pattern();
     return put(facet, i, ios, fill, tp, str.data(), str.data() + str.size());
   }
   else
   {
     time_point_units_default<CharT> facet;
     std::basic_string<CharT> str = facet.get_pattern();
     return put(facet, i, ios, fill, tp, str.data(), str.data() + str.size());
   }
 }
Пример #16
0
 iter_type put_unit(duration_units<CharT> const& facet, iter_type s, std::ios_base& ios, char_type fill,
     duration<Rep, Period> const& d) const
 {
   if (facet.template is_named_unit<Period>()) {
     string_type str = facet.get_unit(get_duration_style(ios), d);
     s=std::copy(str.begin(), str.end(), s);
   } else {
     *s++ = CharT('[');
     std::use_facet<std::num_put<CharT, iter_type> >(ios.getloc()).put(s, ios, fill, Period::num);
     *s++ = CharT('/');
     std::use_facet<std::num_put<CharT, iter_type> >(ios.getloc()).put(s, ios, fill, Period::den);
     *s++ = CharT(']');
     string_type str = facet.get_n_d_unit(get_duration_style(ios), d);
     s=std::copy(str.begin(), str.end(), s);
   }
   return s;
 }
Пример #17
0
    InItrT get(InItrT& from,
               InItrT& to,
               std::ios_base& a_ios,
               duration_type& dd) const
    {
        // skip leading whitespace
        while(std::isspace(*from) && from != to) {
            ++from;
        }

        /* num_get.get() will always consume the first character if it
         * is a sign indicator (+/-). Special value strings may begin
         * with one of these signs so we'll need a copy of it
         * in case num_get.get() fails. */
        char_type c = '\0';
        // TODO Are these characters somewhere in the locale?
        if(*from == '-' || *from == '+') {
            c = *from;
        }
        typedef std::num_get<CharT, InItrT> num_get;
        typename duration_type::duration_rep_type val = 0;
        std::ios_base::iostate err = std::ios_base::goodbit;

        if (std::has_facet<num_get>(a_ios.getloc())) {
            from = std::use_facet<num_get>(a_ios.getloc()).get(from, to, a_ios, err, val);
        }
        else {
            num_get* ng = new num_get();
            std::locale l = std::locale(a_ios.getloc(), ng);
            a_ios.imbue(l);
            from = ng->get(from, to, a_ios, err, val);
        }
        if(err & std::ios_base::failbit) {
            typedef typename special_values_parser_type::match_results match_results;
            match_results mr;
            if(c == '-' || c == '+') { // was the first character consumed?
                mr.cache += c;
            }
            m_sv_parser.match(from, to, mr);
            if(mr.current_match == match_results::PARSE_ERROR) {
                boost::throw_exception(std::ios_base::failure("Parse failed. No match found for '" + mr.cache + "'"));
                BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(return from); // should never reach
            }
            dd = duration_type(static_cast<special_values>(mr.current_match));
        }
Пример #18
0
 InputIterator get(
   iter_type b, iter_type e,
   std::ios_base& iob,
   std::ios_base::iostate& err, std::tm* tm,
   const char_type* fmtb, const char_type* fmte) const
 {
   const std::ctype<char_type>& ct = std::use_facet<std::ctype<char_type> >(iob.getloc());
   err = std::ios_base::goodbit;
   while (fmtb != fmte && err == std::ios_base::goodbit)
   {
       if (b == e)
       {
           err = std::ios_base::failbit;
           break;
       }
       if (ct.narrow(*fmtb, 0) == '%')
       {
           if (++fmtb == fmte)
           {
               err = std::ios_base::failbit;
               break;
           }
           char cmd = ct.narrow(*fmtb, 0);
           char opt = '\0';
           if (cmd == 'E' || cmd == '0')
           {
               if (++fmtb == fmte)
               {
                   err = std::ios_base::failbit;
                   break;
               }
               opt = cmd;
               cmd = ct.narrow(*fmtb, 0);
           }
           b = get(b, e, iob, err, tm, cmd, opt);
           ++fmtb;
       }
       else if (ct.is(std::ctype_base::space, *fmtb))
       {
           for (++fmtb; fmtb != fmte && ct.is(std::ctype_base::space, *fmtb); ++fmtb)
               ;
           for (        ;    b != e    && ct.is(std::ctype_base::space, *b);    ++b)
               ;
       }
       else if (ct.toupper(*b) == ct.toupper(*fmtb))
       {
           ++b;
           ++fmtb;
       }
       else
           err = std::ios_base::failbit;
   }
   if (b == e)
       err |= std::ios_base::eofbit;
   return b;
 }
Пример #19
0
void PdfLocaleImbue(std::ios_base& s)
{
#if USE_CXX_LOCALE
    static const std::locale cachedLocale( PdfIOLocale );
    try {
    	s.imbue( cachedLocale );
    } catch (const std::runtime_error & e) {
        std::ostringstream s;
        s << "Failed to set safe locale on stream being used for PDF I/O.";
        s << "Locale set was: \"" << PdfIOLocale << "\".";
        s << "Error reported by STL std::locale: \"" << e.what() << "\"";
        // The info string is copied by PdfError so we're ok to just:
        PODOFO_RAISE_ERROR_INFO(
            ePdfError_InvalidDeviceOperation,
            s.str().c_str()
            );
    }
#endif
}
Пример #20
0
void f3(std::ios_base::event ev, std::ios_base& stream, int index)
{
    if (ev == std::ios_base::erase_event)
    {
        assert(!f1_called);
        assert(!f2_called);
        assert(!f3_called);
        assert(stream.getloc().name() == "C");
        assert(index == 6);
        f3_called = true;
    }
}
Пример #21
0
void f3(std::ios_base::event ev, std::ios_base& stream, int index)
{
    if (ev == std::ios_base::imbue_event)
    {
        assert(!f1_called);
        assert(!f2_called);
        assert(!f3_called);
        assert(stream.getloc().name() == LOCALE_en_US_UTF_8);
        assert(index == 6);
        f3_called = true;
    }
}
Пример #22
0
    OutItrT put(OutItrT next,
                std::ios_base& a_ios,
                char_type fill_char,
                const duration_type& dd) const
    {
      if (dd.is_special()) {
        return do_put_special(next, a_ios, fill_char, dd.get_rep().as_special());
      }

      typedef std::num_put<CharT, OutItrT> num_put;
      if (std::has_facet<num_put>(a_ios.getloc())) {
        return std::use_facet<num_put>(a_ios.getloc()).put(next, a_ios, fill_char, dd.get_rep().as_number());
      }
      else {
        num_put* f = new num_put();
        std::locale l = std::locale(a_ios.getloc(), f);
        a_ios.imbue(l);
        return f->put(next, a_ios, fill_char, dd.get_rep().as_number());
      }

    }
Пример #23
0
 iter_type get_epoch(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err) const
 {
   if (std::has_facet<time_point_units<CharT> >(is.getloc()))
   {
     time_point_units<CharT> const &facet = std::use_facet<time_point_units<CharT> >(is.getloc());
     return get_epoch(facet, i, e, is, err);
   }
   else
   {
     time_point_units_default<CharT> facet;
     return get_epoch(facet, i, e, is, err);
   }
 }
Пример #24
0
 iter_type put_epoch(iter_type i, std::ios_base& os) const
 {
   if (std::has_facet<time_point_units<CharT> >(os.getloc()))
   {
     time_point_units<CharT> const &facet = std::use_facet<time_point_units<CharT> >(os.getloc());
     return put_epoch<Clock> (facet, i, os);
   }
   else
   {
     time_point_units_default<CharT> facet;
     return put_epoch<Clock> (facet, i, os);
   }
 }
Пример #25
0
 iter_type get(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err,
     time_point<Clock, Duration> &tp, const char_type *pattern, const char_type *pat_end) const
 {
   if (std::has_facet<time_point_units<CharT> >(is.getloc()))
   {
     time_point_units<CharT> const &facet = std::use_facet<time_point_units<CharT> >(is.getloc());
     return get(facet, i, e, is, err, tp, pattern, pat_end);
   }
   else
   {
     time_point_units_default<CharT> facet;
     return get(facet, i, e, is, err, tp, pattern, pat_end);
   }
 }
Пример #26
0
void f1(std::ios_base::event ev, std::ios_base& stream, int index)
{
    if (ev == std::ios_base::erase_event)
    {
        assert(!f1_called);
        assert( f2_called);
        assert(!g1_called);
        assert(!g2_called);
        assert(!g3_called);
        assert(stream.getloc().name() == LOCALE_en_US_UTF_8);
        assert(index == 4);
        f1_called = true;
    }
}
Пример #27
0
void g3(std::ios_base::event ev, std::ios_base& stream, int index)
{
    if (ev == std::ios_base::copyfmt_event)
    {
        assert( f1_called);
        assert( f2_called);
        assert(!g1_called);
        assert(!g2_called);
        assert(!g3_called);
        assert(stream.getloc().name() == LOCALE_fr_FR_UTF_8);
        assert(index == 9);
        g3_called = true;
    }
}
Пример #28
0
 iter_type get(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err,
     time_point<Clock, Duration> &tp) const
 {
   if (std::has_facet<time_point_units<CharT> >(is.getloc()))
   {
     time_point_units<CharT> const &facet = std::use_facet<time_point_units<CharT> >(is.getloc());
     std::basic_string<CharT> str = facet.get_pattern();
     return get(facet, i, e, is, err, tp, str.data(), str.data() + str.size());
   }
   else
   {
     time_point_units_default<CharT> facet;
     std::basic_string<CharT> str = facet.get_pattern();
     return get(facet, i, e, is, err, tp, str.data(), str.data() + str.size());
   }
 }
Пример #29
0
      iter_type put(duration_units<CharT> const& units_facet, iter_type s, std::ios_base& ios, char_type fill,
          duration<Rep, Period> const& d, const CharT* pattern, const CharT* pat_end) const
      {

        const std::ctype<char_type>& ct = std::use_facet<std::ctype<char_type> >(ios.getloc());
        for (; pattern != pat_end; ++pattern)
        {
          if (ct.narrow(*pattern, 0) == '%')
          {
            if (++pattern == pat_end)
            {
              *s++ = pattern[-1];
              break;
            }
            char fmt = ct.narrow(*pattern, 0);
            switch (fmt)
            {
            case 'v':
            {
              s = put_value(s, ios, fill, d);
              break;
            }
            case 'u':
            {
              s = put_unit(units_facet, s, ios, fill, d);
              break;
            }
            default:
              BOOST_ASSERT(false && "Boost::Chrono internal error.");
              break;
            }
          }
          else
            *s++ = *pattern;
        }
        return s;
      }
Пример #30
0
      iter_type put(time_point_units<CharT> const& units_facet, iter_type s, std::ios_base& ios, char_type fill,
          time_point<Clock, Duration> const& tp, const CharT* pattern, const CharT* pat_end) const
      {

        const std::ctype<char_type>& ct = std::use_facet<std::ctype<char_type> >(ios.getloc());
        for (; pattern != pat_end; ++pattern)
        {
          if (ct.narrow(*pattern, 0) == '%')
          {
            if (++pattern == pat_end)
            {
              *s++ = pattern[-1];
              break;
            }
            char fmt = ct.narrow(*pattern, 0);
            switch (fmt)
            {
            case 'd':
            {
              s = put_duration(s, ios, fill, tp.time_since_epoch());
              break;
            }
            case 'e':
            {
              s = put_epoch<Clock> (units_facet, s, ios);
              break;
            }
            default:
              AUTOBOOST_ASSERT(false && "Boost::Chrono internal error.");
              break;
            }
          }
          else
            *s++ = *pattern;
        }
        return s;
      }