void KJotsMain::writeBook() { saveFolder(); QString name; while( name.isNull() ) { name = KFileDialog::getSaveFileName(); if ( name.isNull() ) return; QFileInfo f_info(name); if( f_info.exists() ) { if( KMsgBox::yesNo(this, klocale->translate("File exists !"), klocale->translate("File already exists. \n Do you want to overwrite it ?")) == 2 ) name = ""; } } QFile ascii_file(name); if( !ascii_file.open(IO_WriteOnly | IO_Truncate) ) return; QTextStream st( (QIODevice *) &ascii_file); TextEntry *entry; for( entry = entrylist.first(); entry != NULL; entry = entrylist.next() ) { writeEntry( st, entry ); } ascii_file.close(); }
bool EagleeyeIO::read(DynamicArray<T>& arr,std::string& id,std::string file_path,EagleeyeIOMode iomode) { switch(iomode) { case READ_BINARY_MODE: { std::ifstream binary_file(file_path.c_str(),std::ios::binary); if (!binary_file) { return false; } else { //write id int str_len; binary_file.read((char*)(&str_len),sizeof(int)); char* id_data=new char[str_len]; binary_file.read(id_data,sizeof(char)*str_len); id=std::string(id_data); delete[] id_data; //write array data int arr_size=arr.size(); binary_file.read((char*)(&arr_size),sizeof(int)); arr=DynamicArray(arr_size); binary_file.read((char*)(arr.dataptr()),sizeof(T)*arr_size); binary_file.close(); return true; } } case READ_ASCII_MODE: { std::locale::global( std::locale( "",std::locale::all^std::locale::numeric ) ); std::ifstream ascii_file(file_path.c_str()); file_path>>id; file_path>>arr; ascii_file.close(); return false; } default: { return false; } } return false; }
bool EagleeyeIO::read(Matrix<T>& mat,std::string& id,std::string file_path,EagleeyeIOMode iomode) { switch(iomode) { case READ_BINARY_MODE: { std::ifstream binary_file(file_path.c_str(),std::ios::binary); if (!binary_file) { return false; } else { //write id int str_len; binary_file.read((char*)(&str_len),sizeof(int)); char* id_data=new char[str_len]; binary_file.read(id_data,sizeof(char)*str_len); id=std::string(id_data); delete[] id_data; //read mat data int rows; int cols; binary_file.read((char*)(&rows),sizeof(int)); binary_file.read((char*)(&cols),sizeof(int)); mat=Matrix<T>(rows*cols); binary_file.read((char*)(mat.dataptr()),sizeof(T)*rows*cols); binary_file.close(); return true; } } case READ_ASCII_MODE: { std::locale::global( std::locale( "",std::locale::all^std::locale::numeric ) ); std::ifstream ascii_file(file_path.c_str()); ascii_file>>id; ascii_file>>mat; ascii_file.close(); return false; } } return false; }
bool EagleeyeIO::read(DynamicArray<T>& arr,std::string file_path,EagleeyeIOMode iomode) { switch(iomode) { case READ_BINARY_MODE: { std::ifstream binary_file(file_path.c_str(),std::ios::binary); if (!binary_file) { return false; } else { //write array data int arr_size; binary_file.read((char*)(&arr_size),sizeof(int)); arr=DynamicArray<T>(arr_size); binary_file.read((char*)(arr.dataptr()),sizeof(T)*arr_size); binary_file.close(); return true; } } case READ_ASCII_MODE: { std::locale::global( std::locale( "",std::locale::all^std::locale::numeric ) ); std::ifstream ascii_file(file_path.c_str()); if (!ascii_file) { return false; } else { ascii_file>>arr; return true; } } default: { return false; } } return false; }
bool EagleeyeIO::read(Matrix<T>& mat,std::string file_path,EagleeyeIOMode iomode) { switch(iomode) { case READ_BINARY_MODE: { std::locale::global(std::locale("")); std::ifstream binary_file(file_path.c_str(),std::ios::binary); if (!binary_file) { return false; } else { //read mat data int rows; int cols; binary_file.read((char*)(&rows),sizeof(int)); binary_file.read((char*)(&cols),sizeof(int)); mat=Matrix<T>(rows,cols); binary_file.read((char*)(mat.dataptr()),sizeof(T)*rows*cols); binary_file.close(); return true; } } case READ_ASCII_MODE: { std::locale::global( std::locale( "",std::locale::all^std::locale::numeric ) ); std::ifstream ascii_file(file_path.c_str()); ascii_file>>mat; ascii_file.close(); return false; } } return false; }