GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — CGraph/tutorial/T12-Function.cpp at main · feiyunwill/CGraph Expand file tree/ Copy pathT12-Function.cppMore file actions 56 lines (47 loc) · 2.14 KB / Copy pathT12-Function.cppFile metadata and controls56 lines (47 loc) · 2.14 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 /*************************** @Author: Chunel @Contact: [email protected] @File: T12-Function.cpp @Time: 2022/1/23 3:22 下午 @Desc: 本例主要展示,通过GFunction实现节点和函数式混合编程的功能 ***************************/ #include "MyGNode/MyNode1.h" #include "MyGNode/MyWriteParamNode.h" using namespace CGraph; void tutorial_function() { GPipelinePtr pipeline = GPipelineFactory::create(); GElementPtr a, b = nullptr; GFunctionPtr c_function, d_function = nullptr; // 申明两个 GFunction 类型的变量 /** v1.8.3 版本之后,推荐使用+=的形式,对status赋值 */ CStatus status = pipeline->registerGElement<MyNode1>(&a, {}, "nodeA", 1); status += pipeline->registerGElement<MyWriteParamNode>(&b, {a}, "nodeB", 1); status += pipeline->registerGElement<GFunction>(&c_function, {b}, "functionC", 1); // 注册GFunction类型的节点c_function status += pipeline->registerGElement<GFunction>(&d_function, {c_function}, "functionD", 3); if (!status.isOK()) { CGRAPH_ECHO("pipeline register failed for the reason : ", status.getInfo().c_str()); return; } int num = 10; const std::string& info = "Hello, CGraph"; c_function->setFunction(CFunctionType::RUN, [num, info] { CGRAPH_ECHO("input num i = [%d], info = [%s]", num, info.c_str()); // 传递pipeline外部参数,并在pipeline内部节点执行时使用 return CStatus(); }); /** 通过链式调用的方式,注册多个执行函数 */ d_function->setFunction(CFunctionType::INIT, [d_function] { CGRAPH_ECHO("[%s] do init function ...", d_function->getName().c_str()); return CStatus(); })->setFunction(CFunctionType::RUN, [d_function, num] { auto param = d_function->getGParamWithNoEmpty<MyParam>("param1"); param->iCount += num; CGRAPH_ECHO("[%s] do run function, iCount = [%d], iValue = [%d] ...", d_function->getName().c_str(), param->iCount, ++param->iValue); return CStatus(); }); pipeline->process(); GPipelineFactory::remove(pipeline); } int main() { tutorial_function(); return 0; } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |