1#include <Dataflow/Core/NodeFactory.hpp>
3#include <Core/Utils/Log.hpp>
4#include <Dataflow/Core/DataflowGraph.hpp>
15auto NodeFactory::name() const ->
std::
string {
20 const nlohmann::json& data,
22 if (
auto itr = m_nodesCreators.find( nodeType ); itr != m_nodesCreators.end() ) {
24 if ( owningGraph !=
nullptr ) { owningGraph->add_node( node ); }
34 if (
auto itr = m_nodesCreators.find( nodeType ); itr == m_nodesCreators.end() ) {
35 m_nodesCreators[nodeType] = {
std::move( nodeCreator ), nodeCategory };
38 LOG( Ra::Core::Utils::logWARNING )
39 <<
"NodeFactory (" << name()
40 <<
") : trying to add an already existing node creator for type " << nodeType <<
".";
44auto NodeFactory::next_node_id() ->
size_t {
45 return ++m_nodesCreated;
49 const nlohmann::json& data,
51 for (
const auto& itr : m_factories ) {
52 if (
auto node = itr.second->create_node( nodeType, data, owningGraph ); node ) {
56 LOG( Ra::Core::Utils::logERROR ) <<
"NodeFactorySet: unable to find constructor for "
57 << nodeType <<
" in any managed factory.";
61namespace NodeFactoriesManager {
69 return s_factoryManager;
76auto create_factory(
const NodeFactorySet::key_type& name ) -> NodeFactorySet::mapped_type {
76auto create_factory(
const NodeFactorySet::key_type& name ) -> NodeFactorySet::mapped_type {
…}
85auto factory(
const NodeFactorySet::key_type& name ) -> NodeFactorySet::mapped_type {
87 if (
auto factory = factories.find( name );
factory != factories.end() ) {
85auto factory(
const NodeFactorySet::key_type& name ) -> NodeFactorySet::mapped_type {
…}
61namespace NodeFactoriesManager {
…}
Represent a set of connected nodes that define a Direct Acyclic Computational Graph Ownership of node...
auto create_node(const std::string &nodeType, const nlohmann::json &data, DataflowGraph *owningGraph=nullptr) -> std::shared_ptr< Node >
Create a node using one of the functor (if it exists) registered in one factory for the given type na...
NodeFactory(std::string name)
auto register_node_creator(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(const NodeFactorySet::key_type &name) -> NodeFactorySet::mapped_type
Gets the given factory from the manager.
auto unregister_factory(const NodeFactorySet::key_type &name) -> bool
Unregister the factory from the manager.
auto register_factory(NodeFactorySet::mapped_type factory) -> bool
Register a factory into the manager. The key will be fetched from the factory (its name)
auto default_factory() -> NodeFactorySet::mapped_type
Gets the "default" factory for nodes exported by the Core dataflow library.
auto create_factory(const NodeFactorySet::key_type &name) -> NodeFactorySet::mapped_type
Create and register a factory to the manager.
auto factory_manager() -> NodeFactorySet &
Allow static initialization without init order problems.
hepler function to manage enum as underlying types in VariableSet