From 71ccce4a3d5e780980d669f506220108835c1da4 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 12 May 2024 19:49:46 +0100 Subject: [PATCH] [EXT] Added assignment operator overload and copy constructor --- src/protocols/ExternalRadio/ExternalRadio.cpp | 21 +++++++++++++++++++ src/protocols/ExternalRadio/ExternalRadio.h | 17 +++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/protocols/ExternalRadio/ExternalRadio.cpp b/src/protocols/ExternalRadio/ExternalRadio.cpp index 0748b495..d8c3a5fa 100644 --- a/src/protocols/ExternalRadio/ExternalRadio.cpp +++ b/src/protocols/ExternalRadio/ExternalRadio.cpp @@ -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); } diff --git a/src/protocols/ExternalRadio/ExternalRadio.h b/src/protocols/ExternalRadio/ExternalRadio.h index 8c551726..823674bc 100644 --- a/src/protocols/ExternalRadio/ExternalRadio.h +++ b/src/protocols/ExternalRadio/ExternalRadio.h @@ -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.