Loading...
Searching...
No Matches
ofstreamPointer Class Reference

A wrapped std::ofstream with possible compression handling (ogzstream) that behaves much like a std::unique_ptr. More...

#include <fstreamPointer.H>

Inheritance diagram for ofstreamPointer:

Public Member Functions

 ofstreamPointer (const ofstreamPointer &)=delete
 No copy construct.
 ofstreamPointer (ofstreamPointer &&)=default
 Move construct.
void operator= (const ofstreamPointer &)=delete
 No copy assignment.
ofstreamPointeroperator= (ofstreamPointer &&)=default
 Move assignment.
 ~ofstreamPointer ()=default
 Destructor.
 ofstreamPointer () noexcept
 Default construct (empty).
 ofstreamPointer (std::nullptr_t)
 Construct as null output stream (Foam::ocountstream).
 ofstreamPointer (const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), IOstreamOption::appendType append=IOstreamOption::NO_APPEND, bool atomic=false)
 Construct from pathname, option, append, file handling atomic.
 ofstreamPointer (const fileName &pathname, IOstreamOption::compressionType comp, IOstreamOption::appendType append=IOstreamOption::NO_APPEND, bool atomic=false)
 Construct from pathname, compression, append, file handling atomic.
 operator bool () const noexcept
 True if it holds a valid pointer.
std::ostream * get () noexcept
 The stream pointer (ofstream or ogzstream).
const std::ostream * get () const noexcept
 The stream pointer (ofstream or ogzstream).
IOstreamOption::compressionType whichCompression () const
 Which compression type?
bool is_appending () const noexcept
 True if opened in append mode and file already existed.
bool is_atomic () const noexcept
 True if file creation behaves as atomic.
std::ostream * release () noexcept
 Return managed pointer and release ownership.
void reset (std::ostream *ptr) noexcept
 Replace the managed pointer.
std::ostream & operator* ()
 Reference to the stream (no nullptr checking).
const std::ostream & operator* () const
 Const-reference to the stream (no nullptr checking).
std::ostream * operator-> () noexcept
 Pointer dereference.
const std::ostream * operator-> () const noexcept
 Pointer dereference.

Static Public Member Functions

static bool supports_gz () noexcept
 True if compiled with libz support.

Protected Member Functions

void reopen (const std::string &pathname)
 Reopen for compressed/non-compressed. Discards append status.
void close (const std::string &pathname)
 Close stream and rename file.

Detailed Description

A wrapped std::ofstream with possible compression handling (ogzstream) that behaves much like a std::unique_ptr.

Note
No operator bool to avoid inheritance ambiguity with std::ios::operator bool.
Source files

Definition at line 239 of file fstreamPointer.H.

Constructor & Destructor Documentation

◆ ofstreamPointer() [1/6]

ofstreamPointer ( const ofstreamPointer & )
delete

No copy construct.

References ofstreamPointer().

Referenced by OFstream::OFstream(), OFstream::OFstream(), ofstreamPointer(), ofstreamPointer(), ofstreamPointer(), operator=(), operator=(), and ~ofstreamPointer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ofstreamPointer() [2/6]

ofstreamPointer ( ofstreamPointer && )
default

Move construct.

References ofstreamPointer().

Here is the call graph for this function:

◆ ~ofstreamPointer()

~ofstreamPointer ( )
default

Destructor.

References append(), Foam::noexcept, ofstreamPointer(), and supports_gz().

Here is the call graph for this function:

◆ ofstreamPointer() [3/6]

ofstreamPointer ( )
noexcept

Default construct (empty).

Definition at line 81 of file fstreamPointers.C.

References Foam::noexcept.

◆ ofstreamPointer() [4/6]

ofstreamPointer ( std::nullptr_t )
explicit

Construct as null output stream (Foam::ocountstream).

Definition at line 88 of file fstreamPointers.C.

◆ ofstreamPointer() [5/6]

ofstreamPointer ( const fileName & pathname,
IOstreamOption streamOpt = IOstreamOption(),
IOstreamOption::appendType append = IOstreamOption::NO_APPEND,
bool atomic = false )
explicit

Construct from pathname, option, append, file handling atomic.

Parameters
pathnameThe file name to open for writing
streamOptRespects (UNCOMPRESSED | COMPRESSED)
appendOpen in specified append mode
atomicWrite into temporary file (not target file). This option should only be used with a stream wrapper (eg, OFstream) that handles the final renaming.
Note
There are two different append modes: append at every write, or only append after opening.

Definition at line 95 of file fstreamPointers.C.

References append(), IOstreamOption::APPEND_APP, IOstreamOption::APPEND_ATE, IOstreamOption::COMPRESSED, IOstreamOption::compression(), Foam::endl(), fileName::FILE, filePtr, Foam::nl, IOstreamOption::NO_APPEND, Foam::rm(), fileName::SYMLINK, Foam::type(), IOstreamOption::UNCOMPRESSED, fileName::UNDEFINED, and Foam::Warning.

Here is the call graph for this function:

◆ ofstreamPointer() [6/6]

ofstreamPointer ( const fileName & pathname,
IOstreamOption::compressionType comp,
IOstreamOption::appendType append = IOstreamOption::NO_APPEND,
bool atomic = false )

Construct from pathname, compression, append, file handling atomic.

Parameters
pathnameThe file name to open for writing
compUNCOMPRESSED | COMPRESSED
appendOpen in append mode
atomicWrite into temporary file (not target file). This option should only be used with a stream wrapper (eg, OFstream) that handles the final renaming.

Definition at line 289 of file fstreamPointers.C.

References append(), and ofstreamPointer().

Here is the call graph for this function:

Member Function Documentation

◆ reopen()

void reopen ( const std::string & pathname)
protected

Reopen for compressed/non-compressed. Discards append status.

Definition at line 381 of file fstreamPointers.C.

Referenced by OFstream::rewind().

Here is the caller graph for this function:

◆ close()

void close ( const std::string & pathname)
protected

Close stream and rename file.

Definition at line 447 of file fstreamPointers.C.

Referenced by OFstream::~OFstream().

Here is the caller graph for this function:

◆ operator=() [1/2]

void operator= ( const ofstreamPointer & )
delete

No copy assignment.

References ofstreamPointer().

Here is the call graph for this function:

◆ operator=() [2/2]

ofstreamPointer & operator= ( ofstreamPointer && )
default

Move assignment.

References ofstreamPointer().

Here is the call graph for this function:

◆ supports_gz()

bool supports_gz ( )
staticnoexcept

True if compiled with libz support.

Definition at line 46 of file fstreamPointers.C.

References Foam::noexcept.

Referenced by Time::readDict(), and ~ofstreamPointer().

Here is the caller graph for this function:

◆ operator bool()

operator bool ( ) const
inlineexplicitnoexcept

True if it holds a valid pointer.

Definition at line 386 of file fstreamPointer.H.

References Foam::noexcept.

◆ get() [1/2]

std::ostream * get ( )
inlinenoexcept

The stream pointer (ofstream or ogzstream).

Definition at line 391 of file fstreamPointer.H.

References Foam::noexcept.

Referenced by OFstream::OFstream(), OFstream::OFstream(), OFstream::rewind(), OFstream::stdStream(), and OFstream::stdStream().

Here is the caller graph for this function:

◆ get() [2/2]

const std::ostream * get ( ) const
inlinenoexcept

The stream pointer (ofstream or ogzstream).

Definition at line 396 of file fstreamPointer.H.

References Foam::noexcept.

◆ whichCompression()

Foam::IOstreamOption::compressionType whichCompression ( ) const

Which compression type?

Definition at line 510 of file fstreamPointers.C.

References IOstreamOption::COMPRESSED, and IOstreamOption::UNCOMPRESSED.

◆ is_appending()

bool is_appending ( ) const
inlinenoexcept

True if opened in append mode and file already existed.

Definition at line 406 of file fstreamPointer.H.

References Foam::noexcept.

Referenced by OFstream::is_appending().

Here is the caller graph for this function:

◆ is_atomic()

bool is_atomic ( ) const
inlinenoexcept

True if file creation behaves as atomic.

Definition at line 414 of file fstreamPointer.H.

References Foam::noexcept.

Referenced by OFstream::is_atomic().

Here is the caller graph for this function:

◆ release()

std::ostream * release ( )
inlinenoexcept

Return managed pointer and release ownership.

Definition at line 425 of file fstreamPointer.H.

References Foam::noexcept.

◆ reset()

void reset ( std::ostream * ptr)
inlinenoexcept

Replace the managed pointer.

Definition at line 434 of file fstreamPointer.H.

◆ operator*() [1/2]

std::ostream & operator* ( )
inline

Reference to the stream (no nullptr checking).

Definition at line 446 of file fstreamPointer.H.

◆ operator*() [2/2]

const std::ostream & operator* ( ) const
inline

Const-reference to the stream (no nullptr checking).

Definition at line 451 of file fstreamPointer.H.

◆ operator->() [1/2]

std::ostream * operator-> ( )
inlinenoexcept

Pointer dereference.

Definition at line 456 of file fstreamPointer.H.

References Foam::noexcept.

◆ operator->() [2/2]

const std::ostream * operator-> ( ) const
inlinenoexcept

Pointer dereference.

Definition at line 461 of file fstreamPointer.H.

References Foam::noexcept.


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