Rosetta 3.3
Public Member Functions | Static Public Member Functions | Friends
utility::io::ozstream Class Reference

ozstream: Output file stream wrapper for uncompressed and compressed files More...

#include <ozstream.hh>

Inheritance diagram for utility::io::ozstream:
Inheritance graph
[legend]
Collaboration diagram for utility::io::ozstream:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ozstream ()
 Default constructor.
 ozstream (std::string const &filename_a, std::ios_base::openmode open_mode=std::ios_base::out, std::streamsize buf_size=OZSTREAM_DEFAULT_BUFFER_SIZE)
 Filename constructor.
virtual ~ozstream ()
 Destructor.
 operator bool () const
 bool conversion
 operator std::ostream const & () const
 Stream conversion.
 operator std::ostream & ()
 Stream conversion.
template<typename T >
ozstreamoperator<< (T const &t)
 Stream output: override to preserve type of return value.
ozstreamoperator<< (manipulator m)
 Stream output overload to replace std::endl with
to avoid flushing.
void open (std::string const &filename_a, std::ios_base::openmode open_mode=std::ios_base::out)
 Open a file.
void open_append (std::string const &filename_a)
 Open a text file for appending.
void open_append_if_existed (std::string const &filename_a, std::stringstream &preprinted_header)
 open file as append if it exists, return true if file existed before, false if it is new.
ozstreamput (char const c)
 Write a char.
ozstreamwrite (char const *str, std::streamsize const count)
 Write a string.
ozstreamwrite (std::string const &str, std::streamsize const count)
 Write a string.
ozstreamflush ()
 Flush the stream -- currently alias to flush_finalize()
ozstreamflush_finalize ()
 Flush the streams and finalize the zip stream.
void zflush ()
 Flush the zip_ostream.
void zflush_finalize ()
 Flush and finalize the zip_stream.
void clear ()
 Clear the stream.
void close ()
 Close the ofstream and reset the state.
std::ostream const & operator() () const
 Stream access.
std::ostream & operator() ()
 Stream access.
std::ostream const & stream () const
 Stream access.
std::ostream & stream ()
 Stream access.
std::streambuf * rdbuf () const
 Pointer to the stream buffer.
std::string const & filename () const
 File name.
bool good () const
 Good?
bool eof () const
 End of file?
bool fail () const
 Fail?
bool bad () const
 Bad?
bool compressed () const
 Compressed?
bool uncompressed () const
 Uncompressed?
bool gzipped () const
 gzipped?
std::streamsize buffer_size () const
 get buffer size (bytes)
void buffer_size (std::streamsize const &buf_size)
 set buffer size (bytes)

Static Public Member Functions

static void enable_MPI_reroute (int min_client_rank, int master_rank)
static int MPI_reroute_rank ()

Friends

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

Detailed Description

ozstream: Output file stream wrapper for uncompressed and compressed files


Constructor & Destructor Documentation

utility::io::ozstream::ozstream ( ) [inline]

Default constructor.

utility::io::ozstream::ozstream ( std::string const &  filename_a,
std::ios_base::openmode  open_mode = std::ios_base::out,
std::streamsize  buf_size = OZSTREAM_DEFAULT_BUFFER_SIZE 
) [inline, explicit]

Filename constructor.

Parameters:
[in]filename_afilename
[in]open_modeopening mode bitmask, use std::ios_base::out for gzip files
[in]buf_sizebuffer size (bytes), enforced lower bound of 4KB

References buffer_size(), and open().

virtual utility::io::ozstream::~ozstream ( ) [inline, virtual]

Destructor.

References close().


Member Function Documentation

bool utility::io::ozstream::bad ( ) const [inline, virtual]

Bad?

Implements utility::io::orstream.

References stream().

void utility::io::ozstream::buffer_size ( std::streamsize const &  buf_size) [inline]

set buffer size (bytes)

In uncompressed mode this is the size of the character buffer. In compressed mode this is the size of the zip buffer. Lower bound of 4KB is enforced due to zipstream requirements. Operation is skipped if the file is currently open, as the buffer is considered locked.

References utility::max().

std::streamsize utility::io::ozstream::buffer_size ( ) const [inline]

get buffer size (bytes)

In uncompressed mode this is the size of the character buffer. In compressed mode this is the size of the zip buffer.

Referenced by ozstream().

void utility::io::ozstream::clear ( ) [inline, virtual]

Clear the stream.

Implements utility::io::orstream.

void utility::io::ozstream::close ( ) [inline]
bool utility::io::ozstream::compressed ( ) const [inline, virtual]

Compressed?

Implements utility::io::orstream.

void utility::io::ozstream::enable_MPI_reroute ( int  min_client_rank,
int  master_rank 
) [static]
bool utility::io::ozstream::eof ( ) const [inline, virtual]

End of file?

Implements utility::io::orstream.

References stream().

bool utility::io::ozstream::fail ( ) const [inline, virtual]

Fail?

Implements utility::io::orstream.

References stream().

std::string const& utility::io::ozstream::filename ( ) const [inline]

File name.

ozstream& utility::io::ozstream::flush ( ) [inline, virtual]

Flush the stream -- currently alias to flush_finalize()

Instead doing a regular flush, we currently force a completion of the zip stream. We do this to pre-empt against several things: (1) the expensive operation of closing and re-opening a stream (2) confusion and inconvenience that may result from users calling flushes and ending upon with broken or corrupted files if a job is somehow interrupted (e.g. on a cluster). Please note that calling flush_finalize() too often can seriously degrade compression. zlib documentation appears to imply that every 1MB or so is a reasonable rule of thumb.

Implements utility::io::orstream.

References zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::zflush_finalize().

Referenced by operator<<().

ozstream& utility::io::ozstream::flush_finalize ( ) [inline]

Flush the streams and finalize the zip stream.

Calling this will complete the zip stream. Upon the next write, a new zip stream will be started. Please note that calling flush_finalize() too often can seriously degrade compression. zlib documentation appears to imply that every 1MB or so is a reasonable rule of thumb.

References zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::zflush_finalize().

bool utility::io::ozstream::good ( ) const [inline, virtual]
bool utility::io::ozstream::gzipped ( ) const [inline, virtual]

gzipped?

Implements utility::io::orstream.

static int utility::io::ozstream::MPI_reroute_rank ( ) [inline, static]
void utility::io::ozstream::open ( std::string const &  filename_a,
std::ios_base::openmode  open_mode = std::ios_base::out 
)
void utility::io::ozstream::open_append ( std::string const &  filename_a)
void utility::io::ozstream::open_append_if_existed ( std::string const &  filename_a,
std::stringstream &  preprinted_header 
)

open file as append if it exists, return true if file existed before, false if it is new.

special "atomic" method to open a stream and print a header if it is new. This is necessary to avoid process competition when checking for existance to decided whether or not to write a header.

References close(), utility::file::file_exists(), good(), open(), and open_append().

utility::io::ozstream::operator bool ( ) const [inline, virtual]

bool conversion

Implements utility::io::orstream.

utility::io::ozstream::operator std::ostream & ( ) [inline, virtual]

Stream conversion.

Implements utility::io::orstream.

utility::io::ozstream::operator std::ostream const & ( ) const [inline, virtual]

Stream conversion.

Implements utility::io::orstream.

std::ostream const& utility::io::ozstream::operator() ( ) const [inline, virtual]

Stream access.

Implements utility::io::orstream.

std::ostream& utility::io::ozstream::operator() ( ) [inline, virtual]

Stream access.

Implements utility::io::orstream.

template<typename T >
ozstream& utility::io::ozstream::operator<< ( T const &  t) [inline]

Stream output: override to preserve type of return value.

Reimplemented from utility::io::orstream.

References sd::t.

ozstream& utility::io::ozstream::operator<< ( manipulator  m) [inline, virtual]

Stream output overload to replace std::endl with
to avoid flushing.

and call ozstream::flush() when passed std::flush

Implements utility::io::orstream.

References flush().

ozstream& utility::io::ozstream::put ( char const  c) [inline, virtual]
std::streambuf* utility::io::ozstream::rdbuf ( ) const [inline, virtual]

Pointer to the stream buffer.

Implements utility::io::orstream.

References stream().

std::ostream const& utility::io::ozstream::stream ( ) const [inline, virtual]

Stream access.

Implements utility::io::orstream.

Referenced by bad(), eof(), fail(), good(), rdbuf(), and write().

std::ostream& utility::io::ozstream::stream ( ) [inline, virtual]

Stream access.

Implements utility::io::orstream.

bool utility::io::ozstream::uncompressed ( ) const [inline, virtual]

Uncompressed?

Implements utility::io::orstream.

ozstream& utility::io::ozstream::write ( std::string const &  str,
std::streamsize const  count 
) [inline, virtual]

Write a string.

Implements utility::io::orstream.

References get_pdb::count, and stream().

ozstream& utility::io::ozstream::write ( char const *  str,
std::streamsize const  count 
) [inline, virtual]
void utility::io::ozstream::zflush ( ) [inline]

Flush the zip_ostream.

this will flush but *not* finalize the zip stream

References zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::zflush().

void utility::io::ozstream::zflush_finalize ( ) [inline]

Flush and finalize the zip_stream.

Calling this will complete the zip stream. Upon the next write, a new zip stream will be started Please note that calling zflush_finalize() too often can seriously degrade compression. zlib documentation appears to imply that every 1MB or so is a reasonable rule of thumb.

References zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::zflush_finalize().


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]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines