Rosetta Utilities  2014.35
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
utility::io::izstream Class Reference

izstream: Input file stream wrapper for uncompressed and compressed files More...

#include <izstream.hh>

Public Member Functions

 izstream ()
 Default constructor. More...
 
 izstream (std::string const &filename_a, std::ios_base::openmode open_mode=std::ios_base::in)
 Filename constructor. More...
 
virtual ~izstream ()
 Destructor. More...
 
 operator bool () const
 bool conversion More...
 
 operator std::istream const & () const
 Stream conversion. More...
 
 operator std::istream & ()
 Stream conversion. More...
 
template<typename T >
std::istream & operator>> (T &t)
 Stream input. More...
 
std::istream & operator>> (manipulator m)
 Stream manipulator input. More...
 
std::istream & operator>> (std_manipulator m)
 Stream manipulator input. More...
 
void open (std::string const &filename_a, std::ios_base::openmode open_mode=std::ios_base::in)
 Open a file. More...
 
void clear ()
 Clear the stream(s) More...
 
void close ()
 Close the ifstream and reset the state. More...
 
void seek_beg ()
 Seek to the beginning. More...
 
int get ()
 Get the next character. More...
 
izstreamget (char &c)
 Get the next character. More...
 
izstreamget (char *str, std::streamsize const count)
 Get the next specified number of characters. More...
 
izstreamget (char *str, std::streamsize const count, char const delim)
 Get the next specified number of characters. More...
 
izstreamget (std::string &str, std::streamsize const count)
 Get the next specified number of characters. More...
 
izstreamget (std::string &str, std::streamsize const count, char const delim)
 Get the next specified number of characters. More...
 
izstreamgetline (char *line, std::streamsize const count)
 Get the rest of the line. More...
 
izstreamgetline (char *line, std::streamsize const count, char const delim)
 Get the rest of the line. More...
 
izstreamgetline (std::string &line)
 Get the rest of the line. More...
 
izstreamgetline (std::string &line, char const delim)
 Get the rest of the line. More...
 
izstreamread (char *str, std::streamsize const count)
 Read the next specified number of characters. More...
 
izstreamread (std::string &str, std::streamsize const count)
 Read the next specified number of characters. More...
 
std::streamsize readsome (char *str, std::streamsize const count)
 Read the next available specified number of characters. More...
 
std::streamsize readsome (std::string &str, std::streamsize const count)
 Read the next available specified number of characters. More...
 
izstreamignore ()
 Skip over the next character. More...
 
izstreamignore (std::streamsize const count)
 Skip over the next specified number of characters. More...
 
izstreamignore (std::streamsize const count, char const delim)
 Skip over the next specified number of characters. More...
 
int peek ()
 Returns the next character without extracting it. More...
 
izstreamunget ()
 Put the last character read back into the stream. More...
 
izstreamputback (char c)
 Put the last character read back into the stream and check that passed character is correct. More...
 
std::istream const & operator() () const
 Stream access. More...
 
std::istream & operator() ()
 Stream access. More...
 
std::istream const & stream () const
 Stream access. More...
 
std::istream & stream ()
 Stream access. More...
 
std::streambuf * rdbuf () const
 Pointer to the stream buffer. More...
 
std::string const & filename () const
 File name. More...
 
std::streamsize gcount () const
 Get the number of characters read by the last unformatted read. More...
 
bool good () const
 Good? More...
 
bool eof () const
 End of file? More...
 
bool fail () const
 Fail? More...
 
bool bad () const
 Bad? More...
 
bool compressed () const
 Compressed? More...
 
bool uncompressed () const
 Uncompressed? More...
 
bool gzipped () const
 gzipped? More...
 
- Public Member Functions inherited from utility::io::irstream
virtual ~irstream ()
 Destructor. More...
 
template<typename T >
irstreamoperator>> (T &t)
 Stream input. More...
 

Static Public Member Functions

static void set_alternative_search_paths (vector1< std::string > alternative_search_paths)
 
static vector1< std::string > get_alternative_search_paths ()
 

