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

Add copy constructor, move constructor and move assignment operator. Fix memory leak

This commit is contained in:
Carles Fernandez 2019-07-05 16:13:35 +02:00
parent 5d679a3eef
commit 755dd7901f
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
2 changed files with 64 additions and 2 deletions

View File

@ -48,7 +48,6 @@ public:
// Verify that the version of the library that we linked against is
// compatible with the version of the headers we compiled against.
GOOGLE_PROTOBUF_VERIFY_VERSION;
monitor_.New();
}
~Serdes_Monitor_Pvt()
@ -56,6 +55,36 @@ public:
// google::protobuf::ShutdownProtobufLibrary();
}
inline Serdes_Monitor_Pvt(Serdes_Monitor_Pvt&& other) //!< Copy constructor
{
this->monitor_ = other.monitor_;
}
inline Serdes_Monitor_Pvt& operator=(const Serdes_Monitor_Pvt& rhs) //!< Copy assignment operator
{
// Only do assignment if RHS is a different object from this.
if (this != &rhs)
{
// Deallocate, allocate new space, copy values...
this->monitor_ = rhs.monitor_;
}
return *this;
}
inline Serdes_Monitor_Pvt(const Serdes_Monitor_Pvt& other) //!< Move constructor
{
this->monitor_ = std::move(other.monitor_);
}
inline Serdes_Monitor_Pvt& operator=(Serdes_Monitor_Pvt&& other) //!< Move assignment operator
{
if (this != &other)
{
this->monitor_ = std::move(other.monitor_);
}
return *this;
}
inline std::string createProtobuffer(const Monitor_Pvt& monitor) //!< Serialization into a string
{
monitor_.Clear();
@ -91,6 +120,8 @@ public:
monitor_.set_hdop(monitor.hdop);
monitor_.set_vdop(monitor.vdop);
monitor_.CheckInitialized();
monitor_.SerializeToString(&data);
return data;
}

View File

@ -50,7 +50,6 @@ public:
// Verify that the version of the library that we linked against is
// compatible with the version of the headers we compiled against.
GOOGLE_PROTOBUF_VERIFY_VERSION;
observables.New();
}
~Serdes_Gnss_Synchro()
@ -58,6 +57,36 @@ public:
google::protobuf::ShutdownProtobufLibrary();
}
inline Serdes_Gnss_Synchro(Serdes_Gnss_Synchro&& other) //!< Copy constructor
{
this->observables = other.observables;
}
inline Serdes_Gnss_Synchro& operator=(const Serdes_Gnss_Synchro& rhs) //!< Copy assignment operator
{
// Only do assignment if RHS is a different object from this.
if (this != &rhs)
{
// Deallocate, allocate new space, copy values...
this->observables = rhs.observables;
}
return *this;
}
inline Serdes_Gnss_Synchro(const Serdes_Gnss_Synchro& other) //!< Move constructor
{
this->observables = std::move(other.observables);
}
inline Serdes_Gnss_Synchro& operator=(Serdes_Gnss_Synchro&& other) //!< Move assignment operator
{
if (this != &other)
{
this->observables = std::move(other.observables);
}
return *this;
}
inline std::string createProtobuffer(const std::vector<Gnss_Synchro>& vgs) //!< Serialization into a string
{
observables.Clear();
@ -101,6 +130,8 @@ public:
obs->set_rx_time(gs.RX_time);
obs->set_flag_valid_pseudorange(gs.Flag_valid_pseudorange);
obs->set_interp_tow_ms(gs.interp_TOW_ms);
obs->CheckInitialized();
}
observables.SerializeToString(&data);
return data;