Skip to content

Commit

Permalink
Settings: Minor code simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
frankosterfeld authored and RalphSteinhagen committed Oct 9, 2023
1 parent bce73f5 commit 9fa747e
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions core/include/gnuradio-4.0/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class basic_settings : public settings_base {
auto iterate_over_member = [&](auto member) {
using RawType = std::remove_cvref_t<decltype(member(*_node))>;
using Type = unwrap_if_wrapped_t<RawType>;
if constexpr ((!traits::node::detail::is_port_or_collection<Type>()) && is_writable(member) && (std::is_arithmetic_v<Type> || std::is_same_v<Type, std::string> || gr::meta::vector_type<Type>) ) {
if constexpr (!traits::node::detail::is_port_or_collection<Type>() && is_writable(member) && is_supported_type<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());
Expand Down Expand Up @@ -365,26 +365,27 @@ class basic_settings : public settings_base {
bool is_set = false;
auto iterate_over_member = [&, this](auto member) {
using Type = unwrap_if_wrapped_t<std::remove_cvref_t<decltype(member(*_node))>>;
if constexpr ((!traits::node::detail::is_port_or_collection<Type>()) && is_writable(member) && (std::is_arithmetic_v<Type> || std::is_same_v<Type, std::string> || gr::meta::vector_type<Type>) ) {
if (std::string(get_display_name(member)) == key && std::holds_alternative<Type>(value)) {
if constexpr (!traits::node::detail::is_port_or_collection<Type>() && is_writable(member) && is_supported_type<Type>()) {
if (std::string(get_display_name(member)) == key) {
if (!std::holds_alternative<Type>(value)) {
throw std::invalid_argument(fmt::format("The {} has a wrong type", key));
}

if (_auto_update.contains(key)) {
_auto_update.erase(key);
}
_staged.insert_or_assign(key, value);
settings_base::_changed.store(true);
is_set = true;
}
if (std::string(get_display_name(member)) == key && !std::holds_alternative<Type>(value)) {
throw std::invalid_argument(fmt::format("The {} has a wrong type", key));
}
}
};
if constexpr (detail::HasBaseType<Node>) {
refl::util::for_each(refl::reflect<typename std::remove_cvref_t<Node>::base_t>().members, iterate_over_member);
}
refl::util::for_each(refl::reflect<Node>().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));
}
}
Expand Down Expand Up @@ -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<std::remove_cvref_t<decltype(member(*_node))>>;
if constexpr ((!traits::node::detail::is_port_or_collection<Type>()) && is_writable(member) && (std::is_arithmetic_v<Type> || std::is_same_v<Type, std::string> || gr::meta::vector_type<Type>) ) {
if constexpr (!traits::node::detail::is_port_or_collection<Type>() && is_writable(member) && is_supported_type<Type>()) {
if (std::string(get_display_name(member)) == key && std::holds_alternative<Type>(value)) {
_staged.insert_or_assign(key, value);
settings_base::_changed.store(true);
Expand Down Expand Up @@ -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<decltype(member(*_node))>;
using Type = unwrap_if_wrapped_t<RawType>;
if constexpr ((!traits::node::detail::is_port_or_collection<Type>()) && is_writable(member) && is_supported_type<Type>()) {
if constexpr (!traits::node::detail::is_port_or_collection<Type>() && is_writable(member) && is_supported_type<Type>()) {
if (std::string(get_display_name(member)) == key && std::holds_alternative<Type>(staged_value)) {
if constexpr (is_annotated<RawType>()) {
if (member(*_node).validate_and_set(std::get<Type>(staged_value))) {
Expand Down Expand Up @@ -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<std::remove_cvref_t<decltype(member(*_node))>>;
if constexpr ((!traits::node::detail::is_port_or_collection<Type>()) && is_readable(member) && is_supported_type<Type>()) {
if constexpr (!traits::node::detail::is_port_or_collection<Type>() && is_readable(member) && is_supported_type<Type>()) {
_active.insert_or_assign(get_display_name(member), pmtv::pmt(member(*_node)));
}
};
Expand Down Expand Up @@ -618,7 +619,7 @@ class basic_settings : public settings_base {
auto iterate_over_member = [&, this](auto member) {
using Type = unwrap_if_wrapped_t<std::remove_cvref_t<decltype(member(*_node))>>;

if constexpr ((!traits::node::detail::is_port_or_collection<Type>()) && is_readable(member) && is_supported_type<Type>()) {
if constexpr (!traits::node::detail::is_port_or_collection<Type>() && is_readable(member) && is_supported_type<Type>()) {
oldSettings.insert_or_assign(get_display_name(member), pmtv::pmt(member(*_node)));
}
};
Expand All @@ -632,7 +633,7 @@ class basic_settings : public settings_base {
template<typename Type>
inline constexpr static bool
is_supported_type() {
return std::integral<Type> || std::floating_point<Type> || std::is_same_v<Type, std::string> || gr::meta::vector_type<Type>;
return std::is_arithmetic_v<Type> || std::is_same_v<Type, std::string> || gr::meta::vector_type<Type>;
}

template<typename NodeType, typename Func>
Expand Down

0 comments on commit 9fa747e

Please sign in to comment.