Goby3  3.1.5a
2024.05.23
system_clock.h
Go to the documentation of this file.
1 // Copyright 2019-2021:
2 // GobySoft, LLC (2013-)
3 // Community contributors (see AUTHORS file)
4 // File authors:
5 // Toby Schneider <toby@gobysoft.org>
6 //
7 //
8 // This file is part of the Goby Underwater Autonomy Project Libraries
9 // ("The Goby Libraries").
10 //
11 // The Goby Libraries are free software: you can redistribute them and/or modify
12 // them under the terms of the GNU Lesser General Public License as published by
13 // the Free Software Foundation, either version 2.1 of the License, or
14 // (at your option) any later version.
15 //
16 // The Goby Libraries are distributed in the hope that they will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public License
22 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
23 
24 #ifndef GOBY_TIME_SYSTEM_CLOCK_H
25 #define GOBY_TIME_SYSTEM_CLOCK_H
26 
27 #include <chrono>
28 #include <cstdint>
29 
30 #include "goby/time/simulation.h"
31 
32 namespace goby
33 {
35 
36 
44 namespace time
45 {
48 {
52  typedef std::chrono::microseconds duration;
53  typedef duration::rep rep;
54  typedef duration::period period;
55  typedef std::chrono::time_point<SystemClock> time_point;
56  static const bool is_steady = false;
57 
63  static time_point now() noexcept
64  {
65  using namespace std::chrono;
66  auto now = system_clock::now();
67 
69  return time_point(duration_cast<duration>(now.time_since_epoch()));
70  else
71  return warp(now);
72  }
73 
75  template <typename TimeType> static TimeType now();
76 
78  warp(const std::chrono::system_clock::time_point& real_time);
79 
80  static std::chrono::system_clock::time_point
82 };
83 
84 } // namespace time
85 
87 
88 } // namespace goby
89 
90 #endif
goby::time::SystemClock::now
static time_point now() noexcept
Returns the current system time unless SimulatorSettings::using_sim_time is set to true,...
Definition: system_clock.h:63
goby::time::SystemClock
Essentially the same as std::chrono::system_clock except the time returned by SystemClock::now() can ...
Definition: system_clock.h:47
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
goby::time::SystemClock::is_steady
static const bool is_steady
Definition: system_clock.h:56
goby::time::SystemClock::duration
std::chrono::microseconds duration
Duration type.
Definition: system_clock.h:52
goby::time::SystemClock::warp
static goby::time::SystemClock::time_point warp(const std::chrono::system_clock::time_point &real_time)
goby::time::SystemClock::rep
duration::rep rep
Definition: system_clock.h:53
goby::time::SystemClock::time_point
std::chrono::time_point< SystemClock > time_point
Definition: system_clock.h:55
goby::time::SimulatorSettings::using_sim_time
static bool using_sim_time
Enables simulation time if true (if false, none of the remaining parameters are used)
Definition: simulation.h:38
boost::units::si::time
unit< time_dimension, si::system > time
Definition: time.hpp:22
simulation.h
goby::time::SystemClock::unwarp
static std::chrono::system_clock::time_point unwarp(const goby::time::SystemClock::time_point &sim_time)
goby::time::SystemClock::period
duration::period period
Definition: system_clock.h:54