posix_time_config.hpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #ifndef POSIX_TIME_CONFIG_HPP___
  2. #define POSIX_TIME_CONFIG_HPP___
  3. /* Copyright (c) 2002,2003,2005,2020 CrystalClear Software, Inc.
  4. * Use, modification and distribution is subject to the
  5. * Boost Software License, Version 1.0. (See accompanying
  6. * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  7. * Author: Jeff Garland, Bart Garst
  8. * $Date$
  9. */
  10. #include <cstdlib> //for MCW 7.2 std::abs(long long)
  11. #include <boost/limits.hpp>
  12. #include <boost/cstdint.hpp>
  13. #include <boost/config/no_tr1/cmath.hpp>
  14. #include <boost/date_time/time_duration.hpp>
  15. #include <boost/date_time/time_resolution_traits.hpp>
  16. #include <boost/date_time/gregorian/gregorian_types.hpp>
  17. #include <boost/date_time/wrapping_int.hpp>
  18. #include <boost/date_time/compiler_config.hpp>
  19. namespace boost {
  20. namespace posix_time {
  21. #ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
  22. // set up conditional test compilations
  23. #define BOOST_DATE_TIME_HAS_NANOSECONDS
  24. typedef date_time::time_resolution_traits<boost::date_time::time_resolution_traits_adapted64_impl, boost::date_time::nano,
  25. 1000000000, 9 > time_res_traits;
  26. #else
  27. // set up conditional test compilations
  28. #undef BOOST_DATE_TIME_HAS_NANOSECONDS
  29. typedef date_time::time_resolution_traits<
  30. boost::date_time::time_resolution_traits_adapted64_impl, boost::date_time::micro,
  31. 1000000, 6 > time_res_traits;
  32. #endif
  33. //! Base time duration type
  34. /*! \ingroup time_basics
  35. */
  36. class BOOST_SYMBOL_VISIBLE time_duration :
  37. public date_time::time_duration<time_duration, time_res_traits>
  38. {
  39. public:
  40. typedef time_res_traits rep_type;
  41. typedef time_res_traits::day_type day_type;
  42. typedef time_res_traits::hour_type hour_type;
  43. typedef time_res_traits::min_type min_type;
  44. typedef time_res_traits::sec_type sec_type;
  45. typedef time_res_traits::fractional_seconds_type fractional_seconds_type;
  46. typedef time_res_traits::tick_type tick_type;
  47. typedef time_res_traits::impl_type impl_type;
  48. BOOST_CXX14_CONSTEXPR time_duration(hour_type hour,
  49. min_type min,
  50. sec_type sec,
  51. fractional_seconds_type fs=0) :
  52. date_time::time_duration<time_duration, time_res_traits>(hour,min,sec,fs)
  53. {}
  54. BOOST_CXX14_CONSTEXPR time_duration() :
  55. date_time::time_duration<time_duration, time_res_traits>(0,0,0)
  56. {}
  57. //! Construct from special_values
  58. BOOST_CXX14_CONSTEXPR time_duration(boost::date_time::special_values sv) :
  59. date_time::time_duration<time_duration, time_res_traits>(sv)
  60. {}
  61. //Give duration access to ticks constructor -- hide from users
  62. friend class date_time::time_duration<time_duration, time_res_traits>;
  63. protected:
  64. BOOST_CXX14_CONSTEXPR explicit time_duration(impl_type tick_count) :
  65. date_time::time_duration<time_duration, time_res_traits>(tick_count)
  66. {}
  67. };
  68. #ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
  69. //! Simple implementation for the time rep
  70. struct simple_time_rep
  71. {
  72. typedef gregorian::date date_type;
  73. typedef time_duration time_duration_type;
  74. BOOST_CXX14_CONSTEXPR simple_time_rep(date_type d, time_duration_type tod) :
  75. day(d),
  76. time_of_day(tod)
  77. {
  78. // make sure we have sane values for date & time
  79. if(!day.is_special() && !time_of_day.is_special()){
  80. if(time_of_day >= time_duration_type(24,0,0)) {
  81. while(time_of_day >= time_duration_type(24,0,0)) {
  82. day += date_type::duration_type(1);
  83. time_of_day -= time_duration_type(24,0,0);
  84. }
  85. }
  86. else if(time_of_day.is_negative()) {
  87. while(time_of_day.is_negative()) {
  88. day -= date_type::duration_type(1);
  89. time_of_day += time_duration_type(24,0,0);
  90. }
  91. }
  92. }
  93. }
  94. date_type day;
  95. time_duration_type time_of_day;
  96. BOOST_CXX14_CONSTEXPR bool is_special()const
  97. {
  98. return(is_pos_infinity() || is_neg_infinity() || is_not_a_date_time());
  99. }
  100. BOOST_CXX14_CONSTEXPR bool is_pos_infinity()const
  101. {
  102. return(day.is_pos_infinity() || time_of_day.is_pos_infinity());
  103. }
  104. BOOST_CXX14_CONSTEXPR bool is_neg_infinity()const
  105. {
  106. return(day.is_neg_infinity() || time_of_day.is_neg_infinity());
  107. }
  108. BOOST_CXX14_CONSTEXPR bool is_not_a_date_time()const
  109. {
  110. return(day.is_not_a_date() || time_of_day.is_not_a_date_time());
  111. }
  112. };
  113. class BOOST_SYMBOL_VISIBLE posix_time_system_config
  114. {
  115. public:
  116. typedef simple_time_rep time_rep_type;
  117. typedef gregorian::date date_type;
  118. typedef gregorian::date_duration date_duration_type;
  119. typedef time_duration time_duration_type;
  120. typedef time_res_traits::tick_type int_type;
  121. typedef time_res_traits resolution_traits;
  122. #if (defined(BOOST_DATE_TIME_NO_MEMBER_INIT)) //help bad compilers
  123. #else
  124. BOOST_STATIC_CONSTANT(boost::int64_t, tick_per_second = 1000000000);
  125. #endif
  126. };
  127. #else
  128. class millisec_posix_time_system_config
  129. {
  130. public:
  131. typedef boost::int64_t time_rep_type;
  132. //typedef time_res_traits::tick_type time_rep_type;
  133. typedef gregorian::date date_type;
  134. typedef gregorian::date_duration date_duration_type;
  135. typedef time_duration time_duration_type;
  136. typedef time_res_traits::tick_type int_type;
  137. typedef time_res_traits::impl_type impl_type;
  138. typedef time_res_traits resolution_traits;
  139. #if (defined(BOOST_DATE_TIME_NO_MEMBER_INIT)) //help bad compilers
  140. #else
  141. BOOST_STATIC_CONSTANT(boost::int64_t, tick_per_second = 1000000);
  142. #endif
  143. };
  144. #endif
  145. } }//namespace posix_time
  146. #endif