Skip to content

Commit 9055c58

Browse files
committed
OIUtils: Parse "capture_keys" section from configs
1 parent 1f66ef0 commit 9055c58

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

oi/OICodeGen.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,20 @@ class OICodeGen {
5959
Config(Config&& other) = delete;
6060
Config& operator=(Config&& other) = delete;
6161

62+
struct KeyToCapture {
63+
std::optional<std::string> type;
64+
std::optional<std::string> member;
65+
bool topLevel = false;
66+
};
67+
6268
bool useDataSegment;
6369
FeatureSet features;
6470
std::set<std::filesystem::path> containerConfigPaths;
6571
std::set<std::string> defaultHeaders;
6672
std::set<std::string> defaultNamespaces;
6773
std::vector<std::pair<std::string, std::string>> membersToStub;
6874
std::vector<ContainerInfo> passThroughTypes;
75+
std::vector<KeyToCapture> keysToCapture;
6976

7077
std::string toString() const;
7178
std::vector<std::string> toOptions() const;

oi/OIUtils.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,38 @@ std::optional<FeatureSet> processConfigFile(
170170
}
171171
}
172172
}
173+
if (toml::array* arr = (*codegen)["capture_keys"].as_array()) {
174+
for (auto&& el : *arr) {
175+
if (toml::table* captureKeys = el.as_table()) {
176+
auto* type = (*captureKeys)["type"].as_string();
177+
auto* topLevel = (*captureKeys)["top_level"].as_boolean();
178+
if (!((type == nullptr) ^ (topLevel == nullptr))) {
179+
LOG(ERROR) << "Config entry 'capture_keys' must specify either a "
180+
"type or 'top_level'";
181+
return {};
182+
}
183+
184+
if (type) {
185+
auto* members = (*captureKeys)["members"].as_array();
186+
if (!members) {
187+
generatorConfig.keysToCapture.push_back(
188+
OICodeGen::Config::KeyToCapture{type->value_or(""), "*",
189+
false});
190+
} else {
191+
for (auto&& member : *members) {
192+
generatorConfig.keysToCapture.push_back(
193+
OICodeGen::Config::KeyToCapture{
194+
type->value_or(""), member.value_or(""), false});
195+
}
196+
}
197+
} else if (topLevel) {
198+
generatorConfig.keysToCapture.push_back(
199+
OICodeGen::Config::KeyToCapture{std::nullopt, std::nullopt,
200+
true});
201+
}
202+
}
203+
}
204+
}
173205
}
174206

175207
FeatureSet enabledFeatures;

0 commit comments

Comments
 (0)