123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- #ifndef DATE_TIME_TIME_RESOLUTION_TRAITS_HPP
- #define DATE_TIME_TIME_RESOLUTION_TRAITS_HPP
- #include <boost/cstdint.hpp>
- #include <boost/date_time/time_defs.hpp>
- #include <boost/date_time/int_adapter.hpp>
- #include <boost/date_time/compiler_config.hpp>
- namespace boost {
- namespace date_time {
-
- template <typename T>
-
-
- inline T absolute_value(T x)
- {
- return x < 0 ? -x : x;
- }
-
- struct time_resolution_traits_bi32_impl {
- typedef boost::int32_t int_type;
- typedef boost::int32_t impl_type;
- static int_type as_number(impl_type i){ return i;}
-
- static bool is_adapted() { return false;}
- };
-
- struct time_resolution_traits_adapted32_impl {
- typedef boost::int32_t int_type;
- typedef boost::date_time::int_adapter<boost::int32_t> impl_type;
- static int_type as_number(impl_type i){ return i.as_number();}
-
- static bool is_adapted() { return true;}
- };
-
- struct time_resolution_traits_bi64_impl {
- typedef boost::int64_t int_type;
- typedef boost::int64_t impl_type;
- static int_type as_number(impl_type i){ return i;}
-
- static bool is_adapted() { return false;}
- };
-
- struct time_resolution_traits_adapted64_impl {
- typedef boost::int64_t int_type;
- typedef boost::date_time::int_adapter<boost::int64_t> impl_type;
- static int_type as_number(impl_type i){ return i.as_number();}
-
- static bool is_adapted() { return true;}
- };
- template<typename frac_sec_type,
- time_resolutions res,
- #if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
- boost::int64_t resolution_adjust,
- #else
- typename frac_sec_type::int_type resolution_adjust,
- #endif
- unsigned short frac_digits,
- typename v_type = boost::int32_t >
- class time_resolution_traits {
- public:
- typedef typename frac_sec_type::int_type fractional_seconds_type;
- typedef typename frac_sec_type::int_type tick_type;
- typedef typename frac_sec_type::impl_type impl_type;
- typedef v_type day_type;
- typedef v_type hour_type;
- typedef v_type min_type;
- typedef v_type sec_type;
-
- static fractional_seconds_type as_number(impl_type i)
- {
- return frac_sec_type::as_number(i);
- }
- static bool is_adapted()
- {
- return frac_sec_type::is_adapted();
- }
-
- #if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
- BOOST_STATIC_CONSTANT(boost::int64_t, ticks_per_second = resolution_adjust);
- #else
- BOOST_STATIC_CONSTANT(fractional_seconds_type, ticks_per_second = resolution_adjust);
- #endif
- static time_resolutions resolution()
- {
- return res;
- }
- static unsigned short num_fractional_digits()
- {
- return frac_digits;
- }
- static fractional_seconds_type res_adjust()
- {
- return resolution_adjust;
- }
-
- static tick_type to_tick_count(hour_type hours,
- min_type minutes,
- sec_type seconds,
- fractional_seconds_type fs)
- {
- if(hours < 0 || minutes < 0 || seconds < 0 || fs < 0)
- {
- hours = absolute_value(hours);
- minutes = absolute_value(minutes);
- seconds = absolute_value(seconds);
- fs = absolute_value(fs);
- return (((((fractional_seconds_type(hours)*3600)
- + (fractional_seconds_type(minutes)*60)
- + seconds)*res_adjust()) + fs) * -1);
- }
- return (((fractional_seconds_type(hours)*3600)
- + (fractional_seconds_type(minutes)*60)
- + seconds)*res_adjust()) + fs;
- }
- };
- typedef time_resolution_traits<time_resolution_traits_adapted32_impl, milli, 1000, 3 > milli_res;
- typedef time_resolution_traits<time_resolution_traits_adapted64_impl, micro, 1000000, 6 > micro_res;
- typedef time_resolution_traits<time_resolution_traits_adapted64_impl, nano, 1000000000, 9 > nano_res;
- } }
- #endif
|