forked from Yasna1998/stackoverflow-in-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContent.cpp
More file actions
57 lines (48 loc) · 1.35 KB
/
Content.cpp
File metadata and controls
57 lines (48 loc) · 1.35 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
#include "Content.h"
#include <iostream>
#include <vector>
using namespace std;
Content::Content(std::string body, ContentType type):body(body), type(type){
this->visits = 0;
}
Content::~Content() {
int end = relations.size();
for (int i = 0; i < end;i++){
delete relations[0];
}
}
void Content::add_relation(ContentRelationType type, Content &dest){
ContentRelation* cp = new ContentRelation(&dest, this, type);
relations.push_back(cp);
dest.relations.push_back(cp);
}
void Content::edit_content(std::string body) {
this->body = body;
}
void Content::print_answers() {
for (int i=0;i<relations.size();i++){
if (relations[i]->type == ANSWER_TO){
cout<<i+1<<". "<<relations[i]->source->body<<endl;
}
}
cout<<"\n\n";
}
ContentRelation::ContentRelation(Content* destination, Content* source ,ContentRelationType type) {
this->destination = destination;
this->source = source;
this->type = type;
}
ContentRelation::~ContentRelation() {
vector<ContentRelation*> *c1 = &(this->destination->relations);
for (auto i = c1->begin(); i < c1->end(); i++) {
if (*i == this) {
c1->erase(i);
}
}
c1 = &(this->source->relations);
for (auto i = c1->begin(); i < c1->end(); i++) {
if (*i == this) {
c1->erase(i);
}
}
}