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 +-----------------------------------------------------------------------------*/
9 /*------------------------------------------------------------------------------
10 itl_ptime provides adapter code for boost::posix_time::ptime.
11 It implements incrementation (++) decrementation (--) and a neutral element
12 w.r.t. addition (identity_element()).
13 ------------------------------------------------------------------------------*/
15 #ifndef BOOST_ICL_PTIME_HPP_JOFA_080416
16 #define BOOST_ICL_PTIME_HPP_JOFA_080416
18 #include <boost/icl/detail/boost_config.hpp>
19 #include <boost/detail/workaround.hpp>
23 #pragma warning(disable:4100) // boost/date_time/time.hpp(80) : warning C4100: 'as_offset' : unreferenced formal parameter
24 #pragma warning(disable:4127) // conditional expression is constant
25 #pragma warning(disable:4244) // 'argument' : conversion from 'int' to 'unsigned short', possible loss of data
26 #pragma warning(disable:4702) // boost\lexical_cast.hpp(1159) : warning C4702: unreachable code
27 #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'
34 #include <boost/date_time/posix_time/posix_time.hpp>
40 #include <boost/icl/type_traits/identity_element.hpp>
41 #include <boost/icl/type_traits/difference_type_of.hpp>
42 #include <boost/icl/type_traits/size_type_of.hpp>
43 #include <boost/icl/type_traits/is_discrete.hpp>
45 namespace boost{namespace icl
47 template<> struct is_discrete<boost::posix_time::ptime>
49 typedef is_discrete type;
50 BOOST_STATIC_CONSTANT(bool, value = true);
54 inline boost::posix_time::ptime identity_element<boost::posix_time::ptime>::value()
56 return boost::posix_time::ptime(boost::posix_time::min_date_time);
60 struct has_difference<boost::posix_time::ptime>
62 typedef has_difference type;
63 BOOST_STATIC_CONSTANT(bool, value = true);
67 struct difference_type_of<boost::posix_time::ptime>
69 typedef boost::posix_time::time_duration type;
73 struct size_type_of<boost::posix_time::ptime>
75 typedef boost::posix_time::time_duration type;
78 // ------------------------------------------------------------------------
79 inline boost::posix_time::ptime operator ++(boost::posix_time::ptime& x)
81 return x += boost::posix_time::ptime::time_duration_type::unit();
84 inline boost::posix_time::ptime operator --(boost::posix_time::ptime& x)
86 return x -= boost::posix_time::ptime::time_duration_type::unit();
89 // ------------------------------------------------------------------------
90 template<> struct is_discrete<boost::posix_time::time_duration>
92 typedef is_discrete type;
93 BOOST_STATIC_CONSTANT(bool, value = true);
97 struct has_difference<boost::posix_time::time_duration>
99 typedef has_difference type;
100 BOOST_STATIC_CONSTANT(bool, value = true);
104 struct size_type_of<boost::posix_time::time_duration>
106 typedef boost::posix_time::time_duration type;
109 inline boost::posix_time::time_duration operator ++(boost::posix_time::time_duration& x)
111 return x += boost::posix_time::ptime::time_duration_type::unit();
114 inline boost::posix_time::time_duration operator --(boost::posix_time::time_duration& x)
116 return x -= boost::posix_time::ptime::time_duration_type::unit();
118 }} // namespace icl boost