ptime.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*-----------------------------------------------------------------------------+
  2. Copyright (c) 2008-2009: Joachim Faulhaber
  3. +------------------------------------------------------------------------------+
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENCE.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. +-----------------------------------------------------------------------------*/
  8. /*------------------------------------------------------------------------------
  9. itl_ptime provides adapter code for boost::posix_time::ptime.
  10. It implements incrementation (++) decrementation (--) and a neutral element
  11. w.r.t. addition (identity_element()).
  12. ------------------------------------------------------------------------------*/
  13. #ifndef BOOST_ICL_PTIME_HPP_JOFA_080416
  14. #define BOOST_ICL_PTIME_HPP_JOFA_080416
  15. #include <boost/icl/detail/boost_config.hpp>
  16. #include <boost/detail/workaround.hpp>
  17. #ifdef BOOST_MSVC
  18. #pragma warning(push)
  19. #pragma warning(disable:4100) // boost/date_time/time.hpp(80) : warning C4100: 'as_offset' : unreferenced formal parameter
  20. #pragma warning(disable:4127) // conditional expression is constant
  21. #pragma warning(disable:4244) // 'argument' : conversion from 'int' to 'unsigned short', possible loss of data
  22. #pragma warning(disable:4702) // boost\lexical_cast.hpp(1159) : warning C4702: unreachable code
  23. #pragma warning(disable:4996) // Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
  24. #endif
  25. #include <stdio.h>
  26. #include <string>
  27. #include <sstream>
  28. #include <iostream>
  29. #include <boost/date_time/posix_time/posix_time.hpp>
  30. #ifdef BOOST_MSVC
  31. #pragma warning(pop)
  32. #endif
  33. #include <boost/icl/type_traits/identity_element.hpp>
  34. #include <boost/icl/type_traits/difference_type_of.hpp>
  35. #include <boost/icl/type_traits/size_type_of.hpp>
  36. #include <boost/icl/type_traits/is_discrete.hpp>
  37. namespace boost{namespace icl
  38. {
  39. template<> struct is_discrete<boost::posix_time::ptime>
  40. {
  41. typedef is_discrete type;
  42. BOOST_STATIC_CONSTANT(bool, value = true);
  43. };
  44. template<>
  45. inline boost::posix_time::ptime identity_element<boost::posix_time::ptime>::value()
  46. {
  47. return boost::posix_time::ptime(boost::posix_time::min_date_time);
  48. }
  49. template<>
  50. struct has_difference<boost::posix_time::ptime>
  51. {
  52. typedef has_difference type;
  53. BOOST_STATIC_CONSTANT(bool, value = true);
  54. };
  55. template<>
  56. struct difference_type_of<boost::posix_time::ptime>
  57. {
  58. typedef boost::posix_time::time_duration type;
  59. };
  60. template<>
  61. struct size_type_of<boost::posix_time::ptime>
  62. {
  63. typedef boost::posix_time::time_duration type;
  64. };
  65. // ------------------------------------------------------------------------
  66. inline boost::posix_time::ptime operator ++(boost::posix_time::ptime& x)
  67. {
  68. return x += boost::posix_time::ptime::time_duration_type::unit();
  69. }
  70. inline boost::posix_time::ptime operator --(boost::posix_time::ptime& x)
  71. {
  72. return x -= boost::posix_time::ptime::time_duration_type::unit();
  73. }
  74. // ------------------------------------------------------------------------
  75. template<> struct is_discrete<boost::posix_time::time_duration>
  76. {
  77. typedef is_discrete type;
  78. BOOST_STATIC_CONSTANT(bool, value = true);
  79. };
  80. template<>
  81. struct has_difference<boost::posix_time::time_duration>
  82. {
  83. typedef has_difference type;
  84. BOOST_STATIC_CONSTANT(bool, value = true);
  85. };
  86. template<>
  87. struct size_type_of<boost::posix_time::time_duration>
  88. {
  89. typedef boost::posix_time::time_duration type;
  90. };
  91. inline boost::posix_time::time_duration operator ++(boost::posix_time::time_duration& x)
  92. {
  93. return x += boost::posix_time::ptime::time_duration_type::unit();
  94. }
  95. inline boost::posix_time::time_duration operator --(boost::posix_time::time_duration& x)
  96. {
  97. return x -= boost::posix_time::ptime::time_duration_type::unit();
  98. }
  99. }} // namespace icl boost
  100. #endif