FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp-taskflow/taskflow/core/taskflow.hpp at cpp14 · gicho/cpp-taskflow · GitHub
gicho
cpp-taskflow
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp-taskflow
/
taskflow
/
core
/
taskflow.hpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
218 lines (166 loc) · 4.21 KB
Breadcrumbs
cpp-taskflow
/
taskflow
/
core
/
taskflow.hpp
Copy path
File metadata and controls
218 lines (166 loc) · 4.21 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#
pragma
once
#
include
<
stack
>
#
include
"
flow_builder.hpp
"
#
include
"
topology.hpp
"
namespace
tf
{
/*
*
@class Taskflow
@brief the class to create a task dependency graph
*/
class
Taskflow
:
public
FlowBuilder
{
friend
class
Topology
;
friend
class
Executor
;
public:
/*
*
@brief constructs a taskflow with a given name
*/
Taskflow
(
const
std::string& name);
/*
*
@brief constructs a taskflow
*/
Taskflow
();
/*
*
@brief destroy the taskflow (virtual call)
*/
virtual
~Taskflow
();
/*
*
@brief dumps the taskflow to a std::ostream in DOT format
@param ostream a std::ostream target
*/
void
dump
(std::ostream& ostream)
const
;
/*
*
@brief dumps the taskflow in DOT format to a std::string
*/
std::string
dump
()
const
;
/*
*
@brief queries the number of nodes in the taskflow
*/
size_t
num_nodes
()
const
;
/*
*
@brief queries the emptiness of the taskflow
*/
bool
empty
()
const
;
/*
*
@brief creates a module task from a taskflow
@param taskflow a taskflow object to create the module
*/
tf::Task
composed_of
(Taskflow& taskflow);
/*
*
@brief sets the name of the taskflow
@return @c *this
*/
tf::Taskflow&
name
(
const
std::string&);
/*
*
@brief queries the name of the taskflow
*/
const
std::string&
name
()
const
;
/*
*
@brief clears the associated task dependency graph
*/
void
clear
();
private:
std::string _name;
Graph _graph;
std::mutex _mtx;
std::list<Topology> _topologies;
//
std::deque<Topology*> _topologies;
};
//
Constructor
inline
Taskflow::Taskflow
(
const
std::string& name) :
FlowBuilder {_graph},
_name {name} {
}
//
Constructor
inline
Taskflow::Taskflow
() : FlowBuilder{_graph} {
}
//
Destructor
inline
Taskflow::~Taskflow
() {
assert
(_topologies.
empty
());
}
//
Procedure:
inline
void
Taskflow::clear
() {
_graph.
clear
();
}
//
Function: num_noces
inline
size_t
Taskflow::num_nodes
()
const
{
return
_graph.
size
();
}
//
Function: empty
inline
bool
Taskflow::empty
()
const
{
return
_graph.
empty
();
}
//
Function: name
inline
Taskflow&
Taskflow::name
(
const
std::string &name) {
_name = name;
return
*
this
;
}
//
Function: name
inline
const
std::string&
Taskflow::name
()
const
{
return
_name;
}
//
Function: composed_of
inline
tf::Task
Taskflow::composed_of
(Taskflow& taskflow) {
auto
&node = _graph.
emplace_back
();
node.
_module
= &taskflow;
return
Task
(node);
}
//
Procedure: dump
inline
std::string
Taskflow::dump
()
const
{
std::ostringstream oss;
dump
(oss);
return
oss.
str
();
}
//
Function: dump
inline
void
Taskflow::dump
(std::ostream& os)
const
{
std::stack<
const
Taskflow*> stack;
std::unordered_set<
const
Taskflow*> visited;
os <<
"
digraph Taskflow_
"
;
if
(_name.
empty
()) os <<
'
p
'
<<
this
;
else
os << _name;
os <<
"
{
\n
rankdir=
\"
LR
\"
;
\n
"
;
stack.
push
(
this
);
visited.
insert
(
this
);
while
(!stack.
empty
()) {
auto
f = stack.
top
();
stack.
pop
();
//
create a subgraph field for this taskflow
os <<
"
subgraph cluster_
"
;
if
(f->
_name
.
empty
()) os <<
'
p
'
<< f;
else
os << f->
_name
;
os <<
"
{
\n
"
;
os <<
"
label=
\"
Taskflow_
"
;
if
(f->
_name
.
empty
()) os <<
'
p
'
<< f;
else
os << f->
_name
;
os <<
"
\"
;
\n
"
;
//
dump the details of this taskflow
for
(
const
auto
& n : f->
_graph
.
nodes
()) {
auto
module
= n->
_module
;
//
regular task
if
(!
module
) {
n->
dump
(os);
}
//
module task
else
{
os <<
'
p
'
<< n.
get
() <<
"
[shape=box3d, color=blue, label=
\"
"
;
if
(n->
_name
.
empty
()) os << n.
get
();
else
os << n->
_name
;
os <<
"
(Taskflow_
"
;
if
(
module
->
_name
.
empty
()) os <<
module
;
else
os <<
module
->
_name
;
os <<
"
)
\"
];
\n
"
;
if
(visited.
find
(
module
) == visited.
end
()) {
visited.
insert
(
module
);
stack.
push
(
module
);
}
for
(
const
auto
s : n->
_successors
) {
os <<
'
p
'
<< n.
get
() <<
"
->
"
<<
'
p
'
<< s <<
"
;
\n
"
;
}
}
}
os <<
"
}
\n
"
;
}
os <<
"
}
\n
"
;
}
//
Backward compatibility
using
Framework = Taskflow;
}
//
end of namespace tf. ---------------------------------------------------
Back
|
FazBrowse Home
|
New Git URL