From ac8732867f57f59b8f4aec8d28b8e745046c9ac7 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 20 Aug 2022 23:04:27 +0200 Subject: Added options to inspect archive content in dat utility Old PrintX methods were replaced by higher order functions ForEachX that are intended to give slighly more granual control and move the responsibility of what actually happens to the user without introducing a whole iterator. --- ArchiveEx/Archive.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'ArchiveEx/Archive.cpp') diff --git a/ArchiveEx/Archive.cpp b/ArchiveEx/Archive.cpp index 808b6fc..b39de88 100644 --- a/ArchiveEx/Archive.cpp +++ b/ArchiveEx/Archive.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -292,27 +293,27 @@ Archive::FindFreeSpot(const std::size_t bytes) const void -Archive::PrintNamesOfEntries() const +Archive::ForEachEntry(std::function func) const { for (const auto& entry : entries) - std::printf("%s\n", entry.name); + func(entry.name); } void -Archive::PrintBlocks() const +Archive::ForEachBlock(std::function func) const { - for (std::size_t i = 0; i < blocks.size(); ++i) { - std::printf("%ld\t", i); - switch (blocks[i]) { + for (const int content : blocks) { + switch (content) { case UNUSED_BLOCK: - std::printf("(unused)\n"); + func("(unused)"); break; case DIRECTORY_BLOCK: - std::printf("(dir)\n"); + func("(directory)"); break; default: - std::printf("%s\n", entries[blocks[i]].name); + func(entries[content].name); + break; } } } -- cgit v1.1