BVB Source Codes

mars Show time_resolution_traits.hpp Source code

Return Download mars: download time_resolution_traits.hpp Source code - Download mars Source code - Type:.hpp
  1. #ifndef DATE_TIME_TIME_RESOLUTION_TRAITS_HPP
  2. #define DATE_TIME_TIME_RESOLUTION_TRAITS_HPP
  3.  
  4. /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
  5.  * Use, modification and distribution is subject to the
  6.  * Boost Software License, Version 1.0. (See accompanying
  7.  * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  8.  * Author: Jeff Garland, Bart Garst
  9.  * $Date$
  10.  */
  11.  
  12.  
  13. #include <boost/cstdint.hpp>
  14. #include <boost/date_time/time_defs.hpp>
  15. #include <boost/date_time/int_adapter.hpp>
  16. #include <boost/date_time/compiler_config.hpp>
  17.  
  18. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost {
  19. namespace date_time {
  20.  
  21.   //! Simple function to calculate absolute value of a numeric type
  22.   template <typename T>
  23.   // JDG [7/6/02 made a template],
  24.   // moved here from time_duration.hpp 2003-Sept-4.
  25.   inline T absolute_value(T x)
  26.   {
  27.     return x < 0 ? -x : x;
  28.   }
  29.  
  30.   //! traits struct for time_resolution_traits implementation type
  31.   struct time_resolution_traits_bi32_impl {
  32.     typedef mars_boost::int32_t int_type;
  33.     typedef mars_boost::int32_t impl_type;
  34.     static int_type as_number(impl_type i){ return i;}
  35.     //! Used to determine if implemented type is int_adapter or int
  36.     static bool is_adapted() { return false;}
  37.   };
  38.   //! traits struct for time_resolution_traits implementation type
  39.   struct time_resolution_traits_adapted32_impl {
  40.     typedef mars_boost::int32_t int_type;
  41.     typedef mars_boost::date_time::int_adapter<mars_boost::int32_t> impl_type;
  42.     static int_type as_number(impl_type i){ return i.as_number();}
  43.     //! Used to determine if implemented type is int_adapter or int
  44.     static bool is_adapted() { return true;}
  45.   };
  46.   //! traits struct for time_resolution_traits implementation type
  47.   struct time_resolution_traits_bi64_impl {
  48.     typedef mars_boost::int64_t int_type;
  49.     typedef mars_boost::int64_t impl_type;
  50.     static int_type as_number(impl_type i){ return i;}
  51.     //! Used to determine if implemented type is int_adapter or int
  52.     static bool is_adapted() { return false;}
  53.   };
  54.   //! traits struct for time_resolution_traits implementation type
  55.   struct time_resolution_traits_adapted64_impl {
  56.     typedef mars_boost::int64_t int_type;
  57.     typedef mars_boost::date_time::int_adapter<mars_boost::int64_t> impl_type;
  58.     static int_type as_number(impl_type i){ return i.as_number();}
  59.     //! Used to determine if implemented type is int_adapter or int
  60.     static bool is_adapted() { return true;}
  61.   };
  62.  
  63.   template<typename frac_sec_type,
  64.            time_resolutions res,
  65. #if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
  66.            mars_boost::int64_t resolution_adjust,
  67. #else
  68.            typename frac_sec_type::int_type resolution_adjust,
  69. #endif
  70.            unsigned short frac_digits,
  71.            typename var_type = mars_boost::int32_t >
  72.   class time_resolution_traits {
  73.   public:
  74.     typedef typename frac_sec_type::int_type fractional_seconds_type;
  75.     typedef typename frac_sec_type::int_type tick_type;
  76.     typedef typename frac_sec_type::impl_type impl_type;
  77.     typedef var_type  day_type;
  78.     typedef var_type  hour_type;
  79.     typedef var_type  min_type;
  80.     typedef var_type  sec_type;
  81.  
  82.     // bring in function from frac_sec_type traits structs
  83.     static fractional_seconds_type as_number(impl_type i)
  84.     {
  85.       return frac_sec_type::as_number(i);
  86.     }
  87.     static bool is_adapted()
  88.     {
  89.       return frac_sec_type::is_adapted();
  90.     }
  91.  
  92.     //Would like this to be frac_sec_type, but some compilers complain
  93. #if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
  94.     BOOST_STATIC_CONSTANT(mars_boost::int64_t, ticks_per_second = resolution_adjust);
  95. #else
  96.     BOOST_STATIC_CONSTANT(fractional_seconds_type, ticks_per_second = resolution_adjust);
  97. #endif
  98.  
  99.     static time_resolutions resolution()
  100.     {
  101.       return res;
  102.     }
  103.     static unsigned short num_fractional_digits()
  104.     {
  105.       return frac_digits;
  106.     }
  107.     static fractional_seconds_type res_adjust()
  108.     {
  109.       return resolution_adjust;
  110.     }
  111.     //! Any negative argument results in a negative tick_count
  112.     static tick_type to_tick_count(hour_type hours,
  113.                                    min_type  minutes,
  114.                                    sec_type  seconds,
  115.                                    fractional_seconds_type  fs)
  116.     {
  117.       if(hours < 0 || minutes < 0 || seconds < 0 || fs < 0)
  118.       {
  119.         hours = absolute_value(hours);
  120.         minutes = absolute_value(minutes);
  121.         seconds = absolute_value(seconds);
  122.         fs = absolute_value(fs);
  123.         return (((((fractional_seconds_type(hours)*3600)
  124.                    + (fractional_seconds_type(minutes)*60)
  125.                    + seconds)*res_adjust()) + fs) * -1);
  126.       }
  127.  
  128.       return (((fractional_seconds_type(hours)*3600)
  129.                + (fractional_seconds_type(minutes)*60)
  130.                + seconds)*res_adjust()) + fs;
  131.     }
  132.  
  133.   };
  134.  
  135.   typedef time_resolution_traits<time_resolution_traits_adapted32_impl, milli, 1000, 3 > milli_res;
  136.   typedef time_resolution_traits<time_resolution_traits_adapted64_impl, micro, 1000000, 6 > micro_res;
  137.   typedef time_resolution_traits<time_resolution_traits_adapted64_impl, nano,  1000000000, 9 > nano_res;
  138.  
  139.  
  140. } } //namespace date_time
  141.  
  142.  
  143.  
  144. #endif
  145.  
downloadtime_resolution_traits.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top