functional-dag
Loading...
Searching...
No Matches
filter_sys.hpp
1#pragma once
12
13#include <functional_dag/error_codes.h>
14
15#include <functional_dag/dag_interface.hpp>
16#include <functional_dag/impl/dag_impl.hpp>
17
18namespace fn_dag {
19using namespace std;
20
28template <typename IDType>
30 private:
31 _dag_context m_context; // This is the "global" context used by all dags
32
33 public:
35 vector<_dag_base<IDType> *> m_all_dags;
36
40 m_context.filter_off = false;
41 m_context.run_single_threaded = false;
42 }
43
47 m_context.filter_off = true;
48 clear();
49 }
50
59 template <typename In, typename Out>
60 [[nodiscard]] expected<IDType, error_codes> add_node(
61 IDType _id, dag_node<In, Out> *_new_filter, const IDType &_onto) {
62 if (_new_filter != nullptr) {
63 for (auto t = m_all_dags.cbegin(); t != m_all_dags.cend(); t++) {
64 if ((*t)->dag_contains(_onto) || (*t)->get_id() == _onto) {
65 dag<In, IDType> *tptr = static_cast<dag<In, IDType> *>(*t);
66 return tptr->add_filter(_id, _new_filter, _onto);
67 }
68 }
69 } else {
70 delete _new_filter;
71 return unexpected(error_codes::NULL_PTR_ERROR);
72 }
73 delete _new_filter;
74 return unexpected(error_codes::PARENT_NOT_FOUND);
75 }
76
85 bool manager_contains_id(IDType _id) {
86 for (auto t = m_all_dags.cbegin(); t != m_all_dags.cend(); t++) {
87 if ((*t)->dag_contains(_id) || (*t)->get_id() == _id) return true;
88 }
89 return false;
90 }
91
99 void set_indention_string(string _new_indent_str) {
100 m_context.indent_str = _new_indent_str;
101 }
102
111 void set_logging_stream(ostream *_new_stream) { m_context.log = _new_stream; }
112
124 void run_single_threaded(const bool _is_single_threaded) {
125 m_context.run_single_threaded = _is_single_threaded;
126 }
127
140 template <typename Out>
141 expected<dag<Out, IDType> *, error_codes> add_dag(
142 IDType _id, dag_source<Out> *_new_filter, bool _startImmediately) {
143 if (_new_filter != nullptr) {
145 new dag<Out, IDType>(_id, _new_filter, m_context, _startImmediately);
146 m_all_dags.push_back(t);
147 return t;
148 }
149 return unexpected(error_codes::NULL_PTR_ERROR);
150 }
151
158 *m_context.log << endl;
159 *m_context.log << "------------DAG Forest-----------\n";
160 for (auto t = m_all_dags.cbegin(); t != m_all_dags.cend(); t++)
161 (*t)->print();
162 *m_context.log << "---------------------------------\n";
163 }
164
170 void stahp() { m_context.filter_off = true; }
171
178 void clear() {
179 for (auto t = m_all_dags.begin(); t != m_all_dags.end(); t++) delete *t;
180 m_all_dags.clear();
181 }
182};
183} // namespace fn_dag
void run_single_threaded(const bool _is_single_threaded)
Sets whether to run the DAGs on the same thread.
Definition filter_sys.hpp:124
bool manager_contains_id(IDType _id)
Containment function for checking presence.
Definition filter_sys.hpp:85
void set_logging_stream(ostream *_new_stream)
Set a logging stream to print to.
Definition filter_sys.hpp:111
void print_all_dags()
Print all of the trees for verification purposes.
Definition filter_sys.hpp:157
void clear()
Clears all of the DAGs out of the "forest" of DAGs.
Definition filter_sys.hpp:178
expected< IDType, error_codes > add_node(IDType _id, dag_node< In, Out > *_new_filter, const IDType &_onto)
This function adds a node to the graph.
Definition filter_sys.hpp:60
expected< dag< Out, IDType > *, error_codes > 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:141
dag_manager()
Default constructor.
Definition filter_sys.hpp:39
~dag_manager()
Default deconstructor.
Definition filter_sys.hpp:46
vector< _dag_base< IDType > * > m_all_dags
All of the DAGs the manager maintains.
Definition filter_sys.hpp:35
void set_indention_string(string _new_indent_str)
Indentation delimiter.
Definition filter_sys.hpp:99
void stahp()
Stops all of the DAGs from generating data out.
Definition filter_sys.hpp:170
Interface for all external "mapping" lambdas.
Definition dag_interface.hpp:42
Interface for all external generator lambdas.
Definition dag_interface.hpp:22
The main DAG function that encapulates generation and mapping of the data across the DAG.
Definition dag_impl.hpp:63
expected< IDType, error_codes > add_filter(IDType _newID, dag_node< In, Out > *_new_filter, IDType _on_node)
Adds a new function to the DAG.
Definition dag_impl.hpp:144
Definition guid_generated.h:16
error_codes
Error codes used by the functional dag.
Definition error_codes.h:19
@ NULL_PTR_ERROR
The node you are trying to add is null.
Definition error_codes.h:22
@ PARENT_NOT_FOUND
The parent of the node you are attaching to the dag was not found.
Definition error_codes.h:20