示例#1
0
  inline std::basic_string<charT> to_simple_string_type(time_duration td) {
    std::basic_ostringstream<charT> ss;
    if(td.is_special()) {
      /* simply using 'ss << td.get_rep()' won't work on compilers
       * that don't support locales. This way does. */
      // switch copied from date_names_put.hpp
      switch(td.get_rep().as_special())
      {
      case not_a_date_time:
        //ss << "not-a-number";
        ss << "not-a-date-time";
        break;
      case pos_infin:
        ss << "+infinity";
        break;
      case neg_infin:
        ss << "-infinity";
        break;
      default:
        ss << "";
      }
    }
    else {
      charT fill_char = '0';
      if(td.is_negative()) {
        ss << '-';
      }
      ss  << std::setw(2) << std::setfill(fill_char) 
          << date_time::absolute_value(td.hours()) << ":";
      ss  << std::setw(2) << std::setfill(fill_char) 
          << date_time::absolute_value(td.minutes()) << ":";
      ss  << std::setw(2) << std::setfill(fill_char) 
          << date_time::absolute_value(td.seconds());
      //TODO the following is totally non-generic, yelling FIXME
#if (defined(BOOST_MSVC) && (_MSC_VER <= 1200))  // 1200 == VC++ 6.0
      boost::int64_t frac_sec = 
        date_time::absolute_value(td.fractional_seconds());
      // JDG [7/6/02 VC++ compatibility]
      charT buff[32];
      _i64toa(frac_sec, buff, 10);
#else
      time_duration::fractional_seconds_type frac_sec = 
        date_time::absolute_value(td.fractional_seconds());
#endif
      if (frac_sec != 0) {
        ss  << "." << std::setw(time_duration::num_fractional_digits())
            << std::setfill(fill_char)
          
          // JDG [7/6/02 VC++ compatibility]
#if (defined(BOOST_MSVC) && (_MSC_VER <= 1200))  // 1200 == VC++ 6.0
            << buff;
#else
        << frac_sec;
#endif
      }
 /*!\ingroup time_format
  */
 inline
 std::string
 to_iso_string(time_duration td)
 {
   std::ostringstream ss;
   if(td.is_special()) {
     /* simply using 'ss << td.get_rep()' won't work on compilers
      * that don't support locales. This way does. */
     // switch copied from date_names_put.hpp
     switch(td.get_rep().as_special()) {
     case not_a_date_time:
       //ss << "not-a-number";
       ss << "not-a-date-time";
       break;
     case pos_infin:
       ss << "+infinity";
       break;
     case neg_infin:
       ss << "-infinity";
       break;
     default:
       ss << "";
     }
   }
   else {
     if(td.is_negative()) {
       ss << '-';
     }
     ss  << std::setw(2) << std::setfill('0')
         << date_time::absolute_value(td.hours());
     ss  << std::setw(2) << std::setfill('0')
         << date_time::absolute_value(td.minutes());
     ss  << std::setw(2) << std::setfill('0')
         << date_time::absolute_value(td.seconds());
     //TODO the following is totally non-generic, yelling FIXME
     time_duration::fractional_seconds_type frac_sec =
       date_time::absolute_value(td.fractional_seconds());
     if (frac_sec != 0) {
       ss  << "." << std::setw(time_duration::num_fractional_digits())
           << std::setfill('0')
           << frac_sec;
     }
   }// else
   return ss.str();
 }
示例#3
0
/*!
    \fn CPlayloop::sleep(int duration)
 */
int CPlayloop::sleep(time_duration duration)
{
  int retval = 0;


  if( !duration.is_negative() )
  {
    struct timespec ts_to_sleep, ts_remaining;
    ts_to_sleep.tv_sec = duration.total_seconds();
    ts_to_sleep.tv_nsec = duration.fractional_seconds();
    
    //boost::date_time::time_resolutions 
    if (time_duration::resolution() == boost::date_time::micro) {
      ts_to_sleep.tv_nsec *= 1000;
    }
    
    int retval = nanosleep( &ts_to_sleep, &ts_remaining);
    if(retval != 0)
      cerr << "nanosleep returned early due to a signal!" << endl;
    
  }
    
  return retval;  
}