Private Types

enum  Compression { NONE, UNCOMPRESSED, GZIP }
 
typedef std::istream &(* manipulator )(izstream &)
 
typedef std::istream &(* std_manipulator )(std::istream &)
 

Private Member Functions

bool is_gzip () const
 Is stream attached to a gzip file? More...
 
bool check_crc () const
 CRC of gzip file valid? More...
 
long get_crc () const
 CRC of the uncompressed data (see zipstream documentation) More...
 
long get_in_size () const
 Compressed data size. More...
 
long get_out_size () const
 Uncompressed data size. More...
 
void open_ifstream (std::string const &name, std::ios_base::openmode open_mode)
 Helper function for opening files with alternative search paths. More...
 

Private Attributes

Compression compression_
 Compression state. More...
 
std::ifstream if_stream_
 File stream. More...
 
std::string filename_
 File name. More...
 
zlib_stream::zip_istream * zip_stream_p_
 Zip file stream pointer (owning) More...
 

Static Private Attributes

static vector1< std::string > alternative_search_paths_
 Alternative search paths This initialized by the option system -in:path:path Notice that izstream cannot access the option system (because the utility library comes before the basic library), so setting the alternate search paths is it the responsibility of core::init::init() More...
 

Friends

long utility::file::gzip (std::string const &uncompressedfile, bool overwrite)
 
long utility::file::gunzip (std::string const &compressedfile, bool overwrite)
 

Additional Inherited Members

- Protected Types inherited from utility::io::irstream
typedef std::istream &(* std_manipulator )(std::istream &)
 
- Protected Member Functions inherited from utility::io::irstream
 irstream ()
 Default constructor. More...
 

Detailed Description

izstream: Input file stream wrapper for uncompressed and compressed files

Member Typedef Documentation

typedef std::istream&(* utility::io::izstream::manipulator)(izstream &)
private
typedef std::istream&(* utility::io::izstream::std_manipulator)(std::istream &)
private

Member Enumeration Documentation

Enumerator
NONE 
UNCOMPRESSED 
GZIP 

Constructor & Destructor Documentation

utility::io::izstream::izstream ( )
inline

Default constructor.

utility::io::izstream::izstream ( std::string const &  filename_a,
std::ios_base::openmode  open_mode = std::ios_base::in 
)
inlineexplicit

Filename constructor.

References open().

virtual utility::io::izstream::~izstream ( )
inlinevirtual

Destructor.

References if_stream_, and zip_stream_p_.

Member Function Documentation

bool utility::io::izstream::bad ( ) const
inlinevirtual

Bad?

Implements utility::io::irstream.

References stream().

bool utility::io::izstream::check_crc ( ) const
inlineprivate

CRC of gzip file valid?

References zip_stream_p_.

void utility::io::izstream::clear ( )
inlinevirtual

Clear the stream(s)

Implements utility::io::irstream.

References if_stream_, and zip_stream_p_.

Referenced by basic::database::open(), and utility::PeriodicSplineReader::read().

void utility::io::izstream::close ( )
inline
bool utility::io::izstream::compressed ( ) const
inlinevirtual

Compressed?

Implements utility::io::irstream.

References compression_, and GZIP.

bool utility::io::izstream::eof ( ) const
inlinevirtual

End of file?

Implements utility::io::irstream.

References stream().

Referenced by utility::PeriodicSplineReader::read().

bool utility::io::izstream::fail ( ) const
inlinevirtual

Fail?

Implements utility::io::irstream.

References stream().

Referenced by utility::PeriodicSplineReader::read().

std::string const& utility::io::izstream::filename ( ) const
inline

File name.

References filename_.

std::streamsize utility::io::izstream::gcount ( ) const
inline

Get the number of characters read by the last unformatted read.

References stream().

int utility::io::izstream::get ( )
inlinevirtual

Get the next character.

Implements utility::io::irstream.

References stream().

izstream& utility::io::izstream::get ( char &  c)
inlinevirtual

Get the next character.

Implements utility::io::irstream.

References stream().

