-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResumeManager.cpp
More file actions
68 lines (56 loc) · 1.76 KB
/
Copy pathResumeManager.cpp
File metadata and controls
68 lines (56 loc) · 1.76 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
#include "ResumeManager.hpp"
#include <fstream>
#include <filesystem>
#include <iostream>
using namespace std;
namespace fs = std::filesystem;
ResumeManager::ResumeManager(const string& directory) : storageDirectory(directory) {
ensureDirectoryExists();
}
void ResumeManager::ensureDirectoryExists() const {
if (!fs::exists(storageDirectory)) {
fs::create_directory(storageDirectory);
}
}
string ResumeManager::getFilePath(const string& name) const {
return storageDirectory + "/" + name + ".txt";
}
bool ResumeManager::saveResume(const Resume& resume) const {
string filePath = getFilePath(resume.getName());
ofstream outFile(filePath);
if (!outFile.is_open()) {
return false;
}
outFile << resume.serialize();
outFile.close();
return true;
}
bool ResumeManager::loadResume(const string& name, Resume& resume) const {
string filePath = getFilePath(name);
ifstream inFile(filePath);
if (!inFile.is_open()) {
return false;
}
string data((istreambuf_iterator<char>(inFile)), istreambuf_iterator<char>());
inFile.close();
return resume.deserialize(data);
}
bool ResumeManager::deleteResume(const string& name) const {
string filePath = getFilePath(name);
if (fs::exists(filePath)) {
return fs::remove(filePath);
}
return false;
}
vector<string> ResumeManager::listResumes() const {
vector<string> resumes;
for (const auto& entry : fs::directory_iterator(storageDirectory)) {
if (entry.is_regular_file() && entry.path().extension() == ".txt") {
resumes.push_back(entry.path().stem().string());
}
}
return resumes;
}
bool ResumeManager::resumeExists(const string& name) const {
return fs::exists(getFilePath(name));
}