diff options
author | Thomas Habets <thomas@habets.se> | 2020-04-10 10:34:20 +0100 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2020-04-10 21:38:42 +0200 |
commit | e30b5d796384410db1a4440c0e3692e9a59c508a (patch) | |
tree | 5b650b20f24cb84c42458cd1c46b9dda6b54fd55 | |
parent | 8427b6cdd8112f82ddae5815a87334708db5764e (diff) |
analog: Remove manual memory management
-rw-r--r-- | gr-analog/include/gnuradio/analog/random_uniform_source.h | 7 | ||||
-rw-r--r-- | gr-analog/lib/ctcss_squelch_ff_impl.cc | 14 | ||||
-rw-r--r-- | gr-analog/lib/ctcss_squelch_ff_impl.h | 7 | ||||
-rw-r--r-- | gr-analog/lib/random_uniform_source_impl.cc | 7 | ||||
-rw-r--r-- | gr-analog/lib/random_uniform_source_impl.h | 2 |
5 files changed, 16 insertions, 21 deletions
diff --git a/gr-analog/include/gnuradio/analog/random_uniform_source.h b/gr-analog/include/gnuradio/analog/random_uniform_source.h index b62653a6a0..f05ad2fa1d 100644 --- a/gr-analog/include/gnuradio/analog/random_uniform_source.h +++ b/gr-analog/include/gnuradio/analog/random_uniform_source.h @@ -32,10 +32,9 @@ public: /*! * \brief Return a shared_ptr to a new instance of analog::random_uniform_source_X. * - * To avoid accidental use of raw pointers, analog::random_uniform_source_b's - * constructor is in a private implementation - * class. analog::random_uniform_source_b::make is the public interface for - * creating new instances. + * Since it's perfectly safe to generate non-pointer random source blocks, + * the constructor for this block is public. Nevertheless this make() + * function is exposed for consistency. * \param minimum defines minimal integer value output. * \param maximum output values are below this value * \param seed for Pseudo Random Number Generator. Defaults to 0. In this case current diff --git a/gr-analog/lib/ctcss_squelch_ff_impl.cc b/gr-analog/lib/ctcss_squelch_ff_impl.cc index 6c5ffa342c..66cb6afae8 100644 --- a/gr-analog/lib/ctcss_squelch_ff_impl.cc +++ b/gr-analog/lib/ctcss_squelch_ff_impl.cc @@ -13,6 +13,7 @@ #endif #include "ctcss_squelch_ff_impl.h" +#include <boost/make_unique.hpp> namespace gr { namespace analog { @@ -87,19 +88,14 @@ ctcss_squelch_ff_impl::ctcss_squelch_ff_impl( float f_l, f_r; compute_freqs(d_freq, f_l, f_r); - d_goertzel_l = new fft::goertzel(d_rate, d_len, f_l); - d_goertzel_c = new fft::goertzel(d_rate, d_len, freq); - d_goertzel_r = new fft::goertzel(d_rate, d_len, f_r); + d_goertzel_l = boost::make_unique<fft::goertzel>(d_rate, d_len, f_l); + d_goertzel_c = boost::make_unique<fft::goertzel>(d_rate, d_len, freq); + d_goertzel_r = boost::make_unique<fft::goertzel>(d_rate, d_len, f_r); d_mute = true; } -ctcss_squelch_ff_impl::~ctcss_squelch_ff_impl() -{ - delete d_goertzel_l; - delete d_goertzel_c; - delete d_goertzel_r; -} +ctcss_squelch_ff_impl::~ctcss_squelch_ff_impl() {} std::vector<float> ctcss_squelch_ff_impl::squelch_range() const { diff --git a/gr-analog/lib/ctcss_squelch_ff_impl.h b/gr-analog/lib/ctcss_squelch_ff_impl.h index 568834aa17..11ca92b025 100644 --- a/gr-analog/lib/ctcss_squelch_ff_impl.h +++ b/gr-analog/lib/ctcss_squelch_ff_impl.h @@ -14,6 +14,7 @@ #include "squelch_base_ff_impl.h" #include <gnuradio/analog/ctcss_squelch_ff.h> #include <gnuradio/fft/goertzel.h> +#include <memory> namespace gr { namespace analog { @@ -27,9 +28,9 @@ private: int d_rate; bool d_mute; - fft::goertzel* d_goertzel_l; - fft::goertzel* d_goertzel_c; - fft::goertzel* d_goertzel_r; + std::unique_ptr<fft::goertzel> d_goertzel_l; + std::unique_ptr<fft::goertzel> d_goertzel_c; + std::unique_ptr<fft::goertzel> d_goertzel_r; static int find_tone(float freq); static void compute_freqs(const float& freq, float& f_l, float& f_r); diff --git a/gr-analog/lib/random_uniform_source_impl.cc b/gr-analog/lib/random_uniform_source_impl.cc index 08efd397b8..47f613de8d 100644 --- a/gr-analog/lib/random_uniform_source_impl.cc +++ b/gr-analog/lib/random_uniform_source_impl.cc @@ -33,21 +33,20 @@ random_uniform_source_impl<T>::random_uniform_source_impl(int minimum, int seed) : sync_block("random_uniform_source", io_signature::make(0, 0, 0), - io_signature::make(1, 1, sizeof(T))) + io_signature::make(1, 1, sizeof(T))), + d_rng(seed, minimum, maximum) { - d_rng = new gr::random(seed, minimum, maximum); } template <class T> random_uniform_source_impl<T>::~random_uniform_source_impl() { - delete d_rng; } template <class T> int random_uniform_source_impl<T>::random_value() { - return d_rng->ran_int(); + return d_rng.ran_int(); } template <class T> diff --git a/gr-analog/lib/random_uniform_source_impl.h b/gr-analog/lib/random_uniform_source_impl.h index d8d3aba9b5..8ebb636cce 100644 --- a/gr-analog/lib/random_uniform_source_impl.h +++ b/gr-analog/lib/random_uniform_source_impl.h @@ -22,7 +22,7 @@ template <class T> class random_uniform_source_impl : public random_uniform_source<T> { private: - gr::random* d_rng; + gr::random d_rng; public: random_uniform_source_impl(int minimum, int maximum, int seed); |