Goby3  3.1.5a
2024.05.23
asio.h
Go to the documentation of this file.
1 // Copyright 2020-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_ASIO_H
25 #define GOBY_TIME_ASIO_H
26 
27 #include <boost/asio/time_traits.hpp>
28 #include <boost/date_time.hpp>
29 
30 namespace goby
31 {
32 namespace time
33 {
34 // dummy struct for use with boost::asio::time_traits
36 {
37 };
38 
39 } // namespace time
40 } // namespace goby
41 
42 namespace boost
43 {
44 namespace asio
45 {
47 template <> struct time_traits<goby::time::ASIOGobyTime>
48 {
50  typedef boost::posix_time::ptime time_type;
51 
53  typedef boost::posix_time::time_duration duration_type;
54 
56  static time_type now() { return goby::time::SystemClock::now<boost::posix_time::ptime>(); }
57 
59  static time_type add(const time_type& t, const duration_type& d) { return t + d; }
60 
62  static duration_type subtract(const time_type& t1, const time_type& t2) { return t1 - t2; }
63 
65  static bool less_than(const time_type& t1, const time_type& t2) { return t1 < t2; }
66 
68  static boost::posix_time::time_duration to_posix_duration(const duration_type& d)
69  {
71  }
72 };
73 } // namespace asio
74 } // namespace boost
75 
76 #endif
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
boost::asio::time_traits< goby::time::ASIOGobyTime >::less_than
static bool less_than(const time_type &t1, const time_type &t2)
Test whether one time is less than another.
Definition: asio.h:65
boost::asio::time_traits< goby::time::ASIOGobyTime >::time_type
boost::posix_time::ptime time_type
The time type.
Definition: asio.h:50
boost::asio::time_traits< goby::time::ASIOGobyTime >::duration_type
boost::posix_time::time_duration duration_type
The duration type.
Definition: asio.h:53
boost
Definition: udp_driver.h:41
goby::time::ASIOGobyTime
Definition: asio.h:35
boost::asio::time_traits< goby::time::ASIOGobyTime >::add
static time_type add(const time_type &t, const duration_type &d)
Add a duration to a time.
Definition: asio.h:59
boost::asio::time_traits< goby::time::ASIOGobyTime >::to_posix_duration
static boost::posix_time::time_duration to_posix_duration(const duration_type &d)
Convert to POSIX duration type.
Definition: asio.h:68
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::asio::time_traits< goby::time::ASIOGobyTime >::subtract
static duration_type subtract(const time_type &t1, const time_type &t2)
Subtract one time from another.
Definition: asio.h:62
boost::units::si::time
unit< time_dimension, si::system > time
Definition: time.hpp:22
boost::asio::time_traits< goby::time::ASIOGobyTime >::now
static time_type now()
Get the current time.
Definition: asio.h:56