Loading [MathJax]/extensions/TeX/AMSsymbols.js
Radium Engine  1.5.29
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Ra::Dataflow::Core::Functionals::BinaryOpNode< t_a, t_b, t_result > Class Template Reference

Apply a binary operation on its input. More...

#include <Dataflow/Core/Functionals/BinaryOpNode.hpp>

+ Inheritance diagram for Ra::Dataflow::Core::Functionals::BinaryOpNode< t_a, t_b, t_result >:
+ Collaboration diagram for Ra::Dataflow::Core::Functionals::BinaryOpNode< t_a, t_b, t_result >:

Public Types

using Arg1_type = typename internal::ArgTypeHelper<t_a>::const_value_ref
 
using Arg2_type = typename internal::ArgTypeHelper<t_b>::const_value_ref
 
using Res_type = typename internal::ArgTypeHelper<t_result>::value_type
 
using BinaryOperator = std::function<Res_type( Arg1_type, Arg2_type )>
 
- Public Types inherited from Ra::Dataflow::Core::Node
using PortIndex = Ra::Core::Utils::Index
 
template<typename Port >
using PortCollection = std::vector<Port>
 
template<typename Port >
using PortPtr = std::shared_ptr<Port>
 
template<typename Port >
using PortRawPtr = Port*
 
template<typename Type >
using PortInPtr = PortPtr<PortIn<Type>>
 
template<typename Type >
using PortInRawPtr = PortIn<Type>*
 
template<typename Type >
using PortOutPtr = PortPtr<PortOut<Type>>
 
template<typename Type >
using PortOutRawPtr = PortOut<Type>*
 
using PortBasePtr = PortPtr<PortBase>
 
using PortBaseRawPtr = PortRawPtr<PortBase>
 
using PortBaseCollection = PortCollection<PortBasePtr>
 
using PortBaseInPtr = PortPtr<PortBaseIn>
 
using PortBaseInRawPtr = PortRawPtr<PortBaseIn>
 
using PortBaseInCollection = PortCollection<PortBaseInPtr>
 
using PortBaseOutPtr = PortPtr<PortBaseOut>
 
using PortBaseOutRawPtr = PortRawPtr<PortBaseOut>
 
using PortBaseOutCollection = PortCollection<PortBaseOutPtr>
 
template<typename Port >
using IndexAndPort = std::pair<PortIndex, Port>
 
template<typename T >
using ParamHandle = Ra::Core::VariableSet::VariableHandle<T>
 

Public Member Functions

 BinaryOpNode (const std::string &instanceName, std::optional< BinaryOperator > op={})
 Construct a BinaryOpNode with the given operator.
 
void init () override
 Initializes the node content.
 
bool execute () override
 Executes the node.
 
void set_operator (BinaryOperator op)
 Sets the operator to be evaluated by the node.
 
- Public Member Functions inherited from Ra::Dataflow::Core::Node
virtual ~Node ()=default
 make Node a base abstract class
 
bool operator== (const Node &node)
 Two nodes are considered equal if there model and instance names are the same.
 
void add_metadata (const nlohmann::json &data)
 Add a metadata to the node to store application specific information.
 
const nlohmann::json & metadata ()
 Give access to extra json data stored on the node.
 
bool is_initialized () const
 
Ra::Core::VariableSetparameters ()
 Return node's parameters.
 
Ra::Core::VariableSetinput_variables ()
 Return a variable set of input ports default value reference, if any.
 
bool is_output ()
 Node is output if none of the output ports is linked.
 
bool is_input ()
 Node is input if all input ports have default values and not linked.
 
 Node (const Node &)=delete
 
Nodeoperator= (const Node &)=delete
 
virtual bool compile ()
 Compile the node to check its validity.
 
virtual void destroy ()
 Delete the node's content.
 
auto port_by_name (const std::string &type, const std::string &name) const -> IndexAndPort< PortBaseRawPtr >
 Get a port by its name.
 
auto input_by_name (const std::string &name) const -> IndexAndPort< PortBaseInRawPtr >
 Convenience alias to port_by_name("in", name)
 
auto output_by_name (const std::string &name) const -> IndexAndPort< PortBaseOutRawPtr >
 Convenience alias to port_by_name("out", name)
 
PortBaseRawPtr port_by_index (const std::string &type, PortIndex index) const
 Get a port by its index.
 
auto input_by_index (PortIndex index) const
 Convenience alias to port_by_index("in", index)
 
auto output_by_index (PortIndex index) const
 Convenience alias to port_by_index("out", index)
 
template<typename T >
auto input_by_index (PortIndex index) const
 Convenience alias with typed port.
 
template<typename T >
auto output_by_index (PortIndex index) const
 Convenience alias with typed port.
 
const PortBaseInCollectioninputs () const
 Gets the in ports of the node.
 
const PortBaseOutCollectionoutputs () const
 Gets the out ports of the node.
 
const std::stringmodel_name () const
 Gets the model (type/class) name of the node.
 
const std::stringdisplay_name () const
 Gets the display name of the node (e.g. for gui), no need to be unique in a graph.
 
