Add bt2_common::UuidView::operator<()
[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
6ef77ba5 10#include <array>
b239731a 11#include <cstdint>
6ef77ba5 12#include <string>
b239731a
PP
13
14#include "common/assert.h"
15#include "common/uuid.h"
16
17namespace bt2_common {
18
19class UuidView
20{
21public:
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
c65e7e80
PP
40 bool operator<(const UuidView& other) const noexcept
41 {
42 return bt_uuid_compare(_mUuid, other._mUuid) < 0;
43 }
44
b239731a
PP
45 std::string string() const
46 {
99ddb79d 47 std::string s;
b239731a 48
99ddb79d 49 s.resize(BT_UUID_STR_LEN);
f442e7c3 50 bt_uuid_to_str(_mUuid, &s[0]);
99ddb79d
MJ
51
52 return s;
b239731a
PP
53 }
54
1915d888 55 static constexpr std::size_t size() noexcept
b239731a
PP
56 {
57 return BT_UUID_LEN;
58 }
59
60 const std::uint8_t *data() const noexcept
61 {
62 return _mUuid;
63 }
64
65private:
66 const std::uint8_t *_mUuid;
67};
68
b5f55e9f 69} /* namespace bt2_common */
b239731a 70
b5f55e9f 71#endif /* BABELTRACE_CPP_COMMON_UUID_VIEW_HPP */
This page took 0.029902 seconds and 4 git commands to generate.