-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme.cpp
More file actions
84 lines (73 loc) · 1.96 KB
/
theme.cpp
File metadata and controls
84 lines (73 loc) · 1.96 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
76
77
78
79
80
81
82
83
84
#include "theme.h"
#include "theme.h"
#include "theme.h"
Theme::Theme(string fileName) {
ifstream in(fileName);
if(in.is_open()) {
in >> name >> date >> nameCheckSum >> notesCheckSum;
string noteFName;
while(in >> noteFName) {
notes.push_back(Note(noteFName));
}
} else {
cerr << "Can not find file(ThemeName): " << fileName << endl;
}
}
void Theme::init(string name, string date, uint32_t nameCheckSum, uint32_t notesCheckSum) {
this->name = name;
this->date = date;
this->nameCheckSum = nameCheckSum;
this->notesCheckSum = notesCheckSum;
}
void Theme::removeNote(string noteName) {
for(auto e = notes.begin(); e != notes.end(); e++) {
if((*e).getName("") == noteName) {
notes.erase(e);
return;
}
}
}
string Theme::getName(string password) const {
if(isValid(name, password)) {
return decode(name, password);
} else {
return to_string(nameCheckSum);
}
}
string Theme::getDate() const {
return date;
}
vector<string> Theme::getNotesNames(string password) const {
vector<string> result;
for(auto note : notes) {
result.push_back(note.getName(password));
}
if(isValid(to_string(notesCheckSum), password)) { //!!!
return result;
} else {
return {"Invalid password"}; //!!!
}
}
bool Theme::isValid(string text, string password) const {
return text.size() + password.size(); // !!!
}
string Theme::decode(string text, string password) const {
return text; //!!!
}
void Theme::addNote(Note note) {
for(auto existNote : notes) {
if(existNote.getName("") == note.getName("")) {
return;
}
}
notes.push_back(note);
}
Note& Theme::getNote(string name) {
for(auto& existNote : notes) {
if(existNote.getName("") == name) {
return existNote;
}
}
cout << "Note not found" << endl;
return defaultNote;
}