Esempio n. 1
0
 //allow internal access from operators
 date_type operator+(const duration_type& dd) const
 {
   if(dd.is_special())
   {
     return date_type(date_rep_type(days_) + dd.get_rep());
   }
   return date_type(date_rep_type(days_) + static_cast<date_int_type>(dd.days()));
 }
Esempio n. 2
0
 date_type operator-(const duration_type& dd) const
 {
   if(dd.is_special())
   {
     return date_type(date_rep_type(days_) - dd.get_rep());
   }
   return date_type(date_rep_type(days_) - dd.days());
 }
 bool frontBlock(T& t, duration_type timeout) const
 {
     boost::mutex::scoped_lock lock(mutex_);
     bool gotValue = false;
     if (timeout.count() > 0)
     {
         if (deque_.empty())
         {
             available_.wait_for(lock, timeout);
         }
         if (!deque_.empty())
         {
             t = deque_.front();
             gotValue = true;
         }
     }
     else
     {
         while (deque_.empty())
         {
             available_.wait(lock);
         }
         t = deque_.front();
         gotValue = true;
     }
     return gotValue;
 }
Esempio n. 4
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());
      }

    }
Esempio n. 5
0
  /// Estimate the necessary number of buckets
  std::size_t bucket_count(
      duration_type measurement_period, duration_type sampling_period) {
    if (sampling_period <= duration_type(0)) {
      std::ostringstream os;
      os << "jb::event_rate_estimate - sampling period ("
         << sampling_period.count() << ") must be a positive number";
      throw std::invalid_argument(os.str());
    }
    if (sampling_period > measurement_period) {
      std::ostringstream os;
      os << "jb::event_rate_estimate - measurement period ("
         << measurement_period.count() << ") is smaller than sampling period ("
         << sampling_period.count() << ")";
      throw std::invalid_argument(os.str());
    }

    if ((measurement_period % sampling_period).count() != 0) {
      std::ostringstream os;
      os << "jb::event_rate_estimate - measurement period ("
         << measurement_period.count()
         << ") must be a multiple of the sampling period ("
         << sampling_period.count() << ")";
      throw std::invalid_argument(os.str());
    }

    // ... because measurement_period and sampling_period are positive
    // numbers N will be a positive number ...
    typedef typename duration_type::rep rep;
    typedef typename std::make_unsigned<rep>::type unsigned_rep;
    unsigned_rep N = measurement_period / sampling_period;
    // ... beware, the type may be larger than what can be stored in
    // an std::size_t (weird segmented memory platforms, yuck) ...
    if (N >= std::numeric_limits<std::size_t>::max()) {
      std::ostringstream os;
      os << "jb::event_rate_estimate - measurement period ("
         << measurement_period.count() << ") is too large for sampling period ("
         << sampling_period.count() << ")";
      throw std::invalid_argument(os.str());
    }
    return static_cast<std::size_t>(N);
  }
Esempio n. 6
0
 //allow internal access from operators
 date_type operator+(const duration_type& dd) const
 {
   return date_type(date_rep_type(days_) + dd.days());
 }
Esempio n. 7
0
inline
int_type operator+(int i, duration_type<int_type> dt){
  return i + dt.get_rep();
}