From 1237a29fc90f2e819ca1bddd4f663d83f4f8c25b Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Fri, 5 Jul 2019 14:42:48 +0200 Subject: [PATCH] Add copy constructor, copy assignment operator, move constructor and move assignment operator --- src/core/system_parameters/gnss_signal.cc | 40 +++++++++++++++++++++++ src/core/system_parameters/gnss_signal.h | 4 +++ 2 files changed, 44 insertions(+) diff --git a/src/core/system_parameters/gnss_signal.cc b/src/core/system_parameters/gnss_signal.cc index 0c25a7841..520d7242a 100644 --- a/src/core/system_parameters/gnss_signal.cc +++ b/src/core/system_parameters/gnss_signal.cc @@ -53,6 +53,46 @@ Gnss_Signal::Gnss_Signal(const Gnss_Satellite& satellite_, const std::string& si Gnss_Signal::~Gnss_Signal() = default; +// Copy constructor +Gnss_Signal::Gnss_Signal(Gnss_Signal&& other) +{ + *this = std::move(other); +} + + +// Copy assignment operator +Gnss_Signal& Gnss_Signal::operator=(const Gnss_Signal& rhs) +{ + // Only do assignment if RHS is a different object from this. + if (this != &rhs) + { + // Deallocate, allocate new space, copy values... + this->satellite = rhs.get_satellite(); + this->signal = rhs.get_signal_str(); + } + return *this; +} + + +// Move constructor +Gnss_Signal::Gnss_Signal(const Gnss_Signal& other) +{ + *this = std::move(other); +} + + +// Move assignment operator +Gnss_Signal& Gnss_Signal::operator=(Gnss_Signal&& other) +{ + if (this != &other) + { + this->satellite = std::move(other.get_satellite()); + this->signal = std::move(other.get_signal_str()); + } + return *this; +} + + std::string Gnss_Signal::get_signal_str() const { return this->signal; diff --git a/src/core/system_parameters/gnss_signal.h b/src/core/system_parameters/gnss_signal.h index c2f6e37c4..92051444a 100644 --- a/src/core/system_parameters/gnss_signal.h +++ b/src/core/system_parameters/gnss_signal.h @@ -54,6 +54,10 @@ public: friend bool operator==(const Gnss_Signal& /*sig1*/, const Gnss_Signal& /*sig2*/); //!< operator== for comparison friend std::ostream& operator<<(std::ostream& /*out*/, const Gnss_Signal& /*sig*/); //!< operator<< for pretty printing + Gnss_Signal(Gnss_Signal&& other); //!< Copy constructor + Gnss_Signal& operator=(const Gnss_Signal&); //!< Copy assignment operator + Gnss_Signal(const Gnss_Signal& other); //!< Move constructor + Gnss_Signal& operator=(Gnss_Signal&& other); //!< Move assignment operator private: Gnss_Satellite satellite; std::string signal;