VOX
A little voxel engine
Loading...
Searching...
No Matches
TaskGraph.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "tasks.hpp"
4#include "Executor.hpp"
5#include "Task.hpp"
6#include "Node.hpp"
7#include <functional>
8#include <future>
9#include <string>
10#include <vector>
11#include <map>
12#include <list>
13#include <memory>
14
15namespace task
16{
17
18class TaskNode;
19class Executor;
20class Task;
21class TaskGraph : public std::enable_shared_from_this<TaskGraph>
22{
23private:
24 struct Private { explicit Private() = default;};
25public:
26 TaskGraph(Private){};
27
28 friend class TaskNode;
29 friend class task::Executor;
30 // friend class task::Executor::runningGraph;
31
32 static std::shared_ptr<TaskGraph> create()
33 {
34 return std::make_shared<TaskGraph>(Private());
35 }
36 std::shared_ptr<TaskGraph> getPtr()
37 {
38 return shared_from_this();
39 }
41 TaskGraph(const TaskGraph &) = delete;
42 TaskGraph & operator=(const TaskGraph &) = delete;
43 TaskGraph(TaskGraph &&) = default;
44 TaskGraph & operator=(TaskGraph &&) = default;
45
46 template <typename F>
48 {
49 auto & node = m_nodes.emplace_back(shared_from_this(), std::forward<F>(task));
50 return Task(&node);
51 }
52
53 Task emplace(std::shared_ptr<TaskGraph> graph)
54 {
55 auto & node = m_nodes.emplace_back(shared_from_this(), graph);
56 return Task(&node);
57 }
58
59 void clear()
60 {
61 m_nodes.clear();
62 }
63
64 bool empty()
65 {
66 return m_nodes.empty();
67 }
68
69private:
70 std::list<TaskNode> m_nodes;
71};
72
73}
Definition: Executor.hpp:21
Definition: TaskGraph.hpp:22
void clear()
Definition: TaskGraph.hpp:59
TaskGraph(TaskGraph &&)=default
TaskGraph(Private)
Definition: TaskGraph.hpp:26
TaskGraph(const TaskGraph &)=delete
Task emplace(std::shared_ptr< TaskGraph > graph)
Definition: TaskGraph.hpp:53
~TaskGraph()
Definition: TaskGraph.hpp:40
bool empty()
Definition: TaskGraph.hpp:64
static std::shared_ptr< TaskGraph > create()
Definition: TaskGraph.hpp:32
TaskGraph & operator=(const TaskGraph &)=delete
std::shared_ptr< TaskGraph > getPtr()
Definition: TaskGraph.hpp:36
TaskGraph & operator=(TaskGraph &&)=default
Task emplace(F &&task)
Definition: TaskGraph.hpp:47
Definition: Node.hpp:16
Definition: Task.hpp:10
Definition: Executor.cpp:5