Porytiles
Loading...
Searching...
No Matches
artifact_checksum_provider.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <unordered_map>
5
9
10namespace porytiles {
11
23 public:
24 virtual ~ArtifactChecksumProvider() = default;
25
32 [[nodiscard]] virtual std::unordered_map<ArtifactKey, std::string>
33 compute_tileset_artifact_checksums(const std::vector<ArtifactKey> &keys) const = 0;
34
41 [[nodiscard]] virtual std::unordered_map<ArtifactKey, std::string>
42 load_cached_tileset_checksums(const std::string &name) const = 0;
43
52 const std::string &name, const std::unordered_map<ArtifactKey, std::string> &checksums) const = 0;
53
65 [[nodiscard]] std::vector<ArtifactKey>
66 find_unsynced_tileset_artifacts(const std::string &name, const std::vector<ArtifactKey> &keys_to_check) const
67 {
68 const auto computed_checksums = compute_tileset_artifact_checksums(keys_to_check);
69 const auto cached_checksums = load_cached_tileset_checksums(name);
70
71 if (cached_checksums.empty()) {
72 return {};
73 }
74
75 std::vector<ArtifactKey> mismatched_keys;
76 for (const auto &key : keys_to_check) {
77 const auto computed_checksum_for_key = computed_checksums.contains(key) ? computed_checksums.at(key) : "";
78 const auto cached_checksum_for_key = cached_checksums.contains(key) ? cached_checksums.at(key) : "";
79 if (computed_checksum_for_key != cached_checksum_for_key) {
80 mismatched_keys.push_back(key);
81 }
82 }
83 return mismatched_keys;
84 }
85
92 [[nodiscard]] bool cached_checksums_exist(const std::string &name) const
93 {
94 return !load_cached_tileset_checksums(name).empty();
95 }
96
109 [[nodiscard]] bool
110 all_checksums_tileset_match(const std::string &name, const std::vector<ArtifactKey> &artifact_keys) const
111 {
112 return find_unsynced_tileset_artifacts(name, artifact_keys).empty();
113 }
114};
115
116} // namespace porytiles
Abstract service for managing artifact checksums.
bool all_checksums_tileset_match(const std::string &name, const std::vector< ArtifactKey > &artifact_keys) const
Checks if all artifact checksums for the given Tileset match their cached values.
std::vector< ArtifactKey > find_unsynced_tileset_artifacts(const std::string &name, const std::vector< ArtifactKey > &keys_to_check) const
Finds all artifacts for the given Tileset with unsynced changes compared to cached checksums.
virtual std::unordered_map< ArtifactKey, std::string > load_cached_tileset_checksums(const std::string &name) const =0
Loads the cached checksums for the given Tileset.
virtual ChainableResult< void > cache_tileset_checksums(const std::string &name, const std::unordered_map< ArtifactKey, std::string > &checksums) const =0
Caches checksums for the given Tileset to persistent storage.
bool cached_checksums_exist(const std::string &name) const
Check if any cached checksums exist for the given tileset.
virtual ~ArtifactChecksumProvider()=default
virtual std::unordered_map< ArtifactKey, std::string > compute_tileset_artifact_checksums(const std::vector< ArtifactKey > &keys) const =0
Computes checksums for the given Tileset artifacts.
A result type that maintains a chainable sequence of errors for debugging and error reporting.