[EXT] Added assignment operator overload and copy constructor

pull/1095/head
jgromes 2024-05-12 19:49:46 +01:00
rodzic e3f851ef6d
commit 71ccce4a3d
2 zmienionych plików z 38 dodań i 0 usunięć

Wyświetl plik

@ -14,6 +14,27 @@ ExternalRadio::ExternalRadio(RadioLibHal *hal, uint32_t pin) : PhysicalLayer(1,
this->prevFrf = 0;
}
ExternalRadio::ExternalRadio(const ExternalRadio& ext) : PhysicalLayer(1, 0) {
this->prevFrf = ext.prevFrf;
if(ext.mod) {
this->mod = new Module(ext.mod->hal, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, ext.mod->getGpio());
}
}
ExternalRadio& ExternalRadio::operator=(const ExternalRadio& ext) {
this->prevFrf = ext.prevFrf;
if(ext.mod) {
this->mod = new Module(ext.mod->hal, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, ext.mod->getGpio());
}
return(*this);
}
ExternalRadio::~ExternalRadio() {
if(this->mod) {
delete this->mod;
}
}
Module* ExternalRadio::getMod() {
return(mod);
}

Wyświetl plik

@ -30,6 +30,23 @@ class ExternalRadio: public PhysicalLayer {
*/
ExternalRadio(RadioLibHal *hal, uint32_t pin = RADIOLIB_NC); // cppcheck-suppress noExplicitConstructor
/*!
\brief Copy constructor.
\param ext ExternalRadio instance to copy.
*/
ExternalRadio(const ExternalRadio& ext);
/*!
\brief Overload for assignment operator.
\param ext rvalue ExternalRadio.
*/
ExternalRadio& operator=(const ExternalRadio& ext);
/*!
\brief Default destructor.
*/
~ExternalRadio();
/*!
\brief Method to retrieve pointer to the underlying Module instance.
\returns Pointer to the Module instance.