cpp-common/bt2: remove useless copy operations
[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 std::uint64_t value() const noexcept
28 {
29 return bt_clock_snapshot_get_value(this->libObjPtr());
30 }
31
32 operator std::uint64_t() const noexcept
33 {
34 return this->value();
35 }
36
37 std::int64_t nsFromOrigin() const
38 {
39 std::int64_t nsFromOrigin;
40 const auto status = bt_clock_snapshot_get_ns_from_origin(this->libObjPtr(), &nsFromOrigin);
41
42 if (status == BT_CLOCK_SNAPSHOT_GET_NS_FROM_ORIGIN_STATUS_OVERFLOW_ERROR) {
43 throw OverflowError {};
44 }
45
46 return nsFromOrigin;
47 }
48 };
49
50 } /* namespace bt2 */
51
52 #endif /* BABELTRACE_CPP_COMMON_BT2_CLOCK_SNAPSHOT_HPP */
This page took 0.032955 seconds and 4 git commands to generate.