Cuberite
A lightweight, fast and extensible game server for Minecraft
UUID.h
Go to the documentation of this file.
1 // UUID.h
2 
3 // Declares the cUUID class representing a Universally Unique Identifier
4 
5 #pragma once
6 
7 
8 // tolua_begin
9 
10 class cUUID
11 {
12 public:
14  cUUID():
15  m_UUID()
16  {
17  }
18 
24  int Compare(const cUUID & a_Other) const
25  {
26  return std::memcmp(m_UUID.data(), a_Other.m_UUID.data(), m_UUID.size());
27  }
28 
30  bool IsNil() const
31  {
32  return (m_UUID == std::array<Byte, 16>{{0}});
33  }
34 
37  bool FromString(const AString & a_StringUUID);
38 
40  AString ToShortString() const;
41 
43  AString ToLongString() const;
44 
46  UInt8 Version() const;
47 
49  UInt8 Variant() const;
50 
52  static cUUID GenerateVersion3(const AString & a_Name);
53 
54  // tolua_end
55 
57  std::array<Byte, 16> ToRaw() const;
58 
60  void FromRaw(const std::array<Byte, 16> & a_Raw);
61 
62 private:
64  std::array<Byte, 16> m_UUID;
65 }; // tolua_export
66 
67 
68 // Comparison operators:
69 
70 inline bool operator == (const cUUID & a_Lhs, const cUUID & a_Rhs)
71 {
72  return (a_Lhs.Compare(a_Rhs) == 0);
73 }
74 
75 inline bool operator != (const cUUID & a_Lhs, const cUUID & a_Rhs)
76 {
77  return (a_Lhs.Compare(a_Rhs) != 0);
78 }
79 
80 inline bool operator < (const cUUID & a_Lhs, const cUUID & a_Rhs)
81 {
82  return (a_Lhs.Compare(a_Rhs) < 0);
83 }
84 
85 inline bool operator <= (const cUUID & a_Lhs, const cUUID & a_Rhs)
86 {
87  return (a_Lhs.Compare(a_Rhs) <= 0);
88 }
89 
90 inline bool operator > (const cUUID & a_Lhs, const cUUID & a_Rhs)
91 {
92  return (a_Lhs.Compare(a_Rhs) > 0);
93 }
94 
95 inline bool operator >= (const cUUID & a_Lhs, const cUUID & a_Rhs)
96 {
97  return (a_Lhs.Compare(a_Rhs) >= 0);
98 }
99 
100 
unsigned char UInt8
Definition: Globals.h:159
std::string AString
Definition: StringUtils.h:11
bool operator<(const cUUID &a_Lhs, const cUUID &a_Rhs)
Definition: UUID.h:80
bool operator>(const cUUID &a_Lhs, const cUUID &a_Rhs)
Definition: UUID.h:90
bool operator>=(const cUUID &a_Lhs, const cUUID &a_Rhs)
Definition: UUID.h:95
bool operator!=(const cUUID &a_Lhs, const cUUID &a_Rhs)
Definition: UUID.h:75
bool operator<=(const cUUID &a_Lhs, const cUUID &a_Rhs)
Definition: UUID.h:85
bool operator==(const cUUID &a_Lhs, const cUUID &a_Rhs)
Definition: UUID.h:70
Definition: UUID.h:11
int Compare(const cUUID &a_Other) const
Lexicographically compare bytes with another UUID.
Definition: UUID.h:24
AString ToShortString() const
Converts the UUID to a short form string (i.e without dashes).
Definition: UUID.cpp:133
bool FromString(const AString &a_StringUUID)
Tries to interpret the string as a short or long form UUID and assign from it.
Definition: UUID.cpp:102
static cUUID GenerateVersion3(const AString &a_Name)
Generates a version 3, variant 1 UUID based on the md5 hash of a_Name.
Definition: UUID.cpp:263
bool IsNil() const
Returns true if this contains the "nil" UUID with all bits set to 0.
Definition: UUID.h:30
std::array< Byte, 16 > m_UUID
Binary UUID stored big-endian.
Definition: UUID.h:64
UInt8 Variant() const
Returns the variant number of the UUID.
Definition: UUID.cpp:179
UInt8 Version() const
Returns the version number of the UUID.
Definition: UUID.cpp:170
cUUID()
Default constructed "nil" UUID.
Definition: UUID.h:14
AString ToLongString() const
Converts the UUID to a long form string (i.e.
Definition: UUID.cpp:151
void FromRaw(const std::array< Byte, 16 > &a_Raw)
Assigns from raw memory representation, respecting UUID variant.
Definition: UUID.cpp:238
std::array< Byte, 16 > ToRaw() const
Converts UUID to raw memory representation, respecting UUID variant.
Definition: UUID.cpp:214