2#include <Dataflow/RaDataflow.hpp>
4#include <Dataflow/Core/Node.hpp>
6#include <Core/Utils/StdOptional.hpp>
10#include <unordered_map>
12#define REGISTER_TYPE_TO_FACTORY( FACTORY, TYPE, NAMESPACE ) \
13 FACTORY->register_node_creator<TYPE>( TYPE::node_typename() + "_", #NAMESPACE )
54 const std::string& nodeCategory =
"RadiumNodes" ) -> bool;
66 auto register_node_creator(
const std::string& instanceNamePrefix,
67 const std::string& nodeCategory =
"RadiumNodes" ) -> bool;
77 auto register_node_creator(
const std::string& nodeType,
79 const std::string& nodeCategory =
"RadiumNodes" ) -> bool;
89 [[nodiscard]]
auto create_node(
const std::string& nodeType,
90 const nlohmann::json& data,
106 [[nodiscard]]
auto factory_map() const -> const
ContainerType&;
113 auto next_node_id() ->
size_t;
116 size_t m_nodesCreated { 0 };
128 using key_type = container_type::key_type;
129 using mapped_type = container_type::mapped_type;
130 using value_type = container_type::value_type;
132 using const_iterator = container_type::const_iterator;
133 using iterator = container_type::iterator;
141 auto add_factory( mapped_type factory ) -> bool;
149 auto has_factory(
const key_type& name ) -> Ra::Core::Utils::optional<mapped_type>;
156 auto remove_factory(
const key_type& name ) -> bool;
174 [[nodiscard]]
auto create_node(
const std::string& nodeType,
175 const nlohmann::json& data,
181 auto begin()
const -> const_iterator;
182 auto end()
const -> const_iterator;
183 auto cbegin()
const -> const_iterator;
184 auto cend()
const -> const_iterator;
185 auto find(
const key_type& key )
const -> const_iterator;
187 auto erase(
const key_type& key ) -> size_t;
189 const std::string& default_factory_name() {
return m_default_factory_name; }
193 const std::string m_default_factory_name {
"Dataflow Nodes" };
207namespace NodeFactoriesManager {
226RA_DATAFLOW_CORE_API
auto create_factory(
const NodeFactorySet::key_type& name )
227 -> NodeFactorySet::mapped_type;
234RA_DATAFLOW_CORE_API
auto factory(
const NodeFactorySet::key_type& name )
235 -> NodeFactorySet::mapped_type;
242RA_DATAFLOW_CORE_API
auto unregister_factory(
const NodeFactorySet::key_type& name ) -> bool;
247RA_DATAFLOW_CORE_API
auto default_factory() -> NodeFactorySet::mapped_type;
256 return register_node_creator( T::node_typename(),
std::move( nodeCreator ), nodeCategory );
262 return register_node_creator(
264 [
this, instanceNamePrefix](
const nlohmann::json& data ) {
266 if ( data.contains(
"instance" ) ) {
267 instanceName = data[
"instance"];
268 this->next_node_id();
271 else { instanceName = instanceNamePrefix +
std::to_string( this->next_node_id() ); }
280 return m_nodesCreators;
284 const auto [loc, inserted] = insert( { factory->name(),
std::move( factory ) } );
289 -> Ra::Core::Utils::optional<NodeFactorySet::mapped_type> {
290 if (
auto fct = m_factories.find( name ); fct != m_factories.end() ) {
return fct->second; }
295 return erase( name );
297inline auto NodeFactorySet::begin() const ->
NodeFactorySet::const_iterator {
298 return m_factories.
begin();
300inline auto NodeFactorySet::end() const -> NodeFactorySet::const_iterator {
301 return m_factories.
end();
303inline auto NodeFactorySet::cbegin() const -> NodeFactorySet::const_iterator {
304 return m_factories.
cbegin();
306inline auto NodeFactorySet::cend() const -> NodeFactorySet::const_iterator {
307 return m_factories.
cend();
309inline auto NodeFactorySet::find(
const NodeFactorySet::key_type& key )
const
310 -> NodeFactorySet::const_iterator {
311 return m_factories.find( key );
313inline auto NodeFactorySet::insert( NodeFactorySet::value_type value )
315 return m_factories.insert(
std::move( value ) );
317inline auto NodeFactorySet::erase(
const NodeFactorySet::key_type& key ) ->
size_t {
318 return m_factories.erase( key );
Represent a set of connected nodes that define a Direct Acyclic Computational Graph Ownership of node...
auto add_factory(mapped_type factory) -> bool
auto has_factory(const key_type &name) -> Ra::Core::Utils::optional< mapped_type >
Test if a factory exists in the set with the given name.
auto remove_factory(const key_type &name) -> bool
Remove the identified factory from the set.
auto factory_map() const -> const ContainerType &
auto register_node_creator(NodeCreatorFunctor nodeCreator, const std::string &nodeCategory="RadiumNodes") -> bool
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