Skip to content

Commit

Permalink
feat: Added move constructor and operator to connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Samega7Cattac committed Jan 11, 2024
1 parent 29daeda commit fc65f01
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
// File const values
static const char CLASS_NAME[] = "Connection";

OZMQPP::Connection::Connection(Connection&& other) :
m_connection_unique_id(other.m_connection_unique_id),
m_zmq_connection(other.m_zmq_connection)
{
other.m_zmq_connection = nullptr;
}

OZMQPP::Connection::~Connection()
{
if (m_zmq_connection != nullptr)
Expand Down Expand Up @@ -173,6 +180,15 @@ OZMQPP::Connection::ContextCloseCall()

}

OZMQPP::Connection&
OZMQPP::Connection::operator=(Connection&& other)
{
m_connection_unique_id = other.m_connection_unique_id;
m_zmq_connection = other.m_zmq_connection;
other.m_zmq_connection = nullptr;
return *this;
}

OZMQPP::Connection::Connection(uint connection_unique_id, void* raw_zmq_connection) :
m_connection_unique_id (connection_unique_id),
m_zmq_connection(raw_zmq_connection)
Expand Down
8 changes: 8 additions & 0 deletions src/Connection.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public:
//!
Connection(const Connection& other) = delete;

//! @brief Move constructor.
//!
Connection(Connection&& other);

//! @brief Class destructor.
//!
//! Check if contains valid raw zeromq resources to de-allocate.
Expand Down Expand Up @@ -101,6 +105,10 @@ public:
//!
Connection& operator=(const Connection& other) = delete;

//! @brief Move operator overload.
//!
Connection& operator=(Connection&& other);

protected:

//! @brief Friend class used to create default connection objects.
Expand Down

0 comments on commit fc65f01

Please sign in to comment.