BVB Source Codes

mars Show chrono.hpp Source code

Return Download mars: download chrono.hpp Source code - Download mars Source code - Type:.hpp
  1. //  posix/chrono.cpp  --------------------------------------------------------------//
  2.  
  3. //  Copyright Beman Dawes 2008
  4. //  Copyright Vicente J. Botet Escriba 2009
  5.  
  6. //  Distributed under the Boost Software License, Version 1.0.
  7. //  See http://www.boost.org/LICENSE_1_0.txt
  8.  
  9. //----------------------------------------------------------------------------//
  10. //                                POSIX                                     //
  11. //----------------------------------------------------------------------------//
  12.  
  13. #include <time.h>  // for clock_gettime
  14.  
  15. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost
  16. {
  17. namespace chrono
  18. {
  19.  
  20.   system_clock::time_point system_clock::now() BOOST_NOEXCEPT
  21.   {
  22.     timespec ts;
  23.     if ( ::clock_gettime( CLOCK_REALTIME, &ts ) )
  24.     {
  25.       BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
  26.     }
  27.  
  28.     return time_point(duration(
  29.       static_cast<system_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
  30.   }
  31.  
  32. #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
  33.   system_clock::time_point system_clock::now(system::error_code & ec)
  34.   {
  35.     timespec ts;
  36.     if ( ::clock_gettime( CLOCK_REALTIME, &ts ) )
  37.     {
  38.         if (BOOST_CHRONO_IS_THROWS(ec))
  39.         {
  40.             mars_boost::throw_exception(
  41.                     system::system_error(
  42.                             errno,
  43.                             BOOST_CHRONO_SYSTEM_CATEGORY,
  44.                             "chrono::system_clock" ));
  45.         }
  46.         else
  47.         {
  48.             ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
  49.             return time_point();
  50.         }
  51.     }
  52.  
  53.     if (!BOOST_CHRONO_IS_THROWS(ec))
  54.     {
  55.         ec.clear();
  56.     }
  57.     return time_point(duration(
  58.       static_cast<system_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
  59.   }
  60. #endif
  61.  
  62.   std::time_t system_clock::to_time_t(const system_clock::time_point& t) BOOST_NOEXCEPT
  63.   {
  64.       return static_cast<std::time_t>( t.time_since_epoch().count() / 1000000000 );
  65.   }
  66.  
  67.   system_clock::time_point system_clock::from_time_t(std::time_t t) BOOST_NOEXCEPT
  68.   {
  69.       return time_point(duration(static_cast<system_clock::rep>(t) * 1000000000));
  70.   }
  71.  
  72. #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
  73.  
  74.   steady_clock::time_point steady_clock::now() BOOST_NOEXCEPT
  75.   {
  76.     timespec ts;
  77.     if ( ::clock_gettime( CLOCK_MONOTONIC, &ts ) )
  78.     {
  79.       BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
  80.     }
  81.  
  82.     return time_point(duration(
  83.       static_cast<steady_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
  84.   }
  85.  
  86. #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
  87.   steady_clock::time_point steady_clock::now(system::error_code & ec)
  88.   {
  89.     timespec ts;
  90.     if ( ::clock_gettime( CLOCK_MONOTONIC, &ts ) )
  91.     {
  92.         if (BOOST_CHRONO_IS_THROWS(ec))
  93.         {
  94.             mars_boost::throw_exception(
  95.                     system::system_error(
  96.                             errno,
  97.                             BOOST_CHRONO_SYSTEM_CATEGORY,
  98.                             "chrono::steady_clock" ));
  99.         }
  100.         else
  101.         {
  102.             ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
  103.             return time_point();
  104.         }
  105.     }
  106.  
  107.     if (!BOOST_CHRONO_IS_THROWS(ec))
  108.     {
  109.         ec.clear();
  110.     }
  111.     return time_point(duration(
  112.       static_cast<steady_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
  113.   }
  114. #endif
  115. #endif
  116.  
  117. }  // namespace chrono
  118. }  // namespace mars_boost
  119.  
  120.  
  121.  
downloadchrono.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top