Lely core libraries  1.9.2
chrono.hpp
Go to the documentation of this file.
1 
22 #ifndef LELY_COAPP_DETAIL_CHRONO_HPP_
23 #define LELY_COAPP_DETAIL_CHRONO_HPP_
24 
25 #include <lely/coapp/coapp.hpp>
26 
27 #include <chrono>
28 #include <limits>
29 
30 namespace lely {
31 
32 namespace canopen {
33 
34 namespace detail {
35 
37 inline ::std::chrono::milliseconds
38 FromTimeout(int timeout) {
39  using namespace ::std::chrono;
40  return timeout <= 0 ? milliseconds::max() : milliseconds(timeout);
41 }
42 
44 template <class Rep, class Period>
45 inline int
46 ToTimeout(const ::std::chrono::duration<Rep, Period>& d) {
47  using namespace ::std::chrono;
48  // The maximum duration is interpreted as an infinite timeout.
49  if (d == duration<Rep, Period>::max()) return 0;
50  auto timeout = duration_cast<milliseconds>(d).count();
51  // A timeout less than 1 ms is rounded up to keep it finite.
52  if (timeout < 1) return 1;
53  if (timeout > ::std::numeric_limits<int>::max())
54  return ::std::numeric_limits<int>::max();
55  return timeout;
56 }
57 
58 } // namespace detail
59 
60 } // namespace canopen
61 
62 } // namespace lely
63 
64 #endif // LELY_COAPP_DETAIL_CHRONO_HPP_
This is the public header file of the C++ CANopen application library.
inline ::std::chrono::milliseconds FromTimeout(int timeout)
Converts an SDO timeout to a duration.
Definition: chrono.hpp:38
int ToTimeout(const ::std::chrono::duration< Rep, Period > &d)
Converts a duration to an SDO timeout.
Definition: chrono.hpp:46
Global namespace for the Lely Industries N.V. libraries.
Definition: buf.hpp:32