diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2025-02-21 16:18:47 +0100 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2025-02-27 09:03:30 +0100 |
commit | a8a167cb206f6c66e52ab4e92e0939e91b8dfed8 (patch) | |
tree | 7861406725739f45a98c1312ed45264bb10b9b35 /src/buildtool/common/artifact_blob.hpp | |
parent | e1880bead60d433de2960104bd62cd9e27bfca17 (diff) | |
download | justbuild-a8a167cb206f6c66e52ab4e92e0939e91b8dfed8.tar.gz |
ArtifactBlob: Convert to a class
Diffstat (limited to 'src/buildtool/common/artifact_blob.hpp')
-rw-r--r-- | src/buildtool/common/artifact_blob.hpp | 55 |
1 files changed, 42 insertions, 13 deletions
diff --git a/src/buildtool/common/artifact_blob.hpp b/src/buildtool/common/artifact_blob.hpp index 57d99f7c..3fc4ba23 100644 --- a/src/buildtool/common/artifact_blob.hpp +++ b/src/buildtool/common/artifact_blob.hpp @@ -24,22 +24,51 @@ #include "src/buildtool/common/artifact_digest.hpp" #include "src/utils/cpp/hash_combine.hpp" -struct ArtifactBlob final { - ArtifactBlob(ArtifactDigest digest, - std::string mydata, - bool is_exec) noexcept - : digest{std::move(digest)}, - data{std::make_shared<std::string>(std::move(mydata))}, - is_exec{is_exec} {} +class ArtifactBlob final { + public: + explicit ArtifactBlob(ArtifactDigest digest, + std::string content, + bool is_exec) noexcept + : digest_{std::move(digest)}, + content_{std::make_shared<std::string const>(std::move(content))}, + is_executable_{is_exec} {} [[nodiscard]] auto operator==(ArtifactBlob const& other) const noexcept -> bool { - return digest == other.digest and is_exec == other.is_exec; + return digest_ == other.digest_ and + is_executable_ == other.is_executable_; } - ArtifactDigest digest; - std::shared_ptr<std::string> data; - bool is_exec = false; + /// \brief Obtain the digest of the content. + [[nodiscard]] auto GetDigest() const noexcept -> ArtifactDigest const& { + return digest_; + } + + /// \brief Obtain the size of the content. + [[nodiscard]] auto GetContentSize() const noexcept -> std::size_t { + return content_->size(); + } + + /// \brief Read the content from source. + [[nodiscard]] auto ReadContent() const noexcept + -> std::shared_ptr<std::string const> { + return content_; + } + + /// \brief Set executable permission. + void SetExecutable(bool is_executable) noexcept { + is_executable_ = is_executable; + } + + /// \brief Obtain executable permission. + [[nodiscard]] auto IsExecutable() const noexcept -> bool { + return is_executable_; + } + + private: + ArtifactDigest digest_; + std::shared_ptr<std::string const> content_; + bool is_executable_; }; namespace std { @@ -48,8 +77,8 @@ struct hash<ArtifactBlob> { [[nodiscard]] auto operator()(ArtifactBlob const& blob) const noexcept -> std::size_t { std::size_t seed{}; - hash_combine(&seed, blob.digest); - hash_combine(&seed, blob.is_exec); + hash_combine(&seed, blob.GetDigest()); + hash_combine(&seed, blob.IsExecutable()); return seed; } }; |