-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOfferFileRepository.cpp
More file actions
55 lines (50 loc) · 1.37 KB
/
Copy pathOfferFileRepository.cpp
File metadata and controls
55 lines (50 loc) · 1.37 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
#include "OfferFileRepository.h"
#include "repository.cpp"
void OfferFileRepository::save(Offer p) throw (MyException) {
Repository<Offer>::save(p);
ofstream fout(filename.c_str(), ios::app);
fout << p;
fout.close();
}
void OfferFileRepository::loadEntities() throw (MyException) {
//string line;
ifstream fin(filename.c_str());
if (!fin.is_open()) {
throw RepositoryException("could not open file");
}
while (fin.good()) {
Offer p { };
fin >> p;
if (p.getDest() != "") {
Repository<Offer>::save(p);
}
}
fin.close();
}
void OfferFileRepository::insertAtPosition(int id, Offer p) throw(MyException) {
Repository<Offer>::insertAtPosition(id, p);
ofstream fout(filename.c_str(), ios::out);
for(int i = 0; i < this->size(); i++) {
Offer p = this->findById(i);
fout << p;
}
fout.close(); fout.close();
}
void OfferFileRepository::update(int id, Offer p) throw(MyException) {
Repository<Offer>::update((unsigned) id, p);
ofstream fout(filename.c_str(), ios::out);
for(int i = 0; i < this->size(); i++) {
Offer p = this->findById(i);
fout << p;
}
fout.close();
}
void OfferFileRepository::remove(int id) throw(MyException) {
Repository<Offer>::remove((unsigned) id);
ofstream fout(filename.c_str(), ios::out);
for(int i = 0; i < this->size(); i++) {
Offer p = this->findById(i);
fout << p;
}
fout.close();
}