2 * Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
4 * SPDX-License-Identifier: MIT
7 #ifndef BABELTRACE_CPP_COMMON_UUID_VIEW_HPP
8 #define BABELTRACE_CPP_COMMON_UUID_VIEW_HPP
15 #include "common/assert.h"
16 #include "common/uuid.h"
18 namespace bt2_common {
23 * A view on existing UUID data.
25 * A `UuidView` object doesn't contain its UUID data: see `Uuid` for a
26 * UUID data container.
31 using Val = std::uint8_t;
32 using ConstIter = const Val *;
35 explicit UuidView(const Val * const uuid) noexcept : _mUuid {uuid}
40 explicit UuidView(const Uuid& uuid) noexcept;
41 UuidView(const UuidView&) noexcept = default;
42 UuidView& operator=(const UuidView&) noexcept = default;
44 UuidView& operator=(const Val * const uuid) noexcept
50 operator Uuid() const noexcept;
52 std::string str() const
56 s.resize(BT_UUID_STR_LEN);
57 bt_uuid_to_str(_mUuid, &s[0]);
62 bool operator==(const UuidView& other) const noexcept
64 return bt_uuid_compare(_mUuid, other._mUuid) == 0;
67 bool operator!=(const UuidView& other) const noexcept
69 return !(*this == other);
72 bool operator<(const UuidView& other) const noexcept
74 return bt_uuid_compare(_mUuid, other._mUuid) < 0;
77 static constexpr std::size_t size() noexcept
82 const Val *data() const noexcept
87 Val operator[](const std::size_t index) const noexcept
92 ConstIter begin() const noexcept
97 ConstIter end() const noexcept
99 return _mUuid + this->size();
102 bool isNil() const noexcept
104 return std::all_of(this->begin(), this->end(), [](const std::uint8_t byte) {
113 } /* namespace bt2_common */
115 #endif /* BABELTRACE_CPP_COMMON_UUID_VIEW_HPP */