cpp-common/bt2: remove useless copy operations
[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
0d218157 14#include "borrowed-object.hpp"
39278ebc 15#include "exc.hpp"
3aafc165
PP
16
17namespace bt2 {
18
0d218157 19class ConstClockSnapshot final : public BorrowedObject<const bt_clock_snapshot>
3aafc165
PP
20{
21public:
0d218157
PP
22 explicit ConstClockSnapshot(const _LibObjPtr libObjPtr) noexcept :
23 _ThisBorrowedObject {libObjPtr}
3aafc165
PP
24 {
25 }
26
3aafc165
PP
27 std::uint64_t value() const noexcept
28 {
341a67c4 29 return bt_clock_snapshot_get_value(this->libObjPtr());
3aafc165
PP
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;
341a67c4 40 const auto status = bt_clock_snapshot_get_ns_from_origin(this->libObjPtr(), &nsFromOrigin);
3aafc165
PP
41
42 if (status == BT_CLOCK_SNAPSHOT_GET_NS_FROM_ORIGIN_STATUS_OVERFLOW_ERROR) {
39278ebc 43 throw OverflowError {};
3aafc165
PP
44 }
45
46 return nsFromOrigin;
47 }
48};
49
b5f55e9f 50} /* namespace bt2 */
3aafc165 51
b5f55e9f 52#endif /* BABELTRACE_CPP_COMMON_BT2_CLOCK_SNAPSHOT_HPP */
This page took 0.03347 seconds and 4 git commands to generate.