void object::test<4>() { set_test_name("combine file path"); std::string str_path("c:\\test\\"), str_file("test.txt"); ensure_equals("combine file path", std::string("c:\\test\\test.txt"), win32::filesystem::combine_file_path(str_path, str_file)); }
void RRDModule::HandlerCallback(const char*objdata,int objsize, const char* path) { std::cout << "This is RRD Handler Callback" << std::endl; std::string str_path(path); mongo::BSONObj bo_data = mongo::BSONObj(objdata); long long time_long = bo_data["time"].numberLong(); time_t timestamp = time_t(time_long); bo_data = bo_data.removeField("time"); const char* key = bo_data.firstElementFieldName(); //获取数据源名称 const std::string ds_name(key); std::string str_path_d =root_file_path +str_path+'/'; std::string str_path_x; int mkdir_sgn; while(str_path_d !="") { mkdir_sgn = str_path_d.find('/'); str_path_x = str_path_x+'/'+str_path_d.substr(0,mkdir_sgn); if(access(str_path_x.c_str(),0)) mkdir(str_path_x.c_str(),0755); str_path_d =str_path_d.substr(mkdir_sgn+1); } std::string str_file =root_file_path +str_path +'/'+ ds_name +".rrd"; const std::string filename = str_file; kelp::RRDOperator opt(filename,ds_name); double data; data = bo_data[ds_name].numberDouble(); opt.InsertNum(timestamp,data); std::cout << "\nEnd of RRD Handler Callback!" <<std::endl; }
const char* weasel_shared_data_dir() { static char path[MAX_PATH] = {0}; GetModuleFileNameA(NULL, path, _countof(path)); std::string str_path(path); size_t k = str_path.find_last_of("/\\"); strcpy(path + k + 1, "data"); return path; }
void Model::loadModel(const char* path){ string str_path(path); // Read file via ASSIMP Assimp::Importer importer; const aiScene* scene = importer.ReadFile(str_path, aiProcess_Triangulate | aiProcess_FlipUVs); // Check for errors if(!scene || scene->mFlags == AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) // if is Not Zero { cout << "ERROR::ASSIMP:: " << importer.GetErrorString() << endl; return; } // Retrieve the directory path of the filepath this->m_directory = str_path.substr(0, str_path.find_last_of('/')); // Process ASSIMP's root node recursively this->processNode(scene->mRootNode, scene); }
static void lParseInclude(const char *path) { #ifdef ISPC_IS_WINDOWS char delim = ';'; #else char delim = ':'; #endif size_t pos = 0, pos_end; std::string str_path(path); do { pos_end = str_path.find(delim, pos); size_t len = (pos_end == std::string::npos) ? // Not found, copy till end of the string. std::string::npos : // Copy [pos, pos_end). (pos_end - pos); std::string s = str_path.substr(pos, len); g->includePath.push_back(s); pos = pos_end+1; } while (pos_end != std::string::npos); }
void MongoModule::HandlerCallback(const char* objdata,int objsize,const char* path) { std::cout << "This is mongo Handler Callback" << std::endl; std::string str_path(path); int loc; std::string dot_path; while(str_path !="") { loc =str_path.find('/'); if(loc ==str_path.npos) { dot_path +=str_path; break; } dot_path = dot_path+str_path.substr(0,loc)+'.'; str_path =str_path.substr(loc+1); } kelp::MongoOperator opt(dbname, dot_path); mongo::BSONObj data = mongo::BSONObj(objdata); opt.Insert(data); std::cout << "\nEnd of MongoDB Handler Callback" << std::endl; }
// (PHP-CALLBACK entry-point) This manually gets a lock where needed but // avoids holding one most of the time as this can be a quite slow operation. void runCallback() { hphp_session_init(Treadmill::SessionKind::Watchman); auto context = g_context.getNoCheck(); SCOPE_EXIT { hphp_context_exit(); hphp_session_exit(); { std::lock_guard<std::mutex> g(s_sharedDataMutex); processNextUpdate(); } }; try { std::string json_data; { std::lock_guard<std::mutex> g(s_sharedDataMutex); if (m_unprocessedCallbackData.empty()) { return; } auto& data = m_unprocessedCallbackData.back(); json_data = toJson(data); m_unprocessedCallbackData.pop_back(); } bool initial; auto unit = lookupUnit( String(m_callbackFile.c_str()).get(), "", &initial, Native::s_noNativeFuncs); if (!unit) { throw std::runtime_error( folly::sformat("Unit '{}' no longer exists.", m_callbackFile)); } auto unit_result = Variant::attach(context->invokeUnit(unit)); auto func = Unit::loadFunc(String(m_callbackFunc.c_str()).get()); if (!func) { throw std::runtime_error( folly::sformat("Callback '{}' no longer exists", m_callbackFunc)); } String str_path(m_path.c_str()); String str_query(m_query.c_str()); String str_name(m_name.c_str()); String str_json_data(json_data.c_str()); String str_socket_path(m_socketPath.c_str()); TypedValue args[] = { str_path.toCell(), str_query.toCell(), str_name.toCell(), str_json_data.toCell(), str_socket_path.toCell(), }; tvDecRefGen( context->invokeFuncFew(func, nullptr, // thisOrCls nullptr, // invName 5, // argc args) ); } catch(Exception& e) { if (m_error.empty()) { m_error = e.getMessage(); } } catch(Object& e) { if (m_error.empty()) { try { m_error = e->invokeToString().data(); } catch(...) { m_error = "PHP exception which cannot be turned into a string"; } } } catch(const std::exception& e) { if (m_error.empty()) { m_error = folly::exceptionStr(e).toStdString(); } } catch(...) { if (m_error.empty()) { m_error = "Unknown error (non std::exception)"; } } }