main(int argc, char *argv[]){ /** Check the number of parameters */ if (argc < 5) { /** Tell the user how to run the program */ cerr << "Usage: " << argv[0] << " token encrows results num_threads" << endl; return 1; } mr_init_threading(); PFC pfc(AES_SECURITY); SecureSelect *db=NULL; int m=0; string query_name(argv[1]); string enctable_name(argv[2]); string results_name(argv[3]); int num_threads = atoi(argv[4]); db = new SecureSelect(&pfc,pfc.order()); if (!ifstream(query_name+"_ptok")){ cout << "Query file doesn't exist" << endl; return 0; } if (!ifstream(enctable_name+"_enc_msgs")){ cout << "Enctable file doesn't exist" << endl; return 0; } #ifdef VERBOSE int start = getMilliCount(); #endif int res_num = db->ApplyPTokenMT(query_name, enctable_name, results_name, num_threads); //int res_num = db->ApplyPToken(query_name, enctable_name, results_name); #ifdef VERBOSE int milliSecondsElapsed = getMilliSpan(start); cout << "\texec time " << milliSecondsElapsed << endl; #endif if(res_num >=0){ cout << res_num << " result(s) found" << endl; return 1; } else return 0; }
Celsius Thermomether::read() const { auto&& device = ifstream( mDevice ); string line; vector< string > lines; while( getline( device, line ) ) lines.emplace_back( line ); if( lines.size() == 2 ) { if( lines[0].find( string{"YES"} ) != string::npos ) { static const string m{"t="}; auto pos = lines[1].find( m ); if( pos != string::npos ) { auto temp_str = lines[ 1 ].substr( pos + m.size() ); auto temp = stold( temp_str ); return { temp / 1000.0L }; } } } throw runtime_error{"Unable to read time"}; }
DialogReaderWriter::DialogReaderWriter(string aFileName, bool isSave) { if(isSave) m_toTxt = ofstream (aFileName); else m_Input = ifstream(aFileName); }
//========================================================================================================== // Process a control message, that is sent for specifying what and how to run a scenario for a single test. // TODO: should enable overriding global vars here? //========================================================================================================== void MServer::process_control_message(string& ctrl_msg, map<string, string>& script_vars) { map<string, Option> options; options.emplace(SCENARIO, Option(true, true)); options.emplace(TEST_DIR, Option(true, true)); options.emplace(DEFAULT_PV_NAME, ParamValOption()); // Will match any var=val and put it as a new option in the map OptionParser parser(ctrl_msg, options); // Mandatory options are scenario to run and test dir. All others are parameters to the scenario. for(auto pair: options) { if(pair.first == SCENARIO || pair.first == TEST_DIR) { vars[pair.first] = pair.second.get_value(); } else { script_vars[pair.first] = pair.second.get_value(); } } if(!ifstream(get_value(TEST_DIR))) { throw string("Dir " + get_value(TEST_DIR) + " doesn't exist"); } set_log_file(get_value(TEST_DIR) + "/mserver.log"); }
/////////////////////////////////////////////////////////////////////////////// // Get an optional value as a string. /////////////////////////////////////////////////////////////////////////////// string ParseCommandLine::getOptionString( vector<string> list, bool exists ) { // Go through the possible flags that denote the option. for( int i = 1; i <= list.size(); i++ ) { for (int j = 0; j < list[i-1].length();++j) { list[i-1][j] = tolower(list[i-1][j]); } // Get the next option if it exists. string option = list[i-1]; if( parsedData.find( option ) != parsedData.end() ) { // If string is meant to be an existing file name, but the file // doesn't exist, set an error and return an empty string. string file = parsedData[option]; if( ( exists == true ) && ( ifstream( file.c_str() ) == NULL ) ) { cerr << "File required for option " << option << " does not exist." << endl; setError(); return ""; } // Return the file. return file; } } // Return an empty string if no option was found. return ""; }
bool StringManager::AddStrings(const std::string& path) { if (!path.empty()) { const size_t MAX_KEY_LENGHT = 32; const size_t MAX_VAL_LENGHT = 1024; char key[MAX_KEY_LENGHT + 1] = {}; char val[MAX_VAL_LENGHT + 1] = {}; std::ifstream ifstream(path.c_str()); if (ifstream.is_open()) { util::Logger::GetInstance().Log("ok opened " + path); while (ifstream.get(key, MAX_KEY_LENGHT, ' ')) { ifstream.ignore(); ifstream.getline(val, MAX_VAL_LENGHT, '\n'); std::wstring wval = util::S2WS(val); AddString(key, wval); util::Logger::GetInstance().Log(key + std::string(" ") + val); } } else util::Logger::GetInstance().Log("Cant not opened file: " + path); } return true; }
void Config::loadConfig() { try { std::ifstream ifstream("Config.spider"); std::string json; ifstream >> json; if (json.empty() == true) return; _pt.clear(); std::istringstream is(json); boost::property_tree::read_json(is, _pt); _id = _pt.get<int>("id"); _token = _pt.get<int>("token"); _ip = _pt.get<std::string>("ip"); } catch (std::exception &e) { std::cout << "Exception boost json : " << e.what() << std::endl; std::ofstream ofstream("Config.spider"); ofstream.flush(); ofstream.close(); } }
void HuffmanProcessor::Decompress(char* input_filename) { input = ifstream(input_filename, ios::binary); root = new Node(); ReadTree(root); }
vector<int> Interface::CSVEntries(string name) { vector<int> result; if (ifstream(name)) { //Variable to store the file holding the data fstream dataFile; //If the file does not exist it will be created dataFile.open(name); //Parse the file and collect a csv string string line; getline(dataFile, line); stringstream lineStream(line); string cell; //Break down the csv string. Each element in the vector represents a single number while (getline(lineStream, cell, ',')) { int convertion = atoi(cell.c_str()); result.push_back(convertion); } dataFile.close(); return result; } else { cout << "File does not exists" << endl; return result; } }
ifstream Osu_Info::getJSON(string _url) { bool reload = false; #ifdef _DEBUG cout<< "Beginning download" << endl; #endif try { bool good = Downloader::getInstance().download((char*)_url.c_str(), reload); #ifdef _DEBUG if(good) cout<< "Download Complete" << endl; #endif } catch (DLExc exc) { #ifdef _DEBUG cout << exc.geterr() <<endl << "Download interrupted" << endl; #endif } return ifstream("data.txt"); }
/** * @brief Function checking the existence of a file * @param[in] filename Pointer to a `const char` containing the name of the file * @retval bool */ bool fexists(const char *filename) { if (ifstream(filename)) return true; else return false; }
void GuiTemplate::render() { if (!_templatesLoaded) { loadTemplates(); _templatesLoaded = true; } if (_textures.size() == 0) return; if (ImGui::CollapsingHeader(_name.c_str())) { bool firstTemplate = true; for (auto& name : _names) { if (!firstTemplate) ImGui::SameLine(0.f, 2.f); firstTemplate = false; if (ImGui::ImageButton((void*)(intptr_t)_textures[name]->getTexId(), ImVec2(128, 128))) { string configPath = string(DATADIR) + "templates/" + name + ".json"; #if HAVE_OSX if (!ifstream(configPath, ios::in | ios::binary)) configPath = "../Resources/templates/" + name + ".json"; #endif setWorldAttribute("loadConfig", {configPath}); } if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", _descriptions[name].data()); } } }
/*! * \reimp */ QString EDLParser::parseDisplayFile(QString filename, QMap<QString, QString> macros, bool partial) { Screen displayInfo; displayInfo.setFileName(filename.toStdString()); // add special macros // !A - application specific // !W - window specific macros["!A"] = QString::number(qApp->applicationPid(), 16); macros["!W"] = QString::number(QDateTime::currentMSecsSinceEpoch(), 16); // QMap to std::map std::map<std::string, std::string> smacros; for(auto it = macros.begin(); it != macros.end(); it++) smacros[it.key().toStdString()] = it.value().toStdString(); displayInfo.setMacros(smacros); std::ifstream ifstream(filename.toStdString().c_str()); displayInfo.parse(ifstream); std::ostringstream osstream; if (partial) displayInfo.toPartialQML(osstream); else displayInfo.toQML(osstream); osstream.flush(); return QString::fromStdString(osstream.str()); }
void SlotAssetsMgr::initMachineWhenFirstLaunch() { bool inited = Preferences::sharedPreferences()->getBoolForKey(KEY_FIRST_LAUNCH_INITED.data(), false); if(!inited) { int mid = MachineService::getInstance()->getFirstMachineId(); stringstream srcSS; #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) srcSS << "assets/zip/" << mid << ".zip"; #else srcSS << "zip/" << mid << ".zip"; #endif if(!CCFileUtils::sharedFileUtils()->isFileExist(srcSS.str().data())) { CCLOG("[assets_init] file %s not exist !", srcSS.str().data()); return; } stringstream dstSS; dstSS << getMachineZipDir() << mid << ".zip"; if(ifstream(dstSS.str().data())) { remove(dstSS.str().data()); } string srcPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(srcSS.str().data()); string dstPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(dstSS.str().data()); unsigned long len = 0; unsigned char *data = NULL; data = CCFileUtils::sharedFileUtils()->getFileData(srcSS.str().data(),"r",&len); if(data==NULL) { CCLOG("[assets_init] file %s data null !", srcSS.str().data()); return; } string dstDir = AssetsUtil::getDir(dstPath); FileUtil::createDirectory(dstDir.data()); FILE *fp = fopen(dstPath.c_str(),"wb"); fwrite(data,sizeof(char),len,fp); fclose(fp); delete []data; data = NULL; CCLOG("[asset_init] copy zip file %s to %s", srcSS.str().data(), dstSS.str().data()); bool unzipResult = FileUtil::uncompressAndRemoveZip(dstSS.str(), getMachineZipDir()); if(!unzipResult) { CCLOG("[asset_init] unzip file error: %s", dstSS.str().data()); return; } // 设置zip版本 string url = getUrl(AssetsType_Machine_Zip, mid); AssetsVersionMgr::getInstance()->setVersion(url, MachineService::getInstance()->getMachineZipVersion(mid)); Preferences::sharedPreferences()->setBoolForKey(KEY_FIRST_LAUNCH_INITED.data(), true); } }
string Md5Map::GetMd5(string processpath){ if (processpath!=""){ string strmd5 = MD5(ifstream(processpath, ios::binary)).toString(); if (strmd5.length()==0) return ""; return strmd5; } return ""; }
void Consumer::run() { if (ID == -1) { cerr << "\nP:Invalid thread ID:" << ID << endl; exit(1); } sprintf(queue_name, "/queue_cons%d", ID); queue_cons = mq_open(queue_name , O_CREAT, S_IRWXU | S_IRWXG, &(this->attr)); if (queue_cons == (mqd_t)-1) { cerr << "\nC:Not created " << strerror(errno) << endl; exit(1); } mq_close(queue_cons); queue_cons = mq_open(queue_name, O_RDWR); if(queue_cons == (mqd_t)-1) { cerr << "\nC:Error opening queue " << strerror(errno) << endl; exit(1); } ofstream fp; char name[strlen(filename)+6]; strcpy(name, filename); strcat(name, ".rslt"); if (ifstream(name)) { remove(name); } fp.open(name, ofstream::out | ios::binary | ofstream::app); do { msg_con_int = mq_receive(queue_cons, reinterpret_cast<char*>(&msg_cons),sizeof(msg_cons),0); if (msg_con_int == -1) { cerr << "\nC:Error Receiving " << strerror(errno) << endl; exit(1); } fp.write(reinterpret_cast<const char*>(&msg_cons.bytes[0]), msg_cons.numb_bytes_read); } while (--(msg_cons.no_of_blocks) > 0); fp.close(); mq_close(queue_cons); pthread_exit(NULL); }
void DataFile::LoadData(string filename, char* &dataStruct){ DataFile::fileReader = ifstream(filename.c_str(), ifstream::binary); DataFile::fileReader.seekg(0, DataFile::fileReader.end); long length = DataFile::fileReader.tellg(); DataFile::fileReader.seekg(0); dataStruct = new char[length]; DataFile::fileReader.read(dataStruct, length); DataFile::fileReader.close(); }
int Settings::load() { ifile = ifstream(configName, ios_base::binary | ios_base::in); if (ifile.is_open()) { if (ifile.eof()) return -1; ifile >> textureQuality >> shadowQuality >> multisampling >> textureAnisotropy >> width >> height >> vsync >> fullscreen >> hdr >> tripleBuffer >> disableAudio >> audioLvl >> showHealthBar; } else return -1;
main() { // Set the random seed for A parameter generation srand(time(NULL)); // Load the master secret key from a file string fname; cout << "Insert the name of key file" << endl; cin >> fname; PFC pfc(AES_SECURITY); // initialise pairing-friendly curve miracl* mip=get_mip(); Big order=pfc.order(); MSK Secret = load_msk(fname, &pfc, mip, order); int len = Secret.len; // Construct a row loaded from a file cout << "Insert the name of the table containing file ("<< len << " cells per row)" << endl; cin >> fname; fstream inputFile(fname); string line, *ROW; string fname2 = fname+"_enc_msgs"; //create_file(fname2); //DEVELOPMENT fname = fname+"_enc_ct"; int i=0; stringstream ss; ss << fname << i; string result = ss.str(); while(ifstream(result)){ i++; stringstream ss; ss << fname << i; result = ss.str(); } while (getline(inputFile, line)){ ROW=create_row2(line,len); time_t seed1,seed2; // Encrypt the row saving it into a file called 'fname_enc_msgs' cout << "Encrypting row " << i+1 << " with n=" << len << endl; time(&seed1); EncryptedRow *ER=Secret.EncRow(ROW, fname2); time(&seed2); cout << "\t" << seed2-seed1 << endl; // Save the encrypted row ciphertext in a file called 'fname_enc_ct' plus a sequential number stringstream ss; ss << fname << i; result = ss.str(); save_er(result, len, ER->ek); i++; } }
// This function check the legality of the input filenames and // prepare the parameters for the multilign calculations // This function should be called before multilign calcultions at least once and // whenever something related to seq/ct changes, e.g. SetIndexSeq, AddOneInput, RemoveOneInput, Randomize, etc. int Multilign_object::PrepInput() { if(inputList.size() < 2) {return 5002;} // check the files exist. for(vvs_it rowIt = inputList.begin(); rowIt != inputList.end(); ++rowIt) { vector<string>::iterator it = rowIt->begin(); // it points to seq filename currently if(!ifstream(it->c_str())) return 5012; // it points to ct filename currently if((++it)->empty()) return 5013; // it points to constraint filename currently if(!(++it)->empty()) if(!ifstream(it->c_str())) return 5001; // it points to SHAPE filename curently if(!(++it)->empty()) if(!ifstream(it->c_str())) return 5011; } if(ErrorCode = PairSeq1()) return ErrorCode; return 0; }
int Program::loadFile(const std::string &filename) { uassert(ifstream(filename).good()) << "Could not load file: " << filename; std::vector<ParseError> errors; int status = content->frontend->parseFile(filename, &content->ctx, &errors); for (auto &error : errors) { content->diags.report() << error.toString(); } uassert(errors.size() == 0) << "during compilation:" << std::endl << content->diags.getMessage(); return status; }
FileCapture::FileCapture(string file){ i = ifstream(file, ios::binary); if (!i){ cerr << file << " can not open!" << endl; exit(10); } i.seekg(0, ios::end); length = i.tellg(); i.seekg(0, ios::beg); i.read((char *)&header, sizeof(header)); }
// assign operator void set(int id, const char* iIp, const char* iPort, const char* iFile, const char* iSocksip, const char* iSocksport) { domId = "m" + to_string(id); strncpy(ip, iIp, INET_ADDRSTRLEN); strncpy(port, iPort, 6); strncpy(filename, iFile, FILENAME_LENGTH); strncpy(socksip, iSocksip, INET_ADDRSTRLEN); strncpy(socksport, iSocksport, 6); // we *logically* only use assign operator when bootstrap // therefore, we open file in ifstream file = ifstream(filename, ifstream::in); }
inline void testSimpleInnerFastInfoset_10() { std::ifstream ifstream("simpleInner_10.xml", std::ios::in | std::ios::binary); std::ofstream ofstream("sample.fis", std::ios::out | std::ios::binary); std::ifstream ifstream2("sample.fis", std::ios::in | std::ios::binary); std::ofstream ofstream2("sampleFinal.xml", std::ios::out | std::ios::binary); std::stringbuf xml1; std::stringbuf fis; std::stringbuf xml2; std::ostream ostxml1(&xml1); std::ostream ofis(&fis); std::istream ifis(&fis); std::ostream oxml2(&xml2); ostxml1 << ifstream.rdbuf(); std::istream ixml1(&xml1); boost::timer::auto_cpu_timer t2; for(int i=0; i< NUMBER_OF_LOOPS; ++i){ xml1.pubseekpos(0); ixml1.rdbuf(&xml1); fis.pubseekpos(0); ofis.rdbuf(&fis); ifis.rdbuf(&fis); xml2.pubseekpos(0); oxml2.rdbuf(&xml2); try { Poco::FastInfoset::Converter::convertToFIS(ixml1, ofis); //std::cout << "Str: " << fis.in_avail() << std::endl; //std::cout << "Data: \n" << fis.str() << std::endl; std::cout << "Strlen: " << fis.str().size() << std::endl; break; Poco::FastInfoset::Converter::convertToXML(ifis, oxml2); } catch(Poco::Exception &ex) { std::cout << ex.what() << std::endl; int i = 0; } } }
void StaticHandler::handle(Request *request, Response *response) { typedef std::istreambuf_iterator<char> char_is; std::ifstream ifstream(path + request->getUri(), std::ios_base::in); if (ifstream.is_open()) { string content(char_is(ifstream.rdbuf()), char_is()); response->setStatusCode(200); response->setContent(content); response->addHeader(http::headers::ContentLength, content.size()); } else { throw Exception(404); } ifstream.close(); }
inline void testSesar() { boost::timer::auto_cpu_timer t1; std::ifstream ifstream("TrajectoryClusterPayload.xml", std::ios::in | std::ios::binary); std::ofstream ofstream("TrajectoryClusterPayload.fis", std::ios::out | std::ios::binary); std::ifstream ifstream2("TrajectoryClusterPayload.fis", std::ios::in | std::ios::binary); std::ofstream ofstream2("TrajectoryClusterPayloadFinal.xml", std::ios::out | std::ios::binary); std::stringbuf xml1; std::stringbuf fis; std::stringbuf xml2; std::ostream ostxml1(&xml1); std::ostream ofis(&fis); std::istream ifis(&fis); std::ostream oxml2(&xml2); ostxml1 << ifstream.rdbuf(); std::istream ixml1(&xml1); boost::timer::auto_cpu_timer t2; for(int i=0; i< 1000; ++i){ xml1.pubseekpos(0); ixml1.rdbuf(&xml1); fis.pubseekpos(0); ofis.rdbuf(&fis); ifis.rdbuf(&fis); xml2.pubseekpos(0); oxml2.rdbuf(&xml2); try { Poco::FastInfoset::Converter::convertToFIS(ixml1, ofis); //std::cout << "Str: " << fis.str().size() << std::endl; //break; Poco::FastInfoset::Converter::convertToXML(ifis, oxml2); } catch(Poco::Exception &ex) { std::cout << ex.what() << std::endl; } } }
/// /// \brief effacement des fichiers relatifs à la creation des grilles ssi le modèle n'est pas affiné /// \param nomGrid nom du fichier Grid en sortie /// \param refine la grille est-elle affinée /// void clearing(std::string const &nomGrid, bool refine) { if (refine == false) { if (ifstream("processing/conv_ptGeo.txt")) ELISE_fp::RmFile("processing/conv_ptGeo.txt"); if (ifstream("processing/conv_ptCarto.txt")) ELISE_fp::RmFile("processing/conv_ptCarto.txt"); if (ifstream("processing/direct_ptGeo.txt")) ELISE_fp::RmFile("processing/direct_ptGeo.txt"); if (ifstream("processing/direct_ptCarto.txt")) ELISE_fp::RmFile("processing/direct_ptCarto.txt"); if (ifstream("processing/indirect_ptGeo.txt")) ELISE_fp::RmFile("processing/indirect_ptGeo.txt"); if (ifstream("processing/indirect_ptCarto.txt")) ELISE_fp::RmFile("processing/indirect_ptCarto.txt"); if (ELISE_fp::IsDirectory("processing")) ELISE_fp::RmDir("processing"); } //effacement de la grille affinee + grilles GRC et binaire std::string gridGRC = nomGrid; std::string refGridGRC2 = nomGrid; refGridGRC2.append("Bin"); if (ifstream(nomGrid.c_str())) ELISE_fp::RmFile(nomGrid.c_str()); if (ifstream(gridGRC.c_str())) ELISE_fp::RmFile(gridGRC.c_str()); if (ifstream(refGridGRC2.c_str())) ELISE_fp::RmFile(refGridGRC2.c_str()); }
inline void testMIPPositions() { std::ifstream ifstream("xml_input_positions.xml", std::ios::in | std::ios::binary); std::ofstream ofstream("xml_input_positions.fis", std::ios::out | std::ios::binary); std::ifstream ifstream2("xml_input_positions.fis", std::ios::in | std::ios::binary); std::ofstream ofstream2("xml_input_positionsFinal.xml", std::ios::out | std::ios::binary); std::stringbuf xml1; std::stringbuf fis; std::stringbuf xml2; std::ostream ostxml1(&xml1); std::ostream ofis(&fis); std::istream ifis(&fis); std::ostream oxml2(&xml2); ostxml1 << ifstream.rdbuf(); std::istream ixml1(&xml1); //boost for(int i=0; i< 1000; ++i){ xml1.pubseekpos(0); ixml1.rdbuf(&xml1); fis.pubseekpos(0); ofis.rdbuf(&fis); ifis.rdbuf(&fis); xml2.pubseekpos(0); oxml2.rdbuf(&xml2); try { Poco::FastInfoset::Converter::convertToFIS(ixml1, ofis); Poco::FastInfoset::Converter::convertToXML(ifis, oxml2); } catch(Poco::Exception &ex) { std::cout << ex.what() << ": " << ex.message() << std::endl; break; } } std::cout << "FAST INFOSET\nMIP Data Set (with Positions)\nSerialized size: " << fis.str().size() << std::endl; }
PointCloud<PointNormal>::Ptr Scanner::getCloudCached(float theta, float phi, Model &model) { Scan scan = { theta, phi }; std::stringstream ss; ss << "scan_" << model.id << "_" << deg(scan.theta) << "_" << deg(scan.phi) << ".pcd"; std::string name = ss.str(); if (ifstream(name.c_str())) { PointCloud<PointNormal>::Ptr cloud (new PointCloud<PointNormal>()); io::loadPCDFile(name, *cloud); return cloud; } else { PointCloud<PointNormal>::Ptr cloud = getCloud(scan, model); io::savePCDFileBinary(name, *cloud); return cloud; } }
static void graph_read(const std::string& file_path, parti_ptr partition, parti_indx_ptr partition_index) { std::ifstream ifstream(file_path.c_str()); if (ifstream.fail()) { ifstream.close(); return; } std::string line; long id = 0; while (getline(ifstream, line)) { long partitionNum = atol(line.c_str()); partition_index->insert(std::pair<long, long>(partitionNum, id)); partition->push_back(partitionNum); id++; } ifstream.close(); };