#pragma once // // This file is distributed under the MIT License. See LICENSE.md for details. // #include #include #include #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "revng/Pipeline/ContainerSet.h" namespace pipeline { /// A container factory set is a collection of factories so that a set of empty /// containers can be spawned on demand. /// /// We keep one of this for each Runner, so that the containers used by that /// runners can be created. class ContainerFactorySet { private: llvm::StringMap Entries; public: using const_iterator = llvm::StringMap::const_iterator; using value_type = llvm::StringMap::value_type; public: const_iterator begin() const { return Entries.begin(); } const_iterator end() const { return Entries.end(); } size_t size() const { return Entries.size(); } public: void registerContainerFactory(llvm::StringRef Name, ContainerFactory Entry) { Entries.insert_or_assign(Name, std::move(Entry)); } template void registerDefaultConstructibleFactory(llvm::StringRef Name) { registerContainerFactory(Name, [](llvm::StringRef Name) { return std::make_unique(Name); }); } ContainerSet createEmpty() const { ContainerSet ToReturn; for (const auto &Entry : Entries) ToReturn.add(Entry.first(), Entry.second); return ToReturn; } }; } // namespace pipeline