configure: enable -Wshadow-field
[babeltrace.git] / src / cpp-common / uuid-view.hpp
CommitLineData
b239731a
PP
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
15namespace bt2_common {
16
17class UuidView
18{
19public:
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::array<char, BT_UUID_STR_LEN> buf;
41
42 bt_uuid_to_str(_mUuid, buf.data());
43 return {buf.data(), buf.size()};
44 }
45
46 static std::size_t size() noexcept
47 {
48 return BT_UUID_LEN;
49 }
50
51 const std::uint8_t *data() const noexcept
52 {
53 return _mUuid;
54 }
55
56private:
57 const std::uint8_t *_mUuid;
58};
59
60} // namespace bt2_common
61
62#endif // BABELTRACE_CPP_COMMON_UUID_VIEW_HPP
This page took 0.027238 seconds and 4 git commands to generate.