Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:36

0001 #ifndef DATE_TIME_C_TIME_HPP___
0002 #define DATE_TIME_C_TIME_HPP___
0003 
0004 /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc.
0005  * Use, modification and distribution is subject to the
0006  * Boost Software License, Version 1.0. (See accompanying
0007  * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
0008  * Author: Jeff Garland, Bart Garst
0009  * $Date$
0010  */
0011 
0012 
0013 /*! @file c_time.hpp
0014   Provide workarounds related to the ctime header
0015 */
0016 
0017 #include <ctime>
0018 #include <string> // to be able to convert from string literals to exceptions
0019 #include <stdexcept>
0020 #include <boost/throw_exception.hpp>
0021 #include <boost/date_time/compiler_config.hpp>
0022 
0023 //Work around libraries that don't put time_t and time in namespace std
0024 #ifdef BOOST_NO_STDC_NAMESPACE
0025 namespace std { using ::time_t; using ::time; using ::localtime;
0026                 using ::tm;  using ::gmtime; }
0027 #endif // BOOST_NO_STDC_NAMESPACE
0028 
0029 //The following is used to support high precision time clocks
0030 #ifdef BOOST_HAS_GETTIMEOFDAY
0031 #include <sys/time.h>
0032 #endif
0033 
0034 #ifdef BOOST_HAS_FTIME
0035 #include <time.h>
0036 #endif
0037 
0038 namespace boost {
0039 namespace date_time {
0040   //! Provides a uniform interface to some 'ctime' functions
0041   /*! Provides a uniform interface to some ctime functions and
0042    * their '_r' counterparts. The '_r' functions require a pointer to a
0043    * user created std::tm struct whereas the regular functions use a
0044    * staticly created struct and return a pointer to that. These wrapper
0045    * functions require the user to create a std::tm struct and send in a
0046    * pointer to it. This struct may be used to store the resulting time.
0047    * The returned pointer may or may not point to this struct, however,
0048    * it will point to the result of the corresponding function.
0049    * All functions do proper checking of the C function results and throw
0050    * exceptions on error. Therefore the functions will never return NULL.
0051    */
0052   struct c_time {
0053     public:
0054 #if defined(BOOST_DATE_TIME_HAS_REENTRANT_STD_FUNCTIONS)
0055       //! requires a pointer to a user created std::tm struct
0056       inline
0057       static std::tm* localtime(const std::time_t* t, std::tm* result)
0058       {
0059         // localtime_r() not in namespace std???
0060 #if defined(__VMS) && __INITIAL_POINTER_SIZE == 64
0061         std::tm tmp;
0062         if(!localtime_r(t,&tmp))
0063             result = 0;
0064         else
0065             *result = tmp;
0066 #else
0067         result = localtime_r(t, result);
0068 #endif
0069         if (!result)
0070           boost::throw_exception(std::runtime_error("could not convert calendar time to local time"));
0071         return result;
0072       }
0073       //! requires a pointer to a user created std::tm struct
0074       inline
0075       static std::tm* gmtime(const std::time_t* t, std::tm* result)
0076       {
0077         // gmtime_r() not in namespace std???
0078 #if defined(__VMS) && __INITIAL_POINTER_SIZE == 64
0079         std::tm tmp;
0080         if(!gmtime_r(t,&tmp))
0081           result = 0;
0082         else
0083           *result = tmp;
0084 #else
0085         result = gmtime_r(t, result);
0086 #endif
0087         if (!result)
0088           boost::throw_exception(std::runtime_error("could not convert calendar time to UTC time"));
0089         return result;
0090       }
0091 #else // BOOST_DATE_TIME_HAS_REENTRANT_STD_FUNCTIONS
0092 
0093 #if defined(__clang__) // Clang has to be checked before MSVC
0094 #pragma clang diagnostic push
0095 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
0096 #elif (defined(_MSC_VER) && (_MSC_VER >= 1400))
0097 #pragma warning(push) // preserve warning settings
0098 #pragma warning(disable : 4996) // disable depricated localtime/gmtime warning on vc8
0099 #endif
0100       //! requires a pointer to a user created std::tm struct
0101       inline
0102       static std::tm* localtime(const std::time_t* t, std::tm* result)
0103       {
0104         result = std::localtime(t);
0105         if (!result)
0106           boost::throw_exception(std::runtime_error("could not convert calendar time to local time"));
0107         return result;
0108       }
0109       //! requires a pointer to a user created std::tm struct
0110       inline
0111       static std::tm* gmtime(const std::time_t* t, std::tm* result)
0112       {
0113         result = std::gmtime(t);
0114         if (!result)
0115           boost::throw_exception(std::runtime_error("could not convert calendar time to UTC time"));
0116         return result;
0117       }
0118 #if defined(__clang__) // Clang has to be checked before MSVC
0119 #pragma clang diagnostic pop
0120 #elif (defined(_MSC_VER) && (_MSC_VER >= 1400))
0121 #pragma warning(pop) // restore warnings to previous state
0122 #endif
0123 
0124 #endif // BOOST_DATE_TIME_HAS_REENTRANT_STD_FUNCTIONS
0125   };
0126 }} // namespaces
0127 
0128 #endif // DATE_TIME_C_TIME_HPP___