-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprayer.hpp
98 lines (76 loc) · 2.2 KB
/
prayer.hpp
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#pragma once
#include "object.hpp"
#include "link.hpp"
#include "gift.hpp"
#include "json.hpp"
using json = nlohmann::json;
class Prayer : public Object {
private:
std::string text_;
Link* link_;
public:
Prayer() : Object() {}
Prayer(const std::string& text)
: Object()
, text_(text)
, link_(nullptr) {}
Prayer(json& data)
: Object(data)
, text_(data["text"])
, link_(nullptr) {}
Prayer(const std::string& text, Link* link)
: Object()
, text_(text)
, link_(link) {
link_->LinkObject(this);
}
Prayer(const Prayer& other) : Object(other) {
text_ = other.text_;
link_ = other.link_;
}
Prayer(Prayer&& other) : Object(other) {
text_ = other.text_;
link_ = other.link_;
if (other.link_)
other.link_ = nullptr;
}
Prayer& operator=(Prayer&& other) {
Object::operator=(std::move(other));
if (link_)
delete link_;
link_ = other.link_;
text_ = other.text_;
return *this;
}
Prayer& operator=(const Prayer& other) {
return *this = Prayer(other);
}
~Prayer() {
link_->UnlinkObject(*this);
}
Link* GetLink() const {
return link_;
}
void SetLink(Link* link) {
link_ = link;
}
const std::string& GetText() const {
return text_;
}
void Show() {
std::cout << "-- Prayer --" << std::endl;
std::cout << "Linked: " << link_->IsLinked() << std::endl;
std::cout << "Prayer id: " << Uuid() << std::endl;
}
virtual std::string ToJson() const {
json data;
data["text"] = text_;
data["id"] = Uuid();
data["link_id"] = link_->Uuid();
std::string json_data = data.dump();
return json_data;
}
virtual ObjectType GetType() const {
return ObjectType::Prayer;
}
};