Loading [MathJax]/extensions/TeX/AMSmath.js
Radium Engine  1.5.28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Port.hpp
1#pragma once
2
3#include "Core/Utils/Color.hpp"
4#include <Core/Types.hpp>
5#include <Dataflow/RaDataflow.hpp>
6
7#include <Core/Utils/TypesUtils.hpp>
8
9#include <string>
10
11namespace Ra {
12namespace Dataflow {
13namespace Core {
14
15class Node;
16
17// forward, defined in port facotory
18template <typename T>
19void add_port_type();
29class RA_DATAFLOW_CORE_API PortBase
30{
31 public:
36 PortBase() = delete;
37 PortBase( const PortBase& ) = delete;
38 PortBase& operator=( const PortBase& ) = delete;
44 PortBase( const std::string& name, std::type_index type, Node* node ) :
45 m_name( name ), m_type( type ), m_node( node ) {}
47
49 virtual ~PortBase() = default;
50
52 const std::string& name() const { return m_name; }
54 void set_name( const std::string& name ) { m_name = name; }
56 std::type_index type() const { return m_type; }
58 Node* node() const { return m_node; }
59
62 std::string port_typename() const { return Ra::Core::Utils::simplifiedDemangledType( m_type ); }
63
65 virtual bool has_data() = 0;
66
67 virtual void to_json( nlohmann::json& data ) { data["name"] = name(); }
68 virtual void from_json( const nlohmann::json& data ) {
69 if ( auto it = data.find( "name" ); it != data.end() ) { set_name( *it ); }
70 }
71
72 private:
73 std::string m_name { "" };
74 std::type_index m_type;
75 Node* m_node { nullptr };
77};
78
79template <typename Port>
80using PortPtr = std::shared_ptr<Port>;
81
82template <typename Port>
83using PortRawPtr = typename PortPtr<Port>::element_type*;
84
85using PortBasePtr = PortPtr<PortBase>;
86using PortBaseRawPtr = PortRawPtr<PortBase>;
87
88} // namespace Core
89} // namespace Dataflow
90} // namespace Ra
Base abstract class for all the nodes added and used by the node system.
Definition Node.hpp:40
Base class for nodes' ports A port is a strongly typed extremity of connections between nodes.
Definition Port.hpp:30
std::string port_typename() const
Gets the human readable type of the port object.
Definition Port.hpp:62
const std::string & name() const
Gets the port's name.
Definition Port.hpp:52
virtual ~PortBase()=default
Make PortBase a base abstract class.
PortBase(const std::string &name, std::type_index type, Node *node)
Definition Port.hpp:44
virtual bool has_data()=0
can we get data from the port ?
std::type_index type() const
Gets the type of the data (efficient for comparisons).
Definition Port.hpp:56
Node * node() const
Gets a pointer to the node this port belongs to.
Definition Port.hpp:58
void set_name(const std::string &name)
Set's port name.
Definition Port.hpp:54
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:4