void ReplaceVariable(ELEMENT* pEle) { /*递归函数,用来访问pEle下所有元素*/ function<void(ELEMENT*, function<void(ELEMENT*)>)> recursiveFunc = [&recursiveFunc](ELEMENT* pEle, function<void(ELEMENT*)> pFunc)->void { if (pFunc != nullptr) { pFunc(pEle); } for (ELEMENT* p = pEle->FirstChildElement(); p != 0; p = p->NextSiblingElement()) { recursiveFunc(p, pFunc); } }; /*以下用来将内容替换成变量中内容*/ for (ELEMENT* p = pEle->FirstChildElement("Variable")->FirstChildElement(); p != 0; p=p->NextSiblingElement()) { std::string vName, vValue; vName = string("$(") + string(p->Name()) + string(")"); vValue = std::string(p->GetText()); recursiveFunc(pEle, [vName,vValue](ELEMENT* p)->void { const char* text; if ((text=p->GetText()) != nullptr) { string str(text); std::size_t pos; while ((pos = str.find(vName)) != str.npos) { str.replace(pos, vName.length(), vValue); } p->SetText(str.c_str()); } }); } }
void recursiveFunc(unsigned depth=3) { OSG::PerfMonitorGuard g("recursiveFunc"); //osgSleep(10); //std::cout << "depth: " << depth << std::endl; if (depth == 0) { return; } else { recursiveFunc(depth-1); } }
void doStuff() { static float x =0; // Value to influence the work static float x_inc =0.01f; x += x_inc; if ((x<=0.0) || (x>=1.0)) { x_inc = -x_inc; x += x_inc; } OSG::PerfMonitorGuard gG("doStuff"); { OSG::PerfMonitorGuard g("Work1"); recursiveFunc(); randWork(unsigned(10.0*x), 1, "10*x"); randWork(unsigned(10.0*(1.0-x)), 1, "10*(1-x)"); } { OSG::PerfMonitorGuard g("Work2"); recursiveFunc(); randWork(unsigned(5.0*x), 1, "5x-1"); randWork(2, 10, "2-10"); } { OSG::PerfMonitorGuard g("Work3"); recursiveFunc(); randWork( 1, unsigned(5.0*x), "1-5x"); randWork(2, 0, "2-0"); } { OSG::PerfMonitorGuard g("Work4"); recursiveFunc(3); } { OSG::PerfMonitorGuard g("Work5"); recursiveFunc(3); } { OSG::PerfMonitorGuard g("Work6"); recursiveFunc(3); } { OSG::PerfMonitorGuard g("Work7"); recursiveFunc(3); } }