Sort includes in C++ files
[babeltrace.git] / src / cpp-common / bt2 / clock-snapshot.hpp
CommitLineData
3aafc165
PP
1/*
2 * Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7#ifndef BABELTRACE_CPP_COMMON_BT2_CLOCK_SNAPSHOT_HPP
8#define BABELTRACE_CPP_COMMON_BT2_CLOCK_SNAPSHOT_HPP
9
10#include <cstdint>
c802cacb 11
3aafc165
PP
12#include <babeltrace2/babeltrace.h>
13
39278ebc 14#include "exc.hpp"
c802cacb 15#include "internal/borrowed-obj.hpp"
3aafc165
PP
16
17namespace bt2 {
18
19class ConstClockSnapshot final : public internal::BorrowedObj<const bt_clock_snapshot>
20{
21public:
22 explicit ConstClockSnapshot(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
23 {
24 }
25
26 ConstClockSnapshot(const ConstClockSnapshot& clkSnapshot) noexcept :
27 _ThisBorrowedObj {clkSnapshot}
28 {
29 }
30
31 ConstClockSnapshot& operator=(const ConstClockSnapshot& clkSnapshot) noexcept
32 {
33 _ThisBorrowedObj::operator=(clkSnapshot);
34 return *this;
35 }
36
37 std::uint64_t value() const noexcept
38 {
341a67c4 39 return bt_clock_snapshot_get_value(this->libObjPtr());
3aafc165
PP
40 }
41
42 operator std::uint64_t() const noexcept
43 {
44 return this->value();
45 }
46
47 std::int64_t nsFromOrigin() const
48 {
49 std::int64_t nsFromOrigin;
341a67c4 50 const auto status = bt_clock_snapshot_get_ns_from_origin(this->libObjPtr(), &nsFromOrigin);
3aafc165
PP
51
52 if (status == BT_CLOCK_SNAPSHOT_GET_NS_FROM_ORIGIN_STATUS_OVERFLOW_ERROR) {
39278ebc 53 throw OverflowError {};
3aafc165
PP
54 }
55
56 return nsFromOrigin;
57 }
58};
59
b5f55e9f 60} /* namespace bt2 */
3aafc165 61
b5f55e9f 62#endif /* BABELTRACE_CPP_COMMON_BT2_CLOCK_SNAPSHOT_HPP */
This page took 0.032439 seconds and 4 git commands to generate.