blob: 3fb49789a8dbd363cca0764dfd5ad6e3f6fbf858 (
plain)
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
|
#include <vector>
#include <string>
#include "LoadFilesCommand.h"
#include "MuseumDeserializer.h"
#include "Exception.h"
#include "FileReaderFactory.h"
#include "FileReader.h"
#include "ToggleMuseumPauseCommand.h"
#include "ParserFactory.h"
using namespace std;
LoadFilesCommand::LoadFilesCommand(Museum & m, int argc, char ** argv) : museum(m) {
vector<string> files = {};
for (size_t i = 0; i < argc; i++) {
files.push_back(string(argv[i]));
}
this->files = files;
}
LoadFilesCommand::LoadFilesCommand(Museum & m, vector<string> files) : museum(m) {
this->files = files;
}
void LoadFilesCommand::load_files() {
ToggleMuseumPauseCommand(this->museum, true).execute();
MuseumDeserializer deserializer { this->museum };
for (string url : files) {
unique_ptr<FileReader> file = FileReaderFactory().create(url);
try {
ParserFactory::parse(*file, deserializer);
} catch (Exception & e) {
throw Exception("parser error: %s (%s)", e.what(), url.c_str());
}
}
}
void LoadFilesCommand::execute() {
try {
this->load_files();
} catch (Exception & e) {
throw Exception("LoadFilesCommand error: %s", e.what());
}
}
|