Goby3  3.1.5a
2024.05.23
steady_clock.h
Go to the documentation of this file.
1 // Copyright 2009-2021:
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 // File authors:
6 // Toby Schneider <toby@gobysoft.org>
7 //
8 //
9 // This file is part of the Goby Underwater Autonomy Project Libraries
10 // ("The Goby Libraries").
11 //
12 // The Goby Libraries are free software: you can redistribute them and/or modify
13 // them under the terms of the GNU Lesser General Public License as published by
14 // the Free Software Foundation, either version 2.1 of the License, or
15 // (at your option) any later version.
16 //
17 // The Goby Libraries are distributed in the hope that they will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public License
23 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
24 
25 #ifndef GOBY_TIME_STEADY_CLOCK_H
26 #define GOBY_TIME_STEADY_CLOCK_H
27 
28 #include <chrono>
29 
30 #include "goby/time/simulation.h"
31 
32 namespace goby
33 {
34 namespace time
35 {
38 {
42  typedef std::chrono::microseconds duration;
43  typedef duration::rep rep;
44  typedef duration::period period;
45  typedef std::chrono::time_point<SteadyClock> time_point;
46  static const bool is_steady = true;
47 
49  static time_point now() noexcept
50  {
51  using namespace std::chrono;
52  auto now = steady_clock::now();
53 
55  return time_point(duration_cast<duration>(now.time_since_epoch()));
56  else
58  duration_cast<duration>(now.time_since_epoch()));
59  }
60 };
61 } // namespace time
62 } // namespace goby
63 
64 #endif
goby::time::SteadyClock::duration
std::chrono::microseconds duration
Duration type.
Definition: steady_clock.h:42
goby::time::SteadyClock::period
duration::period period
Definition: steady_clock.h:44
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
goby::time::SteadyClock::rep
duration::rep rep
Definition: steady_clock.h:43
goby::time::SteadyClock::now
static time_point now() noexcept
Returns the current steady time unless SimulatorSettings::using_sim_time == true in which case a simu...
Definition: steady_clock.h:49
goby::time::SteadyClock::time_point
std::chrono::time_point< SteadyClock > time_point
Definition: steady_clock.h:45
goby::time::SteadyClock::is_steady
static const bool is_steady
Definition: steady_clock.h:46
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
goby::time::SimulatorSettings::warp_factor
static int warp_factor
Warp factor to speed up (or slow time) the time values returned by SteadyClock::now() and SystemClock...
Definition: simulation.h:40
boost::units::si::time
unit< time_dimension, si::system > time
Definition: time.hpp:22
simulation.h
goby::time::SteadyClock
Essentially the same as std::chrono::steady_clock except the time returned by SteadyClock::now() can ...
Definition: steady_clock.h:37