-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReview.cpp
108 lines (91 loc) · 2.91 KB
/
Review.cpp
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
99
100
101
102
103
104
105
106
107
108
#include <iostream>
#include <fstream>
#include "Review.h"
#include "Arquivo.h"
#include <chrono>
using namespace std;
// Construtor com atributos
Review::Review(string id, string text, int upvotes, string app_version, string posted_date) {
this->id = id;
this->text = text;
this->upvotes = upvotes;
this->app_version = app_version;
this->posted_date = posted_date;
}
// Fim Construtor com atributos
// Construtor vazio
Review::Review() {}
// Destrutor
Review::~Review() {
this->id.clear();
this->text.clear();
this->app_version.clear();
this->posted_date.clear();
}
// Getters e Setters
string Review::getId() {
return this->id;
}
void Review::setId(string id) {
this->id = id;
}
string Review::getText() {
return this->text;
}
void Review::setText(string text) {
this->text = text;
}
int Review::getUpvotes() {
return this->upvotes;
}
void Review::setUpvotes(int upvotes) {
this->upvotes = upvotes;
}
string Review::getAppVersion() {
return this->app_version;
}
void Review::setAppVersion(string app_version) {
this->app_version = app_version;
}
string Review::getPostedDate() {
return this->posted_date;
}
void Review::setPostedDate(string posted_date) {
this->posted_date = posted_date;
}
// Fim Getters e Setters
// Imprimir Review
void Review::imprimir() {
cout << "-----------------------------------------------------------------------------------------" << endl;
cout << "Id: " << this->id << endl;
cout << "Text: " << this->text << endl;
cout << "Upvotes: " << to_string(this->upvotes) << endl;
cout << "Version: " << this->app_version << endl;
cout << "Date: " << this->posted_date << endl;
cout << "-----------------------------------------------------------------------------------------" << endl;
}
// Fim Imprimir Review
// Inicio Receber Review
void Review::receberReview(Review* review) {
// Copia todos os dados de um review recebido
this->id = review->id;
this->text = review->text;
this->upvotes = review->upvotes;
this->app_version = review->app_version;
this->posted_date = review->posted_date;
}
// Fim Receber Review
// Inicio Salvar Review
void Review::salvarReview(ofstream &arquivo_bin, ofstream &arquivo_posicoes) {
// Salva posicao do cursor no binario antes de escrever o novo review, ou seja, esta sera a posicao de inicio dele
int posicaoReview = arquivo_bin.tellp();
// Escreve todos os atributos do review no arquivo bin
Arquivo::salvarString(arquivo_bin, this->id);
Arquivo::salvarString(arquivo_bin, this->text);
arquivo_bin.write((char *) &this->upvotes, sizeof(int));
Arquivo::salvarString(arquivo_bin, this->app_version);
Arquivo::salvarString(arquivo_bin, this->posted_date);
// Escreve a posicao desse review no arquivo auxiliar que armazena as posicoes de todos reviews
arquivo_posicoes.write((char *) &posicaoReview, sizeof(int));
}
// Fim Salvar Review