From ba5c7995b7fe43d6f583809f49fa8e75fd8c721b Mon Sep 17 00:00:00 2001 From: Alexander Krimm Date: Fri, 13 Dec 2024 18:09:24 +0100 Subject: [PATCH] NullSources: use only supported SettingsTypes for default_value Since the Sources are instantiated with types not supported by Settings, we have use the base value type, except for string, which is supported. This should probably be revisited since while this works, it causes warnings and unexpected behaviour for the Packet/DataSet/... types since default constructing them with their base value will not create a one item instance with that value, but use it to initialize the first field, in this case an uint64_t timestamp. Signed-off-by: Alexander Krimm --- .../include/gnuradio-4.0/testing/NullSources.hpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/blocks/testing/include/gnuradio-4.0/testing/NullSources.hpp b/blocks/testing/include/gnuradio-4.0/testing/NullSources.hpp index 8d5cfb4f..c6bb1c7b 100644 --- a/blocks/testing/include/gnuradio-4.0/testing/NullSources.hpp +++ b/blocks/testing/include/gnuradio-4.0/testing/NullSources.hpp @@ -25,13 +25,14 @@ static_assert(gr::BlockLike>); template struct ConstantSource : public gr::Block> { + using value_t = std::conditional_t, std::string, meta::fundamental_base_value_type_t>; // use base-type for types not supported by settings using Description = Doc; gr::PortOut out; - Annotated> default_value{}; + Annotated> default_value{}; Annotatedn_samples_max -> signal DONE (0: infinite)">> n_samples_max = 0U; Annotated> count = 0U; @@ -44,7 +45,7 @@ Commonly used for testing and simulations where consistent output and finite exe if (n_samples_max > 0 && count >= n_samples_max) { this->requestStop(); } - return default_value; + return T(default_value.value); } }; @@ -52,11 +53,12 @@ static_assert(gr::BlockLike>); template struct SlowSource : public gr::Block> { + using value_t = std::conditional_t, std::string, meta::fundamental_base_value_type_t>; // use base-type for types not supported by settings using Description = Doc; - gr::PortOut out; - Annotated> default_value{}; - Annotated> n_delay = 100U; + gr::PortOut out; + Annotated> default_value{}; + Annotated> n_delay = 100U; GR_MAKE_REFLECTABLE(SlowSource, out, n_delay); @@ -66,7 +68,7 @@ struct SlowSource : public gr::Block> { if (!lastEventAt || std::chrono::system_clock::now() - *lastEventAt > std::chrono::milliseconds(n_delay)) { lastEventAt = std::chrono::system_clock::now(); - output[0] = default_value; + output[0] = T(default_value.value); output.publish(1UZ); } else { output.publish(0UZ); @@ -100,7 +102,7 @@ Commonly used for testing and simulations where consistent output and finite exe if (n_samples_max > 0 && count >= n_samples_max) { this->requestStop(); } - return default_value + T(count); + return T(default_value.value) + T(count); } };