Sort includes in C++ files
[babeltrace.git] / src / cpp-common / bt2 / clock-snapshot.hpp
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>
11
12 #include <babeltrace2/babeltrace.h>
13
14 #include "exc.hpp"
15 #include "internal/borrowed-obj.hpp"
16
17 namespace bt2 {
18
19 class ConstClockSnapshot final : public internal::BorrowedObj<const bt_clock_snapshot>
20 {
21 public:
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 {
39 return bt_clock_snapshot_get_value(this->libObjPtr());
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;
50 const auto status = bt_clock_snapshot_get_ns_from_origin(this->libObjPtr(), &nsFromOrigin);
51
52 if (status == BT_CLOCK_SNAPSHOT_GET_NS_FROM_ORIGIN_STATUS_OVERFLOW_ERROR) {
53 throw OverflowError {};
54 }
55
56 return nsFromOrigin;
57 }
58 };
59
60 } /* namespace bt2 */
61
62 #endif /* BABELTRACE_CPP_COMMON_BT2_CLOCK_SNAPSHOT_HPP */
This page took 0.032114 seconds and 4 git commands to generate.