aboutsummaryrefslogtreecommitdiff
path: root/include/lldb/Utility/UUID.h
blob: 5e64e90797893e58a64159a96be6a6db80f4be91 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//===-- UUID.h --------------------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_UTILITY_UUID_H
#define LLDB_UTILITY_UUID_H

// C Includes
// C++ Includes
#include <stddef.h>
#include <stdint.h>
#include <string>

namespace llvm {
  class StringRef;
}

namespace lldb_private {

  class Stream;

class UUID {
public:
  // Most UUIDs are 16 bytes, but some Linux build-ids (SHA1) are 20.
  typedef uint8_t ValueType[20];

  //------------------------------------------------------------------
  // Constructors and Destructors
  //------------------------------------------------------------------
  UUID();
  UUID(const UUID &rhs);
  UUID(const void *uuid_bytes, uint32_t num_uuid_bytes);

  ~UUID();

  const UUID &operator=(const UUID &rhs);

  void Clear();

  void Dump(Stream *s) const;

  const void *GetBytes() const;

  size_t GetByteSize() const;

  bool IsValid() const;

  bool SetBytes(const void *uuid_bytes, uint32_t num_uuid_bytes = 16);

  std::string GetAsString(const char *separator = nullptr) const;

  size_t SetFromStringRef(llvm::StringRef str, uint32_t num_uuid_bytes = 16);
  size_t SetFromCString(const char *c_str, uint32_t num_uuid_bytes = 16);

  // Decode as many UUID bytes (up to 16) as possible from the C string "cstr"
  // This is used for auto completion where a partial UUID might have been
  // typed in. It
  //------------------------------------------------------------------
  /// Decode as many UUID bytes (up to 16) as possible from the C
  /// string \a cstr.
  ///
  /// @param[in] cstr
  ///     A NULL terminate C string that points at a UUID string value
  ///     (no leading spaces). The string must contain only hex
  ///     characters and optionally can contain the '-' sepearators.
  ///
  /// @param[in] uuid_bytes
  ///     A buffer of bytes that will contain a full or patially
  ///     decoded UUID.
  ///
  /// @return
  ///     The original string, with all decoded bytes removed.
  //------------------------------------------------------------------
  static llvm::StringRef
  DecodeUUIDBytesFromString(llvm::StringRef str, ValueType &uuid_bytes,
                            uint32_t &bytes_decoded,
                            uint32_t num_uuid_bytes = 16);

protected:
  //------------------------------------------------------------------
  // Classes that inherit from UUID can see and modify these
  //------------------------------------------------------------------
  uint32_t m_num_uuid_bytes; // Should be 16 or 20
  ValueType m_uuid;
};

bool operator==(const UUID &lhs, const UUID &rhs);
bool operator!=(const UUID &lhs, const UUID &rhs);
bool operator<(const UUID &lhs, const UUID &rhs);
bool operator<=(const UUID &lhs, const UUID &rhs);
bool operator>(const UUID &lhs, const UUID &rhs);
bool operator>=(const UUID &lhs, const UUID &rhs);

} // namespace lldb_private

#endif // LLDB_UTILITY_UUID_H