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 
cUUID
Definition: UUID.h:10
cUUID::m_UUID
std::array< Byte, 16 > m_UUID
Binary UUID stored big-endian.
Definition: UUID.h:64
cUUID::cUUID
cUUID()
Default constructed "nil" UUID.
Definition: UUID.h:14
cUUID::Compare
int Compare(const cUUID &a_Other) const
Lexicographically compare bytes with another UUID.
Definition: UUID.h:24
cUUID::ToLongString
AString ToLongString() const
Converts the UUID to a long form string (i.e.
Definition: UUID.cpp:151
cUUID::GenerateVersion3
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
cUUID::ToRaw
std::array< Byte, 16 > ToRaw() const
Converts UUID to raw memory representation, respecting UUID variant.
Definition: UUID.cpp:214
operator==
bool operator==(const cUUID &a_Lhs, const cUUID &a_Rhs)
Definition: UUID.h:70
operator>=
bool operator>=(const cUUID &a_Lhs, const cUUID &a_Rhs)
Definition: UUID.h:95
cUUID::Variant
UInt8 Variant() const
Returns the variant number of the UUID.
Definition: UUID.cpp:179
cUUID::Version
UInt8 Version() const
Returns the version number of the UUID.
Definition: UUID.cpp:170
operator>
bool operator>(const cUUID &a_Lhs, const cUUID &a_Rhs)
Definition: UUID.h:90
cUUID::IsNil
bool IsNil() const
Returns true if this contains the "nil" UUID with all bits set to 0.
Definition: UUID.h:30
operator!=
bool operator!=(const cUUID &a_Lhs, const cUUID &a_Rhs)
Definition: UUID.h:75
operator<=
bool operator<=(const cUUID &a_Lhs, const cUUID &a_Rhs)
Definition: UUID.h:85
cUUID::FromRaw
void FromRaw(const std::array< Byte, 16 > &a_Raw)
Assigns from raw memory representation, respecting UUID variant.
Definition: UUID.cpp:238
operator<
bool operator<(const cUUID &a_Lhs, const cUUID &a_Rhs)
Definition: UUID.h:80
UInt8
unsigned char UInt8
Definition: Globals.h:156
cUUID::ToShortString
AString ToShortString() const
Converts the UUID to a short form string (i.e without dashes).
Definition: UUID.cpp:133
AString
std::string AString
Definition: StringUtils.h:11
cUUID::FromString
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