diff options
author | Thomas Habets <thomas@habets.se> | 2020-08-12 11:11:11 +0100 |
---|---|---|
committer | Martin Braun <martin@gnuradio.org> | 2020-08-14 04:08:48 -0700 |
commit | c85820204393722564a7d697cbd77b4f5aa09bea (patch) | |
tree | 55c5044aecd973ae5726dfd63d8fa35035cbdc86 /gr-digital/lib/interpolating_resampler.cc | |
parent | b5fb4c2eb54164ab57750878fd185b8170823711 (diff) |
digital/symbol_sync: Remove manual memory management
The `cc` version already used more smart pointers, but `d_clock`
didn't need to be a pointer at all.
I consted function args to make it clear in the initializer that they
will not be changed in the constructor body.
Return value for `make` for the TED and interpolator was changed to a
`unique_ptr` to make it clear that ownership is transferred. And it
makes it all but impossible to accidentally memory leak.
(core guidelines F.26. Also relevant I.11,R.20).
Diffstat (limited to 'gr-digital/lib/interpolating_resampler.cc')
-rw-r--r-- | gr-digital/lib/interpolating_resampler.cc | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/gr-digital/lib/interpolating_resampler.cc b/gr-digital/lib/interpolating_resampler.cc index 85cae852f8..1fa78dae63 100644 --- a/gr-digital/lib/interpolating_resampler.cc +++ b/gr-digital/lib/interpolating_resampler.cc @@ -93,52 +93,40 @@ void interpolating_resampler::sync_reset(float phase) /*************************************************************************/ -interpolating_resampler_ccf* interpolating_resampler_ccf::make( +std::unique_ptr<interpolating_resampler_ccf> interpolating_resampler_ccf::make( enum ir_type type, bool derivative, int nfilts, const std::vector<float>& taps) { - interpolating_resampler_ccf* ret = NULL; switch (type) { case IR_MMSE_8TAP: - ret = new interp_resampler_mmse_8tap_cc(derivative); - break; + return boost::make_unique<interp_resampler_mmse_8tap_cc>(derivative); case IR_PFB_NO_MF: - ret = new interp_resampler_pfb_no_mf_cc(derivative, nfilts); - break; + return boost::make_unique<interp_resampler_pfb_no_mf_cc>(derivative, nfilts); case IR_PFB_MF: - ret = new interp_resampler_pfb_mf_ccf(taps, nfilts, derivative); - break; + return boost::make_unique<interp_resampler_pfb_mf_ccf>(taps, nfilts, derivative); case IR_NONE: - default: - throw std::invalid_argument("interpolating_resampler_ccf: invalid " - "interpolating resampler type."); - break; + return nullptr; } - return ret; + throw std::invalid_argument("interpolating_resampler_ccf: invalid " + "interpolating resampler type."); } /*************************************************************************/ -interpolating_resampler_fff* interpolating_resampler_fff::make( +std::unique_ptr<interpolating_resampler_fff> interpolating_resampler_fff::make( enum ir_type type, bool derivative, int nfilts, const std::vector<float>& taps) { - interpolating_resampler_fff* ret = NULL; switch (type) { case IR_MMSE_8TAP: - ret = new interp_resampler_mmse_8tap_ff(derivative); - break; + return boost::make_unique<interp_resampler_mmse_8tap_ff>(derivative); case IR_PFB_NO_MF: - ret = new interp_resampler_pfb_no_mf_ff(derivative, nfilts); - break; + return boost::make_unique<interp_resampler_pfb_no_mf_ff>(derivative, nfilts); case IR_PFB_MF: - ret = new interp_resampler_pfb_mf_fff(taps, nfilts, derivative); - break; + return boost::make_unique<interp_resampler_pfb_mf_fff>(taps, nfilts, derivative); case IR_NONE: - default: - throw std::invalid_argument("interpolating_resampler_fff: invalid " - "interpolating resampler type."); - break; + return nullptr; } - return ret; + throw std::invalid_argument("interpolating_resampler_fff: invalid " + "interpolating resampler type."); } /*************************************************************************/ |