Boost-Graph

 view release on metacpan or  search on metacpan

include/boost/date_time/time_system_counted.hpp  view on Meta::CPAN

#ifndef DATE_TIME_TIME_SYSTEM_COUNTED_HPP
#define DATE_TIME_TIME_SYSTEM_COUNTED_HPP

/* Copyright (c) 2002,2003 CrystalClear Software, Inc.
 * Use, modification and distribution is subject to the 
 * Boost Software License, Version 1.0. (See accompanying
 * file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
 * Author: Jeff Garland, Bart Garst
 * $Date: 2004/12/07 11:00:12 $
 */



#include "boost/date_time/time_defs.hpp"
#include <string>


namespace boost {
namespace date_time {

  //! Time representation that uses a single integer count
  template<class config>
  struct counted_time_rep
  {
    typedef typename config::int_type   int_type;
    typedef typename config::date_type  date_type;
    typedef typename config::impl_type  impl_type;
    typedef typename date_type::duration_type date_duration_type;
    typedef typename date_type::calendar_type calendar_type;
    typedef typename date_type::ymd_type ymd_type;
    typedef typename config::time_duration_type time_duration_type;
    typedef typename config::resolution_traits   resolution_traits;
    
    counted_time_rep(const date_type& d, const time_duration_type& tod) 
      : time_count_(1)
    {
      if(d.is_infinity() || d.is_not_a_date() || tod.is_special()) {
        time_count_ = tod.get_rep() + d.day_count();
        //std::cout << time_count_ << std::endl;
      }
      else {    
        time_count_ = (d.day_number() * frac_sec_per_day()) + tod.ticks();
      }
    }
    explicit counted_time_rep(int_type count) :
      time_count_(count)
    {}
    explicit counted_time_rep(impl_type count) :
      time_count_(count)
    {}
    date_type date() const
    {
      if(time_count_.is_special()) {
        return date_type(time_count_.as_special());
      }
      else {
        typename calendar_type::date_int_type dc = day_count();
        //std::cout << "time_rep here:" << dc << std::endl;
        ymd_type ymd = calendar_type::from_day_number(dc);
        return date_type(ymd);
      }
    }
    //int_type day_count() const
    unsigned long day_count() const
    {
      /* resolution_traits::as_number returns a boost::int64_t & 
       * frac_sec_per_day is also a boost::int64_t so, naturally, 
       * the division operation returns a boost::int64_t. 
       * The static_cast to an unsigned long is ok (results in no data loss) 
       * because frac_sec_per_day is either the number of 
       * microseconds per day, or the number of nanoseconds per day. 
       * Worst case scenario: resolution_traits::as_number returns the 
       * maximum value an int64_t can hold and frac_sec_per_day 
       * is microseconds per day (lowest possible value). 
       * The division operation will then return a value of 106751991 - 
       * easily fitting in an unsigned long. 
       */
      return static_cast<unsigned long>(resolution_traits::as_number(time_count_) / frac_sec_per_day());
    }
    int_type time_count() const
    {
      return resolution_traits::as_number(time_count_);
    }
    int_type tod() const
    {
      return resolution_traits::as_number(time_count_) % frac_sec_per_day();
    }
    static int_type frac_sec_per_day()
    {
      int_type seconds_per_day = 60*60*24;
      int_type fractional_sec_per_sec(resolution_traits::res_adjust());
      return seconds_per_day*fractional_sec_per_sec;
    }
    bool is_pos_infinity()const
    {
      return impl_type::is_pos_inf(time_count_.as_number());
    }
    bool is_neg_infinity()const
    {
      return impl_type::is_neg_inf(time_count_.as_number());
    }
    bool is_not_a_date_time()const
    {
      return impl_type::is_not_a_number(time_count_.as_number());
    }
    bool is_special()const
    {
      return time_count_.is_special();
    }
    impl_type get_rep()const
    {
      return time_count_;
    }
  private:
    impl_type time_count_;
  };

  //! An unadjusted time system implementation.
  template<class time_rep>



( run in 0.630 second using v1.01-cache-2.11-cpan-39bf76dae61 )