izstream& utility::io::izstream::get ( char *  str,
std::streamsize const  count 
)
inlinevirtual

Get the next specified number of characters.

Implements utility::io::irstream.

References stream().

izstream& utility::io::izstream::get ( char *  str,
std::streamsize const  count,
char const  delim 
)
inlinevirtual

Get the next specified number of characters.

Implements utility::io::irstream.

References stream().

izstream& utility::io::izstream::get ( std::string &  str,
std::streamsize const  count 
)
inlinevirtual

Get the next specified number of characters.

Implements utility::io::irstream.

References basic::options::OptionKeys::cp::cp, and stream().

izstream& utility::io::izstream::get ( std::string &  str,
std::streamsize const  count,
char const  delim 
)
inlinevirtual

Get the next specified number of characters.

Implements utility::io::irstream.

References basic::options::OptionKeys::cp::cp, and stream().

static vector1< std::string > utility::io::izstream::get_alternative_search_paths ( )
inlinestatic
long utility::io::izstream::get_crc ( ) const
inlineprivate

CRC of the uncompressed data (see zipstream documentation)

References zip_stream_p_.

long utility::io::izstream::get_in_size ( ) const
inlineprivate

Compressed data size.

References zip_stream_p_.

long utility::io::izstream::get_out_size ( ) const
inlineprivate

Uncompressed data size.

References zip_stream_p_.

izstream& utility::io::izstream::getline ( char *  line,
std::streamsize const  count 
)
inlinevirtual

Get the rest of the line.

Implements utility::io::irstream.

References stream().

Referenced by basic::options::start_files().

izstream& utility::io::izstream::getline ( char *  line,
std::streamsize const  count,
char const  delim 
)
inlinevirtual

Get the rest of the line.

Implements utility::io::irstream.

References stream().

izstream& utility::io::izstream::getline ( std::string &  line)
inlinevirtual

Get the rest of the line.

Implements utility::io::irstream.

References utility::io::getline(), and stream().

izstream& utility::io::izstream::getline ( std::string &  line,
char const  delim 
)
inlinevirtual

Get the rest of the line.

Implements utility::io::irstream.

References utility::io::getline(), and stream().

bool utility::io::izstream::good ( ) const
inlinevirtual
bool utility::io::izstream::gzipped ( ) const
inlinevirtual

gzipped?

Implements utility::io::irstream.

References compression_, and GZIP.

izstream& utility::io::izstream::ignore ( )
inlinevirtual

Skip over the next character.

Implements utility::io::irstream.

References stream().

Referenced by utility::io::skip().

izstream& utility::io::izstream::ignore ( std::streamsize const  count)
inlinevirtual

Skip over the next specified number of characters.

Implements utility::io::irstream.

References stream().

izstream& utility::io::izstream::ignore ( std::streamsize const  count,
char const  delim 
)
inlinevirtual

Skip over the next specified number of characters.

Implements utility::io::irstream.

References stream().

bool utility::io::izstream::is_gzip ( ) const
inlineprivate

Is stream attached to a gzip file?

References zip_stream_p_.

void utility::io::izstream::open ( std::string const &  filename_a,
std::ios_base::openmode  open_mode = std::ios_base::in 
)
void utility::io::izstream::open_ifstream ( std::string const &  name,
std::ios_base::openmode  open_mode 
)
private

Helper function for opening files with alternative search paths.

References alternative_search_paths_, filename_, if_stream_, basic::options::OptionKeys::in::in, name, platform::file::PATH_SEPARATOR(), and utility::file::trytry_ifstream_open().

Referenced by open().

utility::io::izstream::operator bool ( ) const
inlinevirtual

bool conversion

Implements utility::io::irstream.

References if_stream_, and zip_stream_p_.

utility::io::izstream::operator std::istream & ( )
inlinevirtual

Stream conversion.

Implements utility::io::irstream.

References if_stream_, and zip_stream_p_.

utility::io::izstream::operator std::istream const & ( ) const
inlinevirtual

Stream conversion.

Implements utility::io::irstream.

References if_stream_, and zip_stream_p_.

