functional-dag
Loading...
Searching...
No Matches
dag_node_impl.hpp
1#pragma once
2// ---------------------------------------------
3// ___ .___
4// |_ \ __| _/____ ____
5// / \ ______ / __ |\__ \ / ___\
6// / /\ \ /_____/ / /_/ | / __ \_/ /_/ >
7// /_/ \__\ \____ |(____ /\___ /
8// \/ \//_____/
9// ---------------------------------------------
10// @author ndepalma@alum.mit.edu
11
12#include <string>
13#include <mutex>
14#include <thread>
15#include <iostream>
16#include <condition_variable>
17
18#include "functional_dag/dag_interface.hpp"
19#include "functional_dag/impl/dag_fanout_impl.hpp"
20#include "functional_dag/core/dag_utils.hpp"
21
22namespace fn_dag {
23 using namespace std;
24
25 // Forward declaration of dag_fanout_node
26 template<typename Out, typename IDType> class dag_fanout_node;
27
33 template <class Type, class IDType>
34 class _abstract_internal_dag_node {
35 public:
37 virtual ~_abstract_internal_dag_node() = default;
39 virtual IDType get_id() = 0;
41 virtual void run_filter(const Type *_data) = 0;
43 virtual void print(string _plus) = 0;
44 };
45
47 template<typename In, typename Out, typename IDType>
48 class _internal_dag_node : public _abstract_internal_dag_node<In, IDType> {
49 friend class dag_fanout_node<In, IDType>; // Friend classing fanout for the add_node search
50
51 private:
52 dag_node<In,Out> *m_node_hook; // The function to run
53 const IDType m_node_id; // The ID of the node
54 dag_fanout_node<Out, IDType> *m_child; // All of the children to provide our output data to.
55 const fn_dag::_dag_context &g_context; // A hook to the global context of this DAG.
56
57 public:
67 _internal_dag_node(IDType _node_id, dag_node<In,Out> *_node, const fn_dag::_dag_context &_context) :
68 m_node_hook(_node),
69 m_node_id(_node_id),
70 m_child(new dag_fanout_node<Out, IDType>(_context)),
71 g_context(_context){}
72
74 ~_internal_dag_node() {
75 delete m_child;
76 delete m_node_hook;
77 }
78
86 void run_filter(const In *_data) {
87 Out *data_out = m_node_hook->update(_data);
88 if(!g_context.filter_off && data_out != nullptr)
89 m_child->fan_out(data_out);
90 }
91
98 void print(string _indent_str) {
99 *g_context.log << m_node_id << std::endl;
100 m_child->print(_indent_str);
101 }
102
109 IDType get_id() {
110 return m_node_id;
111 }
112 };
113}
The main DAG function that encapulates generation and mapping of the data across the DAG.
Definition dag_impl.hpp:59
void print()
Simple print function to print the ID of this DAG and it's children.
Definition dag_impl.hpp:148