#include <iostream>
#include "Config.h"
#include "FatalException.h"
#include "Logging.h"
#include "Mappings.h"
namespace objcgen {
static void read_table_mappings(const toml::Table& mapping, std::size_t i)
{
for (auto&& [key, value] : mapping) {
if (value.is<std::string>()) {
const auto& value_string = value.as<std::string>();
if (value_string.empty()) {
fatal("`mappings` entry #", i, " for key `", key, "` is empty");
}
add_non_generic_mapping(value_string).add_from(key);
} else {
fatal("`mappings` entry #", i, " for key `", key, "` is not a TOML string");
}
}
}
void read_toml_mappings()
{
if (const auto* mappings_any = config.find("mappings")) {
if (mappings_any->is<toml::Array>()) {
std::size_t i = 0;
for (auto&& mapping_any : mappings_any->as<toml::Array>()) {
if (mapping_any.is<toml::Table>()) {
read_table_mappings(mapping_any.as<toml::Table>(), i);
} else {
fatal("`mappings` entry #", i, " is not a TOML table");
}
i++;
}
} else {
fatal("`mappings` should be a TOML array of tables");
}
}
}
}