UUID.h revision 317032
1//===-- UUID.h --------------------------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLDB_UTILITY_UUID_H
11#define LLDB_UTILITY_UUID_H
12
13// C Includes
14// C++ Includes
15#include <stddef.h>
16#include <stdint.h>
17#include <string>
18
19namespace llvm {
20  class StringRef;
21}
22
23namespace lldb_private {
24
25  class Stream;
26
27class UUID {
28public:
29  // Most UUIDs are 16 bytes, but some Linux build-ids (SHA1) are 20.
30  typedef uint8_t ValueType[20];
31
32  //------------------------------------------------------------------
33  // Constructors and Destructors
34  //------------------------------------------------------------------
35  UUID();
36  UUID(const UUID &rhs);
37  UUID(const void *uuid_bytes, uint32_t num_uuid_bytes);
38
39  ~UUID();
40
41  const UUID &operator=(const UUID &rhs);
42
43  void Clear();
44
45  void Dump(Stream *s) const;
46
47  const void *GetBytes() const;
48
49  size_t GetByteSize();
50
51  bool IsValid() const;
52
53  bool SetBytes(const void *uuid_bytes, uint32_t num_uuid_bytes = 16);
54
55  std::string GetAsString(const char *separator = nullptr) const;
56
57  size_t SetFromCString(const char *c_str, uint32_t num_uuid_bytes = 16);
58
59  // Decode as many UUID bytes (up to 16) as possible from the C string "cstr"
60  // This is used for auto completion where a partial UUID might have been
61  // typed in. It
62  //------------------------------------------------------------------
63  /// Decode as many UUID bytes (up to 16) as possible from the C
64  /// string \a cstr.
65  ///
66  /// @param[in] cstr
67  ///     A NULL terminate C string that points at a UUID string value
68  ///     (no leading spaces). The string must contain only hex
69  ///     characters and optionally can contain the '-' sepearators.
70  ///
71  /// @param[in] uuid_bytes
72  ///     A buffer of bytes that will contain a full or patially
73  ///     decoded UUID.
74  ///
75  /// @return
76  ///     The original string, with all decoded bytes removed.
77  //------------------------------------------------------------------
78  static llvm::StringRef
79  DecodeUUIDBytesFromString(llvm::StringRef str, ValueType &uuid_bytes,
80                            uint32_t &bytes_decoded,
81                            uint32_t num_uuid_bytes = 16);
82
83protected:
84  //------------------------------------------------------------------
85  // Classes that inherit from UUID can see and modify these
86  //------------------------------------------------------------------
87  uint32_t m_num_uuid_bytes; // Should be 16 or 20
88  ValueType m_uuid;
89};
90
91bool operator==(const UUID &lhs, const UUID &rhs);
92bool operator!=(const UUID &lhs, const UUID &rhs);
93bool operator<(const UUID &lhs, const UUID &rhs);
94bool operator<=(const UUID &lhs, const UUID &rhs);
95bool operator>(const UUID &lhs, const UUID &rhs);
96bool operator>=(const UUID &lhs, const UUID &rhs);
97
98} // namespace lldb_private
99
100#endif // LLDB_UTILITY_UUID_H
101