// "chessx.eco.txt" -> "chessx.eco", "chessx.gtm", "chessx.txt" bool compileAsciiEcoFile(const QString& filenameIn, QString filenameOut, QString gtmFile) { // Read in the ECO data if(!parseAsciiEcoData(filenameIn)) { return false; } filenameOut = QFileInfo(filenameIn).absolutePath() + QDir::separator() + filenameOut; gtmFile = QFileInfo(filenameIn).absolutePath() + QDir::separator() + gtmFile; // Write out the main ECO file QFile file(filenameOut); file.open(QIODevice::WriteOnly); QDataStream sout(&file); sout << COMPILED_ECO_FILE_ID; sout << ecoPositions; file.close(); // Write out the GTM (guess-the-move) ECO file QFile gfile(gtmFile); gfile.open(QIODevice::WriteOnly); QDataStream gout(&gfile); gout << COMPILED_GUESS_FILE_ID; gout << gtmPositions; gfile.close(); ecoPositions.clear(); gtmPositions.clear(); return true; }
ITestLoader::Result GTest_Loader::loadFile(const QString &file_name, IFilePtr &file, const QStringList &environment){ ITestCasePtr testcase; QList<QString> listResult; QList<ITestSuitePtr> gtest_suites; QStringList args; ITestSuitePtr google_suite; args << "--gtest_list_tests"; file->setAbsFileName(file_name); Utils::runProcess(file_name, args, listResult); DEBUG(QString("Gtest detected")); foreach(QString line, listResult){ // if there is no spaces - than it is testsuitename if (line[0] != ' '){ google_suite = ITestSuitePtr(new GTest_TestSuite); google_suite->setName(line.remove(QRegExp("[.]|\n"))); // remove dot and \n at the end of line gtest_suites.push_back(google_suite); } else{ // this removes first two spaces testcase = ITestCasePtr(new GTest_TestCase(line.remove(QRegExp("\n|[ ]")))); google_suite->addTestCase(testcase); } } GTest_FilePtr gfile(new GTest_File()); gfile->setTestSuites(gtest_suites); file = gfile.staticCast<IFile>(); return ResultOk; }
KdeIni::KdeIni(const QString &name) { QString buffer; localFile = confPath[0] + name; QFile lfile(localFile); if (lfile.open(QIODevice::ReadOnly)) { localGroup == local.end(); QTextStream stream(&lfile); do { buffer = stream.readLine().trimmed(); if (buffer.startsWith('[')) // group localGroup = local.insert(buffer.mid(1,buffer.length()-2), Entries()); else if (!(buffer.isEmpty() || localGroup == local.end())) localGroup.value().insert(buffer.section('=',0,0), buffer.section('=',1)); } while (!buffer.isNull()); lfile.close(); } QFile gfile(confPath[1] + name); if (gfile.open(QIODevice::ReadOnly)) { localGroup == global.end(); QTextStream stream(&gfile); do { buffer = stream.readLine().trimmed(); if (buffer.startsWith('[')) // group localGroup = global.insert(buffer.mid(1,buffer.length()-2), Entries()); else if (!(buffer.isEmpty() || localGroup == global.end())) localGroup.value().insert(buffer.section('=',0,0), buffer.section('=',1)); } while (!buffer.isNull()); gfile.close(); } localGroup = local.end(); globalGroup = global.constEnd(); }
void MyMoveServer::loadGestures() { if (!QFile::exists(GESTURES_CONF_FILE)) { return; } m_gesturesDouble.clear(); m_gesturesTriple.clear(); QFile gfile(GESTURES_CONF_FILE); gfile.open(QIODevice::ReadOnly); QTextStream stream(&gfile); // Read the version QString version = stream.readLine(); QString line = stream.readLine(); do { QStringList data = line.split("###"); QString id; QString app; QString command; bool reserved = false; qDebug("### Gesture ###"); for (int i = 0; i < data.size(); i++) { qDebug("data %d %s", i, data.at(i).toLatin1().data()); } id = data.at(0); app = data.at(1); command = data.at(2); if (app.size() > 0) { reserved = true; } qDebug("### Gesture END ###"); Gesture gest; gest.command = command; int idnum = id.mid(1, id.length()-1).toInt(); if (id.at(0) == 'd') { qDebug() << "Appending to double gestures: " << id << ", " << command; m_gesturesDouble[idnum] = gest; } else if (id.at(0) == 't') { qDebug() << "Appending to triple gestures: " << id << ", " << command; m_gesturesTriple[idnum] = gest; } line = stream.readLine(); } while (!line.isEmpty()); }
int main(int argc, char** argv){ if(argc == 3){ /* Open the graph file */ std::ifstream gfile(argv[1]); std::ofstream ofile(argv[2]); std::string eline; //std::unordered_map<int,int> in_edge_count; // node <-- number of in edges std::unordered_map<std::string,int> labels; // node_label <-- node_id 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 //in_edge_count.insert(std::make_pair(from,0)); } else { from = labels[from_label]; } 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 //in_edge_count.insert(std::make_pair(to,0)); } else { to = labels[to_label]; //in_edge_count[labels[from_label]] += 1; } //add to converted labels file ofile << from << " " << to << std::endl; } gfile.close(); ofile.close(); } else std::cout << "Unable to open input file for reading." << std::endl;
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; }