Workspace 6.21.5
Public Member Functions | Protected Attributes | List of all members
iautogzstream Class Reference

File stream input with gzip functionality.

#include <Mesh/FileIO/Compression/iautogzstream.h>

Inherits streambuf, and istream.

Public Member Functions

 iautogzstream ()
 
 iautogzstream (std::string fName)
 
 iautogzstream (std::string fName, bool useCompression)
 
 ~iautogzstream () override
 
void Close ()
 
void Flush ()
 
const std::string & GetFileName () const
 
bool IsReady () const
 
bool Open (std::string fName)
 
bool Open (std::string fName, bool useCompression)
 
void Rewind ()
 
bool Seek (std::ios::off_type offset, std::ios_base::seekdir dir)
 
bool Seek (std::ios::pos_type pos)
 
std::ios::pos_type Tell ()
 
bool UsingCompression () const
 

Protected Attributes

std::string fileName
 

Constructor & Destructor Documentation

◆ iautogzstream() [1/3]

◆ iautogzstream() [2/3]

iautogzstream ( std::string  fName)

◆ iautogzstream() [3/3]

iautogzstream ( std::string  fName,
bool  useCompression 
)

◆ ~iautogzstream()

~iautogzstream ( )
inlineoverride

Member Function Documentation

◆ Close()

void Close ( )

Close the currently open file. If one is not open, nothing is done.

Warning
It is the caller's responsibility to not use a closed stream!

◆ Flush()

void Flush ( )
inline

◆ GetFileName()

const std::string & GetFileName ( ) const
inline
Returns
The name of the file currently open or the name that was used to attempt an open. Clients should use IsReady() to test if a file is open and ready for reading.

◆ IsReady()

bool IsReady ( ) const
inline
Returns
TRUE if the file is ready for input.

◆ Open() [1/2]

bool Open ( std::string  fName)

This form of Open() automatically detects whether on-the-fly gzip compression is required by checking for a .gz extension on the file name.

Returns
True if the file was able to be opened.

◆ Open() [2/2]

bool Open ( std::string  fName,
bool  useCompression 
)
Parameters
fNameName of file to open.
useCompressionIf TRUE, on-the-fly gzip compression will be used. Otherwise the file is opened as plain text.

Opens a file for input with the specified gzip behaviour. If useCompression==TRUE and fName does not end in .gz, it will be appended to the file name automatically. If a file is already open, it will be closed and the new name opened in its place.

You should check the success of this operation with the IsReady() function.

Returns
True if the file was able to be opened.

◆ Rewind()

void Rewind ( )

Rewind the file so that input is taken from the beginning again. You should check the result with the good() function, as usual.

◆ Seek() [1/2]

bool Seek ( std::ios::off_type  offset,
std::ios_base::seekdir  dir 
)

Set the current read position to offset relative to the position dir. Be warned that if compression is being used on the input file, this function could be very slow.

Returns
True if the seek was able to be performed.

◆ Seek() [2/2]

bool Seek ( std::ios::pos_type  pos)

Set the current read position to pos (an absolute position). Be warned that if compression is being used on the input file, this function could be very slow.

Returns
True if the seek was able to be performed.

◆ Tell()

std::ios::pos_type Tell ( )
Returns
The current read position in the file. If there is an error, it will return pos_type(off_type(-1)).

◆ UsingCompression()

bool UsingCompression ( ) const
inline

Public member function so that user can enquire if compression is being used. Hiding the usingCompression data member stops an ignorant user from wrongly trying to switch the file type.

Member Data Documentation

◆ fileName

std::string fileName
protected