From 090017dfaa583da234487c941007d0f9c299a3fa Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sat, 25 Mar 2023 18:11:29 +0100 Subject: [PATCH] Improve copy and move constructors --- src/core/system_parameters/gnss_satellite.cc | 18 +++---- src/core/system_parameters/gnss_satellite.h | 2 +- .../libs/acquisition_dump_reader.cc | 52 +++++-------------- .../libs/acquisition_dump_reader.h | 2 +- 4 files changed, 25 insertions(+), 49 deletions(-) diff --git a/src/core/system_parameters/gnss_satellite.cc b/src/core/system_parameters/gnss_satellite.cc index 9c386fb9b..7f1b1030c 100644 --- a/src/core/system_parameters/gnss_satellite.cc +++ b/src/core/system_parameters/gnss_satellite.cc @@ -73,16 +73,16 @@ bool operator==(const Gnss_Satellite& sat1, const Gnss_Satellite& sat2) // Copy constructor Gnss_Satellite::Gnss_Satellite(const Gnss_Satellite& other) noexcept + : system(other.system), + block(other.block), + PRN(other.PRN), + rf_link(other.rf_link) { - system = other.system; - block = other.block; - PRN = other.PRN; - rf_link = other.rf_link; } // Copy assignment operator -Gnss_Satellite& Gnss_Satellite::operator=(const Gnss_Satellite& rhs) +Gnss_Satellite& Gnss_Satellite::operator=(const Gnss_Satellite& rhs) noexcept { // Only do assignment if RHS is a different object from this. if (this != &rhs) @@ -98,11 +98,11 @@ Gnss_Satellite& Gnss_Satellite::operator=(const Gnss_Satellite& rhs) // Move constructor Gnss_Satellite::Gnss_Satellite(Gnss_Satellite&& other) noexcept + : system(std::move(other.system)), + block(std::move(other.block)), + PRN(other.PRN), + rf_link(other.rf_link) { - system = std::move(other.system); - block = std::move(other.block); - PRN = other.PRN; - rf_link = other.rf_link; other.reset(); } diff --git a/src/core/system_parameters/gnss_satellite.h b/src/core/system_parameters/gnss_satellite.h index 9830e2a0b..e7a2759f8 100644 --- a/src/core/system_parameters/gnss_satellite.h +++ b/src/core/system_parameters/gnss_satellite.h @@ -44,7 +44,7 @@ public: ~Gnss_Satellite() = default; //!< Default Destructor. Gnss_Satellite(const Gnss_Satellite& other) noexcept; //!< Copy constructor - Gnss_Satellite& operator=(const Gnss_Satellite&); //!< Copy assignment operator + Gnss_Satellite& operator=(const Gnss_Satellite&) noexcept; //!< Copy assignment operator Gnss_Satellite(Gnss_Satellite&& other) noexcept; //!< Move constructor Gnss_Satellite& operator=(Gnss_Satellite&& other) noexcept; //!< Move assignment operator diff --git a/src/tests/unit-tests/signal-processing-blocks/libs/acquisition_dump_reader.cc b/src/tests/unit-tests/signal-processing-blocks/libs/acquisition_dump_reader.cc index da08e0367..fb87911d6 100644 --- a/src/tests/unit-tests/signal-processing-blocks/libs/acquisition_dump_reader.cc +++ b/src/tests/unit-tests/signal-processing-blocks/libs/acquisition_dump_reader.cc @@ -221,30 +221,6 @@ Acquisition_Dump_Reader::Acquisition_Dump_Reader(const std::string& basename, } } -// Copy constructor -Acquisition_Dump_Reader::Acquisition_Dump_Reader(const Acquisition_Dump_Reader& other) noexcept - : doppler(other.doppler), - samples(other.samples), - mag(other.mag), - acq_doppler_hz(other.acq_doppler_hz), - acq_delay_samples(other.acq_delay_samples), - test_statistic(other.test_statistic), - input_power(other.input_power), - threshold(other.threshold), - positive_acq(other.positive_acq), - PRN(other.PRN), - num_dwells(other.num_dwells), - sample_counter(other.sample_counter), - d_basename(other.d_basename), - d_dump_filename(other.d_dump_filename), - d_sat(other.d_sat), - d_doppler_max(other.d_doppler_max), - d_doppler_step(other.d_doppler_step), - d_samples_per_code(other.d_samples_per_code), - d_num_doppler_bins(other.d_num_doppler_bins) -{ -} - // Copy assignment operator Acquisition_Dump_Reader& Acquisition_Dump_Reader::operator=(const Acquisition_Dump_Reader& other) noexcept @@ -308,23 +284,23 @@ Acquisition_Dump_Reader& Acquisition_Dump_Reader::operator=(Acquisition_Dump_Rea // Move member variables from the other object to this object d_basename = std::move(other.d_basename); d_dump_filename = std::move(other.d_dump_filename); - d_sat = std::move(other.d_sat); - d_doppler_max = std::move(other.d_doppler_max); - d_doppler_step = std::move(other.d_doppler_step); - d_samples_per_code = std::move(other.d_samples_per_code); - d_num_doppler_bins = std::move(other.d_num_doppler_bins); + d_sat = other.d_sat; + d_doppler_max = other.d_doppler_max; + d_doppler_step = other.d_doppler_step; + d_samples_per_code = other.d_samples_per_code; + d_num_doppler_bins = other.d_num_doppler_bins; doppler = std::move(other.doppler); samples = std::move(other.samples); mag = std::move(other.mag); - acq_doppler_hz = std::move(other.acq_doppler_hz); - acq_delay_samples = std::move(other.acq_delay_samples); - test_statistic = std::move(other.test_statistic); - input_power = std::move(other.input_power); - threshold = std::move(other.threshold); - positive_acq = std::move(other.positive_acq); - PRN = std::move(other.PRN); - num_dwells = std::move(other.num_dwells); - sample_counter = std::move(other.sample_counter); + acq_doppler_hz = other.acq_doppler_hz; + acq_delay_samples = other.acq_delay_samples; + test_statistic = other.test_statistic; + input_power = other.input_power; + threshold = other.threshold; + positive_acq = other.positive_acq; + PRN = other.PRN; + num_dwells = other.num_dwells; + sample_counter = other.sample_counter; } return *this; } \ No newline at end of file diff --git a/src/tests/unit-tests/signal-processing-blocks/libs/acquisition_dump_reader.h b/src/tests/unit-tests/signal-processing-blocks/libs/acquisition_dump_reader.h index b28e42742..8c38b30fe 100644 --- a/src/tests/unit-tests/signal-processing-blocks/libs/acquisition_dump_reader.h +++ b/src/tests/unit-tests/signal-processing-blocks/libs/acquisition_dump_reader.h @@ -37,7 +37,7 @@ public: int channel = 0, int execution = 1); - Acquisition_Dump_Reader(const Acquisition_Dump_Reader& other) noexcept; //!< Copy constructor + Acquisition_Dump_Reader(const Acquisition_Dump_Reader& other) noexcept = default; //!< Copy constructor Acquisition_Dump_Reader& operator=(const Acquisition_Dump_Reader& other) noexcept; //!< Copy assignment operator Acquisition_Dump_Reader(Acquisition_Dump_Reader&& other) noexcept; //!< Move constructor Acquisition_Dump_Reader& operator=(Acquisition_Dump_Reader&& other) noexcept; //!< Move assignment operator