mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Template abstract_clock on Clock:
The abstract_clock is now templated on a type meeting the requirements of the Clock concept. It inherits the nested types of the Clock on which it is based. This resolves a problem with the original design which broke the type-safety of time_point from different abstract clocks.
This commit is contained in:
committed by
Nik Bougalis
parent
d9c49386cb
commit
8aa4a027bb
@@ -20,11 +20,8 @@
|
||||
// MODULES: ../impl/chrono_io.cpp
|
||||
|
||||
#include <beast/chrono/abstract_clock.h>
|
||||
#include <beast/chrono/abstract_clock_io.h>
|
||||
#include <beast/chrono/manual_clock.h>
|
||||
|
||||
#include <beast/unit_test/suite.h>
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
@@ -34,7 +31,8 @@ namespace beast {
|
||||
class abstract_clock_test : public unit_test::suite
|
||||
{
|
||||
public:
|
||||
void test (abstract_clock <std::chrono::seconds>& c)
|
||||
template <class Clock>
|
||||
void test (abstract_clock<Clock>& c)
|
||||
{
|
||||
{
|
||||
auto const t1 (c.now ());
|
||||
@@ -53,18 +51,18 @@ public:
|
||||
|
||||
void test_manual ()
|
||||
{
|
||||
typedef manual_clock <std::chrono::seconds> clock_type;
|
||||
using clock_type = manual_clock<std::chrono::steady_clock>;
|
||||
clock_type c;
|
||||
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "now() = " << c.now () << std::endl;
|
||||
ss << "now() = " << c.now().time_since_epoch() << std::endl;
|
||||
|
||||
c.set (clock_type::time_point (std::chrono::seconds (1)));
|
||||
ss << "now() = " << c.now () << std::endl;
|
||||
c.set (clock_type::time_point (std::chrono::seconds(1)));
|
||||
ss << "now() = " << c.now().time_since_epoch() << std::endl;
|
||||
|
||||
c.set (clock_type::time_point (std::chrono::seconds (2)));
|
||||
ss << "now() = " << c.now () << std::endl;
|
||||
c.set (clock_type::time_point (std::chrono::seconds(2)));
|
||||
ss << "now() = " << c.now().time_since_epoch() << std::endl;
|
||||
|
||||
log << ss.str();
|
||||
}
|
||||
@@ -72,16 +70,16 @@ public:
|
||||
void run ()
|
||||
{
|
||||
log << "steady_clock";
|
||||
test (get_abstract_clock <std::chrono::steady_clock,
|
||||
std::chrono::seconds> ());
|
||||
test (get_abstract_clock<
|
||||
std::chrono::steady_clock>());
|
||||
|
||||
log << "system_clock";
|
||||
test (get_abstract_clock <std::chrono::system_clock,
|
||||
std::chrono::seconds> ());
|
||||
test (get_abstract_clock<
|
||||
std::chrono::system_clock>());
|
||||
|
||||
log << "high_resolution_clock";
|
||||
test (get_abstract_clock <std::chrono::high_resolution_clock,
|
||||
std::chrono::seconds> ());
|
||||
test (get_abstract_clock<
|
||||
std::chrono::high_resolution_clock>());
|
||||
|
||||
log << "manual_clock";
|
||||
test_manual ();
|
||||
|
||||
Reference in New Issue
Block a user