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