From 16add863726d91adee888f446a409916c6fbe3d9 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 18 Jan 2024 12:02:38 -0500 Subject: [PATCH] Eliminate final macro. --- Analyser/Static/StaticAnalyser.cpp | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Analyser/Static/StaticAnalyser.cpp b/Analyser/Static/StaticAnalyser.cpp index 32b5cfe38..6dfd90998 100644 --- a/Analyser/Static/StaticAnalyser.cpp +++ b/Analyser/Static/StaticAnalyser.cpp @@ -307,24 +307,24 @@ TargetList Analyser::Static::GetTargets(const std::string &file_name) { TargetList targets; // Check whether the file directly identifies a target; if so then just return that. + const auto try_snapshot = [&](const char *ext, auto loader) -> bool { + if(extension != ext) { + return false; + } + try { + auto target = loader(file_name); + if(target) { + targets.push_back(std::move(target)); + return true; + } + } catch(...) {} + return false; + }; -#define Format(ext, class) \ - if(extension == ext) { \ - try { \ - auto target = Storage::State::class::load(file_name); \ - if(target) { \ - targets.push_back(std::move(target)); \ - return targets; \ - } \ - } catch(...) {} \ - } - - Format("sna", SNA); - Format("szx", SZX); - Format("z80", Z80); - -#undef TryInsert + if(try_snapshot("sna", Storage::State::SNA::load)) return targets; + if(try_snapshot("szx", Storage::State::SZX::load)) return targets; + if(try_snapshot("z80", Storage::State::Z80::load)) return targets; // Otherwise: //