-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUuid.cpp
49 lines (40 loc) · 1.23 KB
/
Uuid.cpp
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
#include "Uuid.hpp"
#include <iostream>
#include <array>
std::ostream &operator<<(std::ostream &os, UUID &uuid) {
os << uuid.format();
return os;
}
std::string UUID::format() {
std::stringstream resultStream;
resultStream << std::hex;
resultStream << this->timeLow;
resultStream << "-";
resultStream << this->timeMid;
resultStream << "-";
resultStream << this->timeHiAndVersion;
resultStream << "-";
resultStream << (int) this->clockSeqHighAndReserved;
resultStream << (int) this->clockSeqLow;
resultStream << "-";
resultStream << this->formatNode();
return resultStream.str();
}
std::string UUID::formatNode() {
std::stringstream resultStream;
resultStream << std::hex;
for (unsigned char c : this->node) {
resultStream << (int) c;
}
return resultStream.str();
}
bool UUID::operator==(UUID &other) const {
return this->timeLow == other.timeLow &&
this->timeMid == other.timeMid &&
this->timeHiAndVersion == other.timeHiAndVersion &&
this->clockSeqHighAndReserved == other.clockSeqHighAndReserved &&
this->clockSeqLow == other.clockSeqLow;
}
bool UUID::operator!=(UUID &other) const {
return !(*this == other);
}