From 83beb3c0e689d7f986d3b9e7d9a1d9c4ba261ac7 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 6 Jun 2021 18:28:02 -0400 Subject: [PATCH] Introduces slightly-less manual `ROM::Request::visit`. --- Machines/Utility/ROMCatalogue.cpp | 21 ++++++ Machines/Utility/ROMCatalogue.hpp | 7 ++ .../xcschemes/Clock Signal Kiosk.xcscheme | 2 +- OSBindings/SDL/main.cpp | 66 +++++++++---------- 4 files changed, 62 insertions(+), 34 deletions(-) diff --git a/Machines/Utility/ROMCatalogue.cpp b/Machines/Utility/ROMCatalogue.cpp index e2059544d..2466491c8 100644 --- a/Machines/Utility/ROMCatalogue.cpp +++ b/Machines/Utility/ROMCatalogue.cpp @@ -149,6 +149,24 @@ void Request::visit( node.visit(enter_list, exit_list, add_item); } +void Request::visit( + const std::function &add_item +) const { + int indentation_level = 0; + node.visit( + [&indentation_level, &add_item] (ROM::Request::ListType type) { + add_item(LineItem::NewList, type, indentation_level, nullptr, false, -1); + ++indentation_level; + }, + [&indentation_level] { + --indentation_level; + }, + [&indentation_level, &add_item] (ROM::Request::ListType type, const ROM::Description &rom, bool is_optional, size_t remaining) { + add_item(LineItem::Description, type, indentation_level, &rom, is_optional, remaining); + } + ); +} + void Request::Node::visit( const std::function &enter_list, const std::function &exit_list, @@ -203,6 +221,9 @@ std::optional Description::from_crc(uint32_t crc32) { std::string Description::description(int flags) const { std::stringstream output; + // If there are no CRCs, don't output them. + if(crc32s.empty()) flags &= ~ DescriptionFlag::CRC; + // Print the file name(s) and the descriptive name. if(flags & DescriptionFlag::Filename) { flags &= ~DescriptionFlag::Filename; diff --git a/Machines/Utility/ROMCatalogue.hpp b/Machines/Utility/ROMCatalogue.hpp index 02ffc4987..2df582024 100644 --- a/Machines/Utility/ROMCatalogue.hpp +++ b/Machines/Utility/ROMCatalogue.hpp @@ -206,6 +206,13 @@ struct Request { const std::function &add_item ) const; + enum class LineItem { + NewList, Description + }; + void visit( + const std::function &add_item + ) const; + private: struct Node { enum class Type { diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal Kiosk.xcscheme b/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal Kiosk.xcscheme index a9a61567e..2787530a5 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal Kiosk.xcscheme +++ b/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal Kiosk.xcscheme @@ -125,7 +125,7 @@ isEnabled = "NO"> diff --git a/OSBindings/SDL/main.cpp b/OSBindings/SDL/main.cpp index 49402eed7..259699147 100644 --- a/OSBindings/SDL/main.cpp +++ b/OSBindings/SDL/main.cpp @@ -776,41 +776,41 @@ int main(int argc, char *argv[]) { std::cerr << "Could not find system ROMs; please install to /usr/local/share/CLK/ or /usr/share/CLK/, or provide a --rompath, e.g. --rompath=~/ROMs." << std::endl; std::cerr << "Needed — but didn't find — "; - int indentation_level = 0; - const auto indent = [&indentation_level] { - if(indentation_level) { - std::cerr << std::endl; - for(int c = 0; c < indentation_level; c++) std::cerr << '\t'; - std::cerr << "* "; - } - }; - - missing_roms.visit([&indentation_level, indent] (ROM::Request::ListType type) { - indent(); - switch(type) { - default: - case ROM::Request::ListType::All: std::cerr << "all of:"; break; - case ROM::Request::ListType::Any: std::cerr << "any of:"; break; - } - ++indentation_level; - }, [&indentation_level] { - --indentation_level; - }, [&indentation_level, indent] (ROM::Request::ListType type, const ROM::Description &rom, bool is_optional, size_t remaining) { - indent(); - if(is_optional) std::cerr << "optionally, "; - - using DescriptionFlag = ROM::Description::DescriptionFlag; - std::cerr << rom.description(DescriptionFlag::Filename | DescriptionFlag::CRC); - - if(remaining) { - std::cerr << ";"; - if(remaining == 1) { - std::cerr << ((type == ROM::Request::ListType::All) ? " and" : " or"); + missing_roms.visit( + [] (ROM::Request::LineItem item, ROM::Request::ListType type, int indentation_level, const ROM::Description *description, bool is_optional, size_t remaining) { + if(indentation_level) { + std::cerr << std::endl; + for(int c = 0; c < indentation_level; c++) std::cerr << '\t'; + std::cerr << "* "; + } + + switch(item) { + case ROM::Request::LineItem::NewList: + switch(type) { + default: + case ROM::Request::ListType::All: std::cerr << "all of:"; break; + case ROM::Request::ListType::Any: std::cerr << "any of:"; break; + } + break; + + case ROM::Request::LineItem::Description: + if(is_optional) std::cerr << "optionally, "; + + using DescriptionFlag = ROM::Description::DescriptionFlag; + std::cerr << description->description(DescriptionFlag::Filename | DescriptionFlag::CRC); + + if(remaining) { + std::cerr << ";"; + if(remaining == 1) { + std::cerr << ((type == ROM::Request::ListType::All) ? " and" : " or"); + } + } else { + std::cerr << "."; + } + break; } - } else { - std::cerr << "."; } - }); + ); std::cerr << std::endl << std::endl << "Searched unsuccessfully: "; bool is_first = true;