functional-dag
Loading...
Searching...
No Matches
dag_node_impl.hpp
1#pragma once
12
13#include <iostream>
14#include <string>
15
16#include "functional_dag/core/dag_utils.hpp"
17#include "functional_dag/dag_interface.hpp"
18#include "functional_dag/impl/dag_fanout_impl.hpp"
19
20namespace fn_dag {
21using namespace std;
22
23// Forward declaration of dag_fanout_node
24template <typename Out, typename IDType>
26
32template <class Type, class IDType>
33class _abstract_internal_dag_node {
34 public:
36 virtual ~_abstract_internal_dag_node() = default;
39 virtual const IDType &get_id() = 0;
41 virtual void run_filter(const Type *const _data) = 0;
43 virtual void print(const string &_plus) = 0;
44};
45
48template <typename In, typename Out, typename IDType>
49class _internal_dag_node : public _abstract_internal_dag_node<In, IDType> {
50 friend class dag_fanout_node<In, IDType>; // Friend classing fanout for the
51 // add_node search
52
53 private:
54 dag_node<In, Out> *m_node_hook; // The function to run
55 const IDType m_node_id; // The ID of the node
57 *m_child; // All of the children to provide our output data to.
58 const fn_dag::_dag_context
59 &g_context; // A hook to the global context of this DAG.
60
61 public:
72 _internal_dag_node(IDType _node_id, dag_node<In, Out> *_node,
73 const fn_dag::_dag_context &_context)
74 : m_node_hook(_node),
75 m_node_id(_node_id),
76 m_child(new dag_fanout_node<Out, IDType>(_context)),
77 g_context(_context) {}
78
80 ~_internal_dag_node() {
81 delete m_child;
82 delete m_node_hook;
83 }
84
93 void run_filter(const In *const _data) {
94 unique_ptr<Out> data_out = m_node_hook->update(_data);
95 if (!g_context.filter_off && data_out != nullptr)
96 m_child->fan_out(std::move(data_out));
97 }
98
105 void print(const string &_indent_str) {
106 *g_context.log << m_node_id << endl;
107 m_child->print(_indent_str);
108 }
109
116 const IDType &get_id() { return m_node_id; }
117};
118} // namespace fn_dag
Internal node to take data from parent and run children.
Definition dag_node_impl.hpp:25
dag_fanout_node(const _dag_context &_context)
This node uses data computed from the previous node to fan-out to it's children.
Definition dag_fanout_impl.hpp:56
void print(const string &_indent)
Printing function.
Definition dag_fanout_impl.hpp:99
Interface for all external "mapping" lambdas.
Definition dag_interface.hpp:42
virtual unique_ptr< Out > update(const In *const _data)=0
Translator function.
Definition guid_generated.h:16