| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
|---|---|
| 2 | |
| 3 | #pragma once |
| 4 | |
| 5 | #include <toml++/toml.hpp> |
| 6 | #include <vector> |
| 7 | |
| 8 | struct IUnit; |
| 9 | using ArgumentMap = std::map<std::string, std::string>; |
| 10 | |
| 11 | static constexpr std::string_view TEMPLATE_SUFFIX = "-template"; |
| 12 | constexpr auto ARGUMENTS_SEPARATOR = '@'; |
| 13 | |
| 14 | class Template : public std::enable_shared_from_this<Template> |
| 15 | { |
| 16 | public: |
| 17 | explicit Template(const std::string &id, const toml::table &table, const ArgumentMap &predefined_args = {}); |
| 18 | |
| 19 | const std::string id; |
| 20 | const toml::table table; |
| 21 | const ArgumentMap predefined_args; |
| 22 | |
| 23 | std::optional<std::pair<std::string, std::shared_ptr<IUnit>>> Instantiate(const ArgumentMap &args) const; |
| 24 | |
| 25 | std::vector<std::string> GetParameters() const |
| 26 | { |
| 27 | // return key in parameters but not in predefined_args |
| 28 | std::vector<std::string> result; |
| 29 | for (const auto ¶m : parameters) |
| 30 | if (!predefined_args.contains(x: param)) |
| 31 | result.push_back(x: param); |
| 32 | return result; |
| 33 | } |
| 34 | |
| 35 | static std::string GetID(const std::string &id, const ArgumentMap &args); |
| 36 | |
| 37 | private: |
| 38 | std::vector<std::string> parameters; |
| 39 | }; |
| 40 |