| 12 | using namespace CGraph; |
| 13 | |
| 14 | void tutorial_singleton() { |
| 15 | GPipelinePtr pipeline = GPipelineFactory::create(); |
| 16 | GElementPtr a, b, c, d, e = nullptr; |
| 17 | |
| 18 | /* 通过GSingleton方式注册的节点,地址相同 */ |
| 19 | pipeline->registerGElement<GSingleton<MyShowAddressNode>>(&a, {}, "singleton", 2); |
| 20 | |
| 21 | /* 通过普通方式注册的节点,地址不同 */ |
| 22 | pipeline->registerGElement<MyShowAddressNode>(&b, {a}, "not singleton"); |
| 23 | pipeline->registerGElement<GSingleton<MyShowAddressNode>>(&c, {a}); // c的地址和a是相同的 |
| 24 | pipeline->registerGElement<GSingleton<MyNode1>>(&d, {c}, "nodeD"); |
| 25 | pipeline->registerGElement<GSingleton<MyShowAddressNode>>(&e, {c}); // e的地址和a也是相同的 |
| 26 | |
| 27 | pipeline->process(); |
| 28 | GPipelineFactory::remove(pipeline); |
| 29 | } |
| 30 | |
| 31 | |
| 32 | int main() { |