use smart pointer when creating an object with an instance of the creator
This commit is contained in:
parent
a0060c8fa8
commit
8fb1a08ce5
6 changed files with 12 additions and 10 deletions
|
@ -9,7 +9,7 @@
|
|||
namespace gns {
|
||||
|
||||
|
||||
GnsNode::GnsNode(const GnsProject *project, const std::string& uuid, const std::vector<GnsPort>& ports) {
|
||||
GnsNode::GnsNode(const std::shared_ptr<const GnsProject>& project, const std::string& uuid, const std::vector<GnsPort>& ports) {
|
||||
this->project = project;
|
||||
this->uuid = uuid;
|
||||
this->ports = ports;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "GnsPort.hpp"
|
||||
|
||||
#include <string>
|
||||
|
@ -18,7 +20,7 @@ class GnsProject;
|
|||
*/
|
||||
class GnsNode {
|
||||
public:
|
||||
GnsNode(const GnsProject* project, const std::string& uuid, const std::vector<GnsPort>& ports);
|
||||
GnsNode(const std::shared_ptr<const GnsProject>& project, const std::string& uuid, const std::vector<GnsPort>& ports);
|
||||
|
||||
/**
|
||||
* Get the base URL for the node API
|
||||
|
@ -44,7 +46,7 @@ public:
|
|||
void start() const;
|
||||
|
||||
private:
|
||||
const GnsProject* project;
|
||||
std::shared_ptr<const GnsProject> project;
|
||||
std::string uuid;
|
||||
std::vector<GnsPort> ports;
|
||||
};
|
||||
|
|
|
@ -10,7 +10,7 @@ using json = nlohmann::json;
|
|||
namespace gns {
|
||||
|
||||
|
||||
GnsProject::GnsProject(const GnsServer* server, const std::string& uuid) {
|
||||
GnsProject::GnsProject(const std::shared_ptr<const GnsServer>& server, const std::string& uuid) {
|
||||
this->server = server;
|
||||
this->uuid = uuid;
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ std::vector<std::shared_ptr<GnsNode>> GnsProject::getNodes() const {
|
|||
|
||||
// save the node
|
||||
nodes.emplace_back(std::make_shared<GnsNode>(
|
||||
this,
|
||||
shared_from_this(),
|
||||
node_data["node_id"],
|
||||
ports
|
||||
));
|
||||
|
|
|
@ -15,9 +15,9 @@ class GnsServer;
|
|||
/**
|
||||
* Represent a GNS3 project.
|
||||
*/
|
||||
class GnsProject {
|
||||
class GnsProject : public std::enable_shared_from_this<GnsProject> {
|
||||
public:
|
||||
GnsProject(const GnsServer* server, const std::string& uuid);
|
||||
GnsProject(const std::shared_ptr<const GnsServer>& server, const std::string& uuid);
|
||||
|
||||
/**
|
||||
* Get the base prefix for an API request
|
||||
|
@ -38,7 +38,7 @@ public:
|
|||
[[nodiscard]] std::vector<std::shared_ptr<GnsNode>> getNodes() const;
|
||||
|
||||
private:
|
||||
const GnsServer* server;
|
||||
std::shared_ptr<const GnsServer> server;
|
||||
std::string uuid;
|
||||
};
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ std::vector<std::shared_ptr<GnsProject>> GnsServer::getProjects() const {
|
|||
projects.reserve(data.size());
|
||||
for (const auto& project_data : data)
|
||||
projects.emplace_back(std::make_shared<GnsProject>(
|
||||
this,
|
||||
shared_from_this(),
|
||||
project_data["project_id"]
|
||||
));
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace gns {
|
|||
* Represent a GNS3 server
|
||||
* Wrapper around the GNS3 API (https://gns3-server.readthedocs.io/en/latest/endpoints.html)
|
||||
*/
|
||||
class GnsServer {
|
||||
class GnsServer : public std::enable_shared_from_this<GnsServer> {
|
||||
public:
|
||||
GnsServer(const std::string& host, std::uint16_t port);
|
||||
|
||||
|
|
Loading…
Reference in a new issue