1 //===-- UUID.h --------------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLDB_UTILITY_UUID_H
11 #define LLDB_UTILITY_UUID_H
18 #include "llvm/ADT/ArrayRef.h"
24 namespace lldb_private {
32 /// Creates a UUID from the data pointed to by the bytes argument. No special
33 /// significance is attached to any of the values.
34 static UUID fromData(const void *bytes, uint32_t num_bytes) {
36 return fromData({reinterpret_cast<const uint8_t *>(bytes), num_bytes});
40 /// Creates a uuid from the data pointed to by the bytes argument. No special
41 /// significance is attached to any of the values.
42 static UUID fromData(llvm::ArrayRef<uint8_t> bytes) { return UUID(bytes); }
44 /// Creates a UUID from the data pointed to by the bytes argument. Data
45 /// consisting purely of zero bytes is treated as an invalid UUID.
46 static UUID fromOptionalData(const void *bytes, uint32_t num_bytes) {
48 return fromOptionalData(
49 {reinterpret_cast<const uint8_t *>(bytes), num_bytes});
53 /// Creates a UUID from the data pointed to by the bytes argument. Data
54 /// consisting purely of zero bytes is treated as an invalid UUID.
55 static UUID fromOptionalData(llvm::ArrayRef<uint8_t> bytes) {
56 if (llvm::all_of(bytes, [](uint8_t b) { return b == 0; }))
61 void Clear() { m_bytes.clear(); }
63 void Dump(Stream *s) const;
65 llvm::ArrayRef<uint8_t> GetBytes() const { return m_bytes; }
67 explicit operator bool() const { return IsValid(); }
68 bool IsValid() const { return !m_bytes.empty(); }
70 std::string GetAsString(llvm::StringRef separator = "-") const;
72 size_t SetFromStringRef(llvm::StringRef str, uint32_t num_uuid_bytes = 16);
74 // Decode as many UUID bytes (up to 16) as possible from the C string "cstr"
75 // This is used for auto completion where a partial UUID might have been
77 //------------------------------------------------------------------
78 /// Decode as many UUID bytes (up to 16) as possible from the C
82 /// A NULL terminate C string that points at a UUID string value
83 /// (no leading spaces). The string must contain only hex
84 /// characters and optionally can contain the '-' sepearators.
86 /// @param[in] uuid_bytes
87 /// A buffer of bytes that will contain a full or patially
91 /// The original string, with all decoded bytes removed.
92 //------------------------------------------------------------------
93 static llvm::StringRef
94 DecodeUUIDBytesFromString(llvm::StringRef str,
95 llvm::SmallVectorImpl<uint8_t> &uuid_bytes,
96 uint32_t num_uuid_bytes = 16);
99 UUID(llvm::ArrayRef<uint8_t> bytes) : m_bytes(bytes.begin(), bytes.end()) {}
101 // GNU ld generates 20-byte build-ids. Size chosen to avoid heap allocations
103 llvm::SmallVector<uint8_t, 20> m_bytes;
105 friend bool operator==(const UUID &LHS, const UUID &RHS) {
106 return LHS.m_bytes == RHS.m_bytes;
108 friend bool operator!=(const UUID &LHS, const UUID &RHS) {
109 return !(LHS == RHS);
111 friend bool operator<(const UUID &LHS, const UUID &RHS) {
112 return LHS.m_bytes < RHS.m_bytes;
114 friend bool operator<=(const UUID &LHS, const UUID &RHS) {
117 friend bool operator>(const UUID &LHS, const UUID &RHS) { return RHS < LHS; }
118 friend bool operator>=(const UUID &LHS, const UUID &RHS) {
122 } // namespace lldb_private
124 #endif // LLDB_UTILITY_UUID_H