1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-06-24 05:53:16 +00:00

Try to avoid non-default move & copy constructors

This commit is contained in:
Carles Fernandez 2019-07-07 18:41:50 +02:00
parent 5f1779c15b
commit cf8f4af527
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
4 changed files with 20 additions and 34 deletions

View File

@ -47,17 +47,8 @@ Gnss_Satellite::Gnss_Satellite(const std::string& system_, uint32_t PRN_)
}
Gnss_Satellite::~Gnss_Satellite() = default;
void Gnss_Satellite::reset()
{
system_set = {"GPS", "Glonass", "SBAS", "Galileo", "Beidou"};
satelliteSystem["GPS"] = "G";
satelliteSystem["Glonass"] = "R";
satelliteSystem["SBAS"] = "S";
satelliteSystem["Galileo"] = "E";
satelliteSystem["Beidou"] = "C";
PRN = 0;
system = std::string("");
block = std::string("");
@ -102,7 +93,7 @@ bool operator==(const Gnss_Satellite& sat1, const Gnss_Satellite& sat2)
// Copy constructor
Gnss_Satellite::Gnss_Satellite(Gnss_Satellite&& other)
{
*this = std::move(other);
*this = other;
}
@ -112,12 +103,10 @@ Gnss_Satellite& Gnss_Satellite::operator=(const Gnss_Satellite& rhs)
// Only do assignment if RHS is a different object from this.
if (this != &rhs)
{
// Deallocate, allocate new space, copy values...
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());
this->system = rhs.system;
this->PRN = rhs.PRN;
this->block = rhs.block;
this->rf_link = rhs.rf_link;
}
return *this;
}
@ -126,7 +115,7 @@ Gnss_Satellite& Gnss_Satellite::operator=(const Gnss_Satellite& rhs)
// Move constructor
Gnss_Satellite::Gnss_Satellite(const Gnss_Satellite& other)
{
*this = other;
*this = std::move(other);
}
@ -135,7 +124,6 @@ Gnss_Satellite& Gnss_Satellite::operator=(Gnss_Satellite&& other)
{
if (this != &other)
{
this->reset();
this->system = std::move(other.get_system());
this->PRN = other.get_PRN();
this->block = std::move(other.get_block());

View File

@ -50,7 +50,7 @@ class Gnss_Satellite
public:
Gnss_Satellite(); //!< Default Constructor.
Gnss_Satellite(const std::string& system_, uint32_t PRN_); //!< Concrete GNSS satellite Constructor.
~Gnss_Satellite(); //!< Default Destructor.
~Gnss_Satellite() = default; //!< Default Destructor.
void update_PRN(uint32_t PRN); //!< Updates the PRN Number when information is decoded, only applies to GLONASS GNAV messages
uint32_t get_PRN() const; //!< Gets satellite's PRN
int32_t get_rf_link() const; //!< Gets the satellite's rf link
@ -68,15 +68,15 @@ public:
Gnss_Satellite& operator=(Gnss_Satellite&& other); //!< Move assignment operator
private:
uint32_t PRN;
std::string system;
std::map<std::string, std::string> satelliteSystem;
std::string block;
int32_t rf_link;
uint32_t PRN{};
int32_t rf_link{};
std::string system{};
std::string block{};
const std::set<std::string> system_set = {"GPS", "Glonass", "SBAS", "Galileo", "Beidou"};
const std::map<std::string, std::string> satelliteSystem = {{"GPS", "G"}, {"Glonass", "R"}, {"SBAS", "S"}, {"Galileo", "E"}, {"Beidou", "C"}};
void set_system(const std::string& system); // Sets the satellite system {"GPS", "GLONASS", "SBAS", "Galileo", "Beidou"}.
void set_PRN(uint32_t PRN); // Sets satellite's PRN
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_);
};

View File

@ -50,9 +50,7 @@ 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)
{
@ -91,7 +89,7 @@ Gnss_Signal& Gnss_Signal::operator=(Gnss_Signal&& other)
}
return *this;
}
*/
std::string Gnss_Signal::get_signal_str() const
{

View File

@ -47,20 +47,20 @@ public:
Gnss_Signal();
Gnss_Signal(const std::string& signal_);
Gnss_Signal(const Gnss_Satellite& satellite_, const std::string& signal_);
~Gnss_Signal();
~Gnss_Signal() = default;
std::string get_signal_str() const; //!< Get the satellite signal {"1C" for GPS L1 C/A, "2S" for GPS L2C (M), "L5" for GPS L5, "1G" for GLONASS L1 C/A, "1B" for Galileo E1B, "5X" for Galileo E5a.
Gnss_Satellite get_satellite() const; //!< Get the Gnss_Satellite associated to the signal
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(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
Gnss_Signal& operator=(Gnss_Signal&& other); //!< Move assignment operator */
private:
Gnss_Satellite satellite;
std::string signal;
Gnss_Satellite satellite{};
std::string signal{};
};
#endif