Horizon
object_ref.hpp
1 #pragma once
2 #include "common/common.hpp"
3 #include "util/uuid.hpp"
4 #include <functional>
5 
6 namespace horizon {
7 class ObjectRef {
8 public:
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 
45 namespace std {
46 template <> 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
std::hash< horizon::UUID >
Definition: uuid.hpp:52
horizon::ObjectRef
Definition: object_ref.hpp:7