#pragma once // // This file is distributed under the MIT License. See LICENSE.md for details. // #include "revng/PipeboxCommon/Common.h" #include "revng/PipeboxCommon/ObjectID.h" namespace revng::pypeline { template class TupleTreeContainer { public: static constexpr Kind Kind = TheKind; static constexpr llvm::StringRef MimeType = "text/x.yaml"; private: bool Disposable = false; std::map> Map; public: std::set objects() const { return std::views::keys(Map) | revng::to>(); } void deserialize(const std::map> Data) { for (const auto &[Key, Value] : Data) { revng_assert(Key->kind() == Kind); llvm::StringRef String{ Value.data(), Value.size() }; Map[*Key] = llvm::cantFail(TupleTree::fromString(String)); } } std::map serialize(const std::vector Objects) const { std::map Result; for (const ObjectID *Object : Objects) { llvm::raw_svector_ostream OS(Result[*Object].data()); Map.at(*Object).serialize(OS); } return Result; } bool verify() const { return true; } void setIsDisposable() { Disposable = true; } void disposeIfPossible() { if (not Disposable) return; Map.clear(); Disposable = false; } public: bool contains(const ObjectID &Key) const { return Map.contains(Key); } TupleTree &getElement(const ObjectID &Key) { return Map[Key]; } const TupleTree &getElement(const ObjectID &Key) const { return Map.at(Key); } }; } // namespace revng::pypeline