Loading [MathJax]/extensions/TeX/AMSmath.js
Radium Engine  1.5.28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FunctionSource.hpp
1#pragma once
2#include "Dataflow/Core/NodeFactory.hpp"
3#pragma once
4#include <Dataflow/Core/Node.hpp>
5
6#include <iostream>
7#include <utility>
8
9namespace Ra {
10namespace Dataflow {
11namespace Core {
12namespace Sources {
13
19template <class R, class... Args>
21{
22
23 public:
24 using function_type = std::function<R( Args... )>;
25
26 explicit FunctionSourceNode( const std::string& name ) :
28
29 bool execute() override;
30
35
40 function_type* data() const;
41
42 protected:
43 FunctionSourceNode( const std::string& instanceName, const std::string& typeName );
44
45 bool fromJsonInternal( const nlohmann::json& data ) override {
47 }
48 void toJsonInternal( nlohmann::json& data ) const override { Node::toJsonInternal( data ); }
49
50 RA_NODE_PORT_IN( function_type, from );
51 RA_NODE_PORT_OUT( function_type, to );
52
53 public:
54 static const std::string& node_typename();
55};
56
57// -----------------------------------------------------------------
58// ---------------------- inline methods ---------------------------
59
60template <class R, class... Args>
61FunctionSourceNode<R, Args...>::FunctionSourceNode( const std::string& instanceName,
62 const std::string& typeName ) :
63 Node( instanceName, typeName ) {
64 m_port_in_from->set_default_value( []( Args... ) { return R {}; } );
65 m_port_out_to->set_data( &m_port_in_from->data() );
66}
67
68template <class R, class... Args>
70 return true;
71}
72
73template <class R, class... Args>
75 m_port_in_from->set_default_value( std::move( data ) );
76 m_port_out_to->set_data( &m_port_in_from->data() );
77}
78
79template <class R, class... Args>
80typename FunctionSourceNode<R, Args...>::function_type*
82 return m_port_in_from->data();
83}
84
85template <class R, class... Args>
87 static std::string demangledTypeName =
88 std::string { "Source<" } + Ra::Core::Utils::simplifiedDemangledType<function_type>() + ">";
89 return demangledTypeName;
90}
91
92} // namespace Sources
93} // namespace Core
94} // namespace Dataflow
95} // 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
Node that deliver a std::function<R( Args... )}}>
void set_data(function_type data)
Set the function to be delivered by the node.
function_type * data() const
Get the delivered data.
bool execute() override
Executes the node.
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.
T move(T... args)
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:4