From 6303c46716cd4bb9304d3e42f5b5e11f38bfe9f4 Mon Sep 17 00:00:00 2001 From: rstein Date: Wed, 11 Oct 2023 17:21:41 +0200 Subject: [PATCH] changed naming of Settings, Transactions, Tag + fixed CMakeLists.txt case-sensitivity bug --- CMakeLists.txt | 4 +- .../gnuradio-4.0/basic/clock_source.hpp | 12 +- .../gnuradio-4.0/basic/common_blocks.hpp | 22 +-- .../include/gnuradio-4.0/basic/data_sink.hpp | 50 +++--- .../include/gnuradio-4.0/basic/selector.hpp | 2 +- blocks/basic/test/qa_data_sink.cpp | 86 +++++----- blocks/basic/test/qa_selector.cpp | 16 +- blocks/basic/test/qa_sources.cpp | 2 +- .../filter/time_domain_filter.hpp | 4 +- .../include/gnuradio-4.0/fourier/fft.hpp | 2 +- blocks/fourier/test/qa_fourier.cpp | 8 +- .../gnuradio-4.0/testing/bm_test_helper.hpp | 2 +- .../gnuradio-4.0/testing/tag_monitors.hpp | 48 +++--- core/benchmarks/bm_fft.cpp | 4 +- core/include/gnuradio-4.0/Block.hpp | 52 +++--- core/include/gnuradio-4.0/DataSet.hpp | 22 +-- core/include/gnuradio-4.0/Graph.hpp | 4 +- .../gnuradio-4.0/Graph_yaml_importer.hpp | 4 +- core/include/gnuradio-4.0/Port.hpp | 10 +- core/include/gnuradio-4.0/Profiler.hpp | 18 +- core/include/gnuradio-4.0/Scheduler.hpp | 6 +- .../{settings.hpp => Settings.hpp} | 160 +++++++++--------- .../include/gnuradio-4.0/{tag.hpp => Tag.hpp} | 44 ++--- .../{transactions.hpp => Transactions.hpp} | 96 +++++------ core/test/CMakeLists.txt | 6 +- core/test/qa_DynamicBlock.cpp | 2 +- core/test/qa_HierBlock.cpp | 24 +-- .../{qa_scheduler.cpp => qa_Scheduler.cpp} | 0 .../test/{qa_settings.cpp => qa_Settings.cpp} | 68 ++++---- core/test/{qa_tags.cpp => qa_Tags.cpp} | 14 +- 30 files changed, 396 insertions(+), 396 deletions(-) rename core/include/gnuradio-4.0/{settings.hpp => Settings.hpp} (83%) rename core/include/gnuradio-4.0/{tag.hpp => Tag.hpp} (73%) rename core/include/gnuradio-4.0/{transactions.hpp => Transactions.hpp} (87%) rename core/test/{qa_scheduler.cpp => qa_Scheduler.cpp} (100%) rename core/test/{qa_settings.cpp => qa_Settings.cpp} (91%) rename core/test/{qa_tags.cpp => qa_Tags.cpp} (89%) diff --git a/CMakeLists.txt b/CMakeLists.txt index e6f110716..dde7e4505 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,12 +152,12 @@ if (ENABLE_TESTING AND UNIX AND NOT APPLE) setup_target_for_coverage_gcovr_xml( NAME coverage EXECUTABLE ctest - DEPENDENCIES qa_buffer qa_data_sink qa_DynamicPort qa_DynamicBlock qa_HierBlock qa_filter qa_settings qa_tags qa_Scheduler qa_thread_pool qa_thread_affinity + DEPENDENCIES qa_buffer qa_data_sink qa_DynamicPort qa_DynamicBlock qa_HierBlock qa_filter qa_Settings qa_Tags qa_Scheduler qa_thread_pool qa_thread_affinity EXCLUDE "$CMAKE_BUILD_DIR/*" "concepts/.*" ".*/test/.*") setup_target_for_coverage_gcovr_html( NAME coverage_html EXECUTABLE ctest - DEPENDENCIES qa_buffer qa_data_sink qa_DynamicPort qa_DynamicBlock qa_HierBlock qa_filter qa_settings qa_tags qa_Scheduler qa_thread_pool qa_thread_affinity + DEPENDENCIES qa_buffer qa_data_sink qa_DynamicPort qa_DynamicBlock qa_HierBlock qa_filter qa_Settings qa_Tags qa_Scheduler qa_thread_pool qa_thread_affinity EXCLUDE "$CMAKE_BUILD_DIR/*" "concepts/.*" ".*/test/.*") endif () message("Building Tests and benchmarks.") diff --git a/blocks/basic/include/gnuradio-4.0/basic/clock_source.hpp b/blocks/basic/include/gnuradio-4.0/basic/clock_source.hpp index 3b0bd3085..648c249bc 100644 --- a/blocks/basic/include/gnuradio-4.0/basic/clock_source.hpp +++ b/blocks/basic/include/gnuradio-4.0/basic/clock_source.hpp @@ -15,7 +15,7 @@ #include #include -#include +#include #include @@ -32,9 +32,9 @@ ClockSource Documentation -- add here )"">> { std::chrono::time_point nextTimePoint = ClockSourceType::now(); // - PortOut out; - std::vector tags{}; - std::size_t next_tag{ 0 }; + PortOut out; + std::vector tags{}; + std::size_t next_tag{ 0 }; // A> n_samples_max = 1024; std::uint32_t n_samples_produced{ 0 }; @@ -85,7 +85,7 @@ ClockSource Documentation -- add here } void - settings_changed(const property_map & /*old_settings*/, const property_map & /*new_settings*/) { + settingsChanged(const property_map & /*old_settings*/, const property_map & /*new_settings*/) { nextTimePoint = ClockSourceType::now(); } @@ -113,7 +113,7 @@ ClockSource Documentation -- add here std::uint32_t samples_to_produce = n_available; while (next_tag < tags.size() && tags[next_tag].index <= static_cast>(n_samples_produced + n_available)) { gr::testing::print_tag(tags[next_tag], fmt::format("{}::processBulk(...)\t publish tag at {:6}", this->name, n_samples_produced)); - tag_t &out_tag = this->output_tags()[0]; + Tag &out_tag = this->output_tags()[0]; out_tag = tags[next_tag]; out_tag.index = tags[next_tag].index - static_cast>(n_samples_produced); samples_to_produce = static_cast(tags[next_tag].index) - n_samples_produced; diff --git a/blocks/basic/include/gnuradio-4.0/basic/common_blocks.hpp b/blocks/basic/include/gnuradio-4.0/basic/common_blocks.hpp index f0fb58001..9852e2351 100644 --- a/blocks/basic/include/gnuradio-4.0/basic/common_blocks.hpp +++ b/blocks/basic/include/gnuradio-4.0/basic/common_blocks.hpp @@ -76,15 +76,15 @@ class multi_adder : public gr::BlockModel { gr::PortOut _output_port; protected: - using setting_map = std::map>; - std::string _name = "multi_adder"; - std::string _type_name = "multi_adder"; - gr::property_map _meta_information; /// used to store non-graph-processing information like UI block position etc. - bool _input_tags_present = false; - bool _output_tags_changed = false; - std::vector _tags_at_input; - std::vector _tags_at_output; - std::unique_ptr _settings = std::make_unique>>(*this); + using setting_map = std::map>; + std::string _name = "multi_adder"; + std::string _type_name = "multi_adder"; + gr::property_map _meta_information; /// used to store non-graph-processing information like UI block position etc. + bool _input_tags_present = false; + bool _output_tags_changed = false; + std::vector _tags_at_input; + std::vector _tags_at_output; + std::unique_ptr _settings = std::make_unique>>(*this); void apply_input_count() { @@ -108,7 +108,7 @@ class multi_adder : public gr::BlockModel { ~multi_adder() override = default; void - settings_changed(const gr::property_map & /*old_setting*/, const gr::property_map & /*new_setting*/) noexcept { + settingsChanged(const gr::property_map & /*old_setting*/, const gr::property_map & /*new_setting*/) noexcept { apply_input_count(); } @@ -195,7 +195,7 @@ class multi_adder : public gr::BlockModel { return _meta_information; } - [[nodiscard]] gr::settings_base & + [[nodiscard]] gr::SettingsBase & settings() const override { return *_settings; } diff --git a/blocks/basic/include/gnuradio-4.0/basic/data_sink.hpp b/blocks/basic/include/gnuradio-4.0/basic/data_sink.hpp index c3081eb23..dadd7e94c 100644 --- a/blocks/basic/include/gnuradio-4.0/basic/data_sink.hpp +++ b/blocks/basic/include/gnuradio-4.0/basic/data_sink.hpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include @@ -35,7 +35,7 @@ concept DataSetCallback = std::invocable>; * Stream callback functions receive the span of data, with optional tags and reference to the sink. */ template -concept StreamCallback = std::invocable> || std::invocable, std::span> || std::invocable, std::span, const data_sink&>; +concept StreamCallback = std::invocable> || std::invocable, std::span> || std::invocable, std::span, const data_sink&>; /** * Used for testing whether a tag should trigger data acquisition. @@ -64,7 +64,7 @@ concept StreamCallback = std::invocable> || std::invocable * // matcher observing three possible tag values, "green", "yellow", "red". * // starting a dataset when seeing "green", stopping on "red", starting a new dataset on "yellow" * struct color_matcher { - * matcher_result operator()(const tag_t &tag) { + * matcher_result operator()(const Tag &tag) { * if (tag == green || tag == yellow) { * return trigger_match_result::Matching; * } @@ -80,7 +80,7 @@ concept StreamCallback = std::invocable> || std::invocable * @see trigger_match_result */ template -concept TriggerMatcher = requires(T matcher, tag_t tag) { +concept TriggerMatcher = requires(T matcher, Tag tag) { { matcher(tag) } -> std::convertible_to; }; @@ -326,7 +326,7 @@ class data_sink : public Block> { gr::CircularBuffer buffer = gr::CircularBuffer(_listener_buffer_size); decltype(buffer.new_reader()) reader = buffer.new_reader(); decltype(buffer.new_writer()) writer = buffer.new_writer(); - gr::CircularBuffer tag_buffer = gr::CircularBuffer(1024); + gr::CircularBuffer tag_buffer = gr::CircularBuffer(1024); decltype(tag_buffer.new_reader()) tag_reader = tag_buffer.new_reader(); decltype(tag_buffer.new_writer()) tag_writer = tag_buffer.new_writer(); std::size_t samples_read = 0; // reader thread @@ -342,14 +342,14 @@ class data_sink : public Block> { } const auto read_data = reader.get(available); - if constexpr (requires { fnc(std::span(), std::span()); }) { + if constexpr (requires { fnc(std::span(), std::span()); }) { const auto tags = tag_reader.get(); const auto it = std::find_if_not(tags.begin(), tags.end(), [until = static_cast(samples_read + available)](const auto &tag) { return tag.index < until; }); - auto relevant_tags = std::vector(tags.begin(), it); + auto relevant_tags = std::vector(tags.begin(), it); for (auto &t : relevant_tags) { t.index -= static_cast(samples_read); } - fnc(read_data, std::span(relevant_tags)); + fnc(read_data, std::span(relevant_tags)); std::ignore = tag_reader.consume(relevant_tags.size()); } else { std::ignore = tag_reader.consume(tag_reader.available()); @@ -392,7 +392,7 @@ class data_sink : public Block> { } void - settings_changed(const property_map & /*old_settings*/, const property_map &new_settings) { + settingsChanged(const property_map & /*old_settings*/, const property_map &new_settings) { if (apply_signal_info(new_settings)) { _has_signal_info_from_settings = true; } @@ -616,17 +616,17 @@ class data_sink : public Block> { template struct continuous_listener : public abstract_listener { static constexpr auto has_callback = !std::is_same_v; - static constexpr auto callback_takes_tags = std::is_invocable_v, std::span> - || std::is_invocable_v, std::span, const data_sink &>; + static constexpr auto callback_takes_tags = std::is_invocable_v, std::span> + || std::is_invocable_v, std::span, const data_sink &>; const data_sink &parent_sink; bool block = false; std::size_t samples_written = 0; // callback-only - std::size_t buffer_fill = 0; - std::vector buffer; - std::vector tag_buffer; + std::size_t buffer_fill = 0; + std::vector buffer; + std::vector tag_buffer; // polling-only std::weak_ptr polling_handler = {}; @@ -639,10 +639,10 @@ class data_sink : public Block> { explicit continuous_listener(std::shared_ptr poller, bool do_block, const data_sink &parent) : parent_sink(parent), block(do_block), polling_handler{ std::move(poller) } {} inline void - call_callback(std::span data, std::span tags) { - if constexpr (std::is_invocable_v, std::span, const data_sink &>) { + call_callback(std::span data, std::span tags) { + if constexpr (std::is_invocable_v, std::span, const data_sink &>) { callback(std::move(data), std::move(tags), parent_sink); - } else if constexpr (std::is_invocable_v, std::span>) { + } else if constexpr (std::is_invocable_v, std::span>) { callback(std::move(data), std::move(tags)); } else { callback(std::move(data)); @@ -660,7 +660,7 @@ class data_sink : public Block> { detail::copy_span(data.first(n), std::span(buffer).subspan(buffer_fill, n)); if constexpr (callback_takes_tags) { if (tag_data0) { - tag_buffer.push_back({ static_cast(buffer_fill), *tag_data0 }); + tag_buffer.push_back({ static_cast(buffer_fill), *tag_data0 }); tag_data0.reset(); } } @@ -678,7 +678,7 @@ class data_sink : public Block> { // send out complete chunks directly while (data.size() >= buffer.size()) { if constexpr (callback_takes_tags) { - std::vector tags; + std::vector tags; if (tag_data0) { tags.push_back({ 0, std::move(*tag_data0) }); tag_data0.reset(); @@ -713,7 +713,7 @@ class data_sink : public Block> { if (to_write > 0) { if (tag_data0) { auto tw = poller->tag_writer.reserve_output_range(1); - tw[0] = { static_cast(samples_written), std::move(*tag_data0) }; + tw[0] = { static_cast(samples_written), std::move(*tag_data0) }; tw.publish(1); } auto write_data = poller->writer.reserve_output_range(to_write); @@ -800,14 +800,14 @@ class data_sink : public Block> { void process(std::span history, std::span in_data, std::optional tag_data0) override { - if (tag_data0 && trigger_matcher(tag_t{ 0, *tag_data0 }) == trigger_match_result::Matching) { + if (tag_data0 && trigger_matcher(Tag{ 0, *tag_data0 }) == trigger_match_result::Matching) { DataSet dataset = dataset_template; dataset.signal_values.reserve(pre_samples + post_samples); // TODO maybe make the circ. buffer smaller but preallocate these const auto pre_sample_view = history.last(std::min(pre_samples, history.size())); dataset.signal_values.insert(dataset.signal_values.end(), pre_sample_view.begin(), pre_sample_view.end()); - dataset.timing_events = { { { static_cast(pre_sample_view.size()), *tag_data0 } } }; + dataset.timing_events = { { { static_cast(pre_sample_view.size()), *tag_data0 } } }; pending_trigger_windows.push_back({ .dataset = std::move(dataset), .pending_post_samples = post_samples }); } @@ -892,11 +892,11 @@ class data_sink : public Block> { void process(std::span, std::span in_data, std::optional tag_data0) override { if (tag_data0) { - const auto obsr = matcher(tag_t{ 0, *tag_data0 }); + const auto obsr = matcher(Tag{ 0, *tag_data0 }); if (obsr == trigger_match_result::NotMatching || obsr == trigger_match_result::Matching) { if (pending_dataset) { if (obsr == trigger_match_result::NotMatching) { - pending_dataset->timing_events[0].push_back({ static_cast(pending_dataset->signal_values.size()), *tag_data0 }); + pending_dataset->timing_events[0].push_back({ static_cast(pending_dataset->signal_values.size()), *tag_data0 }); } this->publish_dataset(std::move(*pending_dataset)); pending_dataset.reset(); @@ -1011,7 +1011,7 @@ class data_sink : public Block> { } DataSet dataset = dataset_template; - dataset.timing_events = { { { -static_cast(it->delay), std::move(it->tag_data) } } }; + dataset.timing_events = { { { -static_cast(it->delay), std::move(it->tag_data) } } }; dataset.signal_values = { in_data[it->pending_samples] }; this->publish_dataset(std::move(dataset)); diff --git a/blocks/basic/include/gnuradio-4.0/basic/selector.hpp b/blocks/basic/include/gnuradio-4.0/basic/selector.hpp index cca9653e2..954fb3cb3 100644 --- a/blocks/basic/include/gnuradio-4.0/basic/selector.hpp +++ b/blocks/basic/include/gnuradio-4.0/basic/selector.hpp @@ -82,7 +82,7 @@ struct Selector : Block, SelectorDoc> { std::uint32_t _selectedSrc = -1U; void - settings_changed(const gr::property_map &old_settings, const gr::property_map &new_settings) { + settingsChanged(const gr::property_map &old_settings, const gr::property_map &new_settings) { if (new_settings.contains("nInputs") || new_settings.contains("nOutputs")) { fmt::print("{}: configuration changed: nInputs {} -> {}, nOutputs {} -> {}\n", static_cast(this), old_settings.at("nInputs"), new_settings.contains("nInputs") ? new_settings.at("nInputs") : "same", old_settings.at("nOutputs"), new_settings.contains("nOutputs") ? new_settings.at("nOutputs") : "same"); diff --git a/blocks/basic/test/qa_data_sink.cpp b/blocks/basic/test/qa_data_sink.cpp index ca31dd1bd..16e555e78 100644 --- a/blocks/basic/test/qa_data_sink.cpp +++ b/blocks/basic/test/qa_data_sink.cpp @@ -20,7 +20,7 @@ auto boost::ut::cfg = boost::ut::runner -struct fmt::formatter { +struct fmt::formatter { template constexpr auto parse(ParseContext &ctx) { @@ -29,7 +29,7 @@ struct fmt::formatter { template constexpr auto - format(const gr::tag_t &tag, FormatContext &ctx) const { + format(const gr::Tag &tag, FormatContext &ctx) const { return fmt::format_to(ctx.out(), "{}", tag.index); } }; @@ -38,17 +38,17 @@ namespace gr::basic::data_sink_test { template struct Source : public Block> { - PortOut out; - std::int32_t n_samples_produced = 0; - std::int32_t n_samples_max = 1024; - std::size_t n_tag_offset = 0; - float sample_rate = 1000.0f; - T next_value = {}; - std::size_t next_tag = 0; - std::vector tags; // must be sorted by index, only one tag per sample + PortOut out; + std::int32_t n_samples_produced = 0; + std::int32_t n_samples_max = 1024; + std::size_t n_tag_offset = 0; + float sample_rate = 1000.0f; + T next_value = {}; + std::size_t next_tag = 0; + std::vector tags; // must be sorted by index, only one tag per sample void - settings_changed(const property_map &, const property_map &) { + settingsChanged(const property_map &, const property_map &) { // optional init function that is called after construction and whenever settings change gr::publish_tag(out, { { "n_samples_max", n_samples_max } }, n_tag_offset); } @@ -73,12 +73,12 @@ struct Source : public Block> { T processOne() noexcept { if (next_tag < tags.size() && tags[next_tag].index <= static_cast>(n_samples_produced)) { - tag_t &out_tag = this->output_tags()[0]; + Tag &out_tag = this->output_tags()[0]; // TODO when not enforcing single samples in available_samples, one would have to do: - // const auto base = std::max(out.streamWriter().position() + 1, tag_t::signed_index_type{0}); - // out_tag = tag_t{ tags[next_tag].index - base, tags[next_tag].map }; + // const auto base = std::max(out.streamWriter().position() + 1, Tag::signed_index_type{0}); + // out_tag = Tag{ tags[next_tag].index - base, tags[next_tag].map }; // Still think there could be nicer API to set a tag from processOne() - out_tag = tag_t{ 0, tags[next_tag].map }; + out_tag = Tag{ 0, tags[next_tag].map }; this->forward_tags(); next_tag++; } @@ -120,7 +120,7 @@ struct Matcher { } trigger_match_result - operator()(const tag_t &tag) { + operator()(const Tag &tag) { const auto ty = tag.get("YEAR"); const auto tm = tag.get("MONTH"); const auto td = tag.get("DAY"); @@ -157,14 +157,14 @@ struct Matcher { } }; -static tag_t -make_tag(tag_t::signed_index_type index, int year, int month, int day) { - return tag_t{ index, { { "YEAR", year }, { "MONTH", month }, { "DAY", day } } }; +static Tag +make_tag(Tag::signed_index_type index, int year, int month, int day) { + return Tag{ index, { { "YEAR", year }, { "MONTH", month }, { "DAY", day } } }; } -static std::vector -make_test_tags(tag_t::signed_index_type first_index, tag_t::signed_index_type interval) { - std::vector tags; +static std::vector +make_test_tags(Tag::signed_index_type first_index, Tag::signed_index_type interval) { + std::vector tags; for (int y = 1; y <= 3; ++y) { for (int m = 1; m <= 2; ++m) { for (int d = 1; d <= 3; ++d) { @@ -198,7 +198,7 @@ to_ascii_art(std::span states) { template std::string -run_matcher_test(std::span tags, M o) { +run_matcher_test(std::span tags, M o) { std::vector r; r.reserve(tags.size()); for (const auto &tag : tags) { @@ -262,11 +262,11 @@ const boost::ut::suite DataSinkTests = [] { } }; - std::mutex m2; - std::size_t samples_seen2 = 0; - std::size_t chunks_seen2 = 0; - std::vector received_tags; - auto callback_with_tags = [&samples_seen2, &chunks_seen2, &m2, &received_tags](std::span buffer, std::span tags) { + std::mutex m2; + std::size_t samples_seen2 = 0; + std::size_t chunks_seen2 = 0; + std::vector received_tags; + auto callback_with_tags = [&samples_seen2, &chunks_seen2, &m2, &received_tags](std::span buffer, std::span tags) { for (std::size_t i = 0; i < buffer.size(); ++i) { expect(eq(buffer[i], static_cast(samples_seen2 + i))); } @@ -276,10 +276,10 @@ const boost::ut::suite DataSinkTests = [] { expect(lt(tag.index, static_cast(buffer.size()))); } - auto lg = std::lock_guard{ m2 }; - std::vector adjusted; + auto lg = std::lock_guard{ m2 }; + std::vector adjusted; std::transform(tags.begin(), tags.end(), std::back_inserter(adjusted), [samples_seen2](const auto &tag) { - return tag_t{ static_cast(samples_seen2) + tag.index, tag.map }; + return Tag{ static_cast(samples_seen2) + tag.index, tag.map }; }); received_tags.insert(received_tags.end(), adjusted.begin(), adjusted.end()); samples_seen2 += buffer.size(); @@ -291,7 +291,7 @@ const boost::ut::suite DataSinkTests = [] { } }; - auto callback_with_tags_and_sink = [&sink](std::span, std::span, const data_sink &passed_sink) { + auto callback_with_tags_and_sink = [&sink](std::span, std::span, const data_sink &passed_sink) { expect(eq(passed_sink.name.value, "test_sink"s)); expect(eq(sink.unique_name, passed_sink.unique_name)); }; @@ -344,12 +344,12 @@ const boost::ut::suite DataSinkTests = [] { auto runner2 = std::async([poller = poller_with_tags] { std::vector received; - std::vector received_tags; + std::vector received_tags; bool seen_finished = false; while (!seen_finished) { seen_finished = poller->finished; while (poller->process([&received, &received_tags](const auto &data, const auto &tags_) { - auto rtags = std::vector(tags_.begin(), tags_.end()); + auto rtags = std::vector(tags_.begin(), tags_.end()); for (auto &t : rtags) { t.index += static_cast(received.size()); } @@ -387,14 +387,14 @@ const boost::ut::suite DataSinkTests = [] { gr::Graph testGraph; auto &src = testGraph.emplaceBlock>({ { "n_samples_max", n_samples } }); - const auto tags = std::vector{ { 3000, { { "TYPE", "TRIGGER" } } }, { 8000, { { "TYPE", "NO_TRIGGER" } } }, { 180000, { { "TYPE", "TRIGGER" } } } }; + const auto tags = std::vector{ { 3000, { { "TYPE", "TRIGGER" } } }, { 8000, { { "TYPE", "NO_TRIGGER" } } }, { 180000, { { "TYPE", "TRIGGER" } } } }; src.tags = tags; auto &sink = testGraph.emplaceBlock>( { { "name", "test_sink" }, { "signal_name", "test signal" }, { "signal_unit", "none" }, { "signal_min", int32_t{ 0 } }, { "signal_max", int32_t{ n_samples - 1 } } }); expect(eq(ConnectionResult::SUCCESS, testGraph.connect<"out">(src).to<"in">(sink))); - auto is_trigger = [](const tag_t &tag) { + auto is_trigger = [](const Tag &tag) { const auto v = tag.get("TYPE"); return v && std::get(v->get()) == "TRIGGER" ? trigger_match_result::Matching : trigger_match_result::Ignore; }; @@ -405,7 +405,7 @@ const boost::ut::suite DataSinkTests = [] { auto polling = std::async([poller] { std::vector received_data; - std::vector received_tags; + std::vector received_tags; bool seen_finished = false; while (!seen_finished) { seen_finished = poller->finished; @@ -461,7 +461,7 @@ const boost::ut::suite DataSinkTests = [] { expect(eq(ConnectionResult::SUCCESS, testGraph.connect<"out">(src).to<"in">(sink))); - auto is_trigger = [](const tag_t &tag) { + auto is_trigger = [](const Tag &tag) { const auto v = tag.get("TYPE"); return (v && std::get(v->get()) == "TRIGGER") ? trigger_match_result::Matching : trigger_match_result::Ignore; }; @@ -603,21 +603,21 @@ const boost::ut::suite DataSinkTests = [] { auto &src = testGraph.emplaceBlock>({ { "n_samples_max", n_samples } }); for (std::size_t i = 0; i < n_triggers; ++i) { - src.tags.push_back(tag_t{ static_cast(60000 + i), { { "TYPE", "TRIGGER" } } }); + src.tags.push_back(Tag{ static_cast(60000 + i), { { "TYPE", "TRIGGER" } } }); } auto &sink = testGraph.emplaceBlock>({ { "name", "test_sink" } }); expect(eq(ConnectionResult::SUCCESS, testGraph.connect<"out">(src).to<"in">(sink))); - auto is_trigger = [](const tag_t &) { return trigger_match_result::Matching; }; + auto is_trigger = [](const Tag &) { return trigger_match_result::Matching; }; auto poller = data_sink_registry::instance().get_trigger_poller(data_sink_query::sink_name("test_sink"), is_trigger, 3000, 2000, blocking_mode::Blocking); expect(neq(poller, nullptr)); auto polling = std::async([poller] { std::vector received_data; - std::vector received_tags; + std::vector received_tags; bool seen_finished = false; while (!seen_finished) { seen_finished = poller->finished.load(); @@ -658,14 +658,14 @@ const boost::ut::suite DataSinkTests = [] { auto &src = testGraph.emplaceBlock>({ { "n_samples_max", n_samples } }); for (std::size_t i = 0; i < n_triggers; ++i) { - src.tags.push_back(tag_t{ static_cast(60000 + i), { { "TYPE", "TRIGGER" } } }); + src.tags.push_back(Tag{ static_cast(60000 + i), { { "TYPE", "TRIGGER" } } }); } auto &sink = testGraph.emplaceBlock>({ { "name", "test_sink" } }); expect(eq(ConnectionResult::SUCCESS, testGraph.connect<"out">(src).to<"in">(sink))); - auto is_trigger = [](const tag_t &) { return trigger_match_result::Matching; }; + auto is_trigger = [](const Tag &) { return trigger_match_result::Matching; }; std::mutex m; std::vector received_data; diff --git a/blocks/basic/test/qa_selector.cpp b/blocks/basic/test/qa_selector.cpp index 848484397..2dbb308e0 100644 --- a/blocks/basic/test/qa_selector.cpp +++ b/blocks/basic/test/qa_selector.cpp @@ -22,7 +22,7 @@ struct repeated_source : public gr::Block> { gr::PortOut out; void - settings_changed(const gr::property_map & /*old_settings*/, const gr::property_map &new_settings) noexcept { + settingsChanged(const gr::property_map & /*old_settings*/, const gr::property_map &new_settings) noexcept { if (new_settings.contains("values")) { values_next = values.cbegin(); } @@ -75,7 +75,7 @@ struct validator_sink : public gr::Block> { } void - settings_changed(const gr::property_map & /*old_settings*/, const gr::property_map &new_settings) noexcept { + settingsChanged(const gr::property_map & /*old_settings*/, const gr::property_map &new_settings) noexcept { if (new_settings.contains("expected_values")) { expected_values_next = expected_values.cbegin(); } @@ -153,20 +153,20 @@ execute_selector_test(test_definition definition) { sources.push_back(std::addressof(graph.emplaceBlock>({ { "remaining_events_count", definition.value_count }, // { "identifier", source_index }, // { "values", definition.input_values[source_index] } }))); - expect(sources[source_index]->settings().apply_staged_parameters().empty()); + expect(sources[source_index]->settings().applyStagedParameters().empty()); expect(gr::ConnectionResult::SUCCESS == graph.dynamic_connect(*sources[source_index], 0, *selector, source_index + 1 /* there's one port before the inputs */)); } for (std::uint32_t sink_index = 0; sink_index < sinks_count; ++sink_index) { sinks.push_back(std::addressof(graph.emplaceBlock>({ { "identifier", sink_index }, // { "expected_values", definition.output_values[sink_index] } }))); - expect(sinks[sink_index]->settings().apply_staged_parameters().empty()); + expect(sinks[sink_index]->settings().applyStagedParameters().empty()); expect(gr::ConnectionResult::SUCCESS == graph.dynamic_connect(*selector, sink_index + 1 /* there's one port before the outputs */, *sinks[sink_index], 0)); } validator_sink *monitor_sink = std::addressof(graph.emplaceBlock>({ { "identifier", static_cast(-1) }, // { "expected_values", definition.monitor_values } })); - expect(monitor_sink->settings().apply_staged_parameters().empty()); + expect(monitor_sink->settings().applyStagedParameters().empty()); expect(gr::ConnectionResult::SUCCESS == graph.dynamic_connect(*selector, 0, *monitor_sink, 0)); for (std::size_t iterration = 0; iterration < definition.value_count * sources_count; ++iterration) { @@ -198,7 +198,7 @@ const boost::ut::suite SelectorTest = [] { "Selector constructor"_test = [] { Selector block_nop({ { "name", "block_nop" } }); - expect(block_nop.settings().apply_staged_parameters().empty()); + expect(block_nop.settings().applyStagedParameters().empty()); expect(eq(block_nop.nInputs, 0U)); expect(eq(block_nop.nOutputs, 0U)); expect(eq(block_nop.inputs.size(), 0U)); @@ -206,7 +206,7 @@ const boost::ut::suite SelectorTest = [] { expect(eq(block_nop._internalMapping.size(), 0U)); Selector block({ { "name", "block" }, { "nInputs", 4U }, { "nOutputs", 3U } }); - expect(block.settings().apply_staged_parameters().empty()); + expect(block.settings().applyStagedParameters().empty()); expect(eq(block.nInputs, 4U)); expect(eq(block.nOutputs, 3U)); expect(eq(block.inputs.size(), 4U)); @@ -218,7 +218,7 @@ const boost::ut::suite SelectorTest = [] { using T = double; const std::vector outputMap{ 1U, 0U }; Selector block({ { "nInputs", 3U }, { "nOutputs", 2U }, { "mapIn", std::vector{ 0U, 1U } }, { "mapOut", outputMap } }); // N.B. 3rd input is unconnected - expect(block.settings().apply_staged_parameters().empty()); + expect(block.settings().applyStagedParameters().empty()); expect(eq(block._internalMapping.size(), 2U)); using internal_mapping_t = decltype(block._internalMapping); diff --git a/blocks/basic/test/qa_sources.cpp b/blocks/basic/test/qa_sources.cpp index 021723860..c4ae5b06b 100644 --- a/blocks/basic/test/qa_sources.cpp +++ b/blocks/basic/test/qa_sources.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include diff --git a/blocks/filter/include/gnuradio-4.0/filter/time_domain_filter.hpp b/blocks/filter/include/gnuradio-4.0/filter/time_domain_filter.hpp index 360ea1831..5de75233d 100644 --- a/blocks/filter/include/gnuradio-4.0/filter/time_domain_filter.hpp +++ b/blocks/filter/include/gnuradio-4.0/filter/time_domain_filter.hpp @@ -23,7 +23,7 @@ H(z) = b[0] + b[1]*z^-1 + b[2]*z^-2 + ... + b[N]*z^-N HistoryBuffer inputHistory{ 32 }; void - settings_changed(const property_map & /*old_settings*/, const property_map &new_settings) noexcept { + settingsChanged(const property_map & /*old_settings*/, const property_map &new_settings) noexcept { if (new_settings.contains("b") && b.size() >= inputHistory.capacity()) { inputHistory = HistoryBuffer(std::bit_ceil(b.size())); } @@ -59,7 +59,7 @@ a are the feedback coefficients HistoryBuffer outputHistory{ 32 }; void - settings_changed(const property_map & /*old_settings*/, const property_map &new_settings) noexcept { + settingsChanged(const property_map & /*old_settings*/, const property_map &new_settings) noexcept { const auto new_size = std::max(a.size(), b.size()); if ((new_settings.contains("b") || new_settings.contains("a")) && (new_size >= inputHistory.capacity() || new_size >= inputHistory.capacity())) { inputHistory = HistoryBuffer(std::bit_ceil(new_size)); diff --git a/blocks/fourier/include/gnuradio-4.0/fourier/fft.hpp b/blocks/fourier/include/gnuradio-4.0/fourier/fft.hpp index 3b015b99e..563fc4fb0 100644 --- a/blocks/fourier/include/gnuradio-4.0/fourier/fft.hpp +++ b/blocks/fourier/include/gnuradio-4.0/fourier/fft.hpp @@ -107,7 +107,7 @@ On the choice of window (mathematically aka. apodisation) functions std::vector _phaseSpectrum = std::vector(_outData.size(), 0); void - settings_changed(const property_map & /*old_settings*/, const property_map &newSettings) noexcept { + settingsChanged(const property_map & /*old_settings*/, const property_map &newSettings) noexcept { if (!newSettings.contains("fftSize") && !newSettings.contains("window")) { // do need to only handle interdependent settings -> can early return return; diff --git a/blocks/fourier/test/qa_fourier.cpp b/blocks/fourier/test/qa_fourier.cpp index 55650c0c8..d4325a450 100644 --- a/blocks/fourier/test/qa_fourier.cpp +++ b/blocks/fourier/test/qa_fourier.cpp @@ -167,7 +167,7 @@ const boost::ut::suite<"Fourier Transforms"> fftTests = [] { std::ignore = fftBlock.settings().set({ { "fftSize", t.N } }); std::ignore = fftBlock.settings().set({ { "outputInDb", t.outputInDb } }); std::ignore = fftBlock.settings().set({ { "window", "None" } }); - std::ignore = fftBlock.settings().apply_staged_parameters(); + std::ignore = fftBlock.settings().applyStagedParameters(); const auto signal{ generateSinSample(t.N, t.sample_rate, t.frequency, t.amplitude) }; std::vector resultingDataSets(1); expect(gr::work::Status::OK == fftBlock.processBulk(signal, resultingDataSets)); @@ -192,7 +192,7 @@ const boost::ut::suite<"Fourier Transforms"> fftTests = [] { constexpr double tolerance{ 1.e-5 }; constexpr std::uint32_t N{ 16 }; FFT fftBlock({ { "fftSize", N }, { "window", "None" } }); - std::ignore = fftBlock.settings().apply_staged_parameters(); + std::ignore = fftBlock.settings().applyStagedParameters(); std::vector signal(N); @@ -244,7 +244,7 @@ const boost::ut::suite<"Fourier Transforms"> fftTests = [] { constexpr std::uint32_t N{ 16 }; constexpr float sample_rate{ 1.f }; FFT fftBlock({ { "fftSize", N }, { "sample_rate", sample_rate } }); - std::ignore = fftBlock.settings().apply_staged_parameters(); + std::ignore = fftBlock.settings().applyStagedParameters(); expect(eq(fftBlock.algorithm, gr::meta::type_name())); std::vector signal(N); @@ -325,7 +325,7 @@ const boost::ut::suite<"Fourier Transforms"> fftTests = [] { for (const auto &window : gr::algorithm::window::TypeList) { std::ignore = fftBlock.settings().set({ { "fftSize", N } }); std::ignore = fftBlock.settings().set({ { "window", std::string(gr::algorithm::window::to_string(window)) } }); - std::ignore = fftBlock.settings().apply_staged_parameters(); + std::ignore = fftBlock.settings().applyStagedParameters(); std::vector signal(N); if constexpr (gr::algorithm::ComplexType) { diff --git a/blocks/testing/include/gnuradio-4.0/testing/bm_test_helper.hpp b/blocks/testing/include/gnuradio-4.0/testing/bm_test_helper.hpp index 04fc359ac..545d74a35 100644 --- a/blocks/testing/include/gnuradio-4.0/testing/bm_test_helper.hpp +++ b/blocks/testing/include/gnuradio-4.0/testing/bm_test_helper.hpp @@ -7,7 +7,7 @@ #include #include -#include +#include inline constexpr std::size_t N_MAX = std::numeric_limits::max(); diff --git a/blocks/testing/include/gnuradio-4.0/testing/tag_monitors.hpp b/blocks/testing/include/gnuradio-4.0/testing/tag_monitors.hpp index ec01c6b40..eafdec633 100644 --- a/blocks/testing/include/gnuradio-4.0/testing/tag_monitors.hpp +++ b/blocks/testing/include/gnuradio-4.0/testing/tag_monitors.hpp @@ -6,7 +6,7 @@ #include #include -#include +#include namespace gr::testing { @@ -16,7 +16,7 @@ enum class ProcessFunction { }; void -print_tag(const tag_t &tag, std::string_view prefix = {}) { +print_tag(const Tag &tag, std::string_view prefix = {}) { fmt::print("{} @index= {}: {{", prefix, tag.index); if (tag.map.empty()) { fmt::print("}}\n"); @@ -65,7 +65,7 @@ mismatch_report(const IterType &mismatchedTag1, const IterType &mismatchedTag2, } bool -equal_tag_lists(const std::vector &tags1, const std::vector &tags2) { +equal_tag_lists(const std::vector &tags1, const std::vector &tags2) { if (tags1.size() != tags2.size()) { fmt::print("vectors have different sizes ({} vs {})\n", tags1.size(), tags2.size()); return false; @@ -81,11 +81,11 @@ equal_tag_lists(const std::vector &tags1, const std::vector &tags2 template struct TagSource : public Block> { - PortOut out; - std::vector tags{}; - std::size_t next_tag{ 0 }; - std::int64_t n_samples_max = 1024; - std::int64_t n_samples_produced{ 0 }; + PortOut out; + std::vector tags{}; + std::size_t next_tag{ 0 }; + std::int64_t n_samples_max = 1024; + std::int64_t n_samples_produced{ 0 }; constexpr std::make_signed_t available_samples(const TagSource &) noexcept { @@ -93,7 +93,7 @@ struct TagSource : public Block> { // '-1' -> DONE, produced enough samples return n_samples_max == n_samples_produced ? -1 : n_samples_max - n_samples_produced; } else if constexpr (UseProcessOne == ProcessFunction::USE_PROCESS_BULK) { - tag_t::signed_index_type nextTagIn = next_tag < tags.size() ? tags[next_tag].index - n_samples_produced : n_samples_max - n_samples_produced; + Tag::signed_index_type nextTagIn = next_tag < tags.size() ? tags[next_tag].index - n_samples_produced : n_samples_max - n_samples_produced; return n_samples_produced < n_samples_max ? std::max(1L, nextTagIn) : -1L; // '-1L' -> DONE, produced enough samples } else { static_assert(gr::meta::always_false, "ProcessFunction-type not handled"); @@ -106,9 +106,9 @@ struct TagSource : public Block> { { if (next_tag < tags.size() && tags[next_tag].index <= n_samples_produced) { print_tag(tags[next_tag], fmt::format("{}::processOne(...)\t publish tag at {:6}", this->name.value, n_samples_produced)); - tag_t &out_tag = this->output_tags()[0]; - out_tag = tags[next_tag]; - out_tag.index = offset; + Tag &out_tag = this->output_tags()[0]; + out_tag = tags[next_tag]; + out_tag.index = offset; this->forward_tags(); next_tag++; n_samples_produced++; @@ -125,9 +125,9 @@ struct TagSource : public Block> { { if (next_tag < tags.size() && tags[next_tag].index <= n_samples_produced) { print_tag(tags[next_tag], fmt::format("{}::processBulk(...{})\t publish tag at {:6}", this->name, output.size(), n_samples_produced)); - tag_t &out_tag = this->output_tags()[0]; - out_tag = tags[next_tag]; - out_tag.index = 0; // indices > 0 write tags in the future ... handle with care + Tag &out_tag = this->output_tags()[0]; + out_tag = tags[next_tag]; + out_tag.index = 0; // indices > 0 write tags in the future ... handle with care this->forward_tags(); next_tag++; } @@ -139,17 +139,17 @@ struct TagSource : public Block> { template struct TagMonitor : public Block> { - PortIn in; - PortOut out; - std::vector tags{}; - std::int64_t n_samples_produced{ 0 }; + PortIn in; + PortOut out; + std::vector tags{}; + std::int64_t n_samples_produced{ 0 }; constexpr T processOne(const T &input) noexcept requires(UseProcessOne == ProcessFunction::USE_PROCESS_ONE) { if (this->input_tags_present()) { - const tag_t &tag = this->input_tags()[0]; + const Tag &tag = this->input_tags()[0]; print_tag(tag, fmt::format("{}::processOne(...)\t received tag at {:6}", this->name, n_samples_produced)); tags.emplace_back(n_samples_produced, tag.map); this->forward_tags(); @@ -163,7 +163,7 @@ struct TagMonitor : public Block> { requires(UseProcessOne == ProcessFunction::USE_PROCESS_BULK) { if (this->input_tags_present()) { - const tag_t &tag = this->input_tags()[0]; + const Tag &tag = this->input_tags()[0]; print_tag(tag, fmt::format("{}::processBulk(...{}, ...{})\t received tag at {:6}", this->name, input.size(), output.size(), n_samples_produced)); tags.emplace_back(n_samples_produced, tag.map); this->forward_tags(); @@ -180,7 +180,7 @@ template struct TagSink : public Block> { using ClockSourceType = std::chrono::system_clock; PortIn in; - std::vector tags{}; + std::vector tags{}; std::int64_t n_samples_produced{ 0 }; std::chrono::time_point timeFirstSample = ClockSourceType::now(); std::chrono::time_point timeLastSample = ClockSourceType::now(); @@ -194,7 +194,7 @@ struct TagSink : public Block> { timeFirstSample = ClockSourceType::now(); } if (this->input_tags_present()) { - const tag_t &tag = this->input_tags()[0]; + const Tag &tag = this->input_tags()[0]; print_tag(tag, fmt::format("{}::processOne(...1) \t received tag at {:6}", this->name, n_samples_produced)); tags.emplace_back(n_samples_produced, tag.map); this->forward_tags(); @@ -212,7 +212,7 @@ struct TagSink : public Block> { timeFirstSample = ClockSourceType::now(); } if (this->input_tags_present()) { - const tag_t &tag = this->input_tags()[0]; + const Tag &tag = this->input_tags()[0]; print_tag(tag, fmt::format("{}::processBulk(...{})\t received tag at {:6}", this->name, input.size(), n_samples_produced)); tags.emplace_back(n_samples_produced, tag.map); this->forward_tags(); diff --git a/core/benchmarks/bm_fft.cpp b/core/benchmarks/bm_fft.cpp index 6d65b351b..3ccba915e 100644 --- a/core/benchmarks/bm_fft.cpp +++ b/core/benchmarks/bm_fft.cpp @@ -79,7 +79,7 @@ testFFT() { { gr::blocks::fft::FFT, FFTw>> fft1({ { "fftSize", N } }); - std::ignore = fft1.settings().apply_staged_parameters(); + std::ignore = fft1.settings().applyStagedParameters(); std::vector> resultingDataSets(1); ::benchmark::benchmark(fmt::format("{} - fftw", type_name())) = [&fft1, &signal, &resultingDataSets] { @@ -88,7 +88,7 @@ testFFT() { } { gr::blocks::fft::FFT, FFT>> fft1({ { "fftSize", N } }); - std::ignore = fft1.settings().apply_staged_parameters(); + std::ignore = fft1.settings().applyStagedParameters(); std::vector> resultingDataSets(1); ::benchmark::benchmark(fmt::format("{} - fft", type_name())) = [&fft1, &signal, &resultingDataSets] { diff --git a/core/include/gnuradio-4.0/Block.hpp b/core/include/gnuradio-4.0/Block.hpp index 7fd68631c..fca616362 100644 --- a/core/include/gnuradio-4.0/Block.hpp +++ b/core/include/gnuradio-4.0/Block.hpp @@ -10,12 +10,12 @@ #include "BlockTraits.hpp" #include "Port.hpp" #include "Sequence.hpp" -#include "tag.hpp" +#include "Tag.hpp" #include "thread/thread_pool.hpp" #include "annotated.hpp" // This needs to be included after fmt/format.h, as it defines formatters only if FMT_FORMAT_H_ is defined #include "reflection.hpp" -#include "settings.hpp" +#include "Settings.hpp" #ifdef FMT_FORMAT_H_ #include @@ -176,7 +176,7 @@ concept BlockLike = requires(T t, std::size_t requested_work) { { t.isBlocking() } noexcept -> std::same_as; - { t.settings() } -> std::same_as; + { t.settings() } -> std::same_as; { t.work(requested_work) } -> std::same_as; // N.B. TODO discuss these requirements @@ -319,7 +319,7 @@ struct Block : protected std::tuple { alignas(hardware_destructive_interference_size) std::shared_ptr ioThreadPool = std::make_shared( "block_thread_pool", gr::thread_pool::TaskType::IO_BOUND, 2_UZ, std::numeric_limits::max()); - constexpr static tag_propagation_policy_t tag_policy = tag_propagation_policy_t::TPP_ALL_TO_ALL; + constexpr static TagPropagationPolicy tag_policy = TagPropagationPolicy::TPP_ALL_TO_ALL; // using RatioValue = std::conditional_t; A1: Interpolate, =1: No change)">, Limits<1_UZ, std::size_t(-1)>> numerator = Resampling::kNumerator; @@ -366,13 +366,13 @@ struct Block : protected std::tuple { PortsStatus ports_status{}; protected: - bool _input_tags_present = false; - bool _output_tags_changed = false; - std::vector _tags_at_input; - std::vector _tags_at_output; + bool _input_tags_present = false; + bool _output_tags_changed = false; + std::vector _tags_at_input; + std::vector _tags_at_output; // intermediate non-real-time<->real-time setting states - std::unique_ptr _settings = std::make_unique>(self()); + std::unique_ptr _settings = std::make_unique>(self()); [[nodiscard]] constexpr auto & self() noexcept { @@ -460,7 +460,7 @@ struct Block : protected std::tuple { Block(std::initializer_list> init_parameter) : _tags_at_input(traits::block::input_port_types::size()) , _tags_at_output(traits::block::output_port_types::size()) - , _settings(std::make_unique>(*static_cast(this))) { // N.B. safe delegated use of this (i.e. not used during construction) + , _settings(std::make_unique>(*static_cast(this))) { // N.B. safe delegated use of this (i.e. not used during construction) if (init_parameter.size() != 0) { const auto failed = settings().set(init_parameter); if (!failed.empty()) { @@ -480,8 +480,8 @@ struct Block : protected std::tuple { init(std::shared_ptr progress_, std::shared_ptr ioThreadPool_) { progress = std::move(progress_); ioThreadPool = std::move(ioThreadPool_); - if (const auto forward_parameters = settings().apply_staged_parameters(); !forward_parameters.empty()) { - std::for_each(_tags_at_output.begin(), _tags_at_output.end(), [&forward_parameters](tag_t &tag) { + if (const auto forward_parameters = settings().applyStagedParameters(); !forward_parameters.empty()) { + std::for_each(_tags_at_output.begin(), _tags_at_output.end(), [&forward_parameters](Tag &tag) { for (const auto &[key, value] : forward_parameters) { tag.map.insert_or_assign(key, value); } @@ -489,8 +489,8 @@ struct Block : protected std::tuple { _output_tags_changed = true; } - // store default settings -> can be recovered with 'reset_defaults()' - settings().store_defaults(); + // store default settings -> can be recovered with 'resetDefaults()' + settings().storeDefaults(); } void @@ -572,28 +572,28 @@ struct Block : protected std::tuple { return false; }; - [[nodiscard]] constexpr std::span + [[nodiscard]] constexpr std::span input_tags() const noexcept { return { _tags_at_input.data(), _tags_at_input.size() }; } - [[nodiscard]] constexpr std::span + [[nodiscard]] constexpr std::span output_tags() const noexcept { return { _tags_at_output.data(), _tags_at_output.size() }; } - [[nodiscard]] constexpr std::span + [[nodiscard]] constexpr std::span output_tags() noexcept { _output_tags_changed = true; return { _tags_at_output.data(), _tags_at_output.size() }; } - [[nodiscard]] constexpr settings_base & + [[nodiscard]] constexpr SettingsBase & settings() const noexcept { return *_settings; } - [[nodiscard]] constexpr settings_base & + [[nodiscard]] constexpr SettingsBase & settings() noexcept { return *_settings; } @@ -740,8 +740,8 @@ struct Block : protected std::tuple { // clear input/output tags after processing, N.B. ranges omitted because of missing Clang/Emscripten support _input_tags_present = false; _output_tags_changed = false; - std::for_each(_tags_at_input.begin(), _tags_at_input.end(), [](tag_t &tag) { tag.reset(); }); - std::for_each(_tags_at_output.begin(), _tags_at_output.end(), [](tag_t &tag) { tag.reset(); }); + std::for_each(_tags_at_input.begin(), _tags_at_input.end(), [](Tag &tag) { tag.reset(); }); + std::for_each(_tags_at_output.begin(), _tags_at_output.end(), [](Tag &tag) { tag.reset(); }); } protected: @@ -922,19 +922,19 @@ struct Block : protected std::tuple { inputPorts(&self())); if (_input_tags_present && !merged_tag_map.empty()) { // apply tags as new settings if matching - settings().auto_update(merged_tag_map); + settings().autoUpdate(merged_tag_map); } - if constexpr (Derived::tag_policy == tag_propagation_policy_t::TPP_ALL_TO_ALL) { + if constexpr (Derived::tag_policy == TagPropagationPolicy::TPP_ALL_TO_ALL) { // N.B. ranges omitted because of missing Clang/Emscripten support - std::for_each(_tags_at_output.begin(), _tags_at_output.end(), [&merged_tag_map](tag_t &tag) { tag.map = merged_tag_map; }); + std::for_each(_tags_at_output.begin(), _tags_at_output.end(), [&merged_tag_map](Tag &tag) { tag.map = merged_tag_map; }); _output_tags_changed = true; } } if (settings().changed() || _input_tags_present || _output_tags_changed) { - if (const auto forward_parameters = settings().apply_staged_parameters(); !forward_parameters.empty()) { - std::for_each(_tags_at_output.begin(), _tags_at_output.end(), [&forward_parameters](tag_t &tag) { + if (const auto forward_parameters = settings().applyStagedParameters(); !forward_parameters.empty()) { + std::for_each(_tags_at_output.begin(), _tags_at_output.end(), [&forward_parameters](Tag &tag) { for (const auto &[key, value] : forward_parameters) { tag.map.insert_or_assign(key, value); } diff --git a/core/include/gnuradio-4.0/DataSet.hpp b/core/include/gnuradio-4.0/DataSet.hpp index a6a4e819a..7d5cf317b 100644 --- a/core/include/gnuradio-4.0/DataSet.hpp +++ b/core/include/gnuradio-4.0/DataSet.hpp @@ -1,12 +1,12 @@ #ifndef GNURADIO_DATASET_HPP #define GNURADIO_DATASET_HPP +#include "reflection.hpp" +#include "Tag.hpp" #include #include #include #include -#include "reflection.hpp" -#include "tag.hpp" #include #include @@ -72,7 +72,7 @@ concept DataSetLike = TensorLike && requires(T t, const std::size_t n_items) // meta data std::is_same_v>; - std::is_same_v>>; + std::is_same_v>>; }; template @@ -99,8 +99,8 @@ struct DataSet { std::vector> signal_ranges; // [[min_0, max_0], [min_1, max_1], …] used for communicating, for example, HW limits // meta data - std::vector meta_information; - std::vector> timing_events; + std::vector meta_information; + std::vector> timing_events; }; static_assert(DataSetLike>, "DataSet concept conformity"); @@ -118,8 +118,8 @@ struct Tensor { using pmt_map = std::map; std::int64_t timestamp = 0; // UTC timestamp [ns] - std::vector extents; // extents[dim0_size, dim1_size, …] - tensor_layout_type layout; // row-major, column-major, “special” + std::vector extents; // extents[dim0_size, dim1_size, …] + tensor_layout_type layout; // row-major, column-major, “special” std::vector signal_values; // size = \PI_i extents[i] std::vector signal_errors; // size = \PI_i extents[i] or '0' if not applicable @@ -148,8 +148,8 @@ static_assert(PacketLike>, "Packet concept conformity" } // namespace gr -ENABLE_REFLECTION(gr::DataSet_double, timestamp, axis_names, axis_units, axis_values, extents, layout, signal_names, signal_units, signal_values, signal_errors, signal_ranges, - meta_information, timing_events) -ENABLE_REFLECTION(gr::DataSet_float, timestamp, axis_names, axis_units, axis_values, extents, layout, signal_names, signal_units, signal_values, signal_errors, signal_ranges, - meta_information, timing_events) +ENABLE_REFLECTION(gr::DataSet_double, timestamp, axis_names, axis_units, axis_values, extents, layout, signal_names, signal_units, signal_values, signal_errors, signal_ranges, meta_information, + timing_events) +ENABLE_REFLECTION(gr::DataSet_float, timestamp, axis_names, axis_units, axis_values, extents, layout, signal_names, signal_units, signal_values, signal_errors, signal_ranges, meta_information, + timing_events) #endif // GNURADIO_DATASET_HPP diff --git a/core/include/gnuradio-4.0/Graph.hpp b/core/include/gnuradio-4.0/Graph.hpp index 97c08aec8..2ed4f5eac 100644 --- a/core/include/gnuradio-4.0/Graph.hpp +++ b/core/include/gnuradio-4.0/Graph.hpp @@ -155,7 +155,7 @@ class BlockModel { uniqueName() const = 0; - [[nodiscard]] virtual settings_base & + [[nodiscard]] virtual SettingsBase & settings() const = 0; @@ -310,7 +310,7 @@ class BlockWrapper : public BlockModel { return blockRef().unique_name; } - [[nodiscard]] settings_base & + [[nodiscard]] SettingsBase & settings() const override { return blockRef().settings(); } diff --git a/core/include/gnuradio-4.0/Graph_yaml_importer.hpp b/core/include/gnuradio-4.0/Graph_yaml_importer.hpp index 2a93bbcda..990ada77f 100644 --- a/core/include/gnuradio-4.0/Graph_yaml_importer.hpp +++ b/core/include/gnuradio-4.0/Graph_yaml_importer.hpp @@ -117,7 +117,7 @@ load_grc(plugin_loader &loader, const std::string &yaml_source) { // clang-format on } else { - const auto &value = kv.second.as(); + const auto &value = kv.second.as(); currentBlock.metaInformation()[key] = value; } } @@ -126,7 +126,7 @@ load_grc(plugin_loader &loader, const std::string &yaml_source) { std::ignore = currentBlock.settings().set(new_properties); // currentBlock.init(); TODO: reverse and first initialise block via property_map constructor and then add to flow-graph -> does the init implicitely then, this is a workaround for the // apply_staged_settigns - std::ignore = currentBlock.settings().apply_staged_parameters(); + std::ignore = currentBlock.settings().applyStagedParameters(); } for (const auto &connection : tree["connections"]) { diff --git a/core/include/gnuradio-4.0/Port.hpp b/core/include/gnuradio-4.0/Port.hpp index fea219dac..080fd65fb 100644 --- a/core/include/gnuradio-4.0/Port.hpp +++ b/core/include/gnuradio-4.0/Port.hpp @@ -11,7 +11,7 @@ #include "Block.hpp" #include "CircularBuffer.hpp" #include "DataSet.hpp" -#include "tag.hpp" +#include "Tag.hpp" namespace gr { @@ -153,7 +153,7 @@ using is_tag_buffer_attribute = std::bool_constant>; template struct DefaultStreamBuffer : StreamBufferType> {}; -struct DefaultTagBuffer : TagBufferType> {}; +struct DefaultTagBuffer : TagBufferType> {}; static_assert(is_stream_buffer_attribute>::value); static_assert(!is_stream_buffer_attribute::value); @@ -186,7 +186,7 @@ struct Async {}; * ───────────────────┐ ┌─────────────────┤ * output-port │ │ input-port │ ... * stream-buffer │>───────┬─────────────────┬───────────>│ │ - * tag-buffer │ tag#0 tag#1 │ │ + * tag-buffer │ tag#0 tag#1 │ │ * │ │ │ * ───────────────────┘ └─────────────────┤ * @@ -844,7 +844,7 @@ static_assert(PortLike); constexpr void publish_tag(PortLike auto &port, property_map &&tag_data, std::size_t tag_offset = 0) noexcept { port.tagWriter().publish( - [&port, data = std::move(tag_data), &tag_offset](std::span tag_output) { + [&port, data = std::move(tag_data), &tag_offset](std::span tag_output) { tag_output[0].index = port.streamWriter().position() + std::make_signed_t(tag_offset); tag_output[0].map = std::move(data); }, @@ -854,7 +854,7 @@ publish_tag(PortLike auto &port, property_map &&tag_data, std::size_t tag_offset constexpr void publish_tag(PortLike auto &port, const property_map &tag_data, std::size_t tag_offset = 0) noexcept { port.tagWriter().publish( - [&port, &tag_data, &tag_offset](std::span tag_output) { + [&port, &tag_data, &tag_offset](std::span tag_output) { tag_output[0].index = port.streamWriter().position() + tag_offset; tag_output[0].map = tag_data; }, diff --git a/core/include/gnuradio-4.0/Profiler.hpp b/core/include/gnuradio-4.0/Profiler.hpp index 3a0e20a70..1683a98ba 100644 --- a/core/include/gnuradio-4.0/Profiler.hpp +++ b/core/include/gnuradio-4.0/Profiler.hpp @@ -139,11 +139,11 @@ concept ProfilerLike = requires(T p) { { p.forThisThread() } -> ProfilerHandlerLike; }; -enum class output_mode_t { StdOut, File }; +enum class OutputMode { StdOut, File }; -struct options { - std::string output_file; - output_mode_t output_mode = output_mode_t::File; +struct Options { + std::string output_file; + OutputMode output_mode = OutputMode::File; }; namespace null { @@ -199,7 +199,7 @@ class Profiler { Handler _handler; public: - constexpr explicit Profiler(const options & = {}) {} + constexpr explicit Profiler(const Options & = {}) {} constexpr void reset() const {} @@ -309,7 +309,7 @@ class Handler { using this_t = Handler; TProfiler &_profiler; TWriterType _writer; - int _nextId = 1; + int _nextId = 1; public: explicit Handler(TProfiler &profiler, TWriterType &&writer) : _profiler(profiler), _writer{ std::move(writer) } {} @@ -382,17 +382,17 @@ class Profiler { detail::time_point _start = detail::clock::now(); public: - explicit Profiler(const options &options = {}) : _buffer(500000) { + explicit Profiler(const Options &options = {}) : _buffer(500000) { _event_handler = std::thread([options, &reader = _reader, &finished = _finished]() { auto file_name = options.output_file; std::ofstream out_file; - if (file_name.empty() && options.output_mode == output_mode_t::File) { + if (file_name.empty() && options.output_mode == OutputMode::File) { static std::atomic counter = 0; file_name = fmt::format("profile.{}.{}.trace", getpid(), counter++); out_file = std::ofstream(file_name, std::ios::out | std::ios::binary); } - std::ostream &out_stream = options.output_mode == output_mode_t::File ? out_file : std::cout; + std::ostream &out_stream = options.output_mode == OutputMode::File ? out_file : std::cout; const int pid = getpid(); // assign numerical values to threads as we see them diff --git a/core/include/gnuradio-4.0/Scheduler.hpp b/core/include/gnuradio-4.0/Scheduler.hpp index 7cbbed0a5..f0837fdfc 100644 --- a/core/include/gnuradio-4.0/Scheduler.hpp +++ b/core/include/gnuradio-4.0/Scheduler.hpp @@ -31,7 +31,7 @@ class SchedulerBase { public: explicit SchedulerBase(gr::Graph &&graph, std::shared_ptr thread_pool = std::make_shared("simple-scheduler-pool", thread_pool::CPU_BOUND), - const profiling::options &profiling_options = {}) + const profiling::Options &profiling_options = {}) : _graph(std::move(graph)), _profiler{ profiling_options }, _profiler_handler{ _profiler.forThisThread() }, _pool(std::move(thread_pool)) {} ~SchedulerBase() { @@ -188,7 +188,7 @@ class Simple : public SchedulerBase { public: explicit Simple(gr::Graph &&graph, std::shared_ptr thread_pool = std::make_shared("simple-scheduler-pool", thread_pool::CPU_BOUND), - const profiling::options &profiling_options = {}) + const profiling::Options &profiling_options = {}) : SchedulerBase(std::forward(graph), thread_pool, profiling_options) {} void @@ -291,7 +291,7 @@ class BreadthFirst : public SchedulerBase { public: explicit BreadthFirst(gr::Graph &&graph, std::shared_ptr thread_pool = std::make_shared("breadth-first-pool", thread_pool::CPU_BOUND), - const profiling::options &profiling_options = {}) + const profiling::Options &profiling_options = {}) : SchedulerBase(std::move(graph), thread_pool, profiling_options) {} void diff --git a/core/include/gnuradio-4.0/settings.hpp b/core/include/gnuradio-4.0/Settings.hpp similarity index 83% rename from core/include/gnuradio-4.0/settings.hpp rename to core/include/gnuradio-4.0/Settings.hpp index 50dfb13e4..d0885a198 100644 --- a/core/include/gnuradio-4.0/settings.hpp +++ b/core/include/gnuradio-4.0/Settings.hpp @@ -13,7 +13,7 @@ #include "Block.hpp" #include "BlockTraits.hpp" #include "reflection.hpp" -#include "tag.hpp" +#include "Tag.hpp" namespace gr { @@ -64,19 +64,19 @@ struct SettingsCtx { }; /** - * @brief a concept verifying whether a processing block optionally provides a `settings_changed` callback to react to + * @brief a concept verifying whether a processing block optionally provides a `settingsChanged` callback to react to * block configuration changes and/or to influence forwarded downstream parameters. * * Implementers may have: - * 1. `settings_changed(oldSettings, newSettings)` - * 2. `settings_changed(oldSettings, newSettings, forwardSettings)` + * 1. `settingsChanged(oldSettings, newSettings)` + * 2. `settingsChanged(oldSettings, newSettings, forwardSettings)` * - where `forwardSettings` is for influencing subsequent blocks. E.g., a decimating block might adjust the `sample_rate` for downstream blocks. */ template concept HasSettingsChangedCallback = requires(BlockType *block, const property_map &oldSettings, property_map &newSettings) { - { block->settings_changed(oldSettings, newSettings) }; + { block->settingsChanged(oldSettings, newSettings) }; } or requires(BlockType *block, const property_map &oldSettings, property_map &newSettings, property_map &forwardSettings) { - { block->settings_changed(oldSettings, newSettings, forwardSettings) }; + { block->settingsChanged(oldSettings, newSettings, forwardSettings) }; }; /** @@ -89,7 +89,7 @@ concept HasSettingsResetCallback = requires(TBlock *block) { }; template -concept Settings = requires(T t, std::span parameter_keys, const std::string ¶meter_key, const property_map ¶meters, SettingsCtx ctx) { +concept SettingsLike = requires(T t, std::span parameter_keys, const std::string ¶meter_key, const property_map ¶meters, SettingsCtx ctx) { /** * @brief returns if there are stages settings that haven't been applied yet. */ @@ -97,18 +97,18 @@ concept Settings = requires(T t, std::span parameter_keys, co /** * @brief stages new key-value pairs that shall replace the block field-based settings. - * N.B. settings become only active after executing 'apply_staged_parameters()' (usually done early on in the 'Block::work()' function) + * N.B. settings become only active after executing 'applyStagedParameters()' (usually done early on in the 'Block::work()' function) * @return key-value pairs that could not be set */ { t.set(parameters, ctx) } -> std::same_as; { t.set(parameters) } -> std::same_as; /** - * @brief updates parameters based on block input tags for those with keys stored in `auto_update_parameters()` - * Parameter changes to down-stream blocks is controlled via `auto_forward_parameters()` + * @brief updates parameters based on block input tags for those with keys stored in `autoUpdateParameters()` + * Parameter changes to down-stream blocks is controlled via `autoForwardParameters()` */ - { t.auto_update(parameters, ctx) } -> std::same_as; - { t.auto_update(parameters) } -> std::same_as; + { t.autoUpdate(parameters, ctx) } -> std::same_as; + { t.autoUpdate(parameters) } -> std::same_as; /** * @brief return all available block settings as key-value pairs @@ -130,27 +130,27 @@ concept Settings = requires(T t, std::span parameter_keys, co /** * @brief returns the staged/not-yet-applied new parameters */ - { t.staged_parameters() } -> std::same_as; + { t.stagedParameters() } -> std::same_as; /** * @brief synchronise map-based with actual block field-based settings */ - { t.apply_staged_parameters() } -> std::same_as; + { t.applyStagedParameters() } -> std::same_as; /** * @brief synchronises the map-based with the block's field-based parameters * (N.B. usually called after the staged parameters have been synchronised) */ - { t.update_active_parameters() } -> std::same_as; + { t.updateActiveParameters() } -> std::same_as; }; -struct settings_base { +struct SettingsBase { std::atomic_bool _changed{ false }; - virtual ~settings_base() = default; + virtual ~SettingsBase() = default; void - swap(settings_base &other) noexcept { + swap(SettingsBase &other) noexcept { if (this == &other) { return; } @@ -170,7 +170,7 @@ struct settings_base { /** * @brief stages new key-value pairs that shall replace the block field-based settings. - * N.B. settings become only active after executing 'apply_staged_parameters()' (usually done early on in the 'Block::work()' function) + * N.B. settings become only active after executing 'applyStagedParameters()' (usually done early on in the 'Block::work()' function) * @return key-value pairs that could not be set */ [[nodiscard]] virtual property_map @@ -178,18 +178,18 @@ struct settings_base { = 0; virtual void - store_defaults() + storeDefaults() = 0; virtual void - reset_defaults() + resetDefaults() = 0; /** - * @brief updates parameters based on block input tags for those with keys stored in `auto_update_parameters()` - * Parameter changes to down-stream blocks is controlled via `auto_forward_parameters()` + * @brief updates parameters based on block input tags for those with keys stored in `autoUpdateParameters()` + * Parameter changes to down-stream blocks is controlled via `autoForwardParameters()` */ virtual void - auto_update(const property_map ¶meters, SettingsCtx = {}) + autoUpdate(const property_map ¶meters, SettingsCtx = {}) = 0; /** @@ -206,15 +206,15 @@ struct settings_base { * @brief returns the staged/not-yet-applied new parameters */ [[nodiscard]] virtual const property_map - staged_parameters() const + stagedParameters() const = 0; [[nodiscard]] virtual std::set> & - auto_update_parameters() noexcept + autoUpdateParameters() noexcept = 0; [[nodiscard]] virtual std::set> & - auto_forward_parameters() noexcept + autoForwardParameters() noexcept = 0; /** @@ -223,7 +223,7 @@ struct settings_base { * to dependent/child blocks. */ [[nodiscard]] virtual const property_map - apply_staged_parameters() noexcept + applyStagedParameters() noexcept = 0; /** @@ -231,7 +231,7 @@ struct settings_base { * (N.B. usually called after the staged parameters have been synchronised) */ virtual void - update_active_parameters() noexcept + updateActiveParameters() noexcept = 0; }; @@ -241,7 +241,7 @@ concept HasBaseType = requires { typename std::remove_cvref_t::base_t; }; }; template -class basic_settings : public settings_base { +class BasicSettings : public SettingsBase { TBlock *_block = nullptr; mutable std::mutex _lock{}; property_map _active{}; // copy of class field settings as pmt-style map @@ -251,12 +251,12 @@ class basic_settings : public settings_base { property_map _default_settings{}; public: - basic_settings() = delete; - ~basic_settings() = default; + BasicSettings() = delete; + ~BasicSettings() = default; - explicit constexpr basic_settings(TBlock &block) noexcept : settings_base(), _block(&block) { - if constexpr (requires { &TBlock::settings_changed; }) { // if settings_changed is defined - static_assert(HasSettingsChangedCallback, "if provided, settings_changed must have either a `(const property_map& old, property_map& new, property_map& fwd)`" + explicit constexpr BasicSettings(TBlock &block) noexcept : SettingsBase(), _block(&block) { + if constexpr (requires { &TBlock::settingsChanged; }) { // if settingsChanged is defined + static_assert(HasSettingsChangedCallback, "if provided, settingsChanged must have either a `(const property_map& old, property_map& new, property_map& fwd)`" "or `(const property_map& old, property_map& new)` parameter signatures."); } @@ -270,7 +270,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::block::detail::is_port_or_collection() && !std::is_const_v && is_writable(member) && is_supported_type()) { + if constexpr (!traits::block::detail::is_port_or_collection() && !std::is_const_v && is_writable(member) && isSupportedType()) { auto matchesIgnoringPrefix = [](std::string_view str, std::string_view prefix, std::string_view target) { if (str.starts_with(prefix)) { str.remove_prefix(prefix.size()); @@ -318,35 +318,35 @@ class basic_settings : public settings_base { } } - constexpr basic_settings(const basic_settings &other) noexcept : settings_base(other) { - basic_settings temp(other); + constexpr BasicSettings(const BasicSettings &other) noexcept : SettingsBase(other) { + BasicSettings temp(other); swap(temp); } - constexpr basic_settings(basic_settings &&other) noexcept : settings_base(std::move(other)) { - basic_settings temp(std::move(other)); + constexpr BasicSettings(BasicSettings &&other) noexcept : SettingsBase(std::move(other)) { + BasicSettings temp(std::move(other)); swap(temp); } - basic_settings & - operator=(const basic_settings &other) noexcept { + BasicSettings & + operator=(const BasicSettings &other) noexcept { swap(other); return *this; } - basic_settings & - operator=(basic_settings &&other) noexcept { - basic_settings temp(std::move(other)); + BasicSettings & + operator=(BasicSettings &&other) noexcept { + BasicSettings temp(std::move(other)); swap(temp); return *this; } void - swap(basic_settings &other) noexcept { + swap(BasicSettings &other) noexcept { if (this == &other) { return; } - settings_base::swap(other); + SettingsBase::swap(other); std::swap(_block, other._block); std::scoped_lock lock(_lock, other._lock); std::swap(_active, other._active); @@ -366,13 +366,13 @@ 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::block::detail::is_port_or_collection() && !std::is_const_v && is_writable(member) && is_supported_type()) { + if constexpr (!traits::block::detail::is_port_or_collection() && !std::is_const_v && is_writable(member) && isSupportedType()) { if (std::string(get_display_name(member)) == key && std::holds_alternative(value)) { if (_auto_update.contains(key)) { _auto_update.erase(key); } _staged.insert_or_assign(key, value); - settings_base::_changed.store(true); + SettingsBase::_changed.store(true); is_set = true; } if (std::string(get_display_name(member)) == key && !std::holds_alternative(value)) { @@ -396,38 +396,38 @@ class basic_settings : public settings_base { unwrap_if_wrapped_t {} } -> std::same_as; }) { - update_maps(ret, _block->meta_information); + updateMaps(ret, _block->meta_information); } return ret; // N.B. returns those parameters that could not be set } void - store_defaults() override { - this->store_default_settings(_default_settings); + storeDefaults() override { + this->storeDefaultSettings(_default_settings); } void - reset_defaults() override { + resetDefaults() override { _staged = _default_settings; - std::ignore = apply_staged_parameters(); + std::ignore = applyStagedParameters(); if constexpr (HasSettingsResetCallback) { _block->reset(); } } void - auto_update(const property_map ¶meters, SettingsCtx = {}) override { + autoUpdate(const property_map ¶meters, SettingsCtx = {}) override { if constexpr (refl::is_reflectable()) { for (const auto &[localKey, localValue] : parameters) { const auto &key = localKey; const auto &value = localValue; auto iterate_over_member = [&](auto member) { using Type = unwrap_if_wrapped_t>; - if constexpr (!traits::block::detail::is_port_or_collection() && !std::is_const_v && is_writable(member) && is_supported_type()) { + if constexpr (!traits::block::detail::is_port_or_collection() && !std::is_const_v && is_writable(member) && isSupportedType()) { if (std::string(get_display_name(member)) == key && std::holds_alternative(value)) { _staged.insert_or_assign(key, value); - settings_base::_changed.store(true); + SettingsBase::_changed.store(true); } } }; @@ -440,7 +440,7 @@ class basic_settings : public settings_base { } [[nodiscard]] const property_map - staged_parameters() const noexcept override { + stagedParameters() const noexcept override { std::lock_guard lg(_lock); return _staged; } @@ -475,12 +475,12 @@ class basic_settings : public settings_base { } [[nodiscard]] std::set> & - auto_update_parameters() noexcept override { + autoUpdateParameters() noexcept override { return _auto_update; } [[nodiscard]] std::set> & - auto_forward_parameters() noexcept override { + autoForwardParameters() noexcept override { return _auto_forward; } @@ -490,7 +490,7 @@ class basic_settings : public settings_base { * to dependent/child blocks. */ [[nodiscard]] const property_map - apply_staged_parameters() noexcept override { + applyStagedParameters() noexcept override { property_map forward_parameters; // parameters that should be forwarded to dependent child blocks if constexpr (refl::is_reflectable()) { std::lock_guard lg(_lock); @@ -498,13 +498,13 @@ class basic_settings : public settings_base { // prepare old settings if required property_map oldSettings; if constexpr (HasSettingsChangedCallback) { - store_default_settings(oldSettings); + storeDefaultSettings(oldSettings); } // check if reset of settings should be performed if (_staged.contains(gr::tag::RESET_DEFAULTS)) { _staged.clear(); - reset_defaults(); + resetDefaults(); } // update staged and forward parameters based on member properties @@ -515,7 +515,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::block::detail::is_port_or_collection() && !std::is_const_v && is_writable(member) && is_supported_type()) { + if constexpr (!traits::block::detail::is_port_or_collection() && !std::is_const_v && is_writable(member) && isSupportedType()) { if (std::string(get_display_name(member)) == key && std::holds_alternative(staged_value)) { if constexpr (is_annotated()) { if (member(*_block).validate_and_set(std::get(staged_value))) { @@ -554,29 +554,29 @@ class basic_settings : public settings_base { } } }; - process_members(apply_member_changes); + processMembers(apply_member_changes); } // update active parameters auto update_active = [this](auto member) { using Type = unwrap_if_wrapped_t>; - if constexpr (!traits::block::detail::is_port_or_collection() && is_readable(member) && is_supported_type()) { + if constexpr (!traits::block::detail::is_port_or_collection() && is_readable(member) && isSupportedType()) { _active.insert_or_assign(get_display_name(member), pmtv::pmt(member(*_block))); } }; - process_members(update_active); + processMembers(update_active); // invoke user-callback function if staged is not empty if (!staged.empty()) { - if constexpr (requires { _block->settings_changed(/* old settings */ _active, /* new settings */ staged); }) { - _block->settings_changed(/* old settings */ oldSettings, /* new settings */ staged); - } else if constexpr (requires { _block->settings_changed(/* old settings */ _active, /* new settings */ staged, /* new forward settings */ forward_parameters); }) { - _block->settings_changed(/* old settings */ oldSettings, /* new settings */ staged, /* new forward settings */ forward_parameters); + if constexpr (requires { _block->settingsChanged(/* old settings */ _active, /* new settings */ staged); }) { + _block->settingsChanged(/* old settings */ oldSettings, /* new settings */ staged); + } else if constexpr (requires { _block->settingsChanged(/* old settings */ _active, /* new settings */ staged, /* new forward settings */ forward_parameters); }) { + _block->settingsChanged(/* old settings */ oldSettings, /* new settings */ staged, /* new forward settings */ forward_parameters); } } if (_staged.contains(gr::tag::STORE_DEFAULTS)) { - store_defaults(); + storeDefaults(); } if constexpr (HasSettingsResetCallback) { @@ -588,18 +588,18 @@ class basic_settings : public settings_base { _staged.clear(); } - settings_base::_changed.store(false); + SettingsBase::_changed.store(false); return forward_parameters; } void - update_active_parameters() noexcept override { + updateActiveParameters() noexcept override { if constexpr (refl::is_reflectable()) { std::lock_guard lg(_lock); auto iterate_over_member = [&, this](auto member) { using Type = unwrap_if_wrapped_t>; - if constexpr ((!traits::block::detail::is_port_or_collection()) && is_readable(member) && is_supported_type()) { + if constexpr ((!traits::block::detail::is_port_or_collection()) && is_readable(member) && isSupportedType()) { _active.insert_or_assign(get_display_name_const(member).str(), member(*_block)); } }; @@ -612,13 +612,13 @@ class basic_settings : public settings_base { private: void - store_default_settings(property_map &oldSettings) { + storeDefaultSettings(property_map &oldSettings) { // take a copy of the field -> map value of the old settings if constexpr (refl::is_reflectable()) { auto iterate_over_member = [&, this](auto member) { using Type = unwrap_if_wrapped_t>; - if constexpr (!traits::block::detail::is_port_or_collection() && is_readable(member) && is_supported_type()) { + if constexpr (!traits::block::detail::is_port_or_collection() && is_readable(member) && isSupportedType()) { oldSettings.insert_or_assign(get_display_name(member), pmtv::pmt(member(*_block))); } }; @@ -631,13 +631,13 @@ class basic_settings : public settings_base { template inline constexpr static bool - is_supported_type() { + isSupportedType() { return std::is_arithmetic_v || std::is_same_v || gr::meta::vector_type; } template inline constexpr static void - process_members(Func func) { + processMembers(Func func) { if constexpr (detail::HasBaseType) { refl::util::for_each(refl::reflect::base_t>().members, func); } @@ -645,7 +645,7 @@ class basic_settings : public settings_base { } }; -static_assert(Settings>); +static_assert(SettingsLike>); } // namespace gr diff --git a/core/include/gnuradio-4.0/tag.hpp b/core/include/gnuradio-4.0/Tag.hpp similarity index 73% rename from core/include/gnuradio-4.0/tag.hpp rename to core/include/gnuradio-4.0/Tag.hpp index 5cb9d83c9..d8bb723d1 100644 --- a/core/include/gnuradio-4.0/tag.hpp +++ b/core/include/gnuradio-4.0/Tag.hpp @@ -28,7 +28,7 @@ inline constexpr std::size_t hardware_constructive_interference_size = 64; namespace gr { -enum class tag_propagation_policy_t { +enum class TagPropagationPolicy { TPP_DONT = 0, /*!< Scheduler doesn't propagate tags from in- to output. The block itself is free to insert tags. */ TPP_ALL_TO_ALL = 1, /*!< Propagate tags from all in- to all outputs. The @@ -42,7 +42,7 @@ enum class tag_propagation_policy_t { using property_map = pmtv::map_t; /** - * @brief 'tag_t' is a metadata structure that can be attached to a stream of data to carry extra information about that data. + * @brief 'Tag' is a metadata structure that can be attached to a stream of data to carry extra information about that data. * A tag can describe a specific time, parameter or meta-information (e.g. sampling frequency, gains, ...), provide annotations, * or indicate events that blocks may trigger actions in downstream blocks. Tags can be inserted or consumed by blocks at * any point in the signal processing flow, allowing for flexible and customisable data processing. @@ -51,17 +51,17 @@ using property_map = pmtv::map_t; * may choose to chunk the data based on the MIN_SAMPLES/MAX_SAMPLES criteria only, or in addition break-up the stream * so that there is only one tag per scheduler iteration. Multiple tags on the same sample shall be merged to one. */ -struct alignas(hardware_constructive_interference_size) tag_t { +struct alignas(hardware_constructive_interference_size) Tag { using signed_index_type = std::make_signed_t; signed_index_type index{ 0 }; property_map map{}; - tag_t() = default; // TODO: remove -- needed only for Clang <=15 + Tag() = default; // TODO: remove -- needed only for Clang <=15 - tag_t(signed_index_type index_, property_map map_) noexcept : index(index_), map(std::move(map_)) {} // TODO: remove -- needed only for Clang <=15 + Tag(signed_index_type index_, property_map map_) noexcept : index(index_), map(std::move(map_)) {} // TODO: remove -- needed only for Clang <=15 bool - operator==(const tag_t &other) const + operator==(const Tag &other) const = default; // TODO: do we need the convenience methods below? @@ -111,13 +111,13 @@ struct alignas(hardware_constructive_interference_size) tag_t { }; } // namespace gr -ENABLE_REFLECTION(gr::tag_t, index, map); +ENABLE_REFLECTION(gr::Tag, index, map); namespace gr { using meta::fixed_string; inline void -update_maps(const property_map &src, property_map &dest) { +updateMaps(const property_map &src, property_map &dest) { for (const auto &[key, value] : src) { if (auto nested_map = std::get_if(&value)) { // If it's a nested map @@ -126,7 +126,7 @@ update_maps(const property_map &src, property_map &dest) { auto dest_nested_map = std::get_if(&(it->second)); if (dest_nested_map) { // Merge the nested maps recursively - update_maps(*nested_map, *dest_nested_map); + updateMaps(*nested_map, *dest_nested_map); } else { // Key exists but not a map, replace it dest[key] = value; @@ -145,7 +145,7 @@ update_maps(const property_map &src, property_map &dest) { constexpr fixed_string GR_TAG_PREFIX = "gr:"; template -class default_tag { +class DefaultTag { constexpr static fixed_string _key = GR_TAG_PREFIX + Key; public: @@ -182,18 +182,18 @@ class default_tag { }; namespace tag { // definition of default tags and names -inline EM_CONSTEXPR_STATIC default_tag<"sample_rate", float, "Hz", "signal sample rate"> SAMPLE_RATE; -inline EM_CONSTEXPR_STATIC default_tag<"sample_rate", float, "Hz", "signal sample rate"> SIGNAL_RATE; -inline EM_CONSTEXPR_STATIC default_tag<"signal_name", std::string, "", "signal name"> SIGNAL_NAME; -inline EM_CONSTEXPR_STATIC default_tag<"signal_unit", std::string, "", "signal's physical SI unit"> SIGNAL_UNIT; -inline EM_CONSTEXPR_STATIC default_tag<"signal_min", float, "a.u.", "signal physical max. (e.g. DAQ) limit"> SIGNAL_MIN; -inline EM_CONSTEXPR_STATIC default_tag<"signal_max", float, "a.u.", "signal physical max. (e.g. DAQ) limit"> SIGNAL_MAX; -inline EM_CONSTEXPR_STATIC default_tag<"trigger_name", std::string> TRIGGER_NAME; -inline EM_CONSTEXPR_STATIC default_tag<"trigger_time", uint64_t, "ns", "UTC-based time-stamp"> TRIGGER_TIME; -inline EM_CONSTEXPR_STATIC default_tag<"trigger_offset", float, "s", "sample delay w.r.t. the trigger (e.g.compensating analog group delays)"> TRIGGER_OFFSET; -inline EM_CONSTEXPR_STATIC default_tag<"context", std::string, "", "multiplexing key to orchestrate node settings/behavioural changes"> CONTEXT; -inline EM_CONSTEXPR_STATIC default_tag<"reset_default", bool, "", "reset block state to stored default"> RESET_DEFAULTS; -inline EM_CONSTEXPR_STATIC default_tag<"store_default", bool, "", "store block settings as default"> STORE_DEFAULTS; +inline EM_CONSTEXPR_STATIC DefaultTag<"sample_rate", float, "Hz", "signal sample rate"> SAMPLE_RATE; +inline EM_CONSTEXPR_STATIC DefaultTag<"sample_rate", float, "Hz", "signal sample rate"> SIGNAL_RATE; +inline EM_CONSTEXPR_STATIC DefaultTag<"signal_name", std::string, "", "signal name"> SIGNAL_NAME; +inline EM_CONSTEXPR_STATIC DefaultTag<"signal_unit", std::string, "", "signal's physical SI unit"> SIGNAL_UNIT; +inline EM_CONSTEXPR_STATIC DefaultTag<"signal_min", float, "a.u.", "signal physical max. (e.g. DAQ) limit"> SIGNAL_MIN; +inline EM_CONSTEXPR_STATIC DefaultTag<"signal_max", float, "a.u.", "signal physical max. (e.g. DAQ) limit"> SIGNAL_MAX; +inline EM_CONSTEXPR_STATIC DefaultTag<"trigger_name", std::string> TRIGGER_NAME; +inline EM_CONSTEXPR_STATIC DefaultTag<"trigger_time", uint64_t, "ns", "UTC-based time-stamp"> TRIGGER_TIME; +inline EM_CONSTEXPR_STATIC DefaultTag<"trigger_offset", float, "s", "sample delay w.r.t. the trigger (e.g.compensating analog group delays)"> TRIGGER_OFFSET; +inline EM_CONSTEXPR_STATIC DefaultTag<"context", std::string, "", "multiplexing key to orchestrate node settings/behavioural changes"> CONTEXT; +inline EM_CONSTEXPR_STATIC DefaultTag<"reset_default", bool, "", "reset block state to stored default"> RESET_DEFAULTS; +inline EM_CONSTEXPR_STATIC DefaultTag<"store_default", bool, "", "store block settings as default"> STORE_DEFAULTS; inline constexpr std::tuple DEFAULT_TAGS = { SAMPLE_RATE, SIGNAL_NAME, SIGNAL_UNIT, SIGNAL_MIN, SIGNAL_MAX, TRIGGER_NAME, TRIGGER_TIME, TRIGGER_OFFSET, CONTEXT, RESET_DEFAULTS, STORE_DEFAULTS }; } // namespace tag diff --git a/core/include/gnuradio-4.0/transactions.hpp b/core/include/gnuradio-4.0/Transactions.hpp similarity index 87% rename from core/include/gnuradio-4.0/transactions.hpp rename to core/include/gnuradio-4.0/Transactions.hpp index 4e57cfe74..2d766ab7a 100644 --- a/core/include/gnuradio-4.0/transactions.hpp +++ b/core/include/gnuradio-4.0/Transactions.hpp @@ -16,8 +16,8 @@ #include -#include "settings.hpp" -#include "tag.hpp" +#include "Settings.hpp" +#include "Tag.hpp" #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-nonliteral" @@ -29,7 +29,7 @@ namespace gr { static auto nullMatchPred = [](auto, auto, auto) { return std::nullopt; }; template -class ctx_settings : public settings_base { +class CtxSettings : public SettingsBase { /** * A predicate for matching two contexts * The third "attempt" parameter indicates the current round of matching being done. @@ -53,9 +53,9 @@ class ctx_settings : public settings_base { MatchPredicate _match_pred = nullMatchPred; public: - explicit ctx_settings(TBlock &block, MatchPredicate matchPred = nullMatchPred) noexcept : settings_base(), _block(&block), _match_pred(matchPred) { - if constexpr (requires { &TBlock::settings_changed; }) { // if settings_changed is defined - static_assert(HasSettingsChangedCallback, "if provided, settings_changed must have either a `(const property_map& old, property_map& new, property_map& fwd)`" + explicit CtxSettings(TBlock &block, MatchPredicate matchPred = nullMatchPred) noexcept : SettingsBase(), _block(&block), _match_pred(matchPred) { + if constexpr (requires { &TBlock::settingsChanged; }) { // if settingsChanged is defined + static_assert(HasSettingsChangedCallback, "if provided, settingsChanged must have either a `(const property_map& old, property_map& new, property_map& fwd)`" "or `(const property_map& old, property_map& new)` paremeter signatures."); } @@ -117,35 +117,35 @@ class ctx_settings : public settings_base { } } - constexpr ctx_settings(const ctx_settings &other) noexcept : settings_base(other) { - ctx_settings temp(other); + constexpr CtxSettings(const CtxSettings &other) noexcept : SettingsBase(other) { + CtxSettings temp(other); swap(temp); } - constexpr ctx_settings(ctx_settings &&other) noexcept : settings_base(std::move(other)) { - ctx_settings temp(std::move(other)); + constexpr CtxSettings(CtxSettings &&other) noexcept : SettingsBase(std::move(other)) { + CtxSettings temp(std::move(other)); swap(temp); } - ctx_settings & - operator=(const ctx_settings &other) noexcept { + CtxSettings & + operator=(const CtxSettings &other) noexcept { swap(other); return *this; } - ctx_settings & - operator=(ctx_settings &&other) noexcept { - ctx_settings temp(std::move(other)); + CtxSettings & + operator=(CtxSettings &&other) noexcept { + CtxSettings temp(std::move(other)); swap(temp); return *this; } void - swap(ctx_settings &other) noexcept { + swap(CtxSettings &other) noexcept { if (this == &other) { return; } - settings_base::swap(other); + SettingsBase::swap(other); std::swap(_block, other._block); std::scoped_lock lock(_lock, other._lock); std::swap(_active, other._active); @@ -172,7 +172,7 @@ class ctx_settings : public settings_base { if (_auto_update.contains(key)) { _auto_update.erase(key); } - settings_base::_changed.store(true); + SettingsBase::_changed.store(true); is_set = true; } } @@ -193,7 +193,7 @@ class ctx_settings : public settings_base { unwrap_if_wrapped_t {} } -> std::same_as; }) { - update_maps(ret, _block->metaInformation); + updateMaps(ret, _block->metaInformation); } _settings[ctx] = parameters; @@ -203,22 +203,22 @@ class ctx_settings : public settings_base { } void - store_defaults() override { - this->store_default_settings(_default_settings); + storeDefaults() override { + this->storeDefaultSettings(_default_settings); } void - reset_defaults() override { + resetDefaults() override { _settings.clear(); _staged = _default_settings; - std::ignore = apply_staged_parameters(); + std::ignore = applyStagedParameters(); if constexpr (HasSettingsResetCallback) { _block->reset(); } } void - auto_update(const property_map ¶meters, SettingsCtx = {}) override { + autoUpdate(const property_map ¶meters, SettingsCtx = {}) override { if constexpr (refl::is_reflectable()) { for (const auto &[localKey, localValue] : parameters) { const auto &key = localKey; @@ -228,7 +228,7 @@ class ctx_settings : public settings_base { if constexpr (!std::is_const_v && 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)) { _staged.insert_or_assign(key, value); - settings_base::_changed.store(true); + SettingsBase::_changed.store(true); } } }; @@ -241,7 +241,7 @@ class ctx_settings : public settings_base { } [[nodiscard]] const property_map - staged_parameters() const noexcept override { + stagedParameters() const noexcept override { std::lock_guard lg(_lock); return _staged; } @@ -281,17 +281,17 @@ class ctx_settings : public settings_base { } [[nodiscard]] std::set> & - auto_update_parameters() noexcept override { + autoUpdateParameters() noexcept override { return _auto_update; } [[nodiscard]] std::set> & - auto_forward_parameters() noexcept override { + autoForwardParameters() noexcept override { return _auto_forward; } [[nodiscard]] const property_map - apply_staged_parameters() noexcept override { + applyStagedParameters() noexcept override { property_map forward_parameters; // parameters that should be forwarded to dependent child nodes if constexpr (refl::is_reflectable()) { std::lock_guard lg(_lock); @@ -299,13 +299,13 @@ class ctx_settings : public settings_base { // prepare old settings if required property_map oldSettings; if constexpr (HasSettingsChangedCallback) { - store_default_settings(oldSettings); + storeDefaultSettings(oldSettings); } // check if reset of settings should be performed if (_staged.contains(gr::tag::RESET_DEFAULTS)) { _staged.clear(); - reset_defaults(); + resetDefaults(); } // update staged and forward parameters based on member properties @@ -316,7 +316,7 @@ class ctx_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 (!std::is_const_v && is_writable(member) && is_supported_type()) { + if constexpr (!std::is_const_v && is_writable(member) && isSupportedType()) { if (std::string(get_display_name(member)) == key && std::holds_alternative(staged_value)) { if constexpr (is_annotated()) { if (member(*_block).validate_and_set(std::get(staged_value))) { @@ -355,29 +355,29 @@ class ctx_settings : public settings_base { } } }; - process_members(apply_member_changes); + processMembers(apply_member_changes); } // update active parameters auto update_active = [this](auto member) { using Type = unwrap_if_wrapped_t>; - if constexpr (is_readable(member) && is_supported_type()) { + if constexpr (is_readable(member) && isSupportedType()) { _active.insert_or_assign(get_display_name(member), pmtv::pmt(member(*_block))); } }; - process_members(update_active); + processMembers(update_active); // invoke user-callback function if staged is not empty if (!staged.empty()) { - if constexpr (requires { _block->settings_changed(/* old settings */ _active, /* new settings */ staged); }) { - _block->settings_changed(/* old settings */ oldSettings, /* new settings */ staged); - } else if constexpr (requires { _block->settings_changed(/* old settings */ _active, /* new settings */ staged, /* new forward settings */ forward_parameters); }) { - _block->settings_changed(/* old settings */ oldSettings, /* new settings */ staged, /* new forward settings */ forward_parameters); + if constexpr (requires { _block->settingsChanged(/* old settings */ _active, /* new settings */ staged); }) { + _block->settingsChanged(/* old settings */ oldSettings, /* new settings */ staged); + } else if constexpr (requires { _block->settingsChanged(/* old settings */ _active, /* new settings */ staged, /* new forward settings */ forward_parameters); }) { + _block->settingsChanged(/* old settings */ oldSettings, /* new settings */ staged, /* new forward settings */ forward_parameters); } } if (_staged.contains(gr::tag::STORE_DEFAULTS)) { - store_defaults(); + storeDefaults(); } if constexpr (HasSettingsResetCallback) { @@ -389,18 +389,18 @@ class ctx_settings : public settings_base { _staged.clear(); } - settings_base::_changed.store(false); + SettingsBase::_changed.store(false); return forward_parameters; } void - update_active_parameters() noexcept override { + updateActiveParameters() noexcept override { if constexpr (refl::is_reflectable()) { std::lock_guard lg(_lock); auto iterate_over_member = [&, this](auto member) { using Type = unwrap_if_wrapped_t>; - if constexpr (is_readable(member) && is_supported_type()) { + if constexpr (is_readable(member) && isSupportedType()) { _active.insert_or_assign(get_display_name_const(member).str(), member(*_block)); } }; @@ -428,13 +428,13 @@ class ctx_settings : public settings_base { } void - store_default_settings(property_map &oldSettings) { + storeDefaultSettings(property_map &oldSettings) { // take a copy of the field -> map value of the old settings if constexpr (refl::is_reflectable()) { auto iterate_over_member = [&, this](auto member) { using Type = unwrap_if_wrapped_t>; - if constexpr (is_readable(member) && is_supported_type()) { + if constexpr (is_readable(member) && isSupportedType()) { oldSettings.insert_or_assign(get_display_name(member), pmtv::pmt(member(*_block))); } }; @@ -447,13 +447,13 @@ class ctx_settings : public settings_base { template inline constexpr static bool - is_supported_type() { + isSupportedType() { return std::integral || std::floating_point || std::is_same_v || gr::meta::vector_type; } template inline constexpr static void - process_members(Func func) { + processMembers(Func func) { if constexpr (detail::HasBaseType) { refl::util::for_each(refl::reflect::base_t>().members, func); } @@ -461,7 +461,7 @@ class ctx_settings : public settings_base { } }; -static_assert(Settings>); +static_assert(SettingsLike>); } // namespace gr diff --git a/core/test/CMakeLists.txt b/core/test/CMakeLists.txt index a7f2dfbde..87336a958 100644 --- a/core/test/CMakeLists.txt +++ b/core/test/CMakeLists.txt @@ -34,10 +34,10 @@ add_ut_test(qa_DynamicBlock) add_ut_test(qa_DynamicPort) add_ut_test(qa_HierBlock) add_ut_test(qa_Block) -add_ut_test(qa_scheduler) +add_ut_test(qa_Scheduler) add_ut_test(qa_reader_writer_lock) -add_ut_test(qa_settings) -add_ut_test(qa_tags) +add_ut_test(qa_Settings) +add_ut_test(qa_Tags) add_ut_test(qa_thread_affinity) add_ut_test(qa_thread_pool) diff --git a/core/test/qa_DynamicBlock.cpp b/core/test/qa_DynamicBlock.cpp index 086e68423..2fbc9da31 100644 --- a/core/test/qa_DynamicBlock.cpp +++ b/core/test/qa_DynamicBlock.cpp @@ -60,7 +60,7 @@ main() { // Function that adds a new source node to the graph, and connects // it to one of adder's ports std::ignore = adder.settings().set({ { "input_port_count", 10 } }); - std::ignore = adder.settings().apply_staged_parameters(); + std::ignore = adder.settings().applyStagedParameters(); std::vector *> sources; for (std::size_t i = 0; i < sources_count; ++i) { diff --git a/core/test/qa_HierBlock.cpp b/core/test/qa_HierBlock.cpp index 8020e0fe6..2f5e2360b 100644 --- a/core/test/qa_HierBlock.cpp +++ b/core/test/qa_HierBlock.cpp @@ -31,17 +31,17 @@ class HierBlock : public grg::BlockModel { const std::string _unique_name = fmt::format("multi_adder#{}", _unique_id); protected: - using setting_map = std::map>; - std::string _name = "multi_adder"; - std::string _type_name = "multi_adder"; - grg::property_map _meta_information; /// used to store non-graph-processing information like UI block position etc. - bool _input_tags_present = false; - bool _output_tags_changed = false; - std::vector _tags_at_input; - std::vector _tags_at_output; - std::unique_ptr _settings = std::make_unique>>(*this); - - using in_port_t = grg::PortIn; + using setting_map = std::map>; + std::string _name = "multi_adder"; + std::string _type_name = "multi_adder"; + grg::property_map _meta_information; /// used to store non-graph-processing information like UI block position etc. + bool _input_tags_present = false; + bool _output_tags_changed = false; + std::vector _tags_at_input; + std::vector _tags_at_output; + std::unique_ptr _settings = std::make_unique>>(*this); + + using in_port_t = grg::PortIn; grg::scheduler::Simple<> _scheduler; @@ -120,7 +120,7 @@ class HierBlock : public grg::BlockModel { return _meta_information; } - [[nodiscard]] grg::settings_base & + [[nodiscard]] grg::SettingsBase & settings() const override { return *_settings; } diff --git a/core/test/qa_scheduler.cpp b/core/test/qa_Scheduler.cpp similarity index 100% rename from core/test/qa_scheduler.cpp rename to core/test/qa_Scheduler.cpp diff --git a/core/test/qa_settings.cpp b/core/test/qa_Settings.cpp similarity index 91% rename from core/test/qa_settings.cpp rename to core/test/qa_Settings.cpp index c4d062621..65bca8276 100644 --- a/core/test/qa_settings.cpp +++ b/core/test/qa_Settings.cpp @@ -11,8 +11,8 @@ #include #include #include -#include -#include +#include +#include using namespace std::string_literals; @@ -99,7 +99,7 @@ struct Source : public Block> { float sample_rate = 1000.0f; void - settings_changed(const property_map & /*old_settings*/, property_map & /*new_settings*/) { + settingsChanged(const property_map & /*old_settings*/, property_map & /*new_settings*/) { // optional init function that is called after construction and whenever settings change gr::publish_tag(out, { { "n_samples_max", n_samples_max } }, static_cast(n_tag_offset)); } @@ -142,7 +142,7 @@ struct TestBlock : public Block, BlockingIO, TestBlockDoc, Su bool resetCalled = false; void - settings_changed(const property_map &old_settings, property_map &new_settings) noexcept { + settingsChanged(const property_map &old_settings, property_map &new_settings) noexcept { // optional function that is called whenever settings change update_count++; @@ -178,7 +178,7 @@ struct Decimate : public Block, SupportedTypes sample_rate = 1.f; void - settings_changed(const property_map & /*old_settings*/, property_map &new_settings, property_map &fwd_settings) noexcept { + settingsChanged(const property_map & /*old_settings*/, property_map &new_settings, property_map &fwd_settings) noexcept { if (new_settings.contains(std::string(gr::tag::SIGNAL_RATE.shortKey())) || new_settings.contains("denominator")) { const float fwdSampleRate = sample_rate / static_cast(this->denominator); fwd_settings[std::string(gr::tag::SIGNAL_RATE.shortKey())] = fwdSampleRate; // TODO: handle 'gr:sample_rate' vs 'sample_rate'; @@ -261,18 +261,18 @@ const boost::ut::suite SettingsTests = [] { // define basic Sink->TestBlock->Sink flow graph auto &src = testGraph.emplaceBlock>({ { "n_samples_max", n_samples } }); expect(eq(src.n_samples_max, n_samples)) << "check map constructor"; - expect(eq(src.settings().auto_update_parameters().size(), 4UL)); - expect(eq(src.settings().auto_forward_parameters().size(), 1UL)); // sample_rate + expect(eq(src.settings().autoUpdateParameters().size(), 4UL)); + expect(eq(src.settings().autoForwardParameters().size(), 1UL)); // sample_rate auto &block1 = testGraph.emplaceBlock>({ { "name", "TestBlock#1" } }); auto &block2 = testGraph.emplaceBlock>({ { "name", "TestBlock#2" } }); auto &sink = testGraph.emplaceBlock>(); - expect(eq(sink.settings().auto_update_parameters().size(), 5UL)); - expect(eq(sink.settings().auto_forward_parameters().size(), 1UL)); // sample_rate + expect(eq(sink.settings().autoUpdateParameters().size(), 5UL)); + expect(eq(sink.settings().autoForwardParameters().size(), 1UL)); // sample_rate block1.context = "Test Context"; - block1.settings().update_active_parameters(); - expect(eq(block1.settings().auto_update_parameters().size(), 6UL)); - expect(eq(block1.settings().auto_forward_parameters().size(), 2UL)); + block1.settings().updateActiveParameters(); + expect(eq(block1.settings().autoUpdateParameters().size(), 6UL)); + expect(eq(block1.settings().autoForwardParameters().size(), 2UL)); expect(block1.settings().get("context").has_value()); expect(block1.settings().get({ "context" }).has_value()); @@ -294,12 +294,12 @@ const boost::ut::suite SettingsTests = [] { expect(not block1.settings().changed()); auto ret2 = block1.settings().set({ { "context", "alt context" } }); - expect(not block1.settings().staged_parameters().empty()); + expect(not block1.settings().stagedParameters().empty()); expect(ret2.empty()) << "setting one known parameter"; expect(block1.settings().changed()) << "settings changed"; - auto forwarding_parameter = block1.settings().apply_staged_parameters(); + auto forwarding_parameter = block1.settings().applyStagedParameters(); expect(eq(forwarding_parameter.size(), 1u)) << "initial forward declarations"; - block1.settings().update_active_parameters(); + block1.settings().updateActiveParameters(); // src -> block1 -> block2 -> sink expect(eq(ConnectionResult::SUCCESS, testGraph.connect<"out">(src).to<"in">(block1))); @@ -308,7 +308,7 @@ const boost::ut::suite SettingsTests = [] { auto thread_pool = std::make_shared("custom pool", gr::thread_pool::CPU_BOUND, 2, 2); // use custom pool to limit number of threads for emscripten gr::scheduler::Simple sched{ std::move(testGraph), thread_pool }; - expect(src.settings().auto_update_parameters().contains("sample_rate")); + expect(src.settings().autoUpdateParameters().contains("sample_rate")); std::ignore = src.settings().set({ { "sample_rate", 49000.0f } }); sched.runAndWait(); expect(eq(src.n_samples_produced, n_samples)) << "did not produce enough output samples"; @@ -324,10 +324,10 @@ const boost::ut::suite SettingsTests = [] { expect(eq(sink.sample_rate, 49000.0f)) << "sink matching src sample_rate"; // check auto-update flags - expect(!src.settings().auto_update_parameters().contains("sample_rate")) << "src should not retain auto-update flag (was manually set)"; - expect(block1.settings().auto_update_parameters().contains("sample_rate")) << "block1 retained auto-update flag"; - expect(block2.settings().auto_update_parameters().contains("sample_rate")) << "block1 retained auto-update flag"; - expect(sink.settings().auto_update_parameters().contains("sample_rate")) << "sink retained auto-update flag"; + expect(!src.settings().autoUpdateParameters().contains("sample_rate")) << "src should not retain auto-update flag (was manually set)"; + expect(block1.settings().autoUpdateParameters().contains("sample_rate")) << "block1 retained auto-update flag"; + expect(block2.settings().autoUpdateParameters().contains("sample_rate")) << "block1 retained auto-update flag"; + expect(sink.settings().autoUpdateParameters().contains("sample_rate")) << "sink retained auto-update flag"; }; "constructor"_test = [] { @@ -341,10 +341,10 @@ const boost::ut::suite SettingsTests = [] { #if !defined(__clang_major__) && __clang_major__ <= 15 "with init parameter"_test = [] { auto block = TestBlock({ { "scaling_factor", 2.f } }); - expect(eq(block.settings().staged_parameters().size(), 1u)); + expect(eq(block.settings().stagedParameters().size(), 1u)); block.init(block.progress, block.ioThreadPool); // N.B. self-assign existing progress and thread-pool (just for unit-tests) - expect(eq(block.settings().staged_parameters().size(), 0u)); - block.settings().update_active_parameters(); + expect(eq(block.settings().stagedParameters().size(), 0u)); + block.settings().updateActiveParameters(); expect(eq(block.settings().get().size(), 11UL)); expect(eq(block.scaling_factor, 2.f)); expect(eq(std::get(*block.settings().get("scaling_factor")), 2.f)); @@ -371,7 +371,7 @@ const boost::ut::suite SettingsTests = [] { "vector-type support"_test = [] { Graph testGraph; auto &block = testGraph.emplaceBlock>(); - block.settings().update_active_parameters(); + block.settings().updateActiveParameters(); expect(eq(block.settings().get().size(), 11UL)); block.debug = true; @@ -456,27 +456,27 @@ const boost::ut::suite SettingsTests = [] { expect(eq(block.scaling_factor, 2.f)); std::ignore = block.settings().set({ { "name", "TestNameAlt" }, { "scaling_factor", 42.f } }); - std::ignore = block.settings().apply_staged_parameters(); + std::ignore = block.settings().applyStagedParameters(); expect(block.name == "TestNameAlt"); expect(eq(block.scaling_factor, 42.f)); expect(not block.resetCalled); - block.settings().reset_defaults(); + block.settings().resetDefaults(); expect(block.resetCalled); block.resetCalled = false; expect(block.name == "TestName"); expect(eq(block.scaling_factor, 2.f)); std::ignore = block.settings().set({ { "name", "TestNameAlt" }, { "scaling_factor", 42.f } }); - std::ignore = block.settings().apply_staged_parameters(); + std::ignore = block.settings().applyStagedParameters(); expect(block.name == "TestNameAlt"); expect(eq(block.scaling_factor, 42.f)); - block.settings().store_defaults(); + block.settings().storeDefaults(); std::ignore = block.settings().set({ { "name", "TestNameAlt2" }, { "scaling_factor", 43.f } }); - std::ignore = block.settings().apply_staged_parameters(); + std::ignore = block.settings().applyStagedParameters(); expect(block.name == "TestNameAlt2"); expect(eq(block.scaling_factor, 43.f)); - block.settings().reset_defaults(); + block.settings().resetDefaults(); expect(block.resetCalled); expect(block.name == "TestNameAlt"); expect(eq(block.scaling_factor, 42.f)); @@ -527,7 +527,7 @@ const boost::ut::suite AnnotationTests = [] { expect(not needPowerOfTwoAlt.validate_and_set(5)); std::ignore = block.settings().set({ { "sample_rate", -1.0f } }); - std::ignore = block.settings().apply_staged_parameters(); // should print out a warning -> TODO: replace with pmt error message on msgOut port + std::ignore = block.settings().applyStagedParameters(); // should print out a warning -> TODO: replace with pmt error message on msgOut port // fmt::print("description:\n {}", gr::node_description>()); }; @@ -557,7 +557,7 @@ const boost::ut::suite TransactionTests = [] { "CtxSettings"_test = [] { Graph testGraph; auto &block = testGraph.emplaceBlock>({ { "name", "TestName" }, { "scaling_factor", 2.f } }); - auto s = ctx_settings(block); + auto s = CtxSettings(block); auto ctx0 = SettingsCtx(std::chrono::system_clock::now()); std::ignore = s.set({ { "name", "TestNameAlt" }, { "scaling_factor", 42.f } }, ctx0); auto ctx1 = SettingsCtx(std::chrono::system_clock::now() + std::chrono::seconds(1)); @@ -581,7 +581,7 @@ const boost::ut::suite TransactionTests = [] { "CtxSettings Matching"_test = [&] { Graph testGraph; auto &block = testGraph.emplaceBlock>({ { "scaling_factor", 42 } }); - auto s = ctx_settings(block, matchPred); + auto s = CtxSettings(block, matchPred); const auto ctx0 = SettingsCtx(std::chrono::system_clock::now(), { { "BPCID", 1 }, { "SID", 1 }, { "BPID", 1 }, { "GID", 1 } }); std::ignore = s.set({ { "scaling_factor", 101 } }, ctx0); const auto ctx1 = SettingsCtx(std::chrono::system_clock::now(), { { "BPCID", 1 }, { "SID", 1 }, { "BPID", 1 } }); @@ -612,7 +612,7 @@ const boost::ut::suite TransactionTests = [] { // the multiplexed Settings can be used as a drop-in replacement for "normal" Settings Graph testGraph; auto &block = testGraph.emplaceBlock>({ { "name", "TestName" }, { "scaling_factor", 2.f } }); - auto s = std::make_unique::type>>(block, matchPred); + auto s = std::make_unique::type>>(block, matchPred); block.setSettings(s); auto ctx0 = SettingsCtx(std::chrono::system_clock::now()); std::ignore = block.settings().set({ { "name", "TestNameAlt" }, { "scaling_factor", 42.f } }, ctx0); diff --git a/core/test/qa_tags.cpp b/core/test/qa_Tags.cpp similarity index 89% rename from core/test/qa_tags.cpp rename to core/test/qa_Tags.cpp index 017c82f22..0e4f7b210 100644 --- a/core/test/qa_tags.cpp +++ b/core/test/qa_Tags.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include @@ -22,15 +22,15 @@ const boost::ut::suite TagTests = [] { using namespace gr; "TagReflection"_test = [] { - static_assert(sizeof(tag_t) % 64 == 0, "needs to meet L1 cache size"); - static_assert(refl::descriptor::type_descriptor::name == "gr::tag_t"); - static_assert(refl::member_list::size == 2, "index and map being declared"); - static_assert(refl::trait::get_t<0, refl::member_list>::name == "index", "class field index is public API"); - static_assert(refl::trait::get_t<1, refl::member_list>::name == "map", "class field map is public API"); + static_assert(sizeof(Tag) % 64 == 0, "needs to meet L1 cache size"); + static_assert(refl::descriptor::type_descriptor::name == "gr::Tag"); + static_assert(refl::member_list::size == 2, "index and map being declared"); + static_assert(refl::trait::get_t<0, refl::member_list>::name == "index", "class field index is public API"); + static_assert(refl::trait::get_t<1, refl::member_list>::name == "map", "class field map is public API"); }; "DefaultTags"_test = [] { - tag_t testTag{}; + Tag testTag{}; testTag.insert_or_assign(tag::SAMPLE_RATE, pmtv::pmt(3.0f)); testTag.insert_or_assign(tag::SAMPLE_RATE(4.0f));