MCPcopy Create free account
hub / github.com/ChunelFeng/CGraph / tutorial_aspect

Function tutorial_aspect

tutorial/T09-Aspect.cpp:17–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15using namespace CGraph;
16
17void tutorial_aspect() {
18 GPipelinePtr pipeline = GPipelineFactory::create();
19
20 GElementPtr a, b_region, c = nullptr;
21 b_region = pipeline->createGGroup<GRegion>({
22 pipeline->createGNode<MyNode1>(GNodeInfo({}, "nodeB1", 1)),
23 pipeline->createGNode<MyNode2>(GNodeInfo({}, "nodeB2", 2))
24 });
25
26 pipeline->registerGElement<MyNode1>(&a, {}, "nodeA", 1);
27 pipeline->registerGElement<GRegion>(&b_region, {a}, "regionB", 1);
28 pipeline->registerGElement<MyNode1>(&c, {b_region}, "nodeC", 1);
29
30 /** 针对node类型,添加 MyTraceAspect 切面逻辑 */
31 a->addGAspect<MyTraceAspect>();
32
33 /** 针对node类型,添加可变参的MyTemplateAspect 切面逻辑 */
34 a->addGAspect<MyTemplateAspect<int, double>>(20, 7.0);
35
36 /** 针对group类型,添加 MyTimerAspect 切面逻辑 */
37 b_region->addGAspect<MyTimerAspect>();
38
39 /**
40 * 给特定的element,统一添加 MyTraceAspect 类型的切面
41 * 不传参数,表示对pipeline内部所有的节点,添加该切面
42 * */
43 pipeline->addGAspect<MyTraceAspect>({b_region, c});
44
45 pipeline->process(); // 运行pipeline
46 GPipelineFactory::remove(pipeline);
47}
48
49
50int main() {

Callers 1

mainFunction · 0.70

Calls 4

createFunction · 0.85
GNodeInfoClass · 0.85
removeFunction · 0.85
processMethod · 0.45

Tested by

no test coverage detected