From 4cb7ca42003c177e3acc80075d7594e555966106 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 18 Oct 2024 16:37:02 +0200 Subject: fix command design pattern --- LoadFilesCommand.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'LoadFilesCommand.cpp') 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 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 files) { - try { - this->load_files(files); - } catch (Exception & e) { - throw Exception("LoadFilesCommand error: %s", e.what()); - } +LoadFilesCommand::LoadFilesCommand(Museum & m, vector files) : museum(m) { + this->files = files; } -void LoadFilesCommand::load_files(vector 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 file = FileReaderFactory::open(url); try { @@ -41,3 +37,11 @@ void LoadFilesCommand::load_files(vector files) { } } +void LoadFilesCommand::execute() { + try { + this->load_files(); + } catch (Exception & e) { + throw Exception("LoadFilesCommand error: %s", e.what()); + } +} + -- cgit v1.2.3