void load_json_dir(std::string const &dirname) { // get a list of all files in the directory std::vector<std::string> dir = get_files_from_path(".json", dirname, true, true); // iterate over each file std::vector<std::string>::iterator it; for (it = dir.begin(); it != dir.end(); it++) { // open the file as a stream std::ifstream infile(it->c_str(), std::ifstream::in | std::ifstream::binary); // and stuff it into ram std::istringstream iss( std::string( (std::istreambuf_iterator<char>(infile)), std::istreambuf_iterator<char>() ) ); infile.close(); // parse it try { JsonIn jsin(iss); load_all_from_json(jsin); } catch( const JsonError &err ) { throw std::runtime_error( *(it) + ": " + err.what() ); } } }
void load_json_dir(std::string const &dirname) { // get a list of all files in the directory std::vector<std::string> dir = listfiles(dirname); // iterate over each file std::vector<std::string>::iterator it; for (it = dir.begin(); it != dir.end(); it++) { // open the file as a stream std::ifstream infile(it->c_str(), std::ifstream::in | std::ifstream::binary); // parse it try { JsonIn jsin(&infile); load_all_from_json(jsin); } catch (std::string e) { throw *(it) + ": " + e; } } }
void DynamicDataLoader::load_data_from_path( const std::string &path, const std::string &src, loading_ui &ui ) { assert( !finalized && "Can't load additional data after finalization. Must be unloaded first." ); // We assume that each folder is consistent in itself, // and all the previously loaded folders. // E.g. the core might provide a vpart "frame-x" // the first loaded mode might provide a vehicle that uses that frame // But not the other way round. // get a list of all files in the directory str_vec files = get_files_from_path( ".json", path, true, true ); if( files.empty() ) { std::ifstream tmp( path.c_str(), std::ios::in ); if( tmp ) { // path is actually a file, don't checking the extension, // assume we want to load this file anyway files.push_back( path ); } } // iterate over each file for( auto &files_i : files ) { const std::string &file = files_i; // open the file as a stream std::ifstream infile( file.c_str(), std::ifstream::in | std::ifstream::binary ); // and stuff it into ram std::istringstream iss( std::string( ( std::istreambuf_iterator<char>( infile ) ), std::istreambuf_iterator<char>() ) ); try { // parse it JsonIn jsin( iss ); load_all_from_json( jsin, src, ui, path, file ); } catch( const JsonError &err ) { throw std::runtime_error( file + ": " + err.what() ); } } }
void DynamicDataLoader::load_data_from_path(const std::string &path) { // We assume that each folder is consistent in itself, // and all the previously loaded folders. // E.g. the core might provide a vpart "frame-x" // the first loaded mode might provide a vehicle that uses that frame // But not the other way round. // get a list of all files in the directory str_vec files = file_finder::get_files_from_path(".json", path, true, true); if (files.empty()) { std::ifstream tmp(path.c_str(), std::ios::in); if (tmp) { // path is actually a file, don't checking the extension, // assume we want to load this file anyway files.push_back(path); } } // iterate over each file for (size_t i = 0; i < files.size(); i++) { const std::string &file = files[i]; // open the file as a stream std::ifstream infile(file.c_str(), std::ifstream::in | std::ifstream::binary); // and stuff it into ram std::istringstream iss( std::string( (std::istreambuf_iterator<char>(infile)), std::istreambuf_iterator<char>() ) ); try { // parse it JsonIn jsin(iss); load_all_from_json(jsin); } catch (std::string e) { DebugLog() << file << ": " << e << "\n"; throw file + ": " + e; } } }