2#include <Dataflow/RaDataflow.hpp>
4#include <Core/Utils/BijectiveAssociation.hpp>
5#include <Core/Utils/Singleton.hpp>
6#include <Dataflow/Core/PortIn.hpp>
7#include <Dataflow/Core/PortOut.hpp>
13class RA_DATAFLOW_CORE_API PortFactory
15 RA_SINGLETON_INTERFACE( PortFactory );
20 using PortOutSetter =
std::function<void( PortBaseOut*, std::any )>;
24 if (
auto itr = m_input_ctor.find( type ); itr != m_input_ctor.end() ) {
25 return itr->second( node, name );
27 LOG( Ra::Core::Utils::logERROR )
28 <<
"input ctor type not found " << Ra::Core::Utils::simplifiedDemangledType( type );
32 if (
auto itr = m_output_ctor.find( type ); itr != m_output_ctor.end() ) {
33 return itr->second( node, name );
35 LOG( Ra::Core::Utils::logERROR )
36 <<
"output ctor type not found " << Ra::Core::Utils::simplifiedDemangledType( type );
42 return make_input_port( node, name, m_type_to_string.key( type ) );
46 return make_output_port( node, name, m_type_to_string.key( type ) );
49 PortOutSetter output_setter(
std::type_index type ) {
return m_output_setter.at( type ); }
50 PortInGetter input_getter(
std::type_index type ) {
return m_input_getter.at( type ); }
53 void add_port_type() {
56 if ( !m_type_to_string.valueIfExists( type ) ) {
57 m_input_ctor[type] = []( Node* node,
const std::string& name ) {
61 m_output_ctor[type] = []( Node* node,
const std::string& name ) {
65 m_input_getter[type] = []( PortBaseIn* port ) -> std::any {
66 auto casted =
dynamic_cast<PortIn<T>*
>( port );
67 return &( casted->data() );
69 m_output_setter[type] = []( PortBaseOut* port, std::any any ) {
70 T* data = std::any_cast<T*>( any );
71 auto casted =
dynamic_cast<PortOut<T>*
>( port );
72 casted->set_data( data );
75 m_type_to_string.insert( type, Ra::Core::Utils::simplifiedDemangledType( type ) );
85 add_port_type<Scalar>();
87 add_port_type<unsigned int>();
88 add_port_type<Utils::Color>();
89 add_port_type<Vector2>();
90 add_port_type<Vector3>();
91 add_port_type<Vector4>();
103void add_port_type() {
104 PortFactory::getInstance()->add_port_type<T>();
Bijective association between two sets {keys} and {values} having the same cardinality....
This namespace contains everything "low level", related to data, datastuctures, and computation.
hepler function to manage enum as underlying types in VariableSet