For source_package_publishing_history::getBuilds(), use an std::generator instead of an std::vector

main
Simon Quigley 7 days ago
parent ea548faaf5
commit 6bcc090407

@ -51,13 +51,12 @@ void source_package_publishing_history::parse_json(const std::string& json_data)
} }
} }
std::vector<build> source_package_publishing_history::getBuilds() const { std::generator<build> source_package_publishing_history::getBuilds() const {
std::vector<build> builds; if (self_link.empty()) { co_return; }
if (self_link.empty()) { return builds; }
std::map<std::string, std::string> params = {{"ws.op", "getBuilds"}}; std::map<std::string, std::string> params = {{"ws.op", "getBuilds"}};
auto response = lp->api_get(self_link, params); auto response = lp->api_get(self_link, params);
if (!response.has_value()) { return builds; } if (!response.has_value()) { co_return; }
try { try {
auto data = nlohmann::json::parse(response.value()); auto data = nlohmann::json::parse(response.value());
@ -66,14 +65,12 @@ std::vector<build> source_package_publishing_history::getBuilds() const {
auto b_opt = build::parse(entry.dump()); auto b_opt = build::parse(entry.dump());
if(!b_opt.has_value()) continue; if(!b_opt.has_value()) continue;
b_opt->set_lp(lp); b_opt->set_lp(lp);
builds.push_back(b_opt.value()); co_yield b_opt.value();
} }
} }
} catch (const std::exception& e) { } catch (const std::exception& e) {
std::cerr << "Error parsing builds: " << e.what() << std::endl; std::cerr << "Error parsing builds: " << e.what() << std::endl;
} }
return builds;
} }
void source_package_publishing_history::set_lp(launchpad* lp_ptr) { void source_package_publishing_history::set_lp(launchpad* lp_ptr) {

@ -18,7 +18,7 @@
#include <string> #include <string>
#include <optional> #include <optional>
#include <vector> #include <generator>
#include "build.h" #include "build.h"
class launchpad; class launchpad;
@ -40,7 +40,7 @@ public:
static std::optional<source_package_publishing_history> parse(const std::string& json_data); static std::optional<source_package_publishing_history> parse(const std::string& json_data);
void parse_json(const std::string& json_data); void parse_json(const std::string& json_data);
std::vector<build> getBuilds() const; std::generator<build> getBuilds() const;
std::string self_link; std::string self_link;
std::string source_package_name; std::string source_package_name;

Loading…
Cancel
Save