FileInputStream file( filename );
ASSERT_MESSAGE( !file.failed(), "failed to open " << makeQuoted( filename ) );
/// \brief A wrapper around a file input stream opened for reading in binary mode. Similar to std::ifstream.
///
/// - Maintains a valid file handle associated with a name passed to the constructor.
/// - Implements SeekableInputStream.
class FileInputStream : public SeekableInputStream
{
std::FILE* m_file;
public:
FileInputStream( const char* name ){
m_file = name[0] == '\0' ? 0 : fopen( name, "rb" );
}
~FileInputStream(){
if ( !failed() ) {
fclose( m_file );
}
}
bool failed() const {
return m_file == 0;
}
size_type read( byte_type* buffer, size_type length ){
return fread( buffer, 1, length, m_file );
}
size_type seek( size_type position ){
return fseek( m_file, static_cast<long>( position ), SEEK_SET );
}
size_type seek( offset_type offset, seekdir direction ){
return fseek( m_file, offset, FileStreamDetail::whence_for_seekdir( direction ) );
}
size_type tell() const {
return ftell( m_file );
}
std::FILE* file(){
return m_file;
}
};
© 2011 q3df.org. Designed by Zeences. All Right Reserved.
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Prostylize Darkgrey style by Ishimaru Design