1 | #ifndef DATE_TIME_C_TIME_HPP___
|
---|
2 | #define DATE_TIME_C_TIME_HPP___
|
---|
3 |
|
---|
4 | /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc.
|
---|
5 | * Use, modification and distribution is subject to the
|
---|
6 | * Boost Software License, Version 1.0. (See accompanying
|
---|
7 | * file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
---|
8 | * Author: Jeff Garland, Bart Garst
|
---|
9 | * $Date: 2005/03/20 16:41:07 $
|
---|
10 | */
|
---|
11 |
|
---|
12 |
|
---|
13 | /*! @file c_time.hpp
|
---|
14 | Provide workarounds related to the ctime header
|
---|
15 | */
|
---|
16 |
|
---|
17 | #include "boost/date_time/compiler_config.hpp"
|
---|
18 | #include <ctime>
|
---|
19 | //Work around libraries that don't put time_t and time in namespace std
|
---|
20 |
|
---|
21 | #ifdef BOOST_NO_STDC_NAMESPACE
|
---|
22 | namespace std { using ::time_t; using ::time; using ::localtime;
|
---|
23 | using ::tm; using ::gmtime; }
|
---|
24 | #endif // BOOST_NO_STDC_NAMESPACE
|
---|
25 |
|
---|
26 | //The following is used to support high precision time clocks
|
---|
27 | #ifdef BOOST_HAS_GETTIMEOFDAY
|
---|
28 | #include <sys/time.h>
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | #ifdef BOOST_HAS_FTIME
|
---|
32 | #include <time.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | namespace boost {
|
---|
36 | namespace date_time {
|
---|
37 | //! Provides a uniform interface to some 'ctime' functions
|
---|
38 | /*! Provides a uniform interface to some ctime functions and
|
---|
39 | * their '_r' counterparts. The '_r' functions require a pointer to a
|
---|
40 | * user created std::tm struct whereas the regular functions use a
|
---|
41 | * staticly created struct and return a pointer to that. These wrapper
|
---|
42 | * functions require the user to create a std::tm struct and send in a
|
---|
43 | * pointer to it. A pointer to the user created struct will be returned. */
|
---|
44 | struct c_time {
|
---|
45 | public:
|
---|
46 | #if defined(BOOST_DATE_TIME_HAS_REENTRANT_STD_FUNCTIONS)
|
---|
47 | //! requires a pointer to a user created std::tm struct
|
---|
48 | inline
|
---|
49 | static std::tm* localtime(const std::time_t* t, std::tm* result)
|
---|
50 | {
|
---|
51 | // localtime_r() not in namespace std???
|
---|
52 | result = localtime_r(t, result);
|
---|
53 | return result;
|
---|
54 | }
|
---|
55 | //! requires a pointer to a user created std::tm struct
|
---|
56 | inline
|
---|
57 | static std::tm* gmtime(const std::time_t* t, std::tm* result)
|
---|
58 | {
|
---|
59 | // gmtime_r() not in namespace std???
|
---|
60 | result = gmtime_r(t, result);
|
---|
61 | return result;
|
---|
62 | }
|
---|
63 | #else
|
---|
64 | //! requires a pointer to a user created std::tm struct
|
---|
65 | inline
|
---|
66 | static std::tm* localtime(const std::time_t* t, std::tm* result)
|
---|
67 | {
|
---|
68 | result = std::localtime(t);
|
---|
69 | return result;
|
---|
70 | }
|
---|
71 | //! requires a pointer to a user created std::tm struct
|
---|
72 | inline
|
---|
73 | static std::tm* gmtime(const std::time_t* t, std::tm* result)
|
---|
74 | {
|
---|
75 | result = std::gmtime(t);
|
---|
76 | return result;
|
---|
77 | }
|
---|
78 | #endif // BOOST_HAS_THREADS
|
---|
79 | };
|
---|
80 | }} // namespaces
|
---|
81 |
|
---|
82 | #endif // DATE_TIME_C_TIME_HPP___
|
---|