/// open file for reading void open(const std::string& a_fname) { if (m_open) return; // make sure exception thrown in case of error m_file.exceptions(std::ifstream::failbit | std::ifstream::badbit); m_file.open(a_fname.c_str(), std::ios::in | std::ios::binary); // further read can set failbit in case there is not enough data // this case should not throw an exception in our class m_file.exceptions(std::ifstream::badbit); m_open = true; m_fname = a_fname; m_buf.reset(); BOOST_ASSERT(m_buf.capacity() > 0); }
bool ReadPicData (std::ifstream &fdata, unsigned char *buffer, int frame_size) { bool ret_stat = true; ios::iostate oldExceptions = fdata.exceptions(); fdata.exceptions (ios::failbit | ios::badbit); try { fdata.read ((char *)buffer, frame_size); } catch (...) { ret_stat = false; } fdata.exceptions (oldExceptions); return ret_stat; }
void open(std::ifstream& stream) const { stream.open(m_path.c_str(), std::ios::in|std::ios::binary); if (!stream.is_open()) { LOG4CXX_ERROR(m_logger, "Couldn't open file [" << m_path << "]"); MR4C_THROW(std::logic_error, "Couldn't open file [" << m_path << "]"); } stream.exceptions(std::ifstream::badbit); }
/** * Opens the prt_ifstream to read from the specified file * @param file Path to the file to read particles from */ void open( const std::string& file ) { m_fin.open( file.c_str(), std::ios::in | std::ios::binary ); if( m_fin.fail() ) throw std::ios_base::failure( "Failed to open file \"" + file + "\"" ); m_filePath = file; m_fin.exceptions( std::ios::badbit ); read_header(); init_zlib(); }
PolyFileReader (Boundary *b_, const string &polyfilename) : is (polyfilename.c_str ()), b (b_) { if (!is) { throw std::runtime_error ("Cannot open \"" + polyfilename + "\""); } is.exceptions (std::ios::failbit | std::ios::badbit); vertex_map.reserve (1000); }
bool Skip (std::ifstream &fdata, int start_frame, int frame_size) { bool ret_stat = true; ios::iostate oldExceptions = fdata.exceptions(); fdata.exceptions (ios::failbit | ios::badbit); try { unsigned char* buffer = new unsigned char[frame_size]; for (int i=0; i<start_frame; ++i) ReadPicData(fdata, buffer, frame_size); delete[] buffer; } catch (...) { std::cerr << "Skipping of first "<< start_frame << " frames failed" << std::endl; ret_stat = false; } fdata.exceptions (oldExceptions); return ret_stat; }
void SettingsFile::LoadFileToString(std::ifstream& file, SettingsFile::StringVector& lines, const std::string& file_name) { // First, tell the file not to throw any exceptions. file.exceptions(std::ios_base::goodbit); // Now load each line from the file into a string. while(file.good() == true) { std::string line; std::getline(file, line); lines.push_back(line); } // If an error occurred while reading (other than reaching EOF), then throw a FileReadException. if(file.fail() == true && file.eof() == false) { file.close(); throw FileReadException(file_name); } }
OBJParser(const char* filename, std::vector<glm::vec3>& positions, std::vector<glm::vec2>& texcoords, std::vector<glm::vec3>& normals, std::vector<GLuint>& position_indices, std::vector<GLuint>& texcoord_indices, std::vector<GLuint>& normal_indices) : filename(filename), positions(positions), texcoords(texcoords), normals(normals), position_indices(position_indices), texcoord_indices(texcoord_indices), normal_indices(normal_indices), ifs(filename, std::ifstream::in), lineno(1), charno(0), type(UNKNOWN) { ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit); }
void WindowsFileOpener::OpenInputStream( std::ifstream &stream, std::ios_base::openmode openModeRequired ) { stream.exceptions( std::ifstream::failbit | std::ifstream::badbit | std::ifstream::eofbit ); stream.open( _filePath.c_str(), openModeRequired ); }