Loading...
Searching...
No Matches
timestamp.hpp
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/* SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl> */
#ifndef __LIBGPIOD_CXX_TIMESTAMP_HPP__
#define __LIBGPIOD_CXX_TIMESTAMP_HPP__
#if !defined(__LIBGPIOD_GPIOD_CXX_INSIDE__)
#error "Only gpiod.hpp can be included directly."
#endif
#include <chrono>
#include <cstdint>
namespace gpiod {
class timestamp final
{
public:
using time_point_monotonic = ::std::chrono::time_point<::std::chrono::steady_clock>;
using time_point_realtime = ::std::chrono::time_point<::std::chrono::system_clock,
::std::chrono::nanoseconds>;
timestamp(::std::uint64_t ns) : _m_ns(ns) { }
timestamp(const timestamp& other) noexcept = default;
timestamp(timestamp&& other) noexcept = default;
timestamp& operator=(const timestamp& other) noexcept = default;
timestamp& operator=(timestamp&& other) noexcept = default;
~timestamp() = default;
operator ::std::uint64_t() noexcept
{
return this->ns();
}
::std::uint64_t ns() const noexcept
{
return this->_m_ns;
}
time_point_monotonic to_time_point_monotonic() const
{
return time_point_monotonic(::std::chrono::nanoseconds(this->ns()));
}
time_point_realtime to_time_point_realtime() const
{
return time_point_realtime(::std::chrono::nanoseconds(this->ns()));
}
private:
::std::uint64_t _m_ns;
};
} /* namespace gpiod */
#endif /* __LIBGPIOD_CXX_TIMESTAMP_HPP__ */
gpiod::timestamp::operator=
timestamp & operator=(timestamp &&other) noexcept=default
Move assignment operator.
gpiod::timestamp::ns
::std::uint64_t ns() const noexcept
Get the timestamp in nanoseconds.
Definition timestamp.hpp:85
gpiod::timestamp::timestamp
timestamp(timestamp &&other) noexcept=default
Move constructor.
gpiod::timestamp::time_point_monotonic
::std::chrono::time_point<::std::chrono::steady_clock > time_point_monotonic
Monotonic time_point.
Definition timestamp.hpp:31
gpiod::timestamp::time_point_realtime
::std::chrono::time_point<::std::chrono::system_clock, ::std::chrono::nanoseconds > time_point_realtime
Real-time time_point.
Definition timestamp.hpp:36
gpiod::timestamp::timestamp
timestamp(const timestamp &other) noexcept=default
Copy constructor.
gpiod::timestamp::operator=
timestamp & operator=(const timestamp &other) noexcept=default
Assignment operator.
gpiod::timestamp::to_time_point_realtime
time_point_realtime to_time_point_realtime() const
Convert the timestamp to a real-time time_point.
Definition timestamp.hpp:103
gpiod::timestamp::timestamp
timestamp(::std::uint64_t ns)
Constructor with implicit conversion from uint64_t.
Definition timestamp.hpp:43
gpiod::timestamp::~timestamp
~timestamp()=default
gpiod::timestamp::to_time_point_monotonic
time_point_monotonic to_time_point_monotonic() const
Convert the timestamp to a monotonic time_point.
Definition timestamp.hpp:94
gpiod
Definition chip-info.hpp:18