std::string ParentTransform::stmtToString(const clang::Stmt* s) { std::string s_str; llvm::raw_string_ostream s_stream(s_str); s->printPretty(s_stream, NULL, Context->getPrintingPolicy()); s_stream.flush(); return s_str; }
static void split( const std::string& str, char delimiter, Strings& items ) { std::stringstream s_stream(str); std::string item; while (std::getline(s_stream, item, delimiter)) { if (!item.empty()) { items.push_back(item); } } }
std::vector<std::string> split(const std::string &s, char delim, std::vector<std::string> &elems) { std::string original(s); std::stringstream s_stream (original); std::string str; while (std::getline(s_stream, str, delim)) { elems.push_back(str); } if (original.find_last_of(delim) == original.size() - 1) elems.push_back(""); return elems; }
void CCustomParser::parse(const std::string& filename) { std::ifstream in(filename); std::string s; while(std::getline(in, s)) { std::istringstream s_stream(s); std::string cur_s; s_stream >> cur_s; if(cur_s == "sphere") { double c_x, c_y, c_z, radius; int r, g, b; s_stream >> c_x >> c_y >> c_z >> radius; s_stream >> r >> g >> b; CMaterial mat; mat.set_color(CColor(r, g, b)); CSphere* sphere = new CSphere(radius, CPoint3D(c_x, c_y, c_z), mat); m_objects.push_back(sphere); } else if(cur_s == "camera") {
void MainWindow::on_pushButton_file_path_clicked() { QFile file; QTextStream stream(&file); if(ui->radioButton_by_images->isChecked()) file.setFileName("sources/image_sample.txt"); else file.setFileName("sources/feature_sample.txt"); if(!QFile::exists(file.fileName()) || !stream.device()->open(QIODevice::ReadOnly)) { QMessageBox::warning(this, "Помилка", QString("Неможливо відкрити файл \"%1\". Перевірте правильність вводу файла.").arg(file.fileName())); return; } // result_imageName.clear(); sample.clear(); cur_index = 0; // QString str; QTextStream s_stream(&str,QIODevice::ReadOnly); try{ if(ui->radioButton_by_images->isChecked()){ dir_path = stream.readLine(); stream.readLine(); stream.readLine(); for(str = stream.readLine(); str.size(); str = stream.readLine(),s_stream.seek(0)) { QPair<QVector<qreal>, QString> pair; pair.first.resize(5); s_stream >> pair.first[0];//first column for(int i = 0; i < 5; i++){ s_stream >> pair.first[i]; pair.first[i]=(pair.first[i]-1)/4; } s_stream >> pair.second; result_imageName.append(pair); str.clear(); setMode(MainWindow::DialogMode); if(open_rec_img(dir_path + result_imageName[cur_index].second)) show_results(result_imageName[cur_index].first); else on_pushButton_skip_clicked(); } }else { stream.readLine(); stream.readLine(); for(str = stream.readLine(); str.size(); str = stream.readLine(),s_stream.seek(0)) { QPair<QVector<qreal>, QVector<qreal> > pair; pair.second.resize(5); for(int i = 0; i < pair.second.size(); i++) s_stream >> pair.second[i]; QString tmp; s_stream >> tmp; pair.first.resize(21); for(int i = 0; i < pair.first.size(); i++) s_stream >> pair.first[i]; sample.append(pair); str.clear(); } emit train_sample_inputed(sample); } }
void GmshIO::read_mesh(std::istream& in) { // This is a serial-only process for now; // the Mesh should be read on processor 0 and // broadcast later libmesh_assert_equal_to (MeshOutput<MeshBase>::mesh().processor_id(), 0); libmesh_assert(in.good()); // clear any data in the mesh MeshBase& mesh = MeshInput<MeshBase>::mesh(); mesh.clear(); // some variables int format=0, size=0; Real version = 1.0; // Keep track of lower-dimensional blocks which are not BCs, but // actually blocks of lower-dimensional elements. std::set<subdomain_id_type> lower_dimensional_blocks; // Mapping from physical id -> (physical dim, physical name) pairs. // These can refer to either "sidesets" or "subdomains"; we need to // wait until the Mesh has been read to know which is which. Note // that we are using 'int' as the key here rather than // subdomain_id_type or boundary_id_type, since at this point, it // could be either. typedef std::pair<unsigned, std::string> GmshPhysical; std::map<int, GmshPhysical> gmsh_physicals; // map to hold the node numbers for translation // note the the nodes can be non-consecutive std::map<unsigned int, unsigned int> nodetrans; // For reading the file line by line std::string s; while (true) { // Try to read something. This may set EOF! std::getline(in, s); if (in) { // Process s... if (s.find("$MeshFormat") == static_cast<std::string::size_type>(0)) { in >> version >> format >> size; if ((version != 2.0) && (version != 2.1) && (version != 2.2)) { // Some notes on gmsh mesh versions: // // Mesh version 2.0 goes back as far as I know. It's not explicitly // mentioned here: http://www.geuz.org/gmsh/doc/VERSIONS.txt // // As of gmsh-2.4.0: // bumped mesh version format to 2.1 (small change in the $PhysicalNames // section, where the group dimension is now required); // [Since we don't even parse the PhysicalNames section at the time // of this writing, I don't think this change affects us.] // // Mesh version 2.2 tested by Manav Bhatia; no other // libMesh code changes were required for support libmesh_error_msg("Error: Unknown msh file version " << version); } if (format) libmesh_error_msg("Error: Unknown data format for mesh in Gmsh reader."); } // Read and process the "PhysicalNames" section. else if (s.find("$PhysicalNames") == static_cast<std::string::size_type>(0)) { // The lines in the PhysicalNames section should look like the following: // 2 1 "frac" lower_dimensional_block // 2 3 "top" // 2 4 "bottom" // 3 2 "volume" // Read in the number of physical groups to expect in the file. unsigned int num_physical_groups = 0; in >> num_physical_groups; // Read rest of line including newline character. std::getline(in, s); for (unsigned int i=0; i<num_physical_groups; ++i) { // Read an entire line of the PhysicalNames section. std::getline(in, s); // Use an istringstream to extract the physical // dimension, physical id, and physical name from // this line. std::istringstream s_stream(s); unsigned phys_dim; int phys_id; std::string phys_name; s_stream >> phys_dim >> phys_id >> phys_name; // Not sure if this is true for all Gmsh files, but // my test file has quotes around the phys_name // string. So let's erase any quotes now... phys_name.erase(std::remove(phys_name.begin(), phys_name.end(), '"'), phys_name.end()); // Record this ID for later assignment of subdomain/sideset names. gmsh_physicals[phys_id] = std::make_pair(phys_dim, phys_name); // If 's' also contains the libmesh-specific string // "lower_dimensional_block", add this block ID to // the list of blocks which are not boundary // conditions. if (s.find("lower_dimensional_block") != std::string::npos) { lower_dimensional_blocks.insert(cast_int<subdomain_id_type>(phys_id)); // The user has explicitly told us that this // block is a subdomain, so set that association // in the Mesh. mesh.subdomain_name(cast_int<subdomain_id_type>(phys_id)) = phys_name; } } }