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

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

This commit is contained in:
Carles Fernandez 2019-07-05 13:08:00 +02:00
parent 620191f818
commit 52c08e3ab4
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
2 changed files with 154 additions and 109 deletions

View File

@ -88,30 +88,61 @@ bool operator==(const Gnss_Satellite& sat1, const Gnss_Satellite& sat2)
if (sat1.get_system() == sat2.get_system())
{
if (sat1.get_PRN() == sat2.get_PRN())
{
if (sat1.get_rf_link() == sat2.get_rf_link())
{
equal = true;
}
}
}
return equal;
}
/*
Gnss_Satellite& Gnss_Satellite::operator=(const Gnss_Satellite &rhs) {
// Copy constructor
Gnss_Satellite::Gnss_Satellite(Gnss_Satellite&& other)
{
*this = std::move(other);
}
// Copy assignment operator
Gnss_Satellite& Gnss_Satellite::operator=(const Gnss_Satellite& rhs)
{
// Only do assignment if RHS is a different object from this.
if (this != &rhs) {
if (this != &rhs)
{
// Deallocate, allocate new space, copy values...
const std::string system_ = rhs.get_system();
const uint32_t PRN_ = rhs.get_PRN();
const std::string block_ = rhs.get_block();
// const int32_t rf_link_ = 0;
this->set_system(system_);
this->set_PRN(PRN_);
this->set_block(system_, PRN_);
//this.rf_link = rf_link_;
this->reset();
this->set_system(rhs.get_system());
this->set_PRN(rhs.get_PRN());
this->set_block(rhs.get_system(), rhs.get_PRN());
this->set_rf_link(rhs.get_rf_link());
}
return *this;
}*/
}
// Move constructor
Gnss_Satellite::Gnss_Satellite(const Gnss_Satellite& other)
{
*this = std::move(other);
}
// Move assignment operator
Gnss_Satellite& Gnss_Satellite::operator=(Gnss_Satellite&& other)
{
if (this != &other)
{
this->reset();
this->system = std::move(other.get_system());
this->PRN = std::move(other.get_PRN());
this->block = std::move(other.get_block());
this->rf_link = std::move(other.get_rf_link());
}
return *this;
}
void Gnss_Satellite::set_system(const std::string& system_)
@ -260,6 +291,14 @@ int32_t Gnss_Satellite::get_rf_link() const
}
void Gnss_Satellite::set_rf_link(int32_t rf_link_)
{
// Set satellite's rf link. Identifies the GLONASS Frequency Channel
rf_link = rf_link_;
return;
}
uint32_t Gnss_Satellite::get_PRN() const
{
// Get satellite's PRN
@ -625,7 +664,7 @@ std::string Gnss_Satellite::what_block(const std::string& system_, uint32_t PRN_
if (system_ == "Beidou")
{
// Check https://en.wikipedia.org/wiki/List_of_BeiDou_satellites
switch ( PRN_ )
switch (PRN_)
{
case 1:
block_ = std::string("Compass-G1"); //!<GEO 140.0°E; launched 2010/01/16

View File

@ -61,7 +61,12 @@ public:
friend bool operator==(const Gnss_Satellite& /*sat1*/, const Gnss_Satellite& /*sat2*/); //!< operator== for comparison
friend std::ostream& operator<<(std::ostream& /*out*/, const Gnss_Satellite& /*sat*/); //!< operator<< for pretty printing
//Gnss_Satellite& operator=(const Gnss_Satellite &);
Gnss_Satellite(Gnss_Satellite&& other); //!< Copy constructor
Gnss_Satellite& operator=(const Gnss_Satellite&); //!< Copy assignment operator
Gnss_Satellite(const Gnss_Satellite& other); //!< Move constructor
Gnss_Satellite& operator=(Gnss_Satellite&& other); //!< Move assignment operator
private:
uint32_t PRN;
std::string system;
@ -73,5 +78,6 @@ private:
void set_block(const std::string& system_, uint32_t PRN_);
std::set<std::string> system_set; // = {"GPS", "GLONASS", "SBAS", "Galileo", "Compass"};
void reset();
void set_rf_link(int32_t rf_link_);
};
#endif