1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
/*
* Copyright Andrey Semashev 2013.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
/*!
* \file support/boost_chrono.hpp
*
* \brief This header enables support for Boost.Chrono time units.
*/
#ifndef BOOST_SYNC_SUPPORT_BOOST_CHRONO_HPP_INCLUDED_
#define BOOST_SYNC_SUPPORT_BOOST_CHRONO_HPP_INCLUDED_
#include <boost/ratio/ratio.hpp>
#include <boost/chrono/duration.hpp>
#include <boost/chrono/time_point.hpp>
#include <boost/chrono/system_clocks.hpp>
#include <boost/sync/detail/config.hpp>
#include <boost/sync/detail/time_traits.hpp>
#include <boost/sync/detail/time_units.hpp>
#include <boost/sync/detail/header.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
#pragma once
#endif
namespace boost {
namespace sync {
namespace detail {
template< typename Rep, typename Period >
struct time_traits< boost::chrono::duration< Rep, Period > >
{
typedef time_duration_tag tag;
typedef system_duration unit_type;
static BOOST_CONSTEXPR_OR_CONST bool is_specialized = true;
static system_duration to_sync_unit(boost::chrono::duration< Rep, Period > const& dur) BOOST_NOEXCEPT
{
typedef boost::chrono::duration< system_duration::native_type, boost::ratio< 1, system_duration::subsecond_fraction > > system_chrono_duration;
return system_duration(boost::chrono::duration_cast< system_chrono_duration >(dur).count());
}
};
template< typename Clock, typename Duration >
struct time_traits< boost::chrono::time_point< Clock, Duration > >
{
typedef time_point_tag tag;
typedef chrono_time_point< boost::chrono::time_point< Clock, Duration > > unit_type;
static BOOST_CONSTEXPR_OR_CONST bool is_specialized = true;
static unit_type to_sync_unit(boost::chrono::time_point< Clock, Duration > const& point) BOOST_NOEXCEPT
{
return unit_type(point);
}
};
template< typename Duration >
struct time_traits< boost::chrono::time_point< boost::chrono::system_clock, Duration > >
{
typedef time_point_tag tag;
typedef system_time_point unit_type;
static BOOST_CONSTEXPR_OR_CONST bool is_specialized = true;
static system_time_point to_sync_unit(boost::chrono::time_point< boost::chrono::system_clock, Duration > const& point) BOOST_NOEXCEPT
{
typedef typename boost::chrono::time_point< boost::chrono::system_clock, Duration >::duration duration;
// system_clock in Boost.Chrono always have epoch at 1st January 1970
return system_time_point(time_traits< duration >::to_sync_unit(point.time_since_epoch()));
}
};
} // namespace detail
} // namespace sync
} // namespace boost
#include <boost/sync/detail/footer.hpp>
#endif // BOOST_SYNC_SUPPORT_BOOST_CHRONO_HPP_INCLUDED_
|