-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPaintingWrapper.cpp
89 lines (67 loc) · 1.66 KB
/
PaintingWrapper.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
//
// PaintingWrapper.cpp
// Project3
//
// Created by Matthew Carmichael on 11/15/15.
// Copyright © 2015 Redline Studios. All rights reserved.
//
#include "PaintingWrapper.hpp"
PaintingWrapper::PaintingWrapper(int id){
p = NULL;
pid = id;
}
int PaintingWrapper::get_pid(){
return pid;
}
Painting *PaintingWrapper::get_p(){
return p;
}
void PaintingWrapper::set_p(){
p = operator->();
}
void PaintingWrapper::unset_p(){
delete p;
p = NULL;
}
Painting* PaintingWrapper::operator->() const{
if (p == NULL) {
stringstream out;
out << pid;
string fileName = out.str()+".txt";
ifstream iFile(fileName.c_str());
string id, title, artist;
/* While there is still a line. */
getline(iFile, id);
getline(iFile, title);
getline(iFile, artist);
iFile.close();
return new Painting(id, title, artist);
}else{
return p;
}
}
void PaintingWrapper::save_painting(){
if (p != NULL) {
stringstream out;
out << pid;
string fileName = out.str()+".txt";
remove(fileName.c_str());
ofstream oFile(fileName.c_str());
string content = out.str()+"\n"+p->get_title()+"\n"+p->get_artistName();
oFile << content;
oFile.close();
}
}
void PaintingWrapper::display(){
Painting *tp;
if (p == NULL) {
tp = operator->();
}else{
tp = p;
}
stringstream out;
out << tp->get_id();
cout << out.str()+"\n";
cout << tp->get_title()+"\n";
cout << tp->get_artistName()+"\n";
}