Exemplo n.º 1
0
 inline
 std::basic_istream<CharT, Traits>&
 operator>>(std::basic_istream<CharT, Traits>& is, time_duration& td)
 {
   boost::io::ios_flags_saver iflags(is);
   typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false);
   if (strm_sentry) {
     try {
       typedef typename date_time::time_input_facet<ptime, CharT> time_input_facet;
       std::istreambuf_iterator<CharT,Traits> sit(is), str_end;
       if(std::has_facet<time_input_facet>(is.getloc())) {
         std::use_facet<time_input_facet>(is.getloc()).get(sit, str_end, is, td);
       }
       else {
         time_input_facet* f = new time_input_facet();
         std::locale l = std::locale(is.getloc(), f);
         is.imbue(l);
         f->get(sit, str_end, is, td);
       }
     }
     catch(...) {
       std::ios_base::iostate exception_mask = is.exceptions();
       if(std::ios_base::failbit & exception_mask) {
         try { is.setstate(std::ios_base::failbit); }
         catch(std::ios_base::failure&) {}
         throw; // rethrow original exception
       }
       else {
         is.setstate(std::ios_base::failbit);
       }
     }
   }
   return is;
 }
Exemplo n.º 2
0
inline
std::basic_istream<CharT, Traits>&
operator>>(std::basic_istream<CharT, Traits>& is, local_date_time& ldt)
{
    boost::io::ios_flags_saver iflags(is);
    typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false);
    if (strm_sentry) {
        try {
            typedef typename local_date_time::utc_time_type utc_time_type;
            typedef typename date_time::time_input_facet<utc_time_type, CharT> time_input_facet;

            // intermediate objects
            std::basic_string<CharT> tz_str;
            utc_time_type pt(not_a_date_time);

            std::istreambuf_iterator<CharT,Traits> sit(is), str_end;
            if(std::has_facet<time_input_facet>(is.getloc())) {
                std::use_facet<time_input_facet>(is.getloc()).get_local_time(sit, str_end, is, pt, tz_str);
            }
            else {
                time_input_facet* f = new time_input_facet();
                std::locale l = std::locale(is.getloc(), f);
                is.imbue(l);
                f->get_local_time(sit, str_end, is, pt, tz_str);
            }
            if(tz_str.empty()) {
                time_zone_ptr null_ptr;
                // a null time_zone_ptr creates a local_date_time that is UTC
                ldt = local_date_time(pt, null_ptr);
            }
            else {
                time_zone_ptr tz_ptr(new posix_time_zone(date_time::convert_string_type<CharT,char>(tz_str)));
                // the "date & time" constructor expects the time label to *not* be utc.
                // a posix_tz_string also expects the time label to *not* be utc.
                ldt = local_date_time(pt.date(), pt.time_of_day(), tz_ptr, local_date_time::EXCEPTION_ON_ERROR);
            }
        }
        catch(...) {
            // mask tells us what exceptions are turned on
            std::ios_base::iostate exception_mask = is.exceptions();
            // if the user wants exceptions on failbit, we'll rethrow our
            // date_time exception & set the failbit
            if(std::ios_base::failbit & exception_mask) {
                try {
                    is.setstate(std::ios_base::failbit);
                }
                catch(std::ios_base::failure&) {} // ignore this one
                throw; // rethrow original exception
            }
            else {
                // if the user want's to fail quietly, we simply set the failbit
                is.setstate(std::ios_base::failbit);
            }

        }
    }
    return is;
}
Exemplo n.º 3
0
 inline
 std::basic_istream<CharT, Traits>&
 operator>>(std::basic_istream<CharT, Traits>& is, ptime& pt)
 {
   boost::io::ios_flags_saver iflags(is);
   typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); 
   if (strm_sentry) {
     try {
       typedef typename date_time::time_input_facet<ptime, CharT> time_input_facet;
       
       std::istreambuf_iterator<CharT,Traits> sit(is), str_end;
       if(std::has_facet<time_input_facet>(is.getloc())) {
         std::use_facet<time_input_facet>(is.getloc()).get(sit, str_end, is, pt);
       }
       else {
         time_input_facet* f = new time_input_facet();
         std::locale l = std::locale(is.getloc(), f);
         is.imbue(l);
         f->get(sit, str_end, is, pt);
       }
     }
     catch(...) { 
       // mask tells us what exceptions are turned on
       std::ios_base::iostate exception_mask = is.exceptions();
       // if the user wants exceptions on failbit, we'll rethrow our 
       // date_time exception & set the failbit
       if(std::ios_base::failbit & exception_mask) {
         try { is.setstate(std::ios_base::failbit); } 
         catch(std::ios_base::failure&) {} // ignore this one
         throw; // rethrow original exception
       }
       else {
         // if the user want's to fail quietly, we simply set the failbit
         is.setstate(std::ios_base::failbit); 
       } 
           
     }
   }
   return is;
 }