From 5e7f9abd8c579bb82dfa818bb95601034897ddbe Mon Sep 17 00:00:00 2001 From: tanneberger Date: Wed, 15 May 2024 21:35:33 +0200 Subject: [PATCH] updating code --- include/config.h | 19 +++++++++++-------- src/config.cpp | 8 ++++---- src/tetra-receiver.cpp | 6 +++--- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/include/config.h b/include/config.h index 514970e..28bde1f 100644 --- a/include/config.h +++ b/include/config.h @@ -1,3 +1,6 @@ +#ifndef CONFIG_H +#define CONFIG_H + #include #include #include @@ -43,9 +46,7 @@ template class Range { /// Check that the given Range is inside the bounds (inclusive) of this Range. [[nodiscard]] auto contains(const Range& other) const noexcept -> bool { - if (other.min_ < min_ || other.max_ > max_) - return false; - return true; + return !static_cast(other.min_ < min_ || other.max_ > max_); }; }; @@ -66,15 +67,15 @@ template class SpectrumSlice { , frequency_range_(center_frequency - sample_rate / 2, center_frequency + sample_rate / 2) , sample_rate_(sample_rate){}; - friend bool operator==(const SpectrumSlice&, const SpectrumSlice&); - friend bool operator!=(const SpectrumSlice&, const SpectrumSlice&); + friend auto operator==(const SpectrumSlice&, const SpectrumSlice&) -> bool; + friend auto operator!=(const SpectrumSlice&, const SpectrumSlice&) -> bool; }; -template bool operator==(const SpectrumSlice& lhs, const SpectrumSlice& rhs) { +template auto operator==(const SpectrumSlice& lhs, const SpectrumSlice& rhs) -> bool { return lhs.center_frequency_ == rhs.center_frequency_ && lhs.sample_rate_ == rhs.sample_rate_; }; -template bool operator!=(const SpectrumSlice& lhs, const SpectrumSlice& rhs) { +template auto operator!=(const SpectrumSlice& lhs, const SpectrumSlice& rhs) -> bool { return !operator==(lhs, rhs); }; @@ -180,7 +181,7 @@ static config::decimate_or_stream get_decimate_or_stream(const config::SpectrumS } template <> struct from { - static config::TopLevel from_toml(const value& v) { + static auto from_toml(const value& v) -> config::TopLevel { const unsigned int center_frequency = find(v, "CenterFrequency"); const std::string device_string = find(v, "DeviceString"); const unsigned int sample_rate = find(v, "SampleRate"); @@ -247,3 +248,5 @@ template <> struct from { }; // namespace toml #endif + +#endif diff --git a/src/config.cpp b/src/config.cpp index bc3f8da..0118c61 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -17,8 +17,8 @@ Stream::Stream(const SpectrumSlice& input_spectrum, const Spectrum const auto& input_sample_rate = input_spectrum.sample_rate_; const auto& sample_rate = spectrum.sample_rate_; decimation_ = input_sample_rate / sample_rate; - auto rem = input_sample_rate % sample_rate; - if (rem != 0) { + auto remainder = input_sample_rate % sample_rate; + if (remainder != 0) { throw std::invalid_argument("Input sample rate is not divisible by Stream block sample rate."); } } @@ -34,9 +34,9 @@ Decimate::Decimate(const SpectrumSlice& input_spectrum, const Spec const auto& input_sample_rate = input_spectrum.sample_rate_; const auto& sample_rate = spectrum.sample_rate_; decimation_ = input_sample_rate / sample_rate; - auto rem = input_sample_rate % sample_rate; + auto remainder = input_sample_rate % sample_rate; - if (rem != 0) { + if (remainder != 0) { throw std::invalid_argument("Input sample rate is not divisible by Decimate block sample rate."); } diff --git a/src/tetra-receiver.cpp b/src/tetra-receiver.cpp index 2c9ebb8..5d7df0e 100644 --- a/src/tetra-receiver.cpp +++ b/src/tetra-receiver.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include @@ -140,7 +140,7 @@ class GnuradioTopBlock { } }; -int main(int argc, char** argv) { +auto main(int argc, char** argv) -> int { try { cxxopts::Options options("tetra-receiver", "Receive multiple TETRA streams at once and send the bits out via UDP"); @@ -166,7 +166,7 @@ int main(int argc, char** argv) { return EXIT_SUCCESS; } - gr::top_block_sptr tb; + gr::top_block_sptr tb = 0; // Read from config file instead if (result.count("config-file")) {