diff options
author | Aki <please@ignore.pl> | 2022-08-20 23:04:27 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-08-20 23:04:27 +0200 |
commit | ac8732867f57f59b8f4aec8d28b8e745046c9ac7 (patch) | |
tree | 68cfa9093dbbb31dc4af3cffd33eb5d0cd178079 /ArchiveEx/Archive.cpp | |
parent | bc9502fbc36946f1d96d3f188e18346baddbf1d5 (diff) | |
download | starshatter-ac8732867f57f59b8f4aec8d28b8e745046c9ac7.zip starshatter-ac8732867f57f59b8f4aec8d28b8e745046c9ac7.tar.gz starshatter-ac8732867f57f59b8f4aec8d28b8e745046c9ac7.tar.bz2 |
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.
Diffstat (limited to 'ArchiveEx/Archive.cpp')
-rw-r--r-- | ArchiveEx/Archive.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
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 <cstdint> #include <cstdio> #include <cstring> +#include <functional> #include <memory> #include <zlib.h> @@ -292,27 +293,27 @@ Archive::FindFreeSpot(const std::size_t bytes) const void -Archive::PrintNamesOfEntries() const +Archive::ForEachEntry(std::function<void(const char*)> func) const { for (const auto& entry : entries) - std::printf("%s\n", entry.name); + func(entry.name); } void -Archive::PrintBlocks() const +Archive::ForEachBlock(std::function<void(const char*)> 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; } } } |