Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a3805e

Browse files
committed
reformat
1 parent ba5979f commit 5a3805e

File tree

7 files changed

+190
-210
lines changed

7 files changed

+190
-210
lines changed

examples/visualization_dsl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <taskflow/dsl/task_dsl.hpp> // for support dsl
88

99
int main(){
10-
1110
tf::Taskflow tf("Visualization Demo");
1211

1312
// ------------------------------------------------------
@@ -25,7 +24,7 @@ int main(){
2524
__link(D) -> E
2625
) {tf};
2726

28-
std::cout << "[dump without name assignment]\n";
27+
// std::cout << "[dump without name assignment]\n";
2928
tf.dump(std::cout);
3029

3130
// TODO: support set name

taskflow/dsl/connection.hpp

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
11
// 2020/08/28 - Created by netcan: https://github.com/netcan
22
#pragma once
33
#include "../core/flow_builder.hpp"
4-
#include "type_list.hpp"
5-
#include "tuple_utils.hpp"
64
#include "job_trait.hpp"
5+
#include "tuple_utils.hpp"
6+
#include "type_list.hpp"
77

88
namespace tf {
9-
template<typename T>
10-
class Connection;
9+
template <typename T> class Connection;
10+
11+
template <typename F, typename T> class Connection<auto(F)->T> {
12+
using FROMs = typename JobTrait<F>::JobList;
13+
using TOs = typename JobTrait<T>::JobList;
1114

12-
template<typename F, typename T>
13-
class Connection<auto(F) -> T> {
14-
using FROMs = typename JobTrait<F>::JobList;
15-
using TOs = typename JobTrait<T>::JobList;
1615
public:
17-
using FromJobList = Unique_t<Flatten_t<FROMs>>;
18-
using ToJobList = Unique_t<Flatten_t<TOs>>;
16+
using FromJobList = Unique_t<Flatten_t<FROMs>>;
17+
using ToJobList = Unique_t<Flatten_t<TOs>>;
1918
};
2019

21-
template<typename FROM, typename TO>
22-
struct OneToOneLink {
23-
template<typename JobsCB>
24-
struct InstanceType {
25-
template<typename J>
26-
struct IsJob {
27-
template<typename JobCb> struct apply
28-
{ constexpr static bool value = std::is_same<typename JobCb::JobType, J>::value; };
29-
};
30-
31-
constexpr void build(JobsCB& jobsCb) {
32-
constexpr size_t JobsCBSize = std::tuple_size<JobsCB>::value;
33-
constexpr size_t FromJobIndex = TupleElementByF_v<JobsCB, IsJob<FROM>::template apply>;
34-
constexpr size_t ToJobIndex = TupleElementByF_v<JobsCB, IsJob<TO>::template apply>;
35-
static_assert(FromJobIndex < JobsCBSize && ToJobIndex < JobsCBSize, "fatal: not find JobCb in JobsCB");
36-
std::get<FromJobIndex>(jobsCb).job_.precede(std::get<ToJobIndex>(jobsCb).job_);
37-
}
20+
template <typename FROM, typename TO> struct OneToOneLink {
21+
template <typename JobsCB> struct InstanceType {
22+
template <typename J> struct IsJob {
23+
template <typename JobCb> struct apply {
24+
constexpr static bool value =
25+
std::is_same<typename JobCb::JobType, J>::value;
26+
};
3827
};
28+
29+
constexpr void build(JobsCB &jobsCb) {
30+
constexpr size_t JobsCBSize = std::tuple_size<JobsCB>::value;
31+
constexpr size_t FromJobIndex =
32+
TupleElementByF_v<JobsCB, IsJob<FROM>::template apply>;
33+
constexpr size_t ToJobIndex =
34+
TupleElementByF_v<JobsCB, IsJob<TO>::template apply>;
35+
static_assert(FromJobIndex < JobsCBSize && ToJobIndex < JobsCBSize,
36+
"fatal: not find JobCb in JobsCB");
37+
std::get<FromJobIndex>(jobsCb).job_.precede(
38+
std::get<ToJobIndex>(jobsCb).job_);
39+
}
40+
};
3941
};
40-
};
42+
}; // namespace tf

taskflow/dsl/job_trait.hpp

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,32 @@
11
// 2020/08/28 - Created by netcan: https://github.com/netcan
22
#pragma once
3-
#include "type_list.hpp"
4-
#include "../core/task.hpp"
53
#include "../core/flow_builder.hpp"
4+
#include "../core/task.hpp"
5+
#include "type_list.hpp"
66
#include <type_traits>
77

88
namespace tf {
99
struct JobSignature {};
1010

11-
template<typename J>
12-
struct JobCb {
13-
using type = JobCb<J>;
14-
using JobType = J;
15-
void build(FlowBuilder& build) {
16-
job_ = build.emplace(JobType{}());
17-
}
18-
Task job_;
11+
template <typename J> struct JobCb {
12+
using type = JobCb<J>;
13+
using JobType = J;
14+
void build(FlowBuilder &build) { job_ = build.emplace(JobType{}()); }
15+
Task job_;
1916
};
2017

21-
template<typename ...J>
22-
struct SomeJob
23-
{ using JobList = TypeList<J...>; };
18+
template <typename... J> struct SomeJob { using JobList = TypeList<J...>; };
2419

25-
template<typename J, typename = void>
26-
struct JobTrait;
20+
template <typename J, typename = void> struct JobTrait;
2721

2822
// a job self
29-
template<typename J>
23+
template <typename J>
3024
struct JobTrait<J, void_t<std::is_base_of<JobSignature, J>>> {
31-
using JobList = TypeList<J>;
25+
using JobList = TypeList<J>;
3226
};
3327

34-
template<typename ...J>
35-
struct JobTrait<SomeJob<J...>> {
36-
using JobList = typename SomeJob<J...>::JobList;
28+
template <typename... J> struct JobTrait<SomeJob<J...>> {
29+
using JobList = typename SomeJob<J...>::JobList;
3730
};
3831

39-
}
32+
} // namespace tf

taskflow/dsl/task_analyzer.hpp

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11
// 2020/08/28 - Created by netcan: https://github.com/netcan
22
#pragma once
3-
#include "type_list.hpp"
43
#include "connection.hpp"
4+
#include "type_list.hpp"
55
#include <type_traits>
66

77
namespace tf {
8-
template<typename ...Links>
9-
class TaskAnalyzer {
10-
template<typename FROMs, typename TOs, typename = void>
11-
struct BuildOneToOneLink;
8+
template <typename... Links> class TaskAnalyzer {
9+
template <typename FROMs, typename TOs, typename = void>
10+
struct BuildOneToOneLink;
11+
12+
template <typename... Fs, typename Ts>
13+
struct BuildOneToOneLink<TypeList<Fs...>, Ts> {
14+
using type = Concat_t<typename BuildOneToOneLink<Fs, Ts>::type...>;
15+
};
1216

13-
template<typename ...Fs, typename Ts>
14-
struct BuildOneToOneLink<TypeList<Fs...>, Ts> {
15-
using type = Concat_t<typename BuildOneToOneLink<Fs, Ts>::type...>;
16-
};
17+
template <typename F, typename... Ts>
18+
struct BuildOneToOneLink<F, TypeList<Ts...>,
19+
std::enable_if_t<!IsTypeList_v<F>>> {
20+
using type = TypeList<OneToOneLink<F, Ts>...>;
21+
};
1722

18-
template<typename F, typename... Ts>
19-
struct BuildOneToOneLink<F, TypeList<Ts...>, std::enable_if_t<!IsTypeList_v<F>>> {
20-
using type = TypeList<OneToOneLink<F, Ts>...>;
21-
};
23+
template <typename Link> class OneToOneLinkSetF {
24+
using FromJobList = typename Link::FromJobList;
25+
using ToJobList = typename Link::ToJobList;
2226

23-
template<typename Link>
24-
class OneToOneLinkSetF {
25-
using FromJobList = typename Link::FromJobList;
26-
using ToJobList = typename Link::ToJobList;
27-
public:
28-
using type = typename BuildOneToOneLink<FromJobList, ToJobList>::type;
29-
};
27+
public:
28+
using type = typename BuildOneToOneLink<FromJobList, ToJobList>::type;
29+
};
3030

3131
public:
32-
using AllJobs = Unique_t<Concat_t<typename Connection<Links>::FromJobList..., typename Connection<Links>::ToJobList...>>;
33-
using OneToOneLinkSet = Unique_t<Flatten_t<Map_t<TypeList<Connection<Links>...>, OneToOneLinkSetF>>>;
32+
using AllJobs = Unique_t<Concat_t<typename Connection<Links>::FromJobList...,
33+
typename Connection<Links>::ToJobList...>>;
34+
using OneToOneLinkSet = Unique_t<
35+
Flatten_t<Map_t<TypeList<Connection<Links>...>, OneToOneLinkSetF>>>;
3436
};
3537

36-
}
38+
} // namespace tf

taskflow/dsl/task_dsl.hpp

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,51 @@
11
// 2020/08/28 - Created by netcan: https://github.com/netcan
22
#pragma once
33
#include "../core/flow_builder.hpp"
4-
#include "task_analyzer.hpp"
54
#include "job_trait.hpp"
5+
#include "task_analyzer.hpp"
66

77
namespace tf {
8-
template<typename ...Links>
9-
class TaskDsl {
10-
using AllJobs = typename TaskAnalyzer<Links...>::AllJobs;
11-
using JobsCb = typename Map_t<AllJobs, JobCb>::template exportTo<std::tuple>;
12-
13-
using OneToOneLinkSet = typename TaskAnalyzer<Links...>::OneToOneLinkSet;
14-
template <typename OneToOneLink>
15-
struct OneToOneLinkInstanceType
16-
{ using type = typename OneToOneLink::template InstanceType<JobsCb>; };
17-
using OneToOneLinkInstances =
18-
typename Map_t<OneToOneLinkSet, OneToOneLinkInstanceType>::template exportTo<std::tuple>;
8+
template <typename... Links> class TaskDsl {
9+
using AllJobs = typename TaskAnalyzer<Links...>::AllJobs;
10+
using JobsCb = typename Map_t<AllJobs, JobCb>::template exportTo<std::tuple>;
11+
12+
using OneToOneLinkSet = typename TaskAnalyzer<Links...>::OneToOneLinkSet;
13+
template <typename OneToOneLink> struct OneToOneLinkInstanceType {
14+
using type = typename OneToOneLink::template InstanceType<JobsCb>;
15+
};
16+
using OneToOneLinkInstances =
17+
typename Map_t<OneToOneLinkSet,
18+
OneToOneLinkInstanceType>::template exportTo<std::tuple>;
19+
1920
public:
20-
constexpr TaskDsl(FlowBuilder& flow_builder) {
21-
build_jobs_cb(flow_builder, std::make_index_sequence<AllJobs::size>{});
22-
build_links(std::make_index_sequence<OneToOneLinkSet::size>{});
23-
}
21+
constexpr TaskDsl(FlowBuilder &flow_builder) {
22+
build_jobs_cb(flow_builder, std::make_index_sequence<AllJobs::size>{});
23+
build_links(std::make_index_sequence<OneToOneLinkSet::size>{});
24+
}
25+
2426
private:
25-
template<size_t ...Is>
26-
void build_jobs_cb(FlowBuilder& flow_builder, std::index_sequence<Is...>) {
27-
(std::get<Is>(jobsCb_).build(flow_builder), ...);
28-
}
29-
30-
template<size_t ...Is>
31-
void build_links(std::index_sequence<Is...>) {
32-
(std::get<Is>(links_).build(jobsCb_), ...);
33-
}
27+
template <size_t... Is>
28+
void build_jobs_cb(FlowBuilder &flow_builder, std::index_sequence<Is...>) {
29+
(std::get<Is>(jobsCb_).build(flow_builder), ...);
30+
}
31+
32+
template <size_t... Is> void build_links(std::index_sequence<Is...>) {
33+
(std::get<Is>(links_).build(jobsCb_), ...);
34+
}
35+
3436
private:
35-
JobsCb jobsCb_;
36-
OneToOneLinkInstances links_;
37+
JobsCb jobsCb_;
38+
OneToOneLinkInstances links_;
3739
};
3840

3941
#define __some_job(...) tf::SomeJob<__VA_ARGS__>
4042
#define __fork(...) __some_job(__VA_ARGS__)
4143
#define __merge(...) auto(__some_job(__VA_ARGS__))
4244
#define __link(Job) auto(Job)
4345
#define __taskbuild(...) tf::TaskDsl<__VA_ARGS__>
44-
#define __def_task(name, ...) struct name { \
45-
auto operator()() __VA_ARGS__ \
46-
}
46+
#define __def_task(name, ...) \
47+
struct name { \
48+
auto operator()() __VA_ARGS__ \
49+
}
4750

48-
}
51+
} // namespace tf

taskflow/dsl/tuple_utils.hpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@
66
namespace tf {
77
namespace detail {
88
// get tuple element index by f, if not exists then index >= tuple_size
9-
template<typename TUP, template<typename> class F, typename = void>
9+
template <typename TUP, template <typename> class F, typename = void>
1010
struct TupleElementByF {
11-
constexpr static size_t Index = 0;
11+
constexpr static size_t Index = 0;
1212
};
1313

14-
template<template<typename> class F, typename H, typename ...Ts>
14+
template <template <typename> class F, typename H, typename... Ts>
1515
struct TupleElementByF<std::tuple<H, Ts...>, F, std::enable_if_t<F<H>::value>> {
16-
constexpr static size_t Index = 0;
16+
constexpr static size_t Index = 0;
1717
};
1818

19-
template<template<typename> class F, typename H, typename ...Ts>
20-
struct TupleElementByF<std::tuple<H, Ts...>, F, std::enable_if_t<! F<H>::value>> {
21-
constexpr static size_t Index = 1 + TupleElementByF<std::tuple<Ts...>, F>::Index;
19+
template <template <typename> class F, typename H, typename... Ts>
20+
struct TupleElementByF<std::tuple<H, Ts...>, F,
21+
std::enable_if_t<!F<H>::value>> {
22+
constexpr static size_t Index =
23+
1 + TupleElementByF<std::tuple<Ts...>, F>::Index;
2224
};
23-
}
25+
} // namespace detail
2426

25-
template<typename TUP, template<typename> class F>
27+
template <typename TUP, template <typename> class F>
2628
constexpr size_t TupleElementByF_v = detail::TupleElementByF<TUP, F>::Index;
27-
}
29+
} // namespace tf

0 commit comments

Comments
 (0)