diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-18 16:37:02 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-18 16:37:02 +0200 |
commit | 4cb7ca42003c177e3acc80075d7594e555966106 (patch) | |
tree | d2f5836d70a1fa2dc1d18c4fb59f1bf1f2f91f5a /LoadFilesCommand.cpp | |
parent | d8289105193707daede1a5b59137f18e20f20aeb (diff) |
fix command design pattern
Diffstat (limited to 'LoadFilesCommand.cpp')
-rw-r--r-- | LoadFilesCommand.cpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/LoadFilesCommand.cpp b/LoadFilesCommand.cpp index ae9f30a..82ede60 100644 --- a/LoadFilesCommand.cpp +++ b/LoadFilesCommand.cpp @@ -11,26 +11,22 @@ using namespace std; -void LoadFilesCommand::execute(int argc, char ** argv) { +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])); } - return this->execute(files); + this->files = files; } -void LoadFilesCommand::execute(vector<string> files) { - try { - this->load_files(files); - } catch (Exception & e) { - throw Exception("LoadFilesCommand error: %s", e.what()); - } +LoadFilesCommand::LoadFilesCommand(Museum & m, vector<string> files) : museum(m) { + this->files = files; } -void LoadFilesCommand::load_files(vector<string> files) { - ToggleMuseumPauseCommand(this).set(true); +void LoadFilesCommand::load_files() { + ToggleMuseumPauseCommand(this->museum, true).execute(); - MuseumDeserializer deserializer { this->get_museum() }; + MuseumDeserializer deserializer { this->museum }; for (string url : files) { unique_ptr<FileReader> file = FileReaderFactory::open(url); try { @@ -41,3 +37,11 @@ void LoadFilesCommand::load_files(vector<string> files) { } } +void LoadFilesCommand::execute() { + try { + this->load_files(); + } catch (Exception & e) { + throw Exception("LoadFilesCommand error: %s", e.what()); + } +} + |