Loading [MathJax]/extensions/TeX/AMSmath.js
Radium Engine  1.5.28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SinkNode.hpp
1#pragma once
2#include <Core/Utils/TypesUtils.hpp>
3#include <Dataflow/Core/Node.hpp>
4#include <stdexcept>
5
6namespace Ra {
7namespace Dataflow {
8namespace Core {
9namespace Sinks {
10
15template <typename T>
16class SinkNode : public Node
17{
18 protected:
19 SinkNode( const std::string& instanceName, const std::string& typeName );
20
21 public:
22 explicit SinkNode( const std::string& name ) : SinkNode( name, SinkNode<T>::node_typename() ) {}
23
27 void init() override;
28 bool execute() override;
29
34 T data() const;
39 const T& data_reference() const;
40
41 protected:
42 void toJsonInternal( nlohmann::json& data ) const override { Node::toJsonInternal( data ); }
43 bool fromJsonInternal( const nlohmann::json& data ) override {
45 }
46
47 private:
50 RA_NODE_PORT_IN( T, from );
51 RA_NODE_PORT_OUT( T, data );
53 public:
54 static const std::string& node_typename();
55};
56
57// -----------------------------------------------------------------
58// ---------------------- inline methods ---------------------------
59
60template <typename T>
61SinkNode<T>::SinkNode( const std::string& instanceName, const std::string& typeName ) :
62 Node( instanceName, typeName ) {}
63
64template <typename T>
66 Node::init();
67}
68
69template <typename T>
71 if ( is_initialized() && m_port_in_from->has_data() ) {
72 m_port_out_data->set_data( &m_port_in_from->data() );
73 return true;
74 }
75 return false;
76}
77
78template <typename T>
80 if ( m_port_out_data->has_data() ) return m_port_out_data->data();
81 throw std::runtime_error( "Sink out port hasn't data" );
82}
83
84template <typename T>
86 if ( m_port_out_data->has_data() ) return m_port_out_data->data();
87 throw std::runtime_error( "Sink out port hasn't data" );
88}
89
90template <typename T>
92 static std::string demangledName =
93 std::string { "Sink<" } + Ra::Core::Utils::simplifiedDemangledType<T>() + ">";
94 return demangledName;
95}
96
97} // namespace Sinks
98} // namespace Core
99} // namespace Dataflow
100} // namespace Ra
Base abstract class for all the nodes added and used by the node system.
Definition Node.hpp:40
virtual void init()
Initializes the node content.
Definition Node.hpp:428
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 store the result of a computation graph.
Definition SinkNode.hpp:17
void toJsonInternal(nlohmann::json &data) const override
Internal json representation of the Node.
Definition SinkNode.hpp:42
bool execute() override
Executes the node.
Definition SinkNode.hpp:70
void init() override
initialize the interface port data pointer
Definition SinkNode.hpp:65
bool fromJsonInternal(const nlohmann::json &data) override
Internal json representation of the Node.
Definition SinkNode.hpp:43
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:4