author | mikek |
Mon, 10 May 2010 19:54:49 +0100 | |
changeset 2 | 39c28ec933dd |
permissions | -rwxr-xr-x |
2
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
1 |
#ifndef DATE_TIME_C_TIME_HPP___ |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
2 |
#define DATE_TIME_C_TIME_HPP___ |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
3 |
|
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
4 |
/* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc. |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
5 |
* Use, modification and distribution is subject to the |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
6 |
* Boost Software License, Version 1.0. (See accompanying |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
7 |
* file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
8 |
* Author: Jeff Garland, Bart Garst |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
9 |
* $Date: 2008-11-12 14:37:53 -0500 (Wed, 12 Nov 2008) $ |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
10 |
*/ |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
11 |
|
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
12 |
|
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
13 |
/*! @file c_time.hpp |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
14 |
Provide workarounds related to the ctime header |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
15 |
*/ |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
16 |
|
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
17 |
#include <ctime> |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
18 |
#include <string> // to be able to convert from string literals to exceptions |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
19 |
#include <stdexcept> |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
20 |
#include <boost/throw_exception.hpp> |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
21 |
#include <boost/date_time/compiler_config.hpp> |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
22 |
|
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
23 |
//Work around libraries that don't put time_t and time in namespace std |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
24 |
#ifdef BOOST_NO_STDC_NAMESPACE |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
25 |
namespace std { using ::time_t; using ::time; using ::localtime; |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
26 |
using ::tm; using ::gmtime; } |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
27 |
#endif // BOOST_NO_STDC_NAMESPACE |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
28 |
|
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
29 |
//The following is used to support high precision time clocks |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
30 |
#ifdef BOOST_HAS_GETTIMEOFDAY |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
31 |
#include <sys/time.h> |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
32 |
#endif |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
33 |
|
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
34 |
#ifdef BOOST_HAS_FTIME |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
35 |
#include <time.h> |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
36 |
#endif |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
37 |
|
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
38 |
namespace boost { |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
39 |
namespace date_time { |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
40 |
//! Provides a uniform interface to some 'ctime' functions |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
41 |
/*! Provides a uniform interface to some ctime functions and |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
42 |
* their '_r' counterparts. The '_r' functions require a pointer to a |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
43 |
* user created std::tm struct whereas the regular functions use a |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
44 |
* staticly created struct and return a pointer to that. These wrapper |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
45 |
* functions require the user to create a std::tm struct and send in a |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
46 |
* pointer to it. A pointer to the user created struct will be returned. |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
47 |
* All functions do proper checking of the C function results and throw |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
48 |
* exceptions on error. Therefore the functions will never return NULL. |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
49 |
*/ |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
50 |
struct c_time { |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
51 |
public: |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
52 |
#if defined(BOOST_DATE_TIME_HAS_REENTRANT_STD_FUNCTIONS) |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
53 |
//! requires a pointer to a user created std::tm struct |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
54 |
inline |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
55 |
static std::tm* localtime(const std::time_t* t, std::tm* result) |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
56 |
{ |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
57 |
// localtime_r() not in namespace std??? |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
58 |
result = localtime_r(t, result); |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
59 |
if (!result) |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
60 |
boost::throw_exception(std::runtime_error("could not convert calendar time to local time")); |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
61 |
return result; |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
62 |
} |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
63 |
//! requires a pointer to a user created std::tm struct |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
64 |
inline |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
65 |
static std::tm* gmtime(const std::time_t* t, std::tm* result) |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
66 |
{ |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
67 |
// gmtime_r() not in namespace std??? |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
68 |
result = gmtime_r(t, result); |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
69 |
if (!result) |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
70 |
boost::throw_exception(std::runtime_error("could not convert calendar time to UTC time")); |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
71 |
return result; |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
72 |
} |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
73 |
#else // BOOST_HAS_THREADS |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
74 |
|
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
75 |
#if (defined(_MSC_VER) && (_MSC_VER >= 1400)) |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
76 |
#pragma warning(push) // preserve warning settings |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
77 |
#pragma warning(disable : 4996) // disable depricated localtime/gmtime warning on vc8 |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
78 |
#endif // _MSC_VER >= 1400 |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
79 |
//! requires a pointer to a user created std::tm struct |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
80 |
inline |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
81 |
static std::tm* localtime(const std::time_t* t, std::tm* result) |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
82 |
{ |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
83 |
result = std::localtime(t); |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
84 |
if (!result) |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
85 |
boost::throw_exception(std::runtime_error("could not convert calendar time to local time")); |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
86 |
return result; |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
87 |
} |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
88 |
//! requires a pointer to a user created std::tm struct |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
89 |
inline |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
90 |
static std::tm* gmtime(const std::time_t* t, std::tm* result) |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
91 |
{ |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
92 |
result = std::gmtime(t); |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
93 |
if (!result) |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
94 |
boost::throw_exception(std::runtime_error("could not convert calendar time to UTC time")); |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
95 |
return result; |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
96 |
} |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
97 |
#if (defined(_MSC_VER) && (_MSC_VER >= 1400)) |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
98 |
#pragma warning(pop) // restore warnings to previous state |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
99 |
#endif // _MSC_VER >= 1400 |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
100 |
|
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
101 |
#endif // BOOST_HAS_THREADS |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
102 |
}; |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
103 |
}} // namespaces |
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
104 |
|
39c28ec933dd
Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff
changeset
|
105 |
#endif // DATE_TIME_C_TIME_HPP___ |