Add aliases for chrono facilities.
diff --git a/asio/include/asio/detail/chrono.hpp b/asio/include/asio/detail/chrono.hpp new file mode 100644 index 0000000..93cf894 --- /dev/null +++ b/asio/include/asio/detail/chrono.hpp
@@ -0,0 +1,66 @@ +// +// detail/chrono.hpp +// ~~~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// +// 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) +// + +#ifndef ASIO_DETAIL_CHRONO_HPP +#define ASIO_DETAIL_CHRONO_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif // defined(_MSC_VER) && (_MSC_VER >= 1200) + +#include "asio/detail/config.hpp" + +#if defined(ASIO_HAS_STD_CHRONO) +# include <chrono> +#elif defined(ASIO_HAS_BOOST_CHRONO) +# include <boost/chrono/system_clocks.hpp> +#endif // defined(ASIO_HAS_BOOST_CHRONO) + +namespace asio { +namespace chrono { + +#if defined(ASIO_HAS_STD_CHRONO) +using std::chrono::duration; +using std::chrono::time_point; +using std::chrono::duration_cast; +using std::chrono::nanoseconds; +using std::chrono::microseconds; +using std::chrono::milliseconds; +using std::chrono::seconds; +using std::chrono::minutes; +using std::chrono::hours; +using std::chrono::time_point_cast; +#if defined(ASIO_HAS_STD_CHRONO_MONOTONIC_CLOCK) +typedef std::chrono::monotonic_clock system_clock; +#else // defined(ASIO_HAS_STD_CHRONO_MONOTONIC_CLOCK) +using std::chrono::system_clock; +#endif // defined(ASIO_HAS_STD_CHRONO_MONOTONIC_CLOCK) +using std::chrono::steady_clock; +using std::chrono::high_resolution_clock; +#elif defined(ASIO_HAS_BOOST_CHRONO) +using boost::chrono::duration; +using boost::chrono::time_point; +using boost::chrono::duration_cast; +using boost::chrono::nanoseconds; +using boost::chrono::microseconds; +using boost::chrono::milliseconds; +using boost::chrono::seconds; +using boost::chrono::minutes; +using boost::chrono::hours; +using boost::chrono::time_point_cast; +using boost::chrono::system_clock; +using boost::chrono::steady_clock; +using boost::chrono::high_resolution_clock; +#endif // defined(ASIO_HAS_BOOST_CHRONO) + +} // namespace chrono +} // namespace asio + +#endif // ASIO_DETAIL_CHRONO_HPP
diff --git a/asio/include/asio/detail/config.hpp b/asio/include/asio/detail/config.hpp index 43a1e1c..01e499f 100644 --- a/asio/include/asio/detail/config.hpp +++ b/asio/include/asio/detail/config.hpp
@@ -454,6 +454,15 @@ # endif // !defined(ASIO_DISABLE_BOOST_CHRONO) #endif // !defined(ASIO_HAS_BOOST_CHRONO) +// Some form of chrono library is available. +#if !defined(ASIO_HAS_CHRONO) +# if defined(ASIO_HAS_STD_CHRONO) \ + || defined(ASIO_HAS_BOOST_CHRONO) +# define ASIO_HAS_CHRONO 1 +# endif // defined(ASIO_HAS_STD_CHRONO) + // || defined(ASIO_HAS_BOOST_CHRONO) +#endif // !defined(ASIO_HAS_CHRONO) + // Boost support for the DateTime library. #if !defined(ASIO_HAS_BOOST_DATE_TIME) # if !defined(ASIO_DISABLE_BOOST_DATE_TIME)
diff --git a/asio/include/asio/detail/impl/handler_tracking.ipp b/asio/include/asio/detail/impl/handler_tracking.ipp index e838a93..4095a01 100644 --- a/asio/include/asio/detail/impl/handler_tracking.ipp +++ b/asio/include/asio/detail/impl/handler_tracking.ipp
@@ -29,12 +29,8 @@ #if defined(ASIO_HAS_BOOST_DATE_TIME) # include "asio/time_traits.hpp" -#else // defined(ASIO_HAS_BOOST_DATE_TIME) -# if defined(ASIO_HAS_STD_CHRONO) -# include <chrono> -# elif defined(ASIO_HAS_BOOST_CHRONO) -# include <boost/chrono/system_clocks.hpp> -# endif +#elif defined(ASIO_HAS_CHRONO) +# include "asio/detail/chrono.hpp" # include "asio/detail/chrono_time_traits.hpp" # include "asio/wait_traits.hpp" #endif // defined(ASIO_HAS_BOOST_DATE_TIME) @@ -61,16 +57,11 @@ boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1)); boost::posix_time::time_duration now = boost::posix_time::microsec_clock::universal_time() - epoch; -#elif defined(ASIO_HAS_STD_CHRONO) - typedef chrono_time_traits<std::chrono::system_clock, - asio::wait_traits<std::chrono::system_clock> > traits_helper; +#elif defined(ASIO_HAS_CHRONO) + typedef chrono_time_traits<chrono::system_clock, + asio::wait_traits<chrono::system_clock> > traits_helper; traits_helper::posix_time_duration now( - std::chrono::system_clock::now().time_since_epoch()); -#elif defined(ASIO_HAS_BOOST_CHRONO) - typedef chrono_time_traits<boost::chrono::system_clock, - asio::wait_traits<boost::chrono::system_clock> > traits_helper; - traits_helper::posix_time_duration now( - boost::chrono::system_clock::now().time_since_epoch()); + chrono::system_clock::now().time_since_epoch()); #endif seconds = static_cast<uint64_t>(now.total_seconds()); microseconds = static_cast<uint64_t>(now.total_microseconds() % 1000000);
diff --git a/asio/include/asio/high_resolution_timer.hpp b/asio/include/asio/high_resolution_timer.hpp index 6ab1324..133d292 100644 --- a/asio/include/asio/high_resolution_timer.hpp +++ b/asio/include/asio/high_resolution_timer.hpp
@@ -17,21 +17,13 @@ #include "asio/detail/config.hpp" -#if defined(ASIO_HAS_STD_CHRONO) \ - || defined(ASIO_HAS_BOOST_CHRONO) \ - || defined(GENERATING_DOCUMENTATION) - -#if defined(ASIO_HAS_STD_CHRONO) -# include <chrono> -#elif defined(ASIO_HAS_BOOST_CHRONO) -# include <boost/chrono/system_clocks.hpp> -#endif +#if defined(ASIO_HAS_CHRONO) || defined(GENERATING_DOCUMENTATION) #include "asio/basic_waitable_timer.hpp" +#include "asio/detail/chrono.hpp" namespace asio { -#if defined(GENERATING_DOCUMENTATION) /// Typedef for a timer based on the high resolution clock. /** * This typedef uses the C++11 @c <chrono> standard library facility, if @@ -44,20 +36,9 @@ typedef basic_waitable_timer< chrono::high_resolution_clock> high_resolution_timer; -#elif defined(ASIO_HAS_STD_CHRONO) -typedef basic_waitable_timer< - std::chrono::high_resolution_clock> - high_resolution_timer; -#elif defined(ASIO_HAS_BOOST_CHRONO) -typedef basic_waitable_timer< - boost::chrono::high_resolution_clock> - high_resolution_timer; -#endif } // namespace asio -#endif // defined(ASIO_HAS_STD_CHRONO) - // || defined(ASIO_HAS_BOOST_CHRONO) - // || defined(GENERATING_DOCUMENTATION) +#endif // defined(ASIO_HAS_CHRONO) || defined(GENERATING_DOCUMENTATION) #endif // ASIO_HIGH_RESOLUTION_TIMER_HPP
diff --git a/asio/include/asio/steady_timer.hpp b/asio/include/asio/steady_timer.hpp index 8e7ca68..73990a9 100644 --- a/asio/include/asio/steady_timer.hpp +++ b/asio/include/asio/steady_timer.hpp
@@ -17,21 +17,13 @@ #include "asio/detail/config.hpp" -#if defined(ASIO_HAS_STD_CHRONO) \ - || defined(ASIO_HAS_BOOST_CHRONO) \ - || defined(GENERATING_DOCUMENTATION) - -#if defined(ASIO_HAS_STD_CHRONO) -# include <chrono> -#elif defined(ASIO_HAS_BOOST_CHRONO) -# include <boost/chrono/system_clocks.hpp> -#endif +#if defined(ASIO_HAS_CHRONO) || defined(GENERATING_DOCUMENTATION) #include "asio/basic_waitable_timer.hpp" +#include "asio/detail/chrono.hpp" namespace asio { -#if defined(GENERATING_DOCUMENTATION) /// Typedef for a timer based on the steady clock. /** * This typedef uses the C++11 @c <chrono> standard library facility, if @@ -42,20 +34,9 @@ * @endcode */ typedef basic_waitable_timer<chrono::steady_clock> steady_timer; -#elif defined(ASIO_HAS_STD_CHRONO) -# if defined(ASIO_HAS_STD_CHRONO_MONOTONIC_CLOCK) -typedef basic_waitable_timer<std::chrono::monotonic_clock> steady_timer; -# else // defined(ASIO_HAS_STD_CHRONO_MONOTONIC_CLOCK) -typedef basic_waitable_timer<std::chrono::steady_clock> steady_timer; -# endif // defined(ASIO_HAS_STD_CHRONO_MONOTONIC_CLOCK) -#elif defined(ASIO_HAS_BOOST_CHRONO) -typedef basic_waitable_timer<boost::chrono::steady_clock> steady_timer; -#endif } // namespace asio -#endif // defined(ASIO_HAS_STD_CHRONO) - // || defined(ASIO_HAS_BOOST_CHRONO) - // || defined(GENERATING_DOCUMENTATION) +#endif // defined(ASIO_HAS_CHRONO) || defined(GENERATING_DOCUMENTATION) #endif // ASIO_STEADY_TIMER_HPP
diff --git a/asio/include/asio/system_timer.hpp b/asio/include/asio/system_timer.hpp index 143056e..8476ac0 100644 --- a/asio/include/asio/system_timer.hpp +++ b/asio/include/asio/system_timer.hpp
@@ -17,21 +17,13 @@ #include "asio/detail/config.hpp" -#if defined(ASIO_HAS_STD_CHRONO) \ - || defined(ASIO_HAS_BOOST_CHRONO) \ - || defined(GENERATING_DOCUMENTATION) - -#if defined(ASIO_HAS_STD_CHRONO) -# include <chrono> -#elif defined(ASIO_HAS_BOOST_CHRONO) -# include <boost/chrono/system_clocks.hpp> -#endif +#if defined(ASIO_HAS_CHRONO) || defined(GENERATING_DOCUMENTATION) #include "asio/basic_waitable_timer.hpp" +#include "asio/detail/chrono.hpp" namespace asio { -#if defined(GENERATING_DOCUMENTATION) /// Typedef for a timer based on the system clock. /** * This typedef uses the C++11 @c <chrono> standard library facility, if @@ -42,16 +34,9 @@ * @endcode */ typedef basic_waitable_timer<chrono::system_clock> system_timer; -#elif defined(ASIO_HAS_STD_CHRONO) -typedef basic_waitable_timer<std::chrono::system_clock> system_timer; -#elif defined(ASIO_HAS_BOOST_CHRONO) -typedef basic_waitable_timer<boost::chrono::system_clock> system_timer; -#endif } // namespace asio -#endif // defined(ASIO_HAS_STD_CHRONO) - // || defined(ASIO_HAS_BOOST_CHRONO) - // || defined(GENERATING_DOCUMENTATION) +#endif // defined(ASIO_HAS_CHRONO) || defined(GENERATING_DOCUMENTATION) #endif // ASIO_SYSTEM_TIMER_HPP
diff --git a/asio/src/tests/unit/io_context.cpp b/asio/src/tests/unit/io_context.cpp index 833c1b7..4617547 100644 --- a/asio/src/tests/unit/io_context.cpp +++ b/asio/src/tests/unit/io_context.cpp
@@ -43,12 +43,9 @@ #if defined(ASIO_HAS_BOOST_DATE_TIME) typedef deadline_timer timer; namespace chronons = boost::posix_time; -#elif defined(ASIO_HAS_STD_CHRONO) +#elif defined(ASIO_HAS_CHRONO) typedef steady_timer timer; -namespace chronons = std::chrono; -#elif defined(ASIO_HAS_BOOST_CHRONO) -typedef steady_timer timer; -namespace chronons = boost::chrono; +namespace chronons = asio::chrono; #endif // defined(ASIO_HAS_BOOST_DATE_TIME) void increment(int* count)
diff --git a/asio/src/tests/unit/strand.cpp b/asio/src/tests/unit/strand.cpp index 5b01e2d..3db5021 100644 --- a/asio/src/tests/unit/strand.cpp +++ b/asio/src/tests/unit/strand.cpp
@@ -45,12 +45,9 @@ #if defined(ASIO_HAS_BOOST_DATE_TIME) typedef deadline_timer timer; namespace chronons = boost::posix_time; -#elif defined(ASIO_HAS_STD_CHRONO) +#elif defined(ASIO_HAS_CHRONO) typedef steady_timer timer; -namespace chronons = std::chrono; -#elif defined(ASIO_HAS_BOOST_CHRONO) -typedef steady_timer timer; -namespace chronons = boost::chrono; +namespace chronons = asio::chrono; #endif // defined(ASIO_HAS_BOOST_DATE_TIME) void increment(int* count)
diff --git a/asio/src/tests/unit/system_timer.cpp b/asio/src/tests/unit/system_timer.cpp index 9aa41ce..9d382ee 100644 --- a/asio/src/tests/unit/system_timer.cpp +++ b/asio/src/tests/unit/system_timer.cpp
@@ -40,8 +40,6 @@ namespace bindns = std; #endif // defined(ASIO_HAS_BOOST_BIND) -namespace chronons = std::chrono; - void increment(int* count) { ++(*count); @@ -55,7 +53,7 @@ int before_value = *count; - t->expires_at(t->expiry() + chronons::seconds(1)); + t->expires_at(t->expiry() + asio::chrono::seconds(1)); t->async_wait(bindns::bind(decrement_to_zero, t, count)); // Completion cannot nest, so count value should remain unchanged. @@ -89,8 +87,8 @@ void system_timer_test() { - using chronons::seconds; - using chronons::microseconds; + using asio::chrono::seconds; + using asio::chrono::microseconds; #if !defined(ASIO_HAS_BOOST_BIND) using std::placeholders::_1; using std::placeholders::_2; @@ -334,13 +332,13 @@ asio::thread th(bindns::bind(io_context_run, &ioc)); - t2.expires_after(chronons::seconds(2)); + t2.expires_after(asio::chrono::seconds(2)); t2.wait(); - t1.expires_after(chronons::seconds(2)); + t1.expires_after(asio::chrono::seconds(2)); t1.async_wait(bindns::bind(increment, &count)); - t2.expires_after(chronons::seconds(4)); + t2.expires_after(asio::chrono::seconds(4)); t2.wait(); ioc.stop(); @@ -353,7 +351,7 @@ asio::system_timer make_timer(asio::io_context& ioc, int* count) { asio::system_timer t(ioc); - t.expires_after(std::chrono::seconds(1)); + t.expires_after(asio::chrono::seconds(1)); t.async_wait(bindns::bind(increment, count)); return t; }