x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
time_system_counted.hpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\references\boost_1_35_0\boost\date_time\time_system_counted.hpp
旋转
特效
属性
历史版本
#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.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date: 2008-02-27 15:00:24 -0500 (Wed, 27 Feb 2008) $ */ #include "boost/date_time/time_defs.hpp" #include
namespace boost { namespace date_time { //! Time representation that uses a single integer count template
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& time_of_day) : time_count_(1) { if(d.is_infinity() || d.is_not_a_date() || time_of_day.is_special()) { time_count_ = time_of_day.get_rep() + d.day_count(); //std::cout << time_count_ << std::endl; } else { time_count_ = (d.day_number() * frac_sec_per_day()) + time_of_day.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
(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 counted_time_system { public: typedef time_rep time_rep_type; typedef typename time_rep_type::impl_type impl_type; typedef typename time_rep_type::time_duration_type time_duration_type; typedef typename time_duration_type::fractional_seconds_type fractional_seconds_type; typedef typename time_rep_type::date_type date_type; typedef typename time_rep_type::date_duration_type date_duration_type; template
static void unused_var(const T&) {} static time_rep_type get_time_rep(const date_type& day, const time_duration_type& tod, date_time::dst_flags dst=not_dst) { unused_var(dst); return time_rep_type(day, tod); } static time_rep_type get_time_rep(special_values sv) { switch (sv) { case not_a_date_time: return time_rep_type(date_type(not_a_date_time), time_duration_type(not_a_date_time)); case pos_infin: return time_rep_type(date_type(pos_infin), time_duration_type(pos_infin)); case neg_infin: return time_rep_type(date_type(neg_infin), time_duration_type(neg_infin)); case max_date_time: { time_duration_type td = time_duration_type(24,0,0,0) - time_duration_type(0,0,0,1); return time_rep_type(date_type(max_date_time), td); } case min_date_time: return time_rep_type(date_type(min_date_time), time_duration_type(0,0,0,0)); default: return time_rep_type(date_type(not_a_date_time), time_duration_type(not_a_date_time)); } } static date_type get_date(const time_rep_type& val) { return val.date(); } static time_duration_type get_time_of_day(const time_rep_type& val) { if(val.is_special()) { return time_duration_type(val.get_rep().as_special()); } else{ return time_duration_type(0,0,0,val.tod()); } } static std::string zone_name(const time_rep_type&) { return ""; } static bool is_equal(const time_rep_type& lhs, const time_rep_type& rhs) { return (lhs.time_count() == rhs.time_count()); } static bool is_less(const time_rep_type& lhs, const time_rep_type& rhs) { return (lhs.time_count() < rhs.time_count()); } static time_rep_type add_days(const time_rep_type& base, const date_duration_type& dd) { if(base.is_special() || dd.is_special()) { return(time_rep_type(base.get_rep() + dd.get_rep())); } else { return time_rep_type(base.time_count() + (dd.days() * time_rep_type::frac_sec_per_day())); } } static time_rep_type subtract_days(const time_rep_type& base, const date_duration_type& dd) { if(base.is_special() || dd.is_special()) { return(time_rep_type(base.get_rep() - dd.get_rep())); } else{ return time_rep_type(base.time_count() - (dd.days() * time_rep_type::frac_sec_per_day())); } } static time_rep_type subtract_time_duration(const time_rep_type& base, const time_duration_type& td) { if(base.is_special() || td.is_special()) { return(time_rep_type(base.get_rep() - td.get_rep())); } else { return time_rep_type(base.time_count() - td.ticks()); } } static time_rep_type add_time_duration(const time_rep_type& base, time_duration_type td) { if(base.is_special() || td.is_special()) { return(time_rep_type(base.get_rep() + td.get_rep())); } else { return time_rep_type(base.time_count() + td.ticks()); } } static time_duration_type subtract_times(const time_rep_type& lhs, const time_rep_type& rhs) { if(lhs.is_special() || rhs.is_special()) { return(time_duration_type( impl_type::to_special((lhs.get_rep() - rhs.get_rep()).as_number()))); } else { fractional_seconds_type fs = lhs.time_count() - rhs.time_count(); return time_duration_type(0,0,0,fs); } } }; } } //namespace date_time #endif
time_system_counted.hpp
网页地址
文件地址
上一页
54/60
下一页
下载
( 8 KB )
Comments
Total ratings:
0
Average rating:
无评论
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.