-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathid.h
64 lines (43 loc) · 1.25 KB
/
id.h
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
#ifndef ID_H
#define ID_H
#include "uuid.h"
#include <ostream>
#include <time.h>
namespace jGL
{
struct Id
{
Id()
: id(Id::NULL_ID_CODE)
{}
Id(uint64_t i)
: id(i)
{}
static uint64_t next(){uint64_t thisId = nextId; nextId++; return thisId;}
static uuids::uuid getRunUUID() {return runUUID;}
size_t hash() const {return std::hash<uint64_t>{}(id);}
uint64_t id;
bool operator==( Id const & rhs ) const {return this->id == rhs.id;}
bool operator<(const Id & rhs) const {return this->id < rhs.id;}
Id & operator=(const Id & j)
{
id = j.id;
return *this;
}
static const uint64_t NULL_ID_CODE = 0;
private:
static std::random_device rd;
static std::mt19937 generator;
static uuids::uuid_random_generator genUUID;
static const uuids::uuid runUUID;
static uint64_t nextId;
};
std::ostream & operator<<(std::ostream & os, Id const & value);
std::string to_string(const Id & i);
const Id NULL_ID = Id();
}
template<> struct std::hash<jGL::Id>
{
std::size_t operator()(const jGL::Id & i) const {return i.hash();}
};
#endif /* ID_H */