void set_display_name (const std::string &name)
 Set the display name.
 
const std::stringinstance_name () const
 Gets the instance name of the node.
 
void set_instance_name (const std::string &name)
 Sets the instance name the node (unused?) instance name must be unique in a graph.
 
void toJson (nlohmann::json &data) const
 Serialize the content of the node.
 
bool fromJson (const nlohmann::json &data)
 Unserialized the content of the node.
 

Static Public Member Functions

static const std::stringnode_typename ()
 

Protected Member Functions

 BinaryOpNode (const std::string &instanceName, const std::string &typeName, std::optional< BinaryOperator > op)
 
void toJsonInternal (nlohmann::json &data) const override
 Internal json representation of the Node.
 
bool fromJsonInternal (const nlohmann::json &data) override
 Internal json representation of the Node.
 
- Protected Member Functions inherited from Ra::Dataflow::Core::Node
 Node (const std::string &instance, const std::string &typeName)
 Construct the base node given its name and type.
 
template<typename PortType >
auto port_by_name (const PortCollection< PortPtr< PortType > > &ports, const std::string &name) const -> IndexAndPort< PortRawPtr< PortType > >
 Gets the Port By Name.
 
template<typename PortType >
auto port_base (const PortCollection< PortPtr< PortType > > &ports, PortIndex idx) const -> PortRawPtr< PortType >
 Gets the PortBase In or Out by its index.
 
template<typename T , typename PortType >
auto port (const PortCollection< PortPtr< PortType > > &ports, PortIndex index) const
 Gets a port in a collection by its index.
 
template<typename PortType >
PortIndex add_port (PortCollection< PortPtr< PortType > > &, PortPtr< PortType > port)
 Adds a port to port collection.
 
PortIndex add_input (PortBaseInPtr in)
 Convenience alias to add_port(inputs(), in)
 
PortIndex add_output (PortBaseOutPtr out)
 Convenience alias to add_port(outputs(), out)
 
template<typename T , typename... U>
auto add_input (U &&... u)
 Adds a typed input port.
 
template<typename T , typename... U>
auto add_output (U &&... u)
 Adds a typed output port.
 
template<typename T >
auto input_port (PortIndex index)
 Gets a typed (input/output) port.
 
template<typename T >
auto output_port (PortIndex index)
 Gets a typed (input/output) port.
 
void remove_input (PortIndex index)
 Remove the given port from the managed (input/output) ports.
 
void remove_output (PortIndex index)
 Remove the given port from the managed (input/output) ports.
 
template<typename T >
auto add_parameter (const std::string &name, const T &value)
 
template<typename T >
bool remove_parameter (const std::string &name)
 
template<typename T >
bool remove_parameter (ParamHandle< T > &handle)
 

Additional Inherited Members

- Protected Attributes inherited from Ra::Dataflow::Core::Node
bool m_initialized { false }
 Flag that checks if the node is already initialized.
 
std::string m_model_name
 The type name of the node. Initialized once at construction.
 
std::string m_instance_name
 The instance name of the node.
 
std::string m_display_name { "" }
 Node's name if needed for display.
 
PortCollection< PortPtr< PortBaseIn > > m_inputs
 The in ports of the node (own by the node)
 
PortCollection< PortPtr< PortBaseOut > > m_outputs
 The out ports of the node (own by the node)
 
Ra::Core::VariableSet m_parameters
 The editable parameters of the node.
 
Ra::Core::VariableSet m_input_variables
 
nlohmann::json m_metadata
 Additional data on the node, added by application or gui or ...
 

Detailed Description

template<typename t_a, typename t_b = t_a, typename t_result = t_a>
class Ra::Dataflow::Core::Functionals::BinaryOpNode< t_a, t_b, t_result >

Apply a binary operation on its input.

Template Parameters
t_atype of the first argument
t_btype of the second argument
t_outtype of the result

This node apply an operator f on its input such that :

  • if t_a, t_b and t_out are collections, r[i] = f(a[i], b[i]) for all elements i in the collections.
  • if t_a and t_out are collections, t_b an object, r[i] = f(a[i], b) for all elements i in the collections.
  • if t_b and t_out are collections, t_a an object, r[i] = f(a, b[i]) for all elements i in the collections.
  • if t_a, t_b and t_out are objects, r = f(a, b). All other configurations of t_a, t_b and t_out are illegal.

This node has three inputs :

  • a : port accepting the input data of type t_a. Must be linked.
  • b : port accepting the input data of type t_b. Must be linked.
  • f : port accepting an operator with profile std::function<Res_type( Arg1_type, Arg2_type )>. Link to this port is not mandatory, the operator might be set once for the node. If this port is linked, the operator will be taken from the port.

This node has one output :

  • out : port giving a t_out such that out = std::transform(a, b, f)

Definition at line 155 of file BinaryOpNode.hpp.

Member Typedef Documentation

◆ Arg1_type

template<typename t_a , typename t_b = t_a, typename t_result = t_a>
using Ra::Dataflow::Core::Functionals::BinaryOpNode< t_a, t_b, t_result >::Arg1_type = typename internal::ArgTypeHelper<t_a>::const_value_ref

BinaryOp operator profile

Definition at line 161 of file BinaryOpNode.hpp.

◆ Arg2_type

template<typename t_a , typename t_b = t_a, typename t_result = t_a>
using Ra::Dataflow::Core::Functionals::BinaryOpNode< t_a, t_b, t_result >::Arg2_type = typename internal::ArgTypeHelper<t_b>::const_value_ref

Definition at line 162 of file BinaryOpNode.hpp.

◆ BinaryOperator

template<typename t_a , typename t_b = t_a, typename t_result = t_a>
using Ra::Dataflow::Core::Functionals::BinaryOpNode< t_a, t_b, t_result >::BinaryOperator = std::function<Res_type( Arg1_type, Arg2_type )>

Definition at line 164 of file BinaryOpNode.hpp.

◆ Res_type

template<typename t_a , typename t_b = t_a, typename t_result = t_a>
using Ra::Dataflow::Core::Functionals::BinaryOpNode< t_a, t_b, t_result >::Res_type = typename internal::ArgTypeHelper<t_result>::value_type

Definition at line 163 of file BinaryOpNode.hpp.

Constructor & Destructor Documentation

◆ BinaryOpNode() [1/2]

template<typename t_a , typename t_b = t_a, typename t_result = t_a>
Ra::Dataflow::Core::Functionals::BinaryOpNode< t_a, t_b, t_result >::BinaryOpNode ( const std::string & instanceName,
std::optional< BinaryOperator > op = {} )
inline

Construct a BinaryOpNode with the given operator.

Parameters
instanceName
op

Definition at line 171 of file BinaryOpNode.hpp.

◆ BinaryOpNode() [2/2]

template<typename t_a , typename t_b = t_a, typename t_result = t_a>
Ra::Dataflow::Core::Functionals::BinaryOpNode< t_a, t_b, t_result >::BinaryOpNode ( const std::string & instanceName,
const std::string & typeName,
std::optional< BinaryOperator > op )
inlineprotected

Definition at line 199 of file BinaryOpNode.hpp.

Member Function Documentation

◆ execute()

template<typename t_a , typename t_b = t_a, typename t_result = t_a>
bool Ra::Dataflow::Core::Functionals::BinaryOpNode< t_a, t_b, t_result >::execute ( )
inlineoverridevirtual

Executes the node.

Execute the node function on the input ports (to be fetched) and write the results to the output ports.

Returns
the execution status.

Implements Ra::Dataflow::Core::Node.

Definition at line 179 of file BinaryOpNode.hpp.

◆ fromJsonInternal()

template<typename t_a , typename t_b = t_a, typename t_result = t_a>
bool Ra::Dataflow::Core::Functionals::BinaryOpNode< t_a, t_b, t_result >::fromJsonInternal ( const nlohmann::json & data)
inlineoverrideprotectedvirtual

Internal json representation of the Node.

Default implementation warn about unsupported deserialization. Effective deserialzation must be implemented by inheriting classes. Be careful with template specialization and function member overriding in derived classes.

Reimplemented from Ra::Dataflow::Core::Node.

Definition at line 208 of file BinaryOpNode.hpp.

+ Here is the call graph for this function:

◆ init()

template<typename t_a , typename t_b = t_a, typename t_result = t_a>
void Ra::Dataflow::Core::Functionals::BinaryOpNode< t_a, t_b, t_result >::init ( )
inlineoverridevirtual

Initializes the node content.

The init() function should be called once at the beginning of the lifetime of the node by the owner of the node (the graph which contains the node). Its goal is to initialize the node's internal data if any. The default do nothing.

Reimplemented from Ra::Dataflow::Core::Node.

Definition at line 174 of file BinaryOpNode.hpp.

+ Here is the call graph for this function:

◆ node_typename()

template<typename t_a , typename t_b = t_a, typename t_result = t_a>
static const std::string & Ra::Dataflow::Core::Functionals::BinaryOpNode< t_a, t_b, t_result >::node_typename ( )
inlinestatic

Definition at line 190 of file BinaryOpNode.hpp.

◆ set_operator()

template<typename t_a , typename t_b = t_a, typename t_result = t_a>
void Ra::Dataflow::Core::Functionals::BinaryOpNode< t_a, t_b, t_result >::set_operator ( BinaryOperator op)
inline

Sets the operator to be evaluated by the node.

Definition at line 188 of file BinaryOpNode.hpp.

◆ toJsonInternal()

template<typename t_a , typename t_b = t_a, typename t_result = t_a>
void Ra::Dataflow::Core::Functionals::BinaryOpNode< t_a, t_b, t_result >::toJsonInternal ( nlohmann::json & data) const
inlineoverrideprotectedvirtual

Internal json representation of the Node.

Default implementation warn about unsupported deserialization. Effective deserialzation must be implemented by inheriting classes. Be careful with template specialization and function member overriding in derived classes.

Reimplemented from Ra::Dataflow::Core::Node.

Definition at line 206 of file BinaryOpNode.hpp.

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: