void SetUp() { graph_file.open(GRAPH_FILENAME, std::fstream::in); ASSERT_FALSE(graph_file.fail()) << "unable to open " << GRAPH_FILENAME; solved_file.open(SOLUTION_FILENAME, std::fstream::in); ASSERT_FALSE(solved_file.fail()) << "unable to open " << SOLUTION_FILENAME; original = fs::DIMACSOriginalImporter<fs::FlowNetwork>(graph_file).read(); ASSERT_NE(original, nullptr) << "DIMACS parse error"; augmented = new fs::FlowNetwork(*original); fs::DIMACSFlowImporter<fs::FlowNetwork>(solved_file, *augmented).read(); }
long long TCPTransport::recvfile(std::fstream& ofs, long long offset, long long size) { if (!m_bConnected) return -1; if (ofs.bad() || ofs.fail()) return -1; ofs.seekp(offset); int block = 1000000; char* buf = new char[block]; long long recd = 0; while (recd < size) { int unit = int((size - recd) > block ? block : size - recd); recv(buf, unit); ofs.write(buf, unit); recd += unit; } delete [] buf; return recd; }
long long TCPTransport::sendfile(std::fstream& ifs, long long offset, long long size) { if (!m_bConnected) return -1; if (ifs.bad() || ifs.fail()) return -1; ifs.seekg(offset); int block = 1000000; char* buf = new char[block]; long long sent = 0; while (sent < size) { int unit = int((size - sent) > block ? block : size - sent); ifs.read(buf, unit); send(buf, unit); sent += unit; } delete [] buf; return sent; }
virtual uint32 read(void *dataPtr, uint32 dataSize) { _fileStream->read((char *)dataPtr, dataSize); if (_fileStream->fail()) { return 0; } return dataSize; }
bool StandardFileProvider::open( std::string name, Mode mode ) { ios::openmode om = ios::binary; switch( mode ) { case MODE_UNDEFINED: case MODE_READ: default: om |= ios::in; _seekg = true; _seekp = false; break; case MODE_MODIFY: om |= ios::in | ios::out; _seekg = true; _seekp = true; break; case MODE_CREATE: om |= ios::in | ios::out | ios::trunc; _seekg = true; _seekp = true; break; } _fstream.open( name.c_str(), om ); _name = name; return _fstream.fail(); }
bool StandardFileProvider::seek( Size pos ) { if( _seekg ) _fstream.seekg( pos, ios::beg ); if( _seekp ) _fstream.seekp( pos, ios::beg ); return _fstream.fail(); }
bool StandardFileProvider::write( const void* buffer, Size size, Size& nout, Size maxChunkSize ) { _fstream.write( (const char*)buffer, size ); if( _fstream.fail() ) return true; nout = size; return false; }
bool StandardFileProvider::read( void* buffer, Size size, Size& nin, Size maxChunkSize ) { _fstream.read( (char*)buffer, size ); if( _fstream.fail() ) return true; nin = _fstream.gcount(); return false; }
void closeLogFile(std::fstream& logFile) { logFile.close(); if (logFile.fail()) { std::cout << "ERROR while closing the log file" << std::endl; exit(EXIT_FAILURE); } }
MyFileReadStream(const char *filename) { _stream = new std::fstream(filename, std::fstream::in); if (_stream->fail()) { isOpen = false; delete _stream; // Primarily done to make sure we crash if this isn't handled. _stream = NULL; } else { isOpen = true; } }
/* void TechBot::Saveunknown_input() { std::fstream fout("unknown.txt", std::ios::out); if(fout.fail()) { throw std::string("Unable to save Unknown Input List"); } Vstr::const_iterator iter = ListOfUnknownInput.begin(); for( ; iter != ListOfUnknownInput.end(); ++iter ) { fout << *iter << std::endl; } fout.flush(); fout.close(); } */ void TechBot::Savelog() { time_t ltime; time(<ime); logfile.open("log.txt", std::ios::out | std::ios::app); if(logfile.fail()) { throw std::string("can't save conversation log"); } logfile << "\n\nConversation log - " << ctime(<ime) << std::endl; }
SeekableFileStream(const char *name) { _fileStream = new std::fstream(); _fileStream->open(name, std::fstream::in | std::fstream::binary); if (_fileStream->fail()) { _length = -1; } else { _fileStream->seekg(0, std::ios_base::end); _length = _fileStream->tellg(); _fileStream->seekg(0, std::ios_base::beg); } }
void openLogFile(std::fstream& logFile, const char* logFileName) { // Open the log file with append flag logFile.open(logFileName, std::ios_base::app); if (logFile.fail()) { GET_TIME std::cout << timeBuffer << "\t" << SYS_CALL_ERR_MSG("open", strerror(errno)); exit(EXIT_FAILURE); } }
/** * Sets the stream position indicator for the stream. The new position, * measured in bytes, is obtained by adding offset bytes to the position * specified by whence. If whence is set to SEEK_SET, SEEK_CUR, or * SEEK_END, the offset is relative to the start of the file, the current * position indicator, or end-of-file, respectively. A successful call * to the seek() method clears the end-of-file indicator for the stream. * * @note The semantics of any implementation of this method are * supposed to match those of ISO C fseek(). * * @param offset the relative offset in bytes * @param whence the seek reference: SEEK_SET, SEEK_CUR, or SEEK_END * @return true on success, false in case of a failure */ virtual bool seek(int32 offset, int whence = SEEK_SET) { if (whence == SEEK_SET) { _stream->seekg(offset, std::ios::beg); } else if (whence == SEEK_CUR) { _stream->seekg(offset, std::ios::cur); } else { _stream->seekg(offset, std::ios::end); } if (_stream->fail()) return false; if (_stream->bad()) return false; return true; }
bool Dollar::OpenScriptStream(const char * pszName, std::fstream& stm) { for(int i = 0;;i++) { std::string fileName; if(i == 0) { // use current dir fileName = pszName; } else if (i == 1) { fileName = GetCurrentHost()->GetAppDataDir(); fileName += "\\"; fileName += pszName; } else if (i == 2) { // exe directory char szPath[_MAX_PATH]; char szDrive[_MAX_PATH]; char szDir[_MAX_PATH]; GetModuleFileNameA(NULL, szPath, _countof(szPath)); _splitpath(szPath, szDrive, szDir, NULL, NULL); fileName = szDrive; fileName += szDir; fileName += pszName; } else { break; } stm.open(fileName, std::fstream::in); if(!stm.fail()) { return true; } } return false; }
bool xmlAttrib::Read(std::fstream &stream) { char t; stream >> t; if (stream.fail()) return false; while (isspace(t)) { stream >> t; if (stream.fail()) return false; } if (isalpha(t)|| t=='_') { char buf[512]; char *p = buf; buf[0] = 0; while (isalnum(t)|| t=='_') { *p++ = t; stream >> t; if (stream.fail()) return false; } *p = 0; name = buf; while (isspace(t)) { stream >> t; if (stream.fail()) return false; } if (t != '=') return false; stream >> t; if (stream.fail()) return false; while (isspace(t)) { stream >> t; if (stream.fail()) return false; } if (t != '\"') return false; if (!ReadTextString(stream, value)) return false; }
bool StandardFileProvider::close() { _fstream.close(); return _fstream.fail(); }