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;
76 auto register_node_creator(
const std::string& nodeType,
78 const std::string& nodeCategory =
"RadiumNodes" ) -> bool;
88 [[nodiscard]]
auto create_node(
const std::string& nodeType,
89 const nlohmann::json& data,
105 [[nodiscard]]
auto factory_map() const -> const
ContainerType&;
112 auto next_node_id() ->
size_t;
115 size_t m_nodesCreated { 0 };
127 using key_type = container_type::key_type;
128 using mapped_type = container_type::mapped_type;
129 using value_type = container_type::value_type;
131 using const_iterator = container_type::const_iterator;
132 using iterator = container_type::iterator;
140 auto add_factory( mapped_type factory ) -> bool;
148 auto has_factory(
const key_type& name ) -> Ra::Core::Utils::optional<mapped_type>;
155 auto remove_factory(
const key_type& name ) -> bool;
173 [[nodiscard]]
auto create_node(
const std::string& nodeType,
174 const nlohmann::json& data,
180 auto begin()
const -> const_iterator;
181 auto end()
const -> const_iterator;
182 auto cbegin()
const -> const_iterator;
183 auto cend()
const -> const_iterator;
184 auto find(
const key_type& key )
const -> const_iterator;
186 auto erase(
const key_type& key ) -> size_t;
188 const std::string& default_factory_name() {
return m_default_factory_name; }
192 const std::string m_default_factory_name {
"Dataflow Nodes" };
206namespace NodeFactoriesManager {
225RA_DATAFLOW_CORE_API
auto create_factory(
const NodeFactorySet::key_type& name )
226 -> NodeFactorySet::mapped_type;
233RA_DATAFLOW_CORE_API
auto factory(
const NodeFactorySet::key_type& name )
234 -> NodeFactorySet::mapped_type;
241RA_DATAFLOW_CORE_API
auto unregister_factory(
const NodeFactorySet::key_type& name ) -> bool;
246RA_DATAFLOW_CORE_API
auto default_factory() -> NodeFactorySet::mapped_type;
255 return register_node_creator( T::node_typename(),
std::move( nodeCreator ), nodeCategory );
261 return register_node_creator(
263 [
this, instanceNamePrefix](
const nlohmann::json& data ) {
265 if ( data.contains(
"instance" ) ) {
266 instanceName = data[
"instance"];
267 this->next_node_id();
270 else { instanceName = instanceNamePrefix +
std::to_string( this->next_node_id() ); }
279 return m_nodesCreators;
283 const auto [loc, inserted] = insert( { factory->name(),
std::move( factory ) } );
288 -> Ra::Core::Utils::optional<NodeFactorySet::mapped_type> {
289 if (
auto fct = m_factories.find( name ); fct != m_factories.end() ) {
return fct->second; }
294 return erase( name );
296inline auto NodeFactorySet::begin() const ->
NodeFactorySet::const_iterator {
297 return m_factories.
begin();
299inline auto NodeFactorySet::end() const -> NodeFactorySet::const_iterator {
300 return m_factories.
end();
302inline auto NodeFactorySet::cbegin() const -> NodeFactorySet::const_iterator {
303 return m_factories.
cbegin();
305inline auto NodeFactorySet::cend() const -> NodeFactorySet::const_iterator {
306 return m_factories.
cend();
308inline auto NodeFactorySet::find(
const NodeFactorySet::key_type& key )
const
309 -> NodeFactorySet::const_iterator {
310 return m_factories.find( key );
312inline auto NodeFactorySet::insert( NodeFactorySet::value_type value )
314 return m_factories.insert(
std::move( value ) );
316inline auto NodeFactorySet::erase(
const NodeFactorySet::key_type& key ) ->
size_t {
317 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