From 9fa747e19444d2e317d5ad553cf42ee02f98a3d7 Mon Sep 17 00:00:00 2001 From: Frank Osterfeld Date: Mon, 9 Oct 2023 12:51:46 +0200 Subject: [PATCH] Settings: Minor code simplification --- core/include/gnuradio-4.0/settings.hpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/core/include/gnuradio-4.0/settings.hpp b/core/include/gnuradio-4.0/settings.hpp index ac05bc2f..f5d30e51 100644 --- a/core/include/gnuradio-4.0/settings.hpp +++ b/core/include/gnuradio-4.0/settings.hpp @@ -269,7 +269,7 @@ class basic_settings : public settings_base { auto iterate_over_member = [&](auto member) { using RawType = std::remove_cvref_t; using Type = unwrap_if_wrapped_t; - if constexpr ((!traits::node::detail::is_port_or_collection()) && is_writable(member) && (std::is_arithmetic_v || std::is_same_v || gr::meta::vector_type) ) { + if constexpr (!traits::node::detail::is_port_or_collection() && is_writable(member) && is_supported_type()) { auto matchesIgnoringPrefix = [](std::string_view str, std::string_view prefix, std::string_view target) { if (str.starts_with(prefix)) { str.remove_prefix(prefix.size()); @@ -365,8 +365,12 @@ class basic_settings : public settings_base { bool is_set = false; auto iterate_over_member = [&, this](auto member) { using Type = unwrap_if_wrapped_t>; - if constexpr ((!traits::node::detail::is_port_or_collection()) && is_writable(member) && (std::is_arithmetic_v || std::is_same_v || gr::meta::vector_type) ) { - if (std::string(get_display_name(member)) == key && std::holds_alternative(value)) { + if constexpr (!traits::node::detail::is_port_or_collection() && is_writable(member) && is_supported_type()) { + if (std::string(get_display_name(member)) == key) { + if (!std::holds_alternative(value)) { + throw std::invalid_argument(fmt::format("The {} has a wrong type", key)); + } + if (_auto_update.contains(key)) { _auto_update.erase(key); } @@ -374,9 +378,6 @@ class basic_settings : public settings_base { settings_base::_changed.store(true); is_set = true; } - if (std::string(get_display_name(member)) == key && !std::holds_alternative(value)) { - throw std::invalid_argument(fmt::format("The {} has a wrong type", key)); - } } }; if constexpr (detail::HasBaseType) { @@ -384,7 +385,7 @@ class basic_settings : public settings_base { } refl::util::for_each(refl::reflect().members, iterate_over_member); if (!is_set) { - fmt::print("The property {} was not set\n", key); + fmt::print(stderr, "The property {} was not set\n", key); ret.insert_or_assign(key, pmtv::pmt(value)); } } @@ -424,7 +425,7 @@ class basic_settings : public settings_base { const auto &value = localValue; auto iterate_over_member = [&](auto member) { using Type = unwrap_if_wrapped_t>; - if constexpr ((!traits::node::detail::is_port_or_collection()) && is_writable(member) && (std::is_arithmetic_v || std::is_same_v || gr::meta::vector_type) ) { + if constexpr (!traits::node::detail::is_port_or_collection() && is_writable(member) && is_supported_type()) { if (std::string(get_display_name(member)) == key && std::holds_alternative(value)) { _staged.insert_or_assign(key, value); settings_base::_changed.store(true); @@ -515,7 +516,7 @@ class basic_settings : public settings_base { auto apply_member_changes = [&key, &staged, &forward_parameters, &staged_value, this](auto member) { using RawType = std::remove_cvref_t; using Type = unwrap_if_wrapped_t; - if constexpr ((!traits::node::detail::is_port_or_collection()) && is_writable(member) && is_supported_type()) { + if constexpr (!traits::node::detail::is_port_or_collection() && is_writable(member) && is_supported_type()) { if (std::string(get_display_name(member)) == key && std::holds_alternative(staged_value)) { if constexpr (is_annotated()) { if (member(*_node).validate_and_set(std::get(staged_value))) { @@ -560,7 +561,7 @@ class basic_settings : public settings_base { // update active parameters auto update_active = [this](auto member) { using Type = unwrap_if_wrapped_t>; - if constexpr ((!traits::node::detail::is_port_or_collection()) && is_readable(member) && is_supported_type()) { + if constexpr (!traits::node::detail::is_port_or_collection() && is_readable(member) && is_supported_type()) { _active.insert_or_assign(get_display_name(member), pmtv::pmt(member(*_node))); } }; @@ -618,7 +619,7 @@ class basic_settings : public settings_base { auto iterate_over_member = [&, this](auto member) { using Type = unwrap_if_wrapped_t>; - if constexpr ((!traits::node::detail::is_port_or_collection()) && is_readable(member) && is_supported_type()) { + if constexpr (!traits::node::detail::is_port_or_collection() && is_readable(member) && is_supported_type()) { oldSettings.insert_or_assign(get_display_name(member), pmtv::pmt(member(*_node))); } }; @@ -632,7 +633,7 @@ class basic_settings : public settings_base { template inline constexpr static bool is_supported_type() { - return std::integral || std::floating_point || std::is_same_v || gr::meta::vector_type; + return std::is_arithmetic_v || std::is_same_v || gr::meta::vector_type; } template