2020-04-17 14:22:43 +02:00
|
|
|
#include "config_adapter.h"
|
|
|
|
|
#include "Emu/system_config.h"
|
|
|
|
|
|
2020-07-28 23:11:27 +02:00
|
|
|
LOG_CHANNEL(cfg_log, "CFG");
|
|
|
|
|
|
2020-04-17 14:22:43 +02:00
|
|
|
// Helper methods to interact with YAML and the config settings.
|
|
|
|
|
namespace cfg_adapter
|
|
|
|
|
{
|
2025-03-04 19:38:16 +01:00
|
|
|
static cfg::_base& get_cfg(const cfg::_base& root, const std::string& name)
|
2020-04-17 14:22:43 +02:00
|
|
|
{
|
|
|
|
|
if (root.get_type() == cfg::type::node)
|
|
|
|
|
{
|
2025-03-04 19:38:16 +01:00
|
|
|
for (const auto& node : static_cast<const cfg::node&>(root).get_nodes())
|
2020-04-17 14:22:43 +02:00
|
|
|
{
|
2021-03-20 18:06:45 +01:00
|
|
|
if (node->get_name() == name)
|
2020-04-17 14:22:43 +02:00
|
|
|
{
|
2021-03-20 18:06:45 +01:00
|
|
|
return *node;
|
2020-04-17 14:22:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt::throw_exception("Node not found: %s", name);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-07 23:05:18 +02:00
|
|
|
static cfg::_base& get_cfg(cfg::_base& root, const cfg_location::const_iterator begin, const cfg_location::const_iterator end)
|
2020-04-17 14:22:43 +02:00
|
|
|
{
|
|
|
|
|
return begin == end ? root : get_cfg(get_cfg(root, *begin), begin + 1, end);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-07 23:05:18 +02:00
|
|
|
YAML::Node get_node(const YAML::Node& node, const cfg_location::const_iterator begin, const cfg_location::const_iterator end)
|
2020-04-17 14:22:43 +02:00
|
|
|
{
|
2020-07-28 23:11:27 +02:00
|
|
|
if (begin == end)
|
|
|
|
|
{
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!node || !node.IsMap())
|
|
|
|
|
{
|
2022-04-09 01:14:31 +02:00
|
|
|
cfg_log.fatal("Node error. A cfg_location does not match its cfg::node (location: %s)", get_yaml_node_location(node));
|
2020-07-28 23:11:27 +02:00
|
|
|
return YAML::Node();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return get_node(node[*begin], begin + 1, end); // TODO
|
2020-04-17 14:22:43 +02:00
|
|
|
}
|
|
|
|
|
|
2021-04-07 23:05:18 +02:00
|
|
|
YAML::Node get_node(const YAML::Node& node, const cfg_location& location)
|
2020-04-17 14:22:43 +02:00
|
|
|
{
|
2021-04-07 23:05:18 +02:00
|
|
|
return get_node(node, location.cbegin(), location.cend());
|
2020-04-17 14:22:43 +02:00
|
|
|
}
|
|
|
|
|
|
2024-11-15 01:55:01 +01:00
|
|
|
std::vector<std::string> get_options(const cfg_location& location)
|
2020-04-17 14:22:43 +02:00
|
|
|
{
|
2024-11-15 01:55:01 +01:00
|
|
|
return cfg_adapter::get_cfg(g_cfg, location.cbegin(), location.cend()).to_list();
|
2020-04-17 14:22:43 +02:00
|
|
|
}
|
2023-01-21 00:53:49 +01:00
|
|
|
|
2021-04-07 23:05:18 +02:00
|
|
|
static bool get_is_dynamic(const cfg_location& location)
|
2020-04-17 14:22:43 +02:00
|
|
|
{
|
2021-04-07 23:05:18 +02:00
|
|
|
return cfg_adapter::get_cfg(g_cfg, location.cbegin(), location.cend()).get_is_dynamic();
|
2020-04-17 14:22:43 +02:00
|
|
|
}
|
2023-01-21 00:53:49 +01:00
|
|
|
|
2020-04-17 14:22:43 +02:00
|
|
|
bool get_is_dynamic(emu_settings_type type)
|
|
|
|
|
{
|
2024-11-05 22:34:38 +01:00
|
|
|
return get_is_dynamic(::at32(settings_location, type));
|
2020-04-17 14:22:43 +02:00
|
|
|
}
|
2020-04-20 22:22:34 +02:00
|
|
|
|
|
|
|
|
std::string get_setting_name(emu_settings_type type)
|
|
|
|
|
{
|
2024-11-05 22:34:38 +01:00
|
|
|
const cfg_location& loc = ::at32(settings_location, type);
|
|
|
|
|
return ::at32(loc, loc.size() - 1);
|
2020-04-20 22:22:34 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
} // namespace cfg_adapter
|