2#include "Core/CoreMacros.hpp"
3#include "Dataflow/Core/Port.hpp"
4#include <Dataflow/Core/Node.hpp>
11namespace Functionals {
23template <
typename A,
bool is_container = false>
26 using const_value_ref =
const A&;
35 using value_type =
typename A::value_type;
36 using const_value_ref =
const typename A::value_type&;
57template <
typename t_a,
61 bool it_a = Ra::Core::Utils::is_container<t_a>::value,
62 bool it_b = Ra::Core::Utils::is_container<t_b>::value,
63 bool it_out = Ra::Core::Utils::is_container<t_out>::value>
65 static t_out executeInternal( t_a&, t_b&, funcType ) {
66 static_assert( ( ( it_a || it_b ) ? it_out : !it_out ),
"Invalid template parameter " );
73template <
typename t_a,
typename t_b,
typename t_out,
typename funcType>
75 static t_out executeInternal( t_a& a, t_b& b, funcType f ) {
81 [f](
typename ArgTypeHelper<t_a>::const_value_ref x,
82 typename ArgTypeHelper<t_b>::const_value_ref y ) ->
83 typename ArgTypeHelper<t_out>::value_type { return f( x, y ); } );
91template <
typename t_a,
typename t_b,
typename t_out,
typename funcType>
93 static t_out executeInternal( t_a& a, t_b& b, funcType f ) {
98 [&b, f](
typename ArgTypeHelper<t_a>::const_value_ref x ) ->
99 typename ArgTypeHelper<t_out>::value_type { return f( x, b ); } );
107template <
typename t_a,
typename t_b,
typename t_out,
typename funcType>
109 static t_out executeInternal( t_a& a, t_b& b, funcType f ) {
114 [&a, f](
typename ArgTypeHelper<t_b>::const_value_ref x ) ->
115 typename ArgTypeHelper<t_out>::value_type { return f( a, x ); } );
123template <
typename t_a,
typename t_b,
typename t_out,
typename funcType>
125 static t_out executeInternal( t_a& a, t_b& b, funcType f ) {
return f( a, b ); }
154template <
typename t_a,
typename t_b = t_a,
typename t_result = t_a>
161 using Arg1_type =
typename internal::ArgTypeHelper<t_a>::const_value_ref;
162 using Arg2_type =
typename internal::ArgTypeHelper<t_b>::const_value_ref;
163 using Res_type =
typename internal::ArgTypeHelper<t_result>::value_type;
175 m_result = t_result {};
181 const auto& f = m_port_in_op->data();
183 m_port_in_a->data(), m_port_in_b->data(), f );
192 std::string {
"BinaryOp<" } + Ra::Core::Utils::simplifiedDemangledType<t_a>() +
" x " +
193 Ra::Core::Utils::simplifiedDemangledType<t_b>() +
" -> " +
194 Ra::Core::Utils::simplifiedDemangledType<t_result>() +
">";
195 return demangledName;
201 std::optional<BinaryOperator> op ) :
202 Node( instanceName, typeName ) {
203 if ( op ) m_port_in_op->set_default_value( *op );
215 RA_NODE_PORT_IN( t_a, a );
216 RA_NODE_PORT_IN( t_b, b );
217 RA_NODE_PORT_IN( BinaryOperator, op );
218 RA_NODE_PORT_OUT_WITH_DATA( t_result, result );
T back_inserter(T... args)
Apply a binary operation on its input.
bool fromJsonInternal(const nlohmann::json &data) override
Internal json representation of the Node.
BinaryOpNode(const std::string &instanceName, std::optional< BinaryOperator > op={})
Construct a BinaryOpNode with the given operator.
bool execute() override
Executes the node.
void toJsonInternal(nlohmann::json &data) const override
Internal json representation of the Node.
void init() override
Initializes the node content.
void set_operator(BinaryOperator op)
Sets the operator to be evaluated by the node.
typename internal::ArgTypeHelper< t_a >::const_value_ref Arg1_type
Base abstract class for all the nodes added and used by the node system.
virtual void init()
Initializes the node content.
virtual bool fromJsonInternal(const nlohmann::json &data)
Internal json representation of the Node.
virtual void toJsonInternal(nlohmann::json &data) const
Internal json representation of the Node.
hepler function to manage enum as underlying types in VariableSet
Type traits giving access to value_type and const ref type.
Manage the call to y = f(a, b) according to inputs aand ouput types of the node.