[EXT] Added assignment operator overload and copy constructor

This commit is contained in:
jgromes 2024-05-12 19:49:46 +01:00
parent e3f851ef6d
commit 71ccce4a3d
2 changed files with 38 additions and 0 deletions

View file

@ -14,6 +14,27 @@ ExternalRadio::ExternalRadio(RadioLibHal *hal, uint32_t pin) : PhysicalLayer(1,
this->prevFrf = 0; 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() { Module* ExternalRadio::getMod() {
return(mod); return(mod);
} }

View file

@ -30,6 +30,23 @@ class ExternalRadio: public PhysicalLayer {
*/ */
ExternalRadio(RadioLibHal *hal, uint32_t pin = RADIOLIB_NC); // cppcheck-suppress noExplicitConstructor 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. \brief Method to retrieve pointer to the underlying Module instance.
\returns Pointer to the Module instance. \returns Pointer to the Module instance.