-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSession.cpp
More file actions
75 lines (74 loc) · 1.72 KB
/
Session.cpp
File metadata and controls
75 lines (74 loc) · 1.72 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
#include "Session.h"
Session::Session(unsigned int _id, Image* i) : id(_id) {
ImageHistory im(i);
session.push_back(im);
}
Session::Session(unsigned int _id, ImageHistory ihistory) :id(_id) {
session.push_back(ihistory);
}
Session::Session(const Session& other) {
id = other.id;
for (ImageHistory im : other.session) {
session.push_back(im);
}
}
Session& Session::operator=(const Session& other) {
if (this != &other) {
id = other.id;
for (ImageHistory im : other.session) {
session.push_back(im);
}
}
return *this;
}
void Session::idMinusOne() {
assert(id >= 2);
id--;
}
void Session::addImage(Image* i) {
ImageHistory im(i);
session.push_back(im);
}
void Session::addChange(std::string command) {
for (ImageHistory& im : session) {
im.addChange(command);
}
}
ImageHistory Session::getImageByName(std::string n) {
for (ImageHistory im : session) {
if (im.getName() == n) return im;
}
throw std::exception("No such image!");
}
void Session::undo() {
for (ImageHistory& im : session) {
im.undoChange();
}
}
void Session::sessioninfo() {
for (ImageHistory& im : session) {
im.printChanges();
}
}
void Session::save() {
for (ImageHistory& im : session) {
im.save();
}
}
void Session::saveAs(std::string name) {
session[0].saveAs(name);
for (unsigned int i = 1; i < session.size(); i++) {
session[i].save();
}
}
void Session::getInfo() {
std::cout << "Current Session's ID: " << id<<'\n';
std::cout << "Images in current session: \n";
for (unsigned int i = 0; i < session.size() - 1; i++) {
std::cout<<session[i].getName()<<',';
}
std::cout << session.back().getName()<<'\n';
for (ImageHistory ih : session) {
ih.printChanges();
}
}