-
Notifications
You must be signed in to change notification settings - Fork 1
/
T02-Param.cpp
66 lines (51 loc) · 1.44 KB
/
T02-Param.cpp
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
/***************************
@Author: Chunel
@Contact: [email protected]
@File: T02-param.cpp
@Time: 2024/9/7 17:32
@Desc:
***************************/
#include <iostream>
#include "./src/CGraph-lite.h"
const std::string& kParamKey = "param_key";
struct MyParam : public GParam {
void reset(const CStatus& curStatus) override {
val_ = 0;
}
int val_ { 0 };
int loop_ { 0 };
};
class MyReadParamNode : public GNode {
public:
CStatus init() override {
auto status = createGParam<MyParam>(kParamKey);
return status;
}
CStatus run() override {
auto param = getGParam<MyParam>(kParamKey);
std::cout << getName() << ": val = " << param->val_ << ", loop = " << param->loop_ << std::endl;
return CStatus();
}
};
class MyWriteParamNode : public GNode {
public:
CStatus run() override {
auto param = getGParam<MyParam>(kParamKey);
param->val_++;
param->loop_++;
std::cout << getName() << ": val = " << param->val_ << ", loop = " << param->loop_ << std::endl;
return CStatus();
}
};
void tutorial_param() {
GElement *w, *r = nullptr;
auto pipeline = GPipelineFactory::create();
pipeline->registerGElement<MyWriteParamNode>(&w, {}, "WriteNode");
pipeline->registerGElement<MyReadParamNode>(&r, {w}, "ReadNode");
pipeline->process(5);
GPipelineFactory::remove(pipeline);
}
int main() {
tutorial_param();
return 0;
}