ofstreamPointer Class Reference

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

Inheritance diagram for ofstreamPointer:

Public Member Functions

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

Static Public Member Functions

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

Protected Member Functions

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

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.

◆ ofstreamPointer() [2/6]

ofstreamPointer ( ofstreamPointer &&  )
default

Move construct.

◆ ~ofstreamPointer()

~ofstreamPointer ( )
default

Destructor.

◆ ofstreamPointer() [3/6]

ofstreamPointer ( )
noexcept

Default construct (empty)

Definition at line 81 of file fstreamPointers.C.

◆ 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 96 of file fstreamPointers.C.

References append(), IOstreamOption::APPEND_APP, IOstreamOption::APPEND_ATE, IOstreamOption::COMPRESSED, IOstreamOption::compression(), stdFoam::end(), Foam::endl(), fileName::FILE, filePtr, Foam::nl, IOstreamOption::NO_APPEND, Foam::rm(), fileName::SYMLINK, Foam::type(), IOstreamOption::UNCOMPRESSED, 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 290 of file fstreamPointers.C.

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.

◆ operator=() [2/2]

ofstreamPointer& operator= ( ofstreamPointer &&  )
default

Move assignment.

◆ supports_gz()

bool supports_gz ( )
staticnoexcept

True if compiled with libz support.

Definition at line 46 of file fstreamPointers.C.

Referenced by Time::readDict().

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.

◆ get() [1/2]

std::ostream* get ( )
inlinenoexcept

The stream pointer (ofstream or ogzstream)

Definition at line 391 of file fstreamPointer.H.

Referenced by OFstream::rewind(), 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.

◆ whichCompression()

Foam::IOstreamOption::compressionType whichCompression ( ) const

Which compression type?

Definition at line 510 of file fstreamPointers.C.

◆ 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.

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.

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.

◆ 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.

◆ operator->() [2/2]

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

Pointer dereference.

Definition at line 461 of file fstreamPointer.H.


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