cpp-common/bt2: rename `bt2::BorrowedObj` -> `bt2::BorrowedObject`
[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 "borrowed-object.hpp"
15 #include "exc.hpp"
16
17 namespace bt2 {
18
19 class ConstClockSnapshot final : public BorrowedObject<const bt_clock_snapshot>
20 {
21 public:
22 explicit ConstClockSnapshot(const _LibObjPtr libObjPtr) noexcept :
23 _ThisBorrowedObject {libObjPtr}
24 {
25 }
26
27 ConstClockSnapshot(const ConstClockSnapshot& clkSnapshot) noexcept :
28 _ThisBorrowedObject {clkSnapshot}
29 {
30 }
31
32 ConstClockSnapshot& operator=(const ConstClockSnapshot& clkSnapshot) noexcept
33 {
34 _ThisBorrowedObject::operator=(clkSnapshot);
35 return *this;
36 }
37
38 std::uint64_t value() const noexcept
39 {
40 return bt_clock_snapshot_get_value(this->libObjPtr());
41 }
42
43 operator std::uint64_t() const noexcept
44 {
45 return this->value();
46 }
47
48 std::int64_t nsFromOrigin() const
49 {
50 std::int64_t nsFromOrigin;
51 const auto status = bt_clock_snapshot_get_ns_from_origin(this->libObjPtr(), &nsFromOrigin);
52
53 if (status == BT_CLOCK_SNAPSHOT_GET_NS_FROM_ORIGIN_STATUS_OVERFLOW_ERROR) {
54 throw OverflowError {};
55 }
56
57 return nsFromOrigin;
58 }
59 };
60
61 } /* namespace bt2 */
62
63 #endif /* BABELTRACE_CPP_COMMON_BT2_CLOCK_SNAPSHOT_HPP */
This page took 0.030087 seconds and 4 git commands to generate.