-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComment.cpp
More file actions
79 lines (63 loc) · 1.45 KB
/
Comment.cpp
File metadata and controls
79 lines (63 loc) · 1.45 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
78
79
#include "Comment.h"
Comment::Comment(const MyString& text, size_t id, size_t createrId, size_t postId)
: text(text), postId(postId), SecondaryDataObject(id, createrId)
{}
const MyString& Comment::getText() const
{
return this->text;
}
size_t Comment::getPostId() const
{
return this->postId;
}
void Comment::setText(const MyString& text)
{
this->text = text;
}
void Comment::setPostId(size_t postId)
{
this->postId = postId;
}
void Comment::addUpvote()
{
upvotesCount++;
}
void Comment::addDownvote()
{
downvotesCount++;
}
size_t Comment::getUpvotes() const
{
return upvotesCount;
}
size_t Comment::getDownvotes() const
{
return downvotesCount;
}
void Comment::serialize(std::ostream& os) const
{
os << getId() << std::endl
<< getCreaterId() << std::endl
<< getPostId() << std::endl
<< getText() << std::endl << std::endl;
}
void Comment::deserialize(std::istream& is)
{
char emptyLine = is.get();
//std::cout << emptyLine;
size_t id;
is >> id;
setId(id);
emptyLine = is.get();
size_t createrId;
is >> createrId;
setCreaterId(createrId);
emptyLine = is.get();
size_t postId;
is >> postId;
setPostId(postId);
emptyLine = is.get();
is >> text;
//std::cout << "Record with id: " << getId() << ' '
// << getCreaterId() << ' ' << getText() << std::endl;
}