Loading [MathJax]/extensions/tex2jax.js
Radium Engine  1.5.28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Ra::Dataflow::Core::NodeFactory Class Reference

#include <Dataflow/Core/NodeFactory.hpp>

+ Collaboration diagram for Ra::Dataflow::Core::NodeFactory:

Public Types

using NodeCreatorFunctor = std::function<std::shared_ptr<Node>( const nlohmann::json& data )>
 
using ContainerType
 

Public Member Functions

 NodeFactory (std::string name)
 
auto name () const -> std::string
 
template<typename T >
auto register_node_creator (NodeCreatorFunctor nodeCreator, const std::string &nodeCategory="RadiumNodes") -> bool
 
template<typename T >
auto register_node_creator (const std::string &instanceNamePrefix, const std::string &nodeCategory="RadiumNodes") -> bool
 
auto register_node_creator (const std::string &nodeType, NodeCreatorFunctor nodeCreator, const std::string &nodeCategory="RadiumNodes") -> bool
 
auto create_node (const std::string &nodeType, const nlohmann::json &data, DataflowGraph *owningGraph=nullptr) -> std::shared_ptr< Node >
 
auto factory_map () const -> const ContainerType &
 

Detailed Description

NodeFactory store a set of functions allowing to dynamically create dataflow nodes. A NodeFactory is used when loading a node graph from a json representation of the graph to instantiate all the loaded nodes.

Definition at line 26 of file NodeFactory.hpp.

Member Typedef Documentation

◆ ContainerType

Initial value:

The type of the associative container used to store the factory this container associate a concrete node type name to a pair <concrete instantiation functor, name of the node category> The name of the node category is helpful for graphical NodeGraph editor. By default this is set to be "RadiumNodes"

Definition at line 99 of file NodeFactory.hpp.

◆ NodeCreatorFunctor

Function that creates and initialize a node. Typical implementation of such a function should do the following : { auto node = new ConcreteNodeType( unique_instance_name ); node->fromJson( data); return node; }

Definition at line 42 of file NodeFactory.hpp.

Constructor & Destructor Documentation

◆ NodeFactory()

Ra::Dataflow::Core::NodeFactory::NodeFactory ( std::string name)
explicit

Creates an empty factory with the given name

Definition at line 13 of file NodeFactory.cpp.

Member Function Documentation

◆ create_node()

auto Ra::Dataflow::Core::NodeFactory::create_node ( const std::string & nodeType,
const nlohmann::json & data,
DataflowGraph * owningGraph = nullptr ) -> std::shared_ptr<Node>
nodiscard

Create a node of the requested type. The node is filled with the given json content. If owningGraph is non null, the node is added to this graph

Parameters
nodeTypeType name of the node to be created.
datajson representation of the node data (might be empty)
owningGraphif non null, the node is added to ths graph
Returns
the new node. Ownership of the returned pointer is left to the caller.

Definition at line 19 of file NodeFactory.cpp.

◆ factory_map()

auto Ra::Dataflow::Core::NodeFactory::factory_map ( ) const -> const ContainerType&
inlinenodiscard

Get a const reference on the associative map

Returns

Definition at line 278 of file NodeFactory.hpp.

◆ name()

auto Ra::Dataflow::Core::NodeFactory::name ( ) const -> std::string
nodiscard

Definition at line 15 of file NodeFactory.cpp.

◆ register_node_creator() [1/3]

template<typename T >
auto Ra::Dataflow::Core::NodeFactory::register_node_creator ( const std::string & instanceNamePrefix,
const std::string & nodeCategory = "RadiumNodes" ) -> bool

Associate, for a given concrete node type, a generic NodeCreatorFunctor

Template Parameters
TConcrete node type identifier
Parameters
instanceNamePrefixprefix of the node instance name (will be called "prefix_i" with i a unique number.
nodeCategoryCategory of the node.
Returns
true if the node creator is successfully added, false if not (e.g. due to a name collision).

Definition at line 259 of file NodeFactory.hpp.

+ Here is the call graph for this function:

◆ register_node_creator() [2/3]

auto Ra::Dataflow::Core::NodeFactory::register_node_creator ( const std::string & nodeType,
NodeCreatorFunctor nodeCreator,
const std::string & nodeCategory = "RadiumNodes" ) -> bool

Associate, for a given concrete node type name, a NodeCreatorFunctor

Parameters
nodeTypethe name of the concrete type (the same as what is obtained by T::node_typename() on a node of type T)
nodeCreatorFunctor to create an node of the corresponding concrete node type.
Returns
true if the node creator is successfully added, false if not (e.g. due to a name collision).

Definition at line 30 of file NodeFactory.cpp.

+ Here is the call graph for this function:

◆ register_node_creator() [3/3]

template<typename T >
auto Ra::Dataflow::Core::NodeFactory::register_node_creator ( NodeCreatorFunctor nodeCreator,
const std::string & nodeCategory = "RadiumNodes" ) -> bool

Associate, for a given concrete node type, a custom NodeCreatorFunctor

Template Parameters
TConcrete node type identifier
Parameters
nodeCreatorFunctor to create an node of the corresponding concrete node type.
nodeCategoryCategory of the node.
Returns
true if the node creator is successfully added, false if not (e.g. due to a name collision).

Definition at line 253 of file NodeFactory.hpp.

+ Here is the call graph for this function:

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