| 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 <cstdint> |
| 11 | |
| 12 | #include "common/assert.h" |
| 13 | #include "common/uuid.h" |
| 14 | |
| 15 | namespace bt2_common { |
| 16 | |
| 17 | class UuidView |
| 18 | { |
| 19 | public: |
| 20 | explicit UuidView(const std::uint8_t * const uuid) noexcept : _mUuid {uuid} |
| 21 | { |
| 22 | BT_ASSERT_DBG(uuid); |
| 23 | } |
| 24 | |
| 25 | UuidView(const UuidView&) noexcept = default; |
| 26 | UuidView& operator=(const UuidView&) noexcept = default; |
| 27 | |
| 28 | bool operator==(const UuidView& other) const noexcept |
| 29 | { |
| 30 | return bt_uuid_compare(_mUuid, other._mUuid) == 0; |
| 31 | } |
| 32 | |
| 33 | bool operator!=(const UuidView& other) const noexcept |
| 34 | { |
| 35 | return !(*this == other); |
| 36 | } |
| 37 | |
| 38 | std::string string() const |
| 39 | { |
| 40 | std::string s; |
| 41 | |
| 42 | s.resize(BT_UUID_STR_LEN); |
| 43 | bt_uuid_to_str(_mUuid, s.data()); |
| 44 | |
| 45 | return s; |
| 46 | } |
| 47 | |
| 48 | static std::size_t size() noexcept |
| 49 | { |
| 50 | return BT_UUID_LEN; |
| 51 | } |
| 52 | |
| 53 | const std::uint8_t *data() const noexcept |
| 54 | { |
| 55 | return _mUuid; |
| 56 | } |
| 57 | |
| 58 | private: |
| 59 | const std::uint8_t *_mUuid; |
| 60 | }; |
| 61 | |
| 62 | } /* namespace bt2_common */ |
| 63 | |
| 64 | #endif /* BABELTRACE_CPP_COMMON_UUID_VIEW_HPP */ |