-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.hpp
More file actions
77 lines (63 loc) · 1.58 KB
/
object.hpp
File metadata and controls
77 lines (63 loc) · 1.58 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma once
#include <uuid/uuid.h>
#include <iostream>
#include "json.hpp"
using json = nlohmann::json;
static constexpr size_t kUUIDBufferSize = 512;
enum class ObjectType {
Object,
Link,
Gift,
Prayer,
};
class Object {
private:
uuid_t id_;
public:
Object() {
uuid_generate(id_);
}
Object(json& data) {
std::string uuid;
if (data.contains("id")) {
uuid = data["id"];
uuid_parse(uuid.c_str(), id_);
}
};
~Object() {
uuid_clear(id_);
}
Object(const Object& other) {
uuid_copy(id_, other.id_);
}
Object(Object&& other) {
uuid_copy(id_, other.id_);
uuid_clear(other.id_);
}
Object& operator=(Object&& other) {
uuid_copy(id_, other.id_);
uuid_clear(other.id_);
return *this;
}
Object& operator=(const Object& other) {
return *this = Object(other);
}
const uuid_t& GetId() const {
return id_;
}
std::string Uuid() const {
char buf[kUUIDBufferSize];
uuid_unparse(id_, buf);
std::string uuid(buf);
return uuid;
}
virtual std::string ToJson() const {
json data;
data["id"] = Uuid();
std::string json_data = data.dump();
return json_data;
}
virtual ObjectType GetType() const {
return ObjectType::Object;
}
};