-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlbumImage.cpp
87 lines (74 loc) · 1.69 KB
/
AlbumImage.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
// Eli Simmonds
// Project 3
// AlbumImage.cpp
#include "AlbumImage.hpp"
int albImageRefCount = 0;
AlbumImage::AlbumImage() {
// initializes all private variables
albImageRefCount++;
_height = _width = _albumID = 0;
_type = _uri = " ";
cachedHeight = cachedWidth = cachedAlbumID
= cachedType = cachedURI = false;
}
AlbumImage::~AlbumImage() {
// decrements the counter that tracks memory allocation
albImageRefCount--;
}
int AlbumImage::height() {
if (cachedHeight)
return _height;
cachedHeight = true;
return _height = valueForIntegerAttribute("height");
}
int AlbumImage::width() {
if (cachedWidth)
return _width;
cachedWidth = true;
return _width = valueForIntegerAttribute("width");
}
int AlbumImage::albumID() {
if (cachedAlbumID)
return _albumID;
cachedAlbumID = true;
return _albumID = valueForIntegerAttribute("album_id");
}
std::string AlbumImage::type() {
if (cachedType)
return _type;
cachedType = true;
return _type = valueForStringAttribute("type");
}
std::string AlbumImage::uri() {
if (cachedURI)
return _uri;
cachedURI = true;
return _uri = valueForStringAttribute("uri");
}
void AlbumImage::print() {
// prints all variables of the image
std::cout << "height: " << height() << '\n'
<< "type: " << type() << '\n'
<< "uri: " << uri() << '\n'
<< "width: " << width() << '\n'
<< "album_id: " << albumID() << '\n'
<< std::endl;
}
std::string AlbumImage::htmlString() {
// creates a string for a single image
std::string html;
html += "<img class=";
html += '"';
html += "image";
html += '"';
html += " width=";
html += width();
html += " height=";
html += height();
html += " src=";
html += '"';
html += uri();
html += '"';
html += ">";
return html;
}