diff --git a/oi/OICodeGen.h b/oi/OICodeGen.h index 534f2e4..aab069f 100644 --- a/oi/OICodeGen.h +++ b/oi/OICodeGen.h @@ -59,6 +59,12 @@ class OICodeGen { Config(Config&& other) = delete; Config& operator=(Config&& other) = delete; + struct KeyToCapture { + std::optional type; + std::optional member; + bool topLevel = false; + }; + bool useDataSegment; FeatureSet features; std::set containerConfigPaths; @@ -66,6 +72,7 @@ class OICodeGen { std::set defaultNamespaces; std::vector> membersToStub; std::vector passThroughTypes; + std::vector keysToCapture; std::string toString() const; std::vector toOptions() const; diff --git a/oi/OIUtils.cpp b/oi/OIUtils.cpp index b4e5f4c..7b99db5 100644 --- a/oi/OIUtils.cpp +++ b/oi/OIUtils.cpp @@ -170,6 +170,38 @@ std::optional 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;