From af6e2a703b3c80c2fa16da477cc52f21c1e70d50 Mon Sep 17 00:00:00 2001 From: "Ralph J. Steinhagen" Date: Wed, 20 Sep 2023 08:02:22 +0200 Subject: [PATCH] refactored port interface ... as outlined by GR Architecture WG and https://github.com/fair-acc/graph-prototype/issues/148 tackled items: * refactored port structure (mandatory enum NTTPs vs. optional type-wrapped arguments) * added optional domain argument * added default init value (needed for cyclic graphs) * add isOptional() annotation * fixed repeated_port name -> name0, name1, name2, ... Signed-off-by: Ralph J. Steinhagen --- src/main.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index dd691b3bd..f368fd57f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,6 +16,7 @@ struct count_source : public fg::node> { return 42; } }; + ENABLE_REFLECTION_FOR_TEMPLATE_FULL((typename T), (count_source), random); template @@ -27,11 +28,12 @@ struct expect_sink : public fg::node> { std::cout << value << std::endl; } }; + ENABLE_REFLECTION_FOR_TEMPLATE_FULL((typename T), (expect_sink), sink); template() * std::declval())> struct scale : public fg::node> { - fg::IN original; + fg::IN original; fg::OUT scaled; template V> @@ -40,12 +42,13 @@ struct scale : public fg::node> { return a * Scale; } }; + ENABLE_REFLECTION_FOR_TEMPLATE_FULL((typename T, T Scale, typename R), (scale), original, scaled); template() + std::declval())> struct adder : public fg::node> { - fg::IN addend0; - fg::IN addend1; + fg::IN addend0; + fg::IN addend1; fg::OUT sum; template V> @@ -54,9 +57,11 @@ struct adder : public fg::node> { return a + b; } }; + ENABLE_REFLECTION_FOR_TEMPLATE_FULL((typename T, typename R), (adder), addend0, addend1, sum); using fg::port_type_t::STREAM, fg::port_direction_t::INPUT, fg::port_direction_t::OUTPUT; + template class duplicate : public fg::node, fair::meta::typelist>, fg::repeated_ports> { using base = fg::node, fair::meta::typelist>, fg::repeated_ports>; @@ -66,23 +71,22 @@ class duplicate : public fg::node, fair::meta::typelist(std::index_sequence) { return std::make_tuple(((void) Is, a)...); } - (std::make_index_sequence()); + return [&a](std::index_sequence) { return std::make_tuple(((void) Is, a)...); }(std::make_index_sequence()); } }; template requires(Depth > 0) struct delay : public fg::node> { - fg::IN in; - fg::OUT out; + fg::IN in; + fg::OUT out; std::array buffer = {}; int pos = 0; [[nodiscard]] constexpr T - process_one(T in) noexcept { + process_one(T val) noexcept { T ret = buffer[pos]; - buffer[pos] = in; + buffer[pos] = val; if (pos == Depth - 1) { pos = 0; } else { @@ -91,6 +95,7 @@ struct delay : public fg::node> { return ret; } }; + ENABLE_REFLECTION_FOR_TEMPLATE_FULL((typename T, std::size_t Depth), (delay), in, out); int