OIUtils: Parse "capture_keys" section from configs

This commit is contained in:
Alastair Robertson 2023-09-22 06:20:38 -07:00 committed by Alastair Robertson
parent 1f66ef064a
commit 9055c5841d
2 changed files with 39 additions and 0 deletions

View File

@ -59,6 +59,12 @@ class OICodeGen {
Config(Config&& other) = delete;
Config& operator=(Config&& other) = delete;
struct KeyToCapture {
std::optional<std::string> type;
std::optional<std::string> member;
bool topLevel = false;
};
bool useDataSegment;
FeatureSet features;
std::set<std::filesystem::path> containerConfigPaths;
@ -66,6 +72,7 @@ class OICodeGen {
std::set<std::string> defaultNamespaces;
std::vector<std::pair<std::string, std::string>> membersToStub;
std::vector<ContainerInfo> passThroughTypes;
std::vector<KeyToCapture> keysToCapture;
std::string toString() const;
std::vector<std::string> toOptions() const;

View File

@ -170,6 +170,38 @@ std::optional<FeatureSet> processConfigFile(
}
}
}
if (toml::array* arr = (*codegen)["capture_keys"].as_array()) {
for (auto&& el : *arr) {
if (toml::table* captureKeys = el.as_table()) {
auto* type = (*captureKeys)["type"].as_string();
auto* topLevel = (*captureKeys)["top_level"].as_boolean();
if (!((type == nullptr) ^ (topLevel == nullptr))) {
LOG(ERROR) << "Config entry 'capture_keys' must specify either a "
"type or 'top_level'";
return {};
}
if (type) {
auto* members = (*captureKeys)["members"].as_array();
if (!members) {
generatorConfig.keysToCapture.push_back(
OICodeGen::Config::KeyToCapture{type->value_or(""), "*",
false});
} else {
for (auto&& member : *members) {
generatorConfig.keysToCapture.push_back(
OICodeGen::Config::KeyToCapture{
type->value_or(""), member.value_or(""), false});
}
}
} else if (topLevel) {
generatorConfig.keysToCapture.push_back(
OICodeGen::Config::KeyToCapture{std::nullopt, std::nullopt,
true});
}
}
}
}
}
FeatureSet enabledFeatures;