2 * SPDX-FileCopyrightText: 2020 Philippe Proulx <pproulx@efficios.com>
4 * SPDX-License-Identifier: MIT
7 #ifndef BABELTRACE_CPP_COMMON_BT2C_UUID_VIEW_HPP
8 #define BABELTRACE_CPP_COMMON_BT2C_UUID_VIEW_HPP
14 #include "common/assert.h"
15 #include "common/uuid.h"
22 * A view on existing UUID data.
24 * A `UuidView` object doesn't contain its UUID data: see `Uuid` for a
25 * UUID data container.
30 using Val = std::uint8_t;
31 using ConstIter = const Val *;
34 explicit UuidView(const Val * const uuid) noexcept : _mUuid {uuid}
39 explicit UuidView(const Uuid& uuid) noexcept;
40 UuidView(const UuidView&) noexcept = default;
41 UuidView& operator=(const UuidView&) noexcept = default;
43 UuidView& operator=(const Val * const uuid) noexcept
49 operator Uuid() const noexcept;
51 std::string str() const
55 s.resize(BT_UUID_STR_LEN);
56 bt_uuid_to_str(_mUuid, &s[0]);
61 bool operator==(const UuidView& other) const noexcept
63 return bt_uuid_compare(_mUuid, other._mUuid) == 0;
66 bool operator!=(const UuidView& other) const noexcept
68 return !(*this == other);
71 bool operator<(const UuidView& other) const noexcept
73 return bt_uuid_compare(_mUuid, other._mUuid) < 0;
76 static constexpr std::size_t size() noexcept
81 const Val *data() const noexcept
86 Val operator[](const std::size_t index) const noexcept
91 ConstIter begin() const noexcept
96 ConstIter end() const noexcept
98 return _mUuid + this->size();
101 bool isNil() const noexcept
103 return std::all_of(this->begin(), this->end(), [](const std::uint8_t byte) {
112 } /* namespace bt2c */
114 #endif /* BABELTRACE_CPP_COMMON_BT2C_UUID_VIEW_HPP */