1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-14 20:20:35 +00:00

Add copy constructor, copy assignment operator, move constructor and move assignment operator

This commit is contained in:
Carles Fernandez 2019-07-05 14:42:48 +02:00
parent 52c08e3ab4
commit 1237a29fc9
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
2 changed files with 44 additions and 0 deletions

View File

@ -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;

View File

@ -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;