2#include <Dataflow/Core/Node.hpp>
11template <
typename Input,
typename Output = Input>
12class FunctionNode :
public Node
16 static auto IdentityFunction(
const Input& x ) -> Output {
return Output { x }; }
18 FunctionNode(
const std::string& instanceName, Function function = IdentityFunction );
21 bool execute()
override;
23 void set_function( Function function ) { m_port_in_op->set_default_value( function ); }
31 bool fromJsonInternal(
const nlohmann::json& data )
override {
36 RA_NODE_PORT_IN( Input, data );
37 RA_NODE_PORT_IN( Function, op );
38 RA_NODE_PORT_OUT_WITH_DATA( Output, result );
43template <
typename Input,
typename Output>
44FunctionNode<Input, Output>::FunctionNode(
const std::string& instanceName, Function function ) :
45 FunctionNode( instanceName, node_typename(), function ) {}
47template <
typename Input,
typename Output>
48bool FunctionNode<Input, Output>::execute() {
49 const auto& f = m_port_in_op->data();
50 const auto& x = m_port_in_data->data();
57template <
typename Input,
typename Output>
58const std::string& FunctionNode<Input, Output>::node_typename() {
60 std::string {
"Function<" } + Ra::Core::Utils::simplifiedDemangledType<Input>() +
">";
64template <
typename Input,
typename Output>
65FunctionNode<Input, Output>::FunctionNode(
const std::string& instanceName,
68 Node( instanceName, typeName ) {
69 m_port_in_op->set_default_value( function );
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