forked from ChunelFeng/CGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathT11-Singleton.cpp
More file actions
35 lines (27 loc) · 1.16 KB
/
T11-Singleton.cpp
File metadata and controls
35 lines (27 loc) · 1.16 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
/***************************
@Author: Chunel
@Contact: chunel@foxmail.com
@File: T11-Singleton.cpp
@Time: 2021/10/30 10:32 下午
@Desc: 本例主要展示,通过添加GSingleton添加的节点,均是同一个节点(指针地址相同)
***************************/
#include "MyGNode/MyShowAddressNode.h"
#include "MyGNode/MyNode1.h"
using namespace CGraph;
void tutorial_singleton() {
GPipelinePtr pipeline = GPipelineFactory::create();
GElementPtr a, b, c, d, e = nullptr;
/* 通过GSingleton方式注册的节点,地址相同 */
pipeline->registerGElement<GSingleton<MyShowAddressNode>>(&a, {}, "singleton", 2);
/* 通过普通方式注册的节点,地址不同 */
pipeline->registerGElement<MyShowAddressNode>(&b, {a}, "not singleton");
pipeline->registerGElement<GSingleton<MyShowAddressNode>>(&c, {a}); // c的地址和a是相同的
pipeline->registerGElement<GSingleton<MyNode1>>(&d, {c}, "nodeD");
pipeline->registerGElement<GSingleton<MyShowAddressNode>>(&e, {c}); // e的地址和a也是相同的
pipeline->process();
GPipelineFactory::remove(pipeline);
}
int main() {
tutorial_singleton();
return 0;
}