functional-dag
Loading...
Searching...
No Matches
filter_sys.hpp
1#pragma once
2// ---------------------------------------------
3// ___ .___
4// |_ \ __| _/____ ____
5// / \ ______ / __ |\__ \ / ___\
6// / /\ \ /_____/ / /_/ | / __ \_/ /_/ >
7// /_/ \__\ \____ |(____ /\___ /
8// \/ \//_____/
9// ---------------------------------------------
10// @author ndepalma@alum.mit.edu
11
12#include <functional_dag/impl/dag_impl.hpp>
13#include <functional_dag/dag_interface.hpp>
14
15namespace fn_dag {
16
22 template <typename IDType>
24 private:
25 _dag_context m_context; // This is the "global" context used by all dags
26
27 public:
29 vector<_dag_base<IDType> *> m_all_dags;
30
34 m_context.filter_off = false;
35 m_context.run_single_threaded = false;
36 }
37
41 m_context.filter_off = true;
42 clear();
43 }
44
53 template <typename In, typename Out>
54 void add_node(IDType _id, dag_node<In,Out> *_new_filter, IDType _onto) {
55 if(_new_filter != nullptr) {
56 for(auto t = m_all_dags.cbegin();t != m_all_dags.cend();t++) {
57 if((*t)->dag_contains(_onto) || (*t)->get_id() == _onto) {
58 dag<In, IDType> *tptr = static_cast<dag<In, IDType>*>(*t);
59 tptr->add_filter(_id, _new_filter, _onto);
60 }
61 }
62 }
63 }
64
73 bool manager_contains_id(IDType _id) {
74 for(auto t = m_all_dags.cbegin();t != m_all_dags.cend();t++) {
75 if((*t)->dag_contains(_id) || (*t)->get_id() == _id)
76 return true;
77 }
78 return false;
79 }
80
88 void set_indention_string(string _new_indent_str) {
89 m_context.indent_str = _new_indent_str;
90 }
91
100 void set_logging_stream(std::ostream *_new_stream) {
101 m_context.log = _new_stream;
102 }
103
114 void run_single_threaded(bool _is_single_threaded) {
115 m_context.run_single_threaded = _is_single_threaded;
116 }
117
128 template <typename Out>
129 dag<Out, IDType> *add_dag(IDType _id, dag_source<Out> *_new_filter, bool _startImmediately) {
130 if(_new_filter != nullptr) {
132 m_all_dags.push_back(t);
133 return t;
134 }
135 return nullptr;
136 }
137
144 *m_context.log << std::endl;
145 *m_context.log << "------------DAG Forest-----------\n";
146 for(auto t = m_all_dags.cbegin();t != m_all_dags.cend();t++)
147 (*t)->print();
148 *m_context.log << "---------------------------------\n";
149 }
150
156 void stahp() {
157 m_context.filter_off = true;
158 }
159
165 void clear() {
166 for(auto t = m_all_dags.begin();t != m_all_dags.end();t++)
167 delete *t;
168 m_all_dags.clear();
169 }
170
171
172 };
173}
The DAG manager manages all of the dags created by the user.
Definition filter_sys.hpp:23
dag< Out, IDType > * add_dag(IDType _id, dag_source< Out > *_new_filter, bool _startImmediately)
Starts a new DAG with a given source of data out.
Definition filter_sys.hpp:129
void add_node(IDType _id, dag_node< In, Out > *_new_filter, IDType _onto)
Implementation to template funcs must be visible to link correctly.
Definition filter_sys.hpp:54
bool manager_contains_id(IDType _id)
Containment function for checking presence.
Definition filter_sys.hpp:73
void print_all_dags()
Print all of the trees for verification purposes.
Definition filter_sys.hpp:143
void run_single_threaded(bool _is_single_threaded)
Sets whether to run the DAGs on the same thread.
Definition filter_sys.hpp:114
void clear()
Clears all of the DAGs out of the "forest" of DAGs.
Definition filter_sys.hpp:165
dag_manager()
Default constructor.
Definition filter_sys.hpp:33
~dag_manager()
Default deconstructor.
Definition filter_sys.hpp:40
vector< _dag_base< IDType > * > m_all_dags
All of the DAGs the manager maintains.
Definition filter_sys.hpp:29
void set_indention_string(string _new_indent_str)
Indentation delimiter.
Definition filter_sys.hpp:88
void stahp()
Stops all of the DAGs from generating data out.
Definition filter_sys.hpp:156
void set_logging_stream(std::ostream *_new_stream)
Set a logging stream to print to.
Definition filter_sys.hpp:100
Interface for all external "mapping" lambdas.
Definition dag_interface.hpp:39
Interface for all external generator lambdas.
Definition dag_interface.hpp:19
The main DAG function that encapulates generation and mapping of the data across the DAG.
Definition dag_impl.hpp:59
void add_filter(IDType _newID, dag_node< In, Out > *_new_filter, IDType _on_node)
Adds a new function to the DAG.
Definition dag_impl.hpp:140
void print()
Simple print function to print the ID of this DAG and it's children.
Definition dag_impl.hpp:148