Skip to content

Commit

Permalink
refactored port<T> interface
Browse files Browse the repository at this point in the history
... as outlined by GR Architecture WG and #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 <r.steinhagen@gsi.de>
  • Loading branch information
RalphSteinhagen committed Sep 20, 2023
1 parent c147ec2 commit af6e2a7
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct count_source : public fg::node<count_source<T>> {
return 42;
}
};

ENABLE_REFLECTION_FOR_TEMPLATE_FULL((typename T), (count_source<T>), random);

template<typename T>
Expand All @@ -27,11 +28,12 @@ struct expect_sink : public fg::node<expect_sink<T>> {
std::cout << value << std::endl;
}
};

ENABLE_REFLECTION_FOR_TEMPLATE_FULL((typename T), (expect_sink<T>), sink);

template<typename T, T Scale, typename R = decltype(std::declval<T>() * std::declval<T>())>
struct scale : public fg::node<scale<T, Scale, R>> {
fg::IN<T> original;
fg::IN<T> original;
fg::OUT<R> scaled;

template<fair::meta::t_or_simd<T> V>
Expand All @@ -40,12 +42,13 @@ struct scale : public fg::node<scale<T, Scale, R>> {
return a * Scale;
}
};

ENABLE_REFLECTION_FOR_TEMPLATE_FULL((typename T, T Scale, typename R), (scale<T, Scale, R>), original, scaled);

template<typename T, typename R = decltype(std::declval<T>() + std::declval<T>())>
struct adder : public fg::node<adder<T>> {
fg::IN<T> addend0;
fg::IN<T> addend1;
fg::IN<T> addend0;
fg::IN<T> addend1;
fg::OUT<R> sum;

template<fair::meta::t_or_simd<T> V>
Expand All @@ -54,9 +57,11 @@ struct adder : public fg::node<adder<T>> {
return a + b;
}
};

ENABLE_REFLECTION_FOR_TEMPLATE_FULL((typename T, typename R), (adder<T, R>), addend0, addend1, sum);

using fg::port_type_t::STREAM, fg::port_direction_t::INPUT, fg::port_direction_t::OUTPUT;

template<typename T, std::size_t Count = 2>
class duplicate : public fg::node<duplicate<T, Count>, fair::meta::typelist<fg::InNamed<T, "in">>, fg::repeated_ports<Count, T, "out", STREAM, OUTPUT>> {
using base = fg::node<duplicate<T, Count>, fair::meta::typelist<fg::InNamed<T, "in">>, fg::repeated_ports<Count, T, "out", STREAM, OUTPUT>>;
Expand All @@ -66,23 +71,22 @@ class duplicate : public fg::node<duplicate<T, Count>, fair::meta::typelist<fg::

[[nodiscard]] constexpr return_type
process_one(T a) const noexcept {
return [&a]<std::size_t... Is>(std::index_sequence<Is...>) { return std::make_tuple(((void) Is, a)...); }
(std::make_index_sequence<Count>());
return [&a]<std::size_t... Is>(std::index_sequence<Is...>) { return std::make_tuple(((void) Is, a)...); }(std::make_index_sequence<Count>());
}
};

template<typename T, std::size_t Depth>
requires(Depth > 0)
struct delay : public fg::node<delay<T, Depth>> {
fg::IN<T> in;
fg::OUT<T> out;
fg::IN<T> in;
fg::OUT<T> out;
std::array<T, Depth> 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 {
Expand All @@ -91,6 +95,7 @@ struct delay : public fg::node<delay<T, Depth>> {
return ret;
}
};

ENABLE_REFLECTION_FOR_TEMPLATE_FULL((typename T, std::size_t Depth), (delay<T, Depth>), in, out);

int
Expand Down

0 comments on commit af6e2a7

Please sign in to comment.