std::istream const& utility::io::izstream::operator() ( ) const
inlinevirtual

Stream access.

Implements utility::io::irstream.

References if_stream_, and zip_stream_p_.

std::istream& utility::io::izstream::operator() ( )
inlinevirtual

Stream access.

Implements utility::io::irstream.

References if_stream_, and zip_stream_p_.

template<typename T >
std::istream& utility::io::izstream::operator>> ( T &  t)
inline

Stream input.

References stream(), and basic::options::OptionKeys::in::file::t.

std::istream& utility::io::izstream::operator>> ( manipulator  m)
inline

Stream manipulator input.

std::istream& utility::io::izstream::operator>> ( std_manipulator  m)
inlinevirtual

Stream manipulator input.

Implements utility::io::irstream.

int utility::io::izstream::peek ( )
inlinevirtual

Returns the next character without extracting it.

Implements utility::io::irstream.

References stream().

izstream& utility::io::izstream::putback ( char  c)
inlinevirtual

Put the last character read back into the stream and check that passed character is correct.

Implements utility::io::irstream.

References stream().

std::streambuf* utility::io::izstream::rdbuf ( ) const
inlinevirtual

Pointer to the stream buffer.

Implements utility::io::irstream.

References stream().

izstream& utility::io::izstream::read ( char *  str,
std::streamsize const  count 
)
inlinevirtual

Read the next specified number of characters.

Implements utility::io::irstream.

References stream().

izstream& utility::io::izstream::read ( std::string &  str,
std::streamsize const  count 
)
inlinevirtual

Read the next specified number of characters.

Implements utility::io::irstream.

References basic::options::OptionKeys::cp::cp, and stream().

std::streamsize utility::io::izstream::readsome ( char *  str,
std::streamsize const  count 
)
inlinevirtual

Read the next available specified number of characters.

Implements utility::io::irstream.

References stream().

std::streamsize utility::io::izstream::readsome ( std::string &  str,
std::streamsize const  count 
)
inlinevirtual

Read the next available specified number of characters.

Implements utility::io::irstream.

References basic::options::OptionKeys::cp::cp, and stream().

void utility::io::izstream::seek_beg ( )
inlinevirtual

Seek to the beginning.

Implements utility::io::irstream.

References if_stream_, and zip_stream_p_.

static void utility::io::izstream::set_alternative_search_paths ( vector1< std::string >  alternative_search_paths)
inlinestatic
std::istream const& utility::io::izstream::stream ( ) const
inlinevirtual
std::istream& utility::io::izstream::stream ( )
inlinevirtual

Stream access.

Implements utility::io::irstream.

References if_stream_, and zip_stream_p_.

bool utility::io::izstream::uncompressed ( ) const
inlinevirtual

Uncompressed?

Implements utility::io::irstream.

References compression_, and UNCOMPRESSED.

izstream& utility::io::izstream::unget ( )
inlinevirtual

Put the last character read back into the stream.

Implements utility::io::irstream.

References stream().

Friends And Related Function Documentation

long utility::file::gunzip ( std::string const &  compressedfile,
bool  overwrite 
)
friend
long utility::file::gzip ( std::string const &  uncompressedfile,
bool  overwrite 
)
friend

Member Data Documentation

vector1< std::string > utility::io::izstream::alternative_search_paths_
staticprivate

Alternative search paths This initialized by the option system -in:path:path Notice that izstream cannot access the option system (because the utility library comes before the basic library), so setting the alternate search paths is it the responsibility of core::init::init()

Referenced by get_alternative_search_paths(), open_ifstream(), and set_alternative_search_paths().

Compression utility::io::izstream::compression_
private

Compression state.

Referenced by close(), compressed(), gzipped(), open(), and uncompressed().

std::string utility::io::izstream::filename_
private

File name.

Referenced by close(), filename(), and open_ifstream().

std::ifstream utility::io::izstream::if_stream_
private
zlib_stream::zip_istream* utility::io::izstream::zip_stream_p_
private

The documentation for this class was generated from the following files: