Ticket #5428: boost central time wrapper.patch

File boost central time wrapper.patch, 3.3 KB (added by Ulrich Eckhardt <ulrich.eckhardt@…>, 11 years ago)

add central point for time() workarounds

  • c_time.hpp

     
    5757      static std::tm* localtime(const std::time_t* t, std::tm* result)
    5858      {
    5959        // localtime_r() not in namespace std???
    60         #if defined(__VMS) && __INITIAL_POINTER_SIZE == 64
    61         std::tm tmp;
    62         if(!localtime_r(t,&tmp))
    63             result = 0;
    64         else
    65             *result = tmp;     
    66         #else
     60#if defined(__VMS) && __INITIAL_POINTER_SIZE == 64
     61        std::tm tmp;
     62        if(!localtime_r(t,&tmp))
     63          result = 0;
     64        else
     65          *result = tmp;
     66#else
    6767        result = localtime_r(t, result);
    68         #endif
     68#endif
    6969        if (!result)
    7070          boost::throw_exception(std::runtime_error("could not convert calendar time to local time"));
    7171        return result;
     
    7575      static std::tm* gmtime(const std::time_t* t, std::tm* result)
    7676      {
    7777        // gmtime_r() not in namespace std???
    78         #if defined(__VMS) && __INITIAL_POINTER_SIZE == 64
    79         std::tm tmp;
    80         if(!gmtime_r(t,&tmp))
     78#if defined(__VMS) && __INITIAL_POINTER_SIZE == 64
     79        std::tm tmp;
     80        if(!gmtime_r(t,&tmp))
    8181          result = 0;
    8282        else
    83           *result = tmp;       
    84         #else
     83          *result = tmp;
     84#else
    8585        result = gmtime_r(t, result);
    86         #endif
     86#endif
    8787        if (!result)
    8888          boost::throw_exception(std::runtime_error("could not convert calendar time to UTC time"));
    8989        return result;
    9090      }
    91 #else // BOOST_HAS_THREADS
     91#else
    9292
    9393#if (defined(_MSC_VER) && (_MSC_VER >= 1400))
    9494#pragma warning(push) // preserve warning settings
     
    116116#pragma warning(pop) // restore warnings to previous state
    117117#endif // _MSC_VER >= 1400
    118118
    119 #endif // BOOST_HAS_THREADS
     119#endif
     120
     121      std::time_t time(std::time_t* t)
     122      {
     123        return std::time(t);
     124      }
    120125  };
    121126}} // namespaces
    122127
  • date_clock_device.hpp

     
    5858  private:
    5959    static ::std::tm* get_local_time(std::tm& result)
    6060    {
    61       ::std::time_t t;
    62       ::std::time(&t);
     61      ::std::time_t t = c_time::time(0);
    6362      return c_time::localtime(&t, &result);
    6463    }
    6564    static ::std::tm* get_universal_time(std::tm& result)
    6665    {
    67       ::std::time_t t;
    68       ::std::time(&t);
     66      ::std::time_t t = c_time::time(0);
    6967      return c_time::gmtime(&t, &result);
    7068    }
    7169
  • time_clock.hpp

     
    3232
    3333    static time_type local_time()
    3434    {
    35       ::std::time_t t;
    36       ::std::time(&t);
     35      ::std::time_t t = c_time::time(0);
    3736      ::std::tm curr, *curr_ptr;
    38       //curr_ptr = ::std::localtime(&t);
    3937      curr_ptr = c_time::localtime(&t, &curr);
    4038      return create_time(curr_ptr);
    4139    }
     
    4543    static time_type universal_time()
    4644    {
    4745
    48       ::std::time_t t;
    49       ::std::time(&t);
     46      ::std::time_t t = c_time::time(0);
    5047      ::std::tm curr, *curr_ptr;
    51       //curr_ptr = ::std::gmtime(&t);
    5248      curr_ptr = c_time::gmtime(&t, &curr);
    5349      return create_time(curr_ptr);
    5450    }