From 8c0562c8ef37cd5e80c58609f7bc7ae352365f65 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 22 Oct 2024 14:44:47 +0200 Subject: refactor parser factory --- LoadFilesCommand.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'LoadFilesCommand.cpp') diff --git a/LoadFilesCommand.cpp b/LoadFilesCommand.cpp index 3fb4978..76cd197 100644 --- a/LoadFilesCommand.cpp +++ b/LoadFilesCommand.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -27,12 +28,15 @@ void LoadFilesCommand::load_files() { ToggleMuseumPauseCommand(this->museum, true).execute(); MuseumDeserializer deserializer { this->museum }; + ParserFactory factory {}; + for (string url : files) { - unique_ptr file = FileReaderFactory().create(url); try { - ParserFactory::parse(*file, deserializer); + unique_ptr file = FileReaderFactory().create(url); + Parser & parser = factory.get_parser(*file); + parser.parse(deserializer); } catch (Exception & e) { - throw Exception("parser error: %s (%s)", e.what(), url.c_str()); + throw Exception("%s (%s)", e.what(), url.c_str()); } } } @@ -41,7 +45,7 @@ void LoadFilesCommand::execute() { try { this->load_files(); } catch (Exception & e) { - throw Exception("LoadFilesCommand error: %s", e.what()); + throw Exception("LoadFilesCommand: %s", e.what()); } } -- cgit v1.2.3