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