Horizon
Loading...
Searching...
No Matches
object_ref.hpp
1#pragma once
2#include "common/common.hpp"
3#include "util/uuid.hpp"
4#include <functional>
5
6namespace horizon {
7class ObjectRef {
8public:
9 ObjectRef(ObjectType ty, const UUID &uu, const UUID &uu2 = UUID()) : type(ty), uuid(uu), uuid2(uu2)
10 {
11 }
12 ObjectRef() : type(ObjectType::INVALID)
13 {
14 }
15 ObjectType type;
16 UUID uuid;
17 UUID uuid2;
18 bool operator<(const ObjectRef &other) const
19 {
20 if (type < other.type) {
21 return true;
22 }
23 if (type > other.type) {
24 return false;
25 }
26 if (uuid < other.uuid) {
27 return true;
28 }
29 else if (uuid > other.uuid) {
30 return false;
31 }
32 return uuid2 < other.uuid2;
33 }
34 bool operator==(const ObjectRef &other) const
35 {
36 return (type == other.type) && (uuid == other.uuid) && (uuid2 == other.uuid2);
37 }
38 bool operator!=(const ObjectRef &other) const
39 {
40 return !(*this == other);
41 }
42};
43} // namespace horizon
44
45namespace std {
46template <> struct hash<horizon::ObjectRef> {
47 std::size_t operator()(const horizon::ObjectRef &k) const
48 {
49 return static_cast<size_t>(k.type) ^ std::hash<horizon::UUID>{}(k.uuid) ^ std::hash<horizon::UUID>{}(k.uuid2);
50 }
51};
52} // namespace std
Definition object_ref.hpp:7
This class encapsulates a UUID and allows it to be uses as a value type.
Definition uuid.hpp:16