posix_time_duration.hpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef POSIX_TIME_DURATION_HPP___
  2. #define POSIX_TIME_DURATION_HPP___
  3. /* Copyright (c) 2002,2003 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
  8. * $Date$
  9. */
  10. #include <boost/core/enable_if.hpp>
  11. #include <boost/date_time/compiler_config.hpp>
  12. #include <boost/date_time/posix_time/posix_time_config.hpp>
  13. #include <boost/numeric/conversion/cast.hpp>
  14. #include <boost/type_traits/is_integral.hpp>
  15. namespace boost {
  16. namespace posix_time {
  17. //! Allows expression of durations as an hour count
  18. //! The argument must be an integral type
  19. /*! \ingroup time_basics
  20. */
  21. class BOOST_SYMBOL_VISIBLE hours : public time_duration
  22. {
  23. public:
  24. template <typename T>
  25. explicit hours(T const& h,
  26. typename boost::enable_if<boost::is_integral<T>, void>::type* = BOOST_DATE_TIME_NULLPTR) :
  27. time_duration(numeric_cast<hour_type>(h), 0, 0)
  28. {}
  29. };
  30. //! Allows expression of durations as a minute count
  31. //! The argument must be an integral type
  32. /*! \ingroup time_basics
  33. */
  34. class BOOST_SYMBOL_VISIBLE minutes : public time_duration
  35. {
  36. public:
  37. template <typename T>
  38. explicit minutes(T const& m,
  39. typename boost::enable_if<boost::is_integral<T>, void>::type* = BOOST_DATE_TIME_NULLPTR) :
  40. time_duration(0, numeric_cast<min_type>(m),0)
  41. {}
  42. };
  43. //! Allows expression of durations as a seconds count
  44. //! The argument must be an integral type
  45. /*! \ingroup time_basics
  46. */
  47. class BOOST_SYMBOL_VISIBLE seconds : public time_duration
  48. {
  49. public:
  50. template <typename T>
  51. explicit seconds(T const& s,
  52. typename boost::enable_if<boost::is_integral<T>, void>::type* = BOOST_DATE_TIME_NULLPTR) :
  53. time_duration(0,0, numeric_cast<sec_type>(s))
  54. {}
  55. };
  56. //! Allows expression of durations as milli seconds
  57. /*! \ingroup time_basics
  58. */
  59. typedef date_time::subsecond_duration<time_duration,1000> millisec;
  60. typedef date_time::subsecond_duration<time_duration,1000> milliseconds;
  61. //! Allows expression of durations as micro seconds
  62. /*! \ingroup time_basics
  63. */
  64. typedef date_time::subsecond_duration<time_duration,1000000> microsec;
  65. typedef date_time::subsecond_duration<time_duration,1000000> microseconds;
  66. //This is probably not needed anymore...
  67. #if defined(BOOST_DATE_TIME_HAS_NANOSECONDS)
  68. //! Allows expression of durations as nano seconds
  69. /*! \ingroup time_basics
  70. */
  71. typedef date_time::subsecond_duration<time_duration,1000000000> nanosec;
  72. typedef date_time::subsecond_duration<time_duration,1000000000> nanoseconds;
  73. #endif
  74. } }//namespace posix_time
  75. #endif