mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
OIUtils: Parse "capture_keys" section from configs
This commit is contained in:
parent
1f66ef064a
commit
9055c5841d
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user