void messageErrorAndExit(string error) { std::ofstream ofile("ERROR.txt", std::ios::out); ofile << error; ofile.close(); exit(-1); }
int main(int argc, char** argv){ if(argc == 5){ /* Open the graph file */ std::ifstream gfile(argv[1]); std::ifstream afile(argv[2]); std::ofstream ofile(argv[3]); int num_cols = atoi(argv[4]); std::string eline; std::unordered_map<std::string,int> labels; // node_label <-- node_id taken from original graph file std::unordered_map<int,std::string> rev_labels; // node_id <-- node_label int node_count = 0; if(gfile.is_open()){ while(getline(gfile, eline)){ /* get an edge from the file */ std::istringstream buff(eline); std::string from_label, to_label; int from, to; buff >> from_label; buff >> to_label; if(labels.find(from_label) == labels.end()) { //if the node is encountered for the first time from = node_count++; labels.insert(std::make_pair(from_label,from)); //index labelled node to a node id rev_labels.insert(std::make_pair(from,from_label)); //index labelled node to a node id } if(labels.find(to_label) == labels.end()) { //if the node is encountered for the first time to = node_count++; labels.insert(std::make_pair(to_label, to)); //index labelled node to a node id rev_labels.insert(std::make_pair(to,to_label)); //index labelled node to a node id } } gfile.close(); std::cout << "printing labels : " << std::endl; for(auto it=labels.begin(); it != labels.end(); ++it){ std::cout << it->first << " -> " << it->second << std::endl; } std::cout << "printing rev labels : " << std::endl; for(auto it=rev_labels.begin(); it != rev_labels.end(); ++it){ std::cout << it->first << " -> " << it->second << std::endl; } if(afile.is_open()){ while(getline(afile, eline)){ /* get an edge from the file */ std::istringstream buff(eline); int node_id; std::string orig_label, temp; for(int i = 0; i < num_cols; i++){ if(i != 0){ ofile << " "; // put space character between values } buff >> node_id; if(rev_labels.find(node_id) != rev_labels.end()) { //if node id in gc format exists in our table orig_label = rev_labels[node_id]; ofile << orig_label; } else std::cout<< node_id <<" not in the map" << std::endl; } //write the rest of the columns as it is while((char)buff.peek() != '\n' && buff.good()){ ofile << " "; // put space character between values buff >> temp; ofile << temp; } ofile << std::endl; // after reading all values on the line, end the line in output file. } afile.close(); ofile.close(); } else std::cout << "Unable to open second input file for reading." << std::endl; }
int main() { // reading the input file QFile ifile("in.txt"); QString content; QStringList list; ifile.open(QIODevice::ReadOnly); // read whole content while (!ifile.atEnd()) { // defining the regexp by which splitting of contents is to be done QRegularExpression exp("(\\(|\\)|\\,|\\=)"); content = ifile.readAll(); list = content.split(exp); } // closing the file after reading has been done ifile.close(); // opening the file to write the splitted data QFile ofile("out.txt"); ofile.open(QIODevice::WriteOnly); QTextStream out(&ofile); out << list.join("\n"); ofile.close(); // defining regexp to save only numbers in the parsed data in a list //QRegularExpression exp1("^[0-9]*$"); QVector<QVector<QString>*> bigV; QVector<QString>* v; QString c; int count = -1; ofile.open(QIODevice::ReadOnly); // read whole content while (!ofile.atEnd()) { c = ofile.readLine(); if(c == "wall\n") { ++count; v = new QVector<QString>(5); (*v)[0] = c; // qDebug() << "wall"; } if(c == "ball\n") { ++count; v = new QVector<QString>(4); (*v)[0] = c; // qDebug() << "ball"; } if(c == "l\n" && count >= 0 && v != NULL) { // qDebug() << "l"; (*v)[1] = ofile.readLine(); } if(c == "h\n" && count >= 0 && v != NULL) { // qDebug() << "h"; (*v)[2] = ofile.readLine(); } if(c == "bx\n" && count >= 0 && v != NULL) { (*v)[3] = ofile.readLine(); } if(c == "by\n" && count >= 0 && v != NULL) { (*v)[4] = ofile.readLine(); } if(c == "r\n" && count >= 0 && v != NULL) { (*v)[1] = ofile.readLine(); } if(c == "cx\n" && count >= 0 && v != NULL) { (*v)[2] = ofile.readLine(); } if(c == "cy\n" && count >= 0 && v != NULL) { (*v)[3] = ofile.readLine(); } if(c == "\n" && count >= 0 && v != NULL) { // qDebug() << "v : " << v; bigV.append(v); //delete v; //v = 0; } } // qDebug() << bigV.count(); ofile.close(); // creating the entity class' object and calling its function entity e; // dxfRW *abc = e.return_dxf(); // DL_WriterA *def = e.return_dw(); // e.startDXF(abc); e.createWall(10, 20, 30, 30, "wall", 256, 1, "CONTINUOUS"); // for (int i = 0; i < bigV.size(); ++i) // { // QVector<QString>* ab = bigV.at(i); // if (ab->at(0) == "wall\n") // { // int j = 1; // e.createWall(abc, ab->at(j).toFloat(), ab->at(j+1).toFloat(), // ab->at(j+2).toFloat(), ab->at(j+3).toFloat(), // "wall", 256, 1, "CONINUOUS"); // } // if (ab->at(0) == "ball\n") // { // int j = 1; // // e.createWall(abc, def, ab->at(j).toFloat(), ab->at(j+1).toFloat(), // // ab->at(j+2).toFloat(), ab->at(j+3).toFloat(), // // "wall", 256, 1, "CONINUOUS"); // } // } // e.createFlange(abc, def, 20, 60, 100); e.closeDXF(); QProcess::execute("librecad file.dxf"); }