cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[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"
6b12d6f5 15#include "clock-class.hpp"
39278ebc 16#include "exc.hpp"
3aafc165
PP
17
18namespace bt2 {
19
0d218157 20class ConstClockSnapshot final : public BorrowedObject<const bt_clock_snapshot>
3aafc165
PP
21{
22public:
d246c457 23 explicit ConstClockSnapshot(const LibObjPtr libObjPtr) noexcept :
0d218157 24 _ThisBorrowedObject {libObjPtr}
3aafc165
PP
25 {
26 }
27
6b12d6f5
PP
28 ConstClockClass clockClass() const noexcept
29 {
30 return ConstClockClass {bt_clock_snapshot_borrow_clock_class_const(this->libObjPtr())};
31 }
32
3aafc165
PP
33 std::uint64_t value() const noexcept
34 {
341a67c4 35 return bt_clock_snapshot_get_value(this->libObjPtr());
3aafc165
PP
36 }
37
38 operator std::uint64_t() const noexcept
39 {
40 return this->value();
41 }
42
43 std::int64_t nsFromOrigin() const
44 {
45 std::int64_t nsFromOrigin;
341a67c4 46 const auto status = bt_clock_snapshot_get_ns_from_origin(this->libObjPtr(), &nsFromOrigin);
3aafc165
PP
47
48 if (status == BT_CLOCK_SNAPSHOT_GET_NS_FROM_ORIGIN_STATUS_OVERFLOW_ERROR) {
39278ebc 49 throw OverflowError {};
3aafc165
PP
50 }
51
52 return nsFromOrigin;
53 }
54};
55
b5f55e9f 56} /* namespace bt2 */
3aafc165 57
b5f55e9f 58#endif /* BABELTRACE_CPP_COMMON_BT2_CLOCK_SNAPSHOT_HPP */
This page took 0.045003 seconds and 4 git commands to generate.