8829019b8154414362c15c0fe6b4612fbeddd92b
[babeltrace.git] / src / cpp-common / uuid-view.hpp
1 /*
2 * Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7 #ifndef BABELTRACE_CPP_COMMON_UUID_VIEW_HPP
8 #define BABELTRACE_CPP_COMMON_UUID_VIEW_HPP
9
10 #include <array>
11 #include <cstdint>
12 #include <string>
13
14 #include "common/assert.h"
15 #include "common/uuid.h"
16
17 namespace bt2_common {
18
19 class UuidView final
20 {
21 public:
22 explicit UuidView(const std::uint8_t * const uuid) noexcept : _mUuid {uuid}
23 {
24 BT_ASSERT_DBG(uuid);
25 }
26
27 UuidView(const UuidView&) noexcept = default;
28 UuidView& operator=(const UuidView&) noexcept = default;
29
30 bool operator==(const UuidView& other) const noexcept
31 {
32 return bt_uuid_compare(_mUuid, other._mUuid) == 0;
33 }
34
35 bool operator!=(const UuidView& other) const noexcept
36 {
37 return !(*this == other);
38 }
39
40 bool operator<(const UuidView& other) const noexcept
41 {
42 return bt_uuid_compare(_mUuid, other._mUuid) < 0;
43 }
44
45 std::string str() const
46 {
47 std::string s;
48
49 s.resize(BT_UUID_STR_LEN);
50 bt_uuid_to_str(_mUuid, &s[0]);
51
52 return s;
53 }
54
55 static constexpr std::size_t size() noexcept
56 {
57 return BT_UUID_LEN;
58 }
59
60 const std::uint8_t *data() const noexcept
61 {
62 return _mUuid;
63 }
64
65 private:
66 const std::uint8_t *_mUuid;
67 };
68
69 } /* namespace bt2_common */
70
71 #endif /* BABELTRACE_CPP_COMMON_UUID_VIEW_HPP */
This page took 0.033365 seconds and 3 git commands to generate.