Commit 8a500e4e authored by Ian McInerney's avatar Ian McInerney

Added copy and assigment constructor

parent 2bd3ecb0
......@@ -89,6 +89,10 @@ class CCRTPPacket {
designated for. */
CCRTPPacket(char *cData, int nDataLength, int nChannel);
CCRTPPacket(char cData, int nPort);
CCRTPPacket( const CCRTPPacket& obj );
CCRTPPacket& operator = (const CCRTPPacket& obj);
/*! \brief Destructor for the packet class
De-initializes the packet and deletes all available payload data
......
......@@ -48,6 +48,32 @@ CCRTPPacket::CCRTPPacket(char cData, int nPort) {
this->setData(&cData, 1);
}
CCRTPPacket& CCRTPPacket::operator = (const CCRTPPacket& obj) {
// Copy all fields properly to the new object (obj)
m_nPort = obj.m_nPort;
m_nChannel = obj.m_nChannel;
m_bIsPingPacket = obj.m_bIsPingPacket;
m_nDataLength = obj.m_nDataLength;
m_cData = new char[m_nDataLength]();
std::memcpy(m_cData, obj.m_cData, m_nDataLength);
return *this;
}
CCRTPPacket::CCRTPPacket( const CCRTPPacket& obj ) {
// Copy all fields properly to the new object (obj)
m_nPort = obj.m_nPort;
m_nChannel = obj.m_nChannel;
m_bIsPingPacket = obj.m_bIsPingPacket;
m_nDataLength = obj.m_nDataLength;
m_cData = new char[m_nDataLength]();
std::memcpy(m_cData, obj.m_cData, m_nDataLength);
}
CCRTPPacket::~CCRTPPacket() {
this->clearData();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment