17 #ifndef INCLUDED_utility_io_ozstream_hh
18 #define INCLUDED_utility_io_ozstream_hh
32 #if defined( USE_FILE_PROVIDER )
82 #if defined( USE_FILE_PROVIDER )
83 ,file_provider_stream( &bad_stream )
96 std::string
const & filename_a,
97 std::ios_base::openmode open_mode = std::ios_base::out,
104 #if defined( USE_FILE_PROVIDER )
105 ,file_provider_stream( &bad_stream )
110 open( filename_a, open_mode );
130 #if defined( USE_FILE_PROVIDER )
131 if ( file_provider_stream->good() ) {
141 operator std::ostream
const &()
const
143 #if defined( USE_FILE_PROVIDER )
144 if ( file_provider_stream->good() ) {
145 return *file_provider_stream;
150 : (
mpi_stream_p_ ?
static_cast< std::ostream const&
> ( *mpi_stream_p_ )
151 :
static_cast< std::ostream
const &
>(
of_stream_ ) )
158 operator std::ostream &()
160 #if defined( USE_FILE_PROVIDER )
161 if ( file_provider_stream->good() ) {
162 return *file_provider_stream;
167 : (
mpi_stream_p_ ?
static_cast< std::ostream &
> ( *mpi_stream_p_ )
168 :
static_cast< std::ostream &
>(
of_stream_ ) )
177 template<
typename T >
182 #if defined( USE_FILE_PROVIDER )
183 if ( file_provider_stream->good() ) {
184 (*file_provider_stream) << t;
189 (*zip_stream_p_) << t;
191 (*mpi_stream_p_) << t;
208 #if defined( USE_FILE_PROVIDER )
209 if ( file_provider_stream->good() ) {
210 (*file_provider_stream) <<
'\n';
215 (*zip_stream_p_) <<
'\n';
217 (*mpi_stream_p_) <<
'\n';
220 #if defined( USE_FILE_PROVIDER )
221 if ( file_provider_stream->good() ) {
222 file_provider_stream->flush();
228 #if defined( USE_FILE_PROVIDER )
229 if ( file_provider_stream->good() ) {
230 (*file_provider_stream) << m;
246 std::string
const & filename_a,
247 std::ios_base::openmode open_mode = std::ios_base::out
264 #if defined( USE_FILE_PROVIDER )
265 if ( file_provider_stream->good() ) {
266 file_provider_stream->
put( c );
287 #if defined( USE_FILE_PROVIDER )
288 if ( file_provider_stream->good() ) {
289 file_provider_stream->
write( str, count );
307 write( std::string
const & str, std::streamsize
const count )
330 #if defined( USE_FILE_PROVIDER )
331 if ( file_provider_stream->good() ) {
332 file_provider_stream->
flush();
360 #if defined( USE_FILE_PROVIDER )
361 if ( file_provider_stream->good() ) {
362 file_provider_stream->
flush();
382 #if defined( USE_FILE_PROVIDER )
383 if ( file_provider_stream->good() ) {
402 #if defined( USE_FILE_PROVIDER )
403 if ( file_provider_stream->good() ) {
415 #if defined( USE_FILE_PROVIDER )
416 if ( file_provider_stream->good() ) {
417 file_provider_stream->clear();
432 #if defined( USE_FILE_PROVIDER )
433 if ( file_provider_stream->good() ) {
464 #if defined( USE_FILE_PROVIDER )
465 return (*file_provider_stream);
470 : static_cast< std::ostream const & >(
of_stream_ ) ) );
479 #if defined( USE_FILE_PROVIDER )
480 if ( file_provider_stream->good() ) {
481 return (*file_provider_stream);
486 : (
mpi_stream_p_ ?
static_cast< std::ostream &
>( *mpi_stream_p_ )
487 :
static_cast< std::ostream &
>(
of_stream_ ) ));
496 #if defined( USE_FILE_PROVIDER )
497 if ( file_provider_stream->good() ) {
498 return (*file_provider_stream);
503 : (
mpi_stream_p_ ?
static_cast< std::ostream
const &
>( *mpi_stream_p_ )
504 :
static_cast< std::ostream
const &
>(
of_stream_ ) ));
513 #if defined( USE_FILE_PROVIDER )
514 if ( file_provider_stream->good() ) {
515 return (*file_provider_stream);
520 : (
mpi_stream_p_ ?
static_cast< std::ostream &
>( *mpi_stream_p_ )
521 :
static_cast< std::ostream &
>(
of_stream_ ) ));
631 std::streamsize
const & buf_size
762 #if defined( USE_FILE_PROVIDER )
763 std::ostream *file_provider_stream;
764 std::stringstream bad_stream;
774 #endif // INCLUDED_utility_io_ozstream_HH
Output stream wrapper abstract base class.
basic_zip_ostream & write(char const *str, std::streamsize const count)
write a string
Altered zipstream library header.
std::streamsize const OZSTREAM_DEFAULT_BUFFER_SIZE
default buffer size for ozstreams (900KB)
bool is_gzip() const
Is stream attached to a gzip file?
ozstream & operator<<(T const &t)
Stream output: override to preserve type of return value.
utility::io::ozstream forward declarations
ozstream & put(char const c)
Write a char.
ozstream & flush_finalize()
Flush the streams and finalize the zip stream.
char * char_buffer_p_
character buffer pointer (owning)
std::streamsize buffer_size() const
get buffer size (bytes)
std::streambuf * rdbuf() const
Pointer to the stream buffer.
ozstream & flush()
Flush the stream – currently alias to flush_finalize()
bool allocate_assign_char_buffer()
if character buffer does not exist, create it and assign it to internal ofstream
basic_zip_ostream< Elem, Tr > & zflush()
flush inner buffer and zipper buffer
std::streamsize buffer_size_
size of buffer (in bytes)
basic_zip_ostream< Elem, Tr > & zflush_finalize()
flush inner and zipper buffers and finalize zip stream
Compression compression_
Compression state.
uLong get_in_size() const
returns the uncompressed data size
basic_zip_ostream & put(char const c)
write char
void zflush()
Flush the zip_ostream.
bool uncompressed() const
Uncompressed?
basic_mpi_ostream & write(char const *str, std::streamsize const count)
write a string
long gzip(std::string const &uncompressedfile, bool overwrite)
gzip: file compression
bool destroy_char_buffer()
if character buffer exists, destroy it
bool is_gzip() const
returns true if it is a gzip
void clear()
Clear the stream.
uLong get_out_size() const
returns the compressed data size
static bool bMPI_reroute_stream_
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...
bool eof() const
End of file?
std::ostream &(* manipulator)(std::ostream &)
long get_in_size() const
Uncompressed data size.
ozstream & write(std::string const &str, std::streamsize const count)
Write a string.
zlib_stream::zip_ostream * zip_stream_p_
Zip file stream pointer (owning)
uLong get_crc() const
returns the uncompressed data crc
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.
std::ostream const & operator()() const
Stream access.
std::string const & filename() const
File name.
mpi_stream::mpi_ostream * mpi_stream_p_
virtual ~ozstream()
Destructor.
std::ostream & stream()
Stream access.
basic_mpi_ostream & flush()
std::string filename_
File name.
static void enable_MPI_reroute(int min_client_rank, int master_rank)
bool gzipped() const
gzipped?
void open_append(std::string const &filename_a)
Open a text file for appending.
long get_crc() const
CRC of the uncompressed data (see zipstream documentation)
orstream: Output stream wrapper base class
void close()
Close the ofstream and reset the state.
static int mpi_FileBuf_master_rank_
basic_mpi_ostream & put(char const c)
write char
void zflush_finalize()
Flush and finalize the zip_stream.
ozstream & write(char const *str, std::streamsize const count)
Write a string.
long gunzip(std::string const &compressedfile, bool overwrite)
gunzip: file decompression
void buffer_size(std::streamsize const &buf_size)
set buffer size (bytes)
std::ostream const & stream() const
Stream access.
ozstream: Output file stream wrapper for uncompressed and compressed files
static int MPI_reroute_rank()
long get_out_size() const
Compressed data size.
void open(std::string const &filename_a, std::ios_base::openmode open_mode=std::ios_base::out)
Open a file.
bool compressed() const
Compressed?
std::ofstream of_stream_
File stream.
ozstream()
Default constructor.