2#include <Dataflow/Core/Node.hpp>
32template <
typename coll_t,
typename v_t =
typename coll_t::value_type>
73 RA_NODE_PORT_IN( v_t,
init );
74 RA_NODE_PORT_IN( coll_t, data );
76 RA_NODE_PORT_OUT_WITH_DATA( v_t, result );
85template <
typename coll_t,
typename v_t>
90 []( const v_t& a, const v_t& ) -> v_t { return a; },
93template <
typename coll_t,
typename v_t>
97 ReduceNode( instanceName, node_typename(), op, initialValue ) {}
99template <
typename coll_t,
typename v_t>
101 m_port_in_op->set_default_value( op );
102 m_port_in_init->set_default_value( initialValue );
105template <
typename coll_t,
typename v_t>
108 m_result = m_port_in_init->data();
111template <
typename coll_t,
typename v_t>
113 const auto& f = m_port_in_op->data();
114 const auto& in = m_port_in_data->data();
116 m_result =
std::accumulate( in.begin(), in.end(), m_port_in_init->data(), f );
121template <
typename coll_t,
typename v_t>
124 std::string {
"Reduce<" } + Ra::Core::Utils::simplifiedDemangledType<coll_t>() +
">";
125 return demangledName;
128template <
typename coll_t,
typename v_t>
133 Node( instanceName, typeName ) {
134 m_port_in_op->set_default_value( op );
135 m_port_in_init->set_default_value( initialValue );
Reduce an iterable collection using a given operator.
void init() override
Initializes the node content.
bool execute() override
Executes the node.
void set_operator(ReduceOperator op, v_t initialValue=v_t {})
Sets the operator on the node.
bool fromJsonInternal(const nlohmann::json &data) override
Internal json representation of the Node.
ReduceNode(const std::string &instanceName)
Construct an identity transformer.
std::function< v_t(const v_t &, const v_t &)> ReduceOperator
void toJsonInternal(nlohmann::json &data) const override
Internal json representation of the Node.
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