1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-22 12:33:29 +00:00

Introduces slightly-less manual ROM::Request::visit.

This commit is contained in:
Thomas Harte 2021-06-06 18:28:02 -04:00
parent 76335e5cf2
commit 83beb3c0e6
4 changed files with 62 additions and 34 deletions

View File

@ -149,6 +149,24 @@ void Request::visit(
node.visit(enter_list, exit_list, add_item);
}
void Request::visit(
const std::function<void(LineItem, ListType, int, const ROM::Description *, bool, size_t)> &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<void(ListType)> &enter_list,
const std::function<void(void)> &exit_list,
@ -203,6 +221,9 @@ std::optional<Description> 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;

View File

@ -206,6 +206,13 @@ struct Request {
const std::function<void(ROM::Request::ListType type, const ROM::Description &, bool is_optional, size_t remaining)> &add_item
) const;
enum class LineItem {
NewList, Description
};
void visit(
const std::function<void(LineItem, ListType, int level, const ROM::Description *, bool is_optional, size_t remaining)> &add_item
) const;
private:
struct Node {
enum class Type {

View File

@ -125,7 +125,7 @@
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "--new=electron"
argument = "--new=msx"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>

View File

@ -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;