annotate DEPENDENCIES/generic/include/boost/date_time/time_resolution_traits.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 #ifndef DATE_TIME_TIME_RESOLUTION_TRAITS_HPP
Chris@16 2 #define DATE_TIME_TIME_RESOLUTION_TRAITS_HPP
Chris@16 3
Chris@16 4 /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
Chris@16 5 * Use, modification and distribution is subject to the
Chris@16 6 * Boost Software License, Version 1.0. (See accompanying
Chris@16 7 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
Chris@16 8 * Author: Jeff Garland, Bart Garst
Chris@101 9 * $Date$
Chris@16 10 */
Chris@16 11
Chris@16 12
Chris@16 13 #include <boost/cstdint.hpp>
Chris@16 14 #include <boost/date_time/time_defs.hpp>
Chris@16 15 #include <boost/date_time/int_adapter.hpp>
Chris@16 16 #include <boost/date_time/compiler_config.hpp>
Chris@16 17
Chris@16 18 namespace boost {
Chris@16 19 namespace date_time {
Chris@16 20
Chris@16 21 //! Simple function to calculate absolute value of a numeric type
Chris@16 22 template <typename T>
Chris@16 23 // JDG [7/6/02 made a template],
Chris@16 24 // moved here from time_duration.hpp 2003-Sept-4.
Chris@16 25 inline T absolute_value(T x)
Chris@16 26 {
Chris@16 27 return x < 0 ? -x : x;
Chris@16 28 }
Chris@16 29
Chris@16 30 //! traits struct for time_resolution_traits implementation type
Chris@16 31 struct time_resolution_traits_bi32_impl {
Chris@16 32 typedef boost::int32_t int_type;
Chris@16 33 typedef boost::int32_t impl_type;
Chris@16 34 static int_type as_number(impl_type i){ return i;}
Chris@16 35 //! Used to determine if implemented type is int_adapter or int
Chris@16 36 static bool is_adapted() { return false;}
Chris@16 37 };
Chris@16 38 //! traits struct for time_resolution_traits implementation type
Chris@16 39 struct time_resolution_traits_adapted32_impl {
Chris@16 40 typedef boost::int32_t int_type;
Chris@16 41 typedef boost::date_time::int_adapter<boost::int32_t> impl_type;
Chris@16 42 static int_type as_number(impl_type i){ return i.as_number();}
Chris@16 43 //! Used to determine if implemented type is int_adapter or int
Chris@16 44 static bool is_adapted() { return true;}
Chris@16 45 };
Chris@16 46 //! traits struct for time_resolution_traits implementation type
Chris@16 47 struct time_resolution_traits_bi64_impl {
Chris@16 48 typedef boost::int64_t int_type;
Chris@16 49 typedef boost::int64_t impl_type;
Chris@16 50 static int_type as_number(impl_type i){ return i;}
Chris@16 51 //! Used to determine if implemented type is int_adapter or int
Chris@16 52 static bool is_adapted() { return false;}
Chris@16 53 };
Chris@16 54 //! traits struct for time_resolution_traits implementation type
Chris@16 55 struct time_resolution_traits_adapted64_impl {
Chris@16 56 typedef boost::int64_t int_type;
Chris@16 57 typedef boost::date_time::int_adapter<boost::int64_t> impl_type;
Chris@16 58 static int_type as_number(impl_type i){ return i.as_number();}
Chris@16 59 //! Used to determine if implemented type is int_adapter or int
Chris@16 60 static bool is_adapted() { return true;}
Chris@16 61 };
Chris@16 62
Chris@16 63 template<typename frac_sec_type,
Chris@16 64 time_resolutions res,
Chris@16 65 #if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
Chris@16 66 boost::int64_t resolution_adjust,
Chris@16 67 #else
Chris@16 68 typename frac_sec_type::int_type resolution_adjust,
Chris@16 69 #endif
Chris@16 70 unsigned short frac_digits,
Chris@101 71 typename var_type = boost::int32_t >
Chris@16 72 class time_resolution_traits {
Chris@16 73 public:
Chris@16 74 typedef typename frac_sec_type::int_type fractional_seconds_type;
Chris@16 75 typedef typename frac_sec_type::int_type tick_type;
Chris@16 76 typedef typename frac_sec_type::impl_type impl_type;
Chris@101 77 typedef var_type day_type;
Chris@101 78 typedef var_type hour_type;
Chris@101 79 typedef var_type min_type;
Chris@101 80 typedef var_type sec_type;
Chris@16 81
Chris@16 82 // bring in function from frac_sec_type traits structs
Chris@16 83 static fractional_seconds_type as_number(impl_type i)
Chris@16 84 {
Chris@16 85 return frac_sec_type::as_number(i);
Chris@16 86 }
Chris@16 87 static bool is_adapted()
Chris@16 88 {
Chris@16 89 return frac_sec_type::is_adapted();
Chris@16 90 }
Chris@16 91
Chris@16 92 //Would like this to be frac_sec_type, but some compilers complain
Chris@16 93 #if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
Chris@16 94 BOOST_STATIC_CONSTANT(boost::int64_t, ticks_per_second = resolution_adjust);
Chris@16 95 #else
Chris@16 96 BOOST_STATIC_CONSTANT(fractional_seconds_type, ticks_per_second = resolution_adjust);
Chris@16 97 #endif
Chris@16 98
Chris@16 99 static time_resolutions resolution()
Chris@16 100 {
Chris@16 101 return res;
Chris@16 102 }
Chris@16 103 static unsigned short num_fractional_digits()
Chris@16 104 {
Chris@16 105 return frac_digits;
Chris@16 106 }
Chris@16 107 static fractional_seconds_type res_adjust()
Chris@16 108 {
Chris@16 109 return resolution_adjust;
Chris@16 110 }
Chris@16 111 //! Any negative argument results in a negative tick_count
Chris@16 112 static tick_type to_tick_count(hour_type hours,
Chris@16 113 min_type minutes,
Chris@16 114 sec_type seconds,
Chris@16 115 fractional_seconds_type fs)
Chris@16 116 {
Chris@16 117 if(hours < 0 || minutes < 0 || seconds < 0 || fs < 0)
Chris@16 118 {
Chris@16 119 hours = absolute_value(hours);
Chris@16 120 minutes = absolute_value(minutes);
Chris@16 121 seconds = absolute_value(seconds);
Chris@16 122 fs = absolute_value(fs);
Chris@16 123 return (((((fractional_seconds_type(hours)*3600)
Chris@16 124 + (fractional_seconds_type(minutes)*60)
Chris@16 125 + seconds)*res_adjust()) + fs) * -1);
Chris@16 126 }
Chris@16 127
Chris@16 128 return (((fractional_seconds_type(hours)*3600)
Chris@16 129 + (fractional_seconds_type(minutes)*60)
Chris@16 130 + seconds)*res_adjust()) + fs;
Chris@16 131 }
Chris@16 132
Chris@16 133 };
Chris@16 134
Chris@16 135 typedef time_resolution_traits<time_resolution_traits_adapted32_impl, milli, 1000, 3 > milli_res;
Chris@16 136 typedef time_resolution_traits<time_resolution_traits_adapted64_impl, micro, 1000000, 6 > micro_res;
Chris@16 137 typedef time_resolution_traits<time_resolution_traits_adapted64_impl, nano, 1000000000, 9 > nano_res;
Chris@16 138
Chris@16 139
Chris@16 140 } } //namespace date_time
Chris@16 141
Chris@16 142
Chris@16 143
Chris@16 144 #endif