Skip to content

Instantly share code, notes, and snippets.

@atsushieno
Last active October 8, 2024 17:24
Show Gist options
  • Save atsushieno/ac65ebfed6cf7ac66ac8273bb1e81eb5 to your computer and use it in GitHub Desktop.
Save atsushieno/ac65ebfed6cf7ac66ac8273bb1e81eb5 to your computer and use it in GitHub Desktop.
// works
auto pluginEntriesToJson(std::vector<remidy::PluginCatalogEntry*> list) {
std::vector<nlohmann::ordered_json> ret{};
for (auto e : list)
ret.emplace_back(nlohmann::ordered_json {
{"format", e->format()},
{"id", e->pluginId()},
{"bundle", e->bundlePath()},
{"name", e->getMetadataProperty(remidy::PluginCatalogEntry::DisplayName)},
{"vendor", e->getMetadataProperty(remidy::PluginCatalogEntry::VendorName)},
{"url", e->getMetadataProperty(remidy::PluginCatalogEntry::ProductUrl)},
});
return ret;
}
// does not
auto pluginEntriesToJson(std::vector<remidy::PluginCatalogEntry*> list) {
return list | std::views::transform([](remidy::PluginCatalogEntry* e) {
return nlohmann::ordered_json {
{"format", e->format()},
{"id", e->pluginId()},
{"bundle", e->bundlePath()},
{"name", e->getMetadataProperty(remidy::PluginCatalogEntry::DisplayName)},
{"vendor", e->getMetadataProperty(remidy::PluginCatalogEntry::VendorName)},
{"url", e->getMetadataProperty(remidy::PluginCatalogEntry::ProductUrl)},
};
});
}
nlohmann::json toJson(remidy::PluginCatalog* catalog) {
auto plugins = pluginEntriesToJson(catalog->getPlugins());
auto denyList = pluginEntriesToJson(catalog->getDenyList());
nlohmann::json j = {
{"plugins", std::vector(plugins.begin(), plugins.end()) },
{"denyList", std::vector(denyList.begin(), denyList.end()) }
};
return j;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment