VOX
A little voxel engine
Loading...
Searching...
No Matches
Node.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <vector>
5#include <future>
6#include <functional>
7
8#include "tasks.hpp"
9#include "Executor.hpp"
10
11namespace task
12{
13 class Executor;
14 class TaskGraph;
16{
17 friend class TaskGraph;
18 friend class task::Executor;
19 // friend class task::Executor::runningGraph;
20public:
21 enum class type
22 {
23 NONE,
24 NODE,
25 GRAPH
26 };
27 //node constructor
28 TaskNode(std::shared_ptr<TaskGraph> graph, std::function<void()> task)
29 : m_type(type::NODE), m_data(NodeData{task, NULL}){};
30
31 //graph constructor
32 TaskNode(std::shared_ptr<TaskGraph> host_graph, std::shared_ptr<TaskGraph> composed_graph)
33 : m_type(type::GRAPH), m_data(GraphData{composed_graph}){};
34
36 TaskNode(const TaskNode &) = delete;
37 TaskNode & operator=(const TaskNode &) = delete;
38 TaskNode(TaskNode &&) = delete;
39 TaskNode & operator=(TaskNode &&) = delete;
40
41 void addDependent(TaskNode & node){
42 m_dependents.push_back(&node);
43 };
44 void addSuccessor(TaskNode & node){
45 m_sucessors.push_back(&node);
46 }
48 m_dependents.erase(std::remove(m_dependents.begin(), m_dependents.end(), &node), m_dependents.end());
49 }
51 m_sucessors.erase(std::remove(m_sucessors.begin(), m_sucessors.end(), &node), m_sucessors.end());
52 }
53
54 void setName(const std::string & name) { m_name = name; }
55 std::string getName() const { return m_name; }
56
57 type getType() const { return m_type; }
58 std::shared_ptr<TaskGraph> getGraph() const { return std::get<GraphData>(m_data).graph; }
59
60 std::vector<TaskNode *> & getDependents() { return m_dependents; }
61 std::vector<TaskNode *> & getSucessors() { return m_sucessors; }
62private:
63
64 struct NodeData
65 {
66 std::function<void()> m_task;
67 void * m_data;
68 };
69
70 struct GraphData
71 {
72 std::shared_ptr<TaskGraph> graph;
73 };
74 std::string m_name;
75 std::vector<TaskNode *> m_dependents;
76 std::vector<TaskNode *> m_sucessors;
77 type m_type;
78 std::variant<NodeData, GraphData> m_data;
79};
80}
Definition: Executor.hpp:21
Definition: TaskGraph.hpp:22
Definition: Node.hpp:16
TaskNode(std::shared_ptr< TaskGraph > host_graph, std::shared_ptr< TaskGraph > composed_graph)
Definition: Node.hpp:32
std::vector< TaskNode * > & getSucessors()
Definition: Node.hpp:61
std::string getName() const
Definition: Node.hpp:55
std::vector< TaskNode * > & getDependents()
Definition: Node.hpp:60
TaskNode(std::shared_ptr< TaskGraph > graph, std::function< void()> task)
Definition: Node.hpp:28
void addSuccessor(TaskNode &node)
Definition: Node.hpp:44
std::shared_ptr< TaskGraph > getGraph() const
Definition: Node.hpp:58
TaskNode & operator=(TaskNode &&)=delete
TaskNode & operator=(const TaskNode &)=delete
void addDependent(TaskNode &node)
Definition: Node.hpp:41
void removeSucessor(TaskNode &node)
Definition: Node.hpp:50
void setName(const std::string &name)
Definition: Node.hpp:54
type
Definition: Node.hpp:22
TaskNode(const TaskNode &)=delete
~TaskNode()
Definition: Node.hpp:35
void removeDependent(TaskNode &node)
Definition: Node.hpp:47
type getType() const
Definition: Node.hpp:57
TaskNode(TaskNode &&)=delete
Definition: Executor.cpp:5