diff options
author | Thomas Habets <thomas@habets.se> | 2020-08-12 12:18:41 +0100 |
---|---|---|
committer | Martin Braun <martin@gnuradio.org> | 2020-08-14 04:08:48 -0700 |
commit | 0da8b71970f919dfc8a51a4c5098d56c6406dcdb (patch) | |
tree | 0b54efa0940c3e21cf8c7c1a39b8a8166368c8ae /gr-digital/lib | |
parent | 8031767b8ad89804a8696ab152d30d9f15110301 (diff) |
digital/probe_mpsk_snr_est: Remove manual memory management
Diffstat (limited to 'gr-digital/lib')
-rw-r--r-- | gr-digital/lib/probe_mpsk_snr_est_c_impl.cc | 55 | ||||
-rw-r--r-- | gr-digital/lib/probe_mpsk_snr_est_c_impl.h | 2 |
2 files changed, 25 insertions, 32 deletions
diff --git a/gr-digital/lib/probe_mpsk_snr_est_c_impl.cc b/gr-digital/lib/probe_mpsk_snr_est_c_impl.cc index 5d48281531..c8f921fa1c 100644 --- a/gr-digital/lib/probe_mpsk_snr_est_c_impl.cc +++ b/gr-digital/lib/probe_mpsk_snr_est_c_impl.cc @@ -14,11 +14,29 @@ #include "probe_mpsk_snr_est_c_impl.h" #include <gnuradio/io_signature.h> +#include <boost/make_unique.hpp> #include <cstdio> namespace gr { namespace digital { +namespace { +std::unique_ptr<mpsk_snr_est> choose_type(snr_est_type_t t, double alpha) +{ + switch (t) { + case (SNR_EST_SIMPLE): + return boost::make_unique<mpsk_snr_est_simple>(alpha); + case (SNR_EST_SKEW): + return boost::make_unique<mpsk_snr_est_skew>(alpha); + case (SNR_EST_M2M4): + return boost::make_unique<mpsk_snr_est_m2m4>(alpha); + case (SNR_EST_SVR): + return boost::make_unique<mpsk_snr_est_svr>(alpha); + } + throw std::invalid_argument("probe_mpsk_snr_est_c_impl: unknown type specified."); +} +} // namespace + probe_mpsk_snr_est_c::sptr probe_mpsk_snr_est_c::make(snr_est_type_t type, int msg_nsamples, double alpha) { @@ -31,13 +49,11 @@ probe_mpsk_snr_est_c_impl::probe_mpsk_snr_est_c_impl(snr_est_type_t type, double alpha) : sync_block("probe_mpsk_snr_est_c", io_signature::make(1, 1, sizeof(gr_complex)), - io_signature::make(0, 0, 0)) + io_signature::make(0, 0, 0)), + d_type(type), + d_nsamples(msg_nsamples), + d_count(0) { - d_snr_est = NULL; - - d_type = type; - d_nsamples = msg_nsamples; - d_count = 0; set_alpha(alpha); set_type(type); @@ -54,11 +70,7 @@ probe_mpsk_snr_est_c_impl::probe_mpsk_snr_est_c_impl(snr_est_type_t type, message_port_register_out(d_noise_port); } -probe_mpsk_snr_est_c_impl::~probe_mpsk_snr_est_c_impl() -{ - if (d_snr_est) - delete d_snr_est; -} +probe_mpsk_snr_est_c_impl::~probe_mpsk_snr_est_c_impl() {} int probe_mpsk_snr_est_c_impl::work(int noutput_items, gr_vector_const_void_star& input_items, @@ -112,27 +124,8 @@ double probe_mpsk_snr_est_c_impl::alpha() const { return d_alpha; } void probe_mpsk_snr_est_c_impl::set_type(snr_est_type_t t) { + d_snr_est = choose_type(t, d_alpha); d_type = t; - - if (d_snr_est) - delete d_snr_est; - - switch (d_type) { - case (SNR_EST_SIMPLE): - d_snr_est = new mpsk_snr_est_simple(d_alpha); - break; - case (SNR_EST_SKEW): - d_snr_est = new mpsk_snr_est_skew(d_alpha); - break; - case (SNR_EST_M2M4): - d_snr_est = new mpsk_snr_est_m2m4(d_alpha); - break; - case (SNR_EST_SVR): - d_snr_est = new mpsk_snr_est_svr(d_alpha); - break; - default: - throw std::invalid_argument("probe_mpsk_snr_est_c_impl: unknown type specified."); - } } void probe_mpsk_snr_est_c_impl::set_msg_nsample(int n) diff --git a/gr-digital/lib/probe_mpsk_snr_est_c_impl.h b/gr-digital/lib/probe_mpsk_snr_est_c_impl.h index 85009349a2..c74c3b4369 100644 --- a/gr-digital/lib/probe_mpsk_snr_est_c_impl.h +++ b/gr-digital/lib/probe_mpsk_snr_est_c_impl.h @@ -22,7 +22,7 @@ private: snr_est_type_t d_type; int d_nsamples, d_count; double d_alpha; - mpsk_snr_est* d_snr_est; + std::unique_ptr<mpsk_snr_est> d_snr_est; // Message port names pmt::pmt_t d_snr_port; |