use smart pointer to avoid memory issue
This commit is contained in:
parent
9c413c0edd
commit
a0060c8fa8
5 changed files with 21 additions and 19 deletions
|
@ -17,8 +17,8 @@ std::string GnsServer::getApiBase() const {
|
|||
return "http://" + this->host + ":" + std::to_string(this->port) + "/v2/";
|
||||
}
|
||||
|
||||
std::vector<GnsProject> GnsServer::getProjects() const {
|
||||
std::vector<GnsProject> projects;
|
||||
std::vector<std::shared_ptr<GnsProject>> GnsServer::getProjects() const {
|
||||
std::vector<std::shared_ptr<GnsProject>> projects;
|
||||
|
||||
// request the API endpoint
|
||||
cpr::Url endpoint = this->getApiBase() + "projects";
|
||||
|
@ -38,20 +38,20 @@ std::vector<GnsProject> GnsServer::getProjects() const {
|
|||
// deserialize the projects
|
||||
projects.reserve(data.size());
|
||||
for (const auto& project_data : data)
|
||||
projects.emplace_back(
|
||||
projects.emplace_back(std::make_shared<GnsProject>(
|
||||
this,
|
||||
project_data["project_id"]
|
||||
);
|
||||
));
|
||||
|
||||
return projects;
|
||||
}
|
||||
|
||||
std::vector<GnsNode> GnsServer::getNodes() const {
|
||||
std::vector<GnsNode> nodes;
|
||||
std::vector<std::shared_ptr<GnsNode>> GnsServer::getNodes() const {
|
||||
std::vector<std::shared_ptr<GnsNode>> nodes;
|
||||
|
||||
// get all the nodes from all the projects
|
||||
for (const GnsProject& project : this->getProjects()) {
|
||||
std::vector<GnsNode> project_nodes = project.getNodes();
|
||||
for (const std::shared_ptr<GnsProject>& project : this->getProjects()) {
|
||||
std::vector<std::shared_ptr<GnsNode>> project_nodes = project->getNodes();
|
||||
nodes.insert(nodes.end(), project_nodes.begin(), project_nodes.end());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue