forked from ChunelFeng/CGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathT01-Simple.cpp
More file actions
58 lines (49 loc) · 2.1 KB
/
T01-Simple.cpp
File metadata and controls
58 lines (49 loc) · 2.1 KB
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
/***************************
@Author: Chunel
@Contact: chunel@foxmail.com
@File: T01-Simple.cpp
@Time: 2021/5/4 4:09 下午
@Desc: 本例主要演示,GPipeline注册和添加依赖关系的流程
***************************/
#include "MyGNode/MyNode1.h"
#include "MyGNode/MyNode2.h"
using namespace CGraph;
void tutorial_simple() {
/* 创建图对应的pipeline */
GPipelinePtr pipeline = GPipelineFactory::create();
CStatus status;
/**
* 本例中为了简化流程,做此写法。实际使用中,建议每个变量定义一行,例:
* GElementPtr a = nullptr;
* GElementPtr b = nullptr;
* GElementPtr c = nullptr;
* GElementPtr d = nullptr;
*/
GElementPtr a, b, c, d = nullptr;
/* 注册节点,其中MyNode1和MyNode2必须为GraphNode的子类,否则无法通过编译。
* MyNode1中run()执行内容为sleep(1s)
* MyNode2中run()执行内容为sleep(2s) */
status = pipeline->registerGElement<MyNode1>(&a, {}, "nodeA"); // 将名为nodeA,无执行依赖的node信息,注册入pipeline中
if (!status.isOK()) {
return; // 使用时,请对所有CGraph接口的返回值做判定。本例子中省略
}
status = pipeline->registerGElement<MyNode2>(&b, {a}, "nodeB"); // 将名为nodeB,依赖a执行的node信息,注册入pipeline中
status = pipeline->registerGElement<MyNode1>(&c, {a}, "nodeC");
status = pipeline->registerGElement<MyNode2>(&d, {b, c}, "nodeD"); // 将名为nodeD,依赖{b,c}执行的node信息,注册入pipeline中
/* 图信息初始化,准备开始计算 */
status = pipeline->init();
/* 运行流图信息。初始化后,支持多次循环计算 */
for (int i = 0; i < 3; i++) {
status = pipeline->run();
std::cout << "[CGraph] tutorial_simple, loop : " << i + 1
<< ", and run status = " << status.getCode()
<< std::endl;
}
/* 图信息逆初始化,准备结束计算 */
status = pipeline->deinit();
GPipelineFactory::destroy(pipeline);
}
int main () {
tutorial_simple();
return 0;
}