Loading [MathJax]/extensions/TeX/AMSmath.js
Radium Engine  1.5.29
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SingleDataSourceNode.hpp
1#pragma once
2
3#include <Core/Containers/VariableSet.hpp>
4#include <Core/Utils/TypesUtils.hpp>
5#include <Dataflow/Core/Node.hpp>
6
7#include <iostream>
8#include <nlohmann/json.hpp>
9#include <utility>
10
11namespace Ra {
12namespace Dataflow {
13namespace Core {
14namespace Sources {
15
25template <typename T>
27{
28 protected:
29 SingleDataSourceNode( const std::string& instanceName, const std::string& typeName );
30
31 public:
32 // warning, hacky specialization for set editable
33 explicit SingleDataSourceNode( const std::string& name ) :
35
36 bool execute() override;
37
43 void set_data( T data );
44
49 T* data() const;
50
51 protected:
52 bool fromJsonInternal( const nlohmann::json& data ) override {
54 }
55
56 void toJsonInternal( nlohmann::json& data ) const override {
57 return Node::toJsonInternal( data );
58 }
59
60 private:
61 RA_NODE_PORT_IN( T, from );
62 RA_NODE_PORT_OUT( T, to );
63
64 public:
65 static const std::string& node_typename();
66};
67
68// -----------------------------------------------------------------
69// ---------------------- inline methods ---------------------------
70
71template <typename T>
72SingleDataSourceNode<T>::SingleDataSourceNode( const std::string& instanceName,
73 const std::string& typeName ) :
74 Node( instanceName, typeName ) {
75 m_port_in_from->set_default_value( T {} );
76 m_port_out_to->set_data( &m_port_in_from->data() );
77}
78
79template <typename T>
81 // update ouput in case input has changed (if not default value))
82 m_port_out_to->set_data( &m_port_in_from->data() );
83 return true;
84}
85
86template <typename T>
88 m_port_in_from->set_default_value( std::move( data ) );
89 m_port_out_to->set_data( &m_port_in_from->data() );
90}
91
92template <typename T>
94 return &( m_port_in_from->data() );
95}
96
97template <typename T>
99 static std::string demangledTypeName =
100 std::string { "Source<" } + Ra::Core::Utils::simplifiedDemangledType<T>() + ">";
101 return demangledTypeName;
102}
103
104} // namespace Sources
105} // namespace Core
106} // namespace Dataflow
107} // namespace Ra
Base abstract class for all the nodes added and used by the node system.
Definition Node.hpp:40
virtual bool fromJsonInternal(const nlohmann::json &data)
Internal json representation of the Node.
Definition Node.cpp:91
virtual void toJsonInternal(nlohmann::json &data) const
Internal json representation of the Node.
Definition Node.cpp:109
Base class for nodes that will give access to some input data to the graph. This class can be used to...
bool fromJsonInternal(const nlohmann::json &data) override
Internal json representation of the Node.
void toJsonInternal(nlohmann::json &data) const override
Internal json representation of the Node.
void set_data(T data)
Set the data to be delivered by the node.
T move(T... args)
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:4