OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
openswmm::io::AtomicOutputFile Class Reference

Own a staging stream and publish it by a checked single-file rename. More...

#include <AtomicOutputFile.hpp>

Collaboration diagram for openswmm::io::AtomicOutputFile:

Public Member Functions

 AtomicOutputFile (const std::filesystem::path &destination, bool binary=false)
 Create an exclusive staging sibling for a single output destination.
 
 ~AtomicOutputFile ()
 Close any open staging stream and best-effort discard unpublished output.
 
 AtomicOutputFile (const AtomicOutputFile &)=delete
 Disallow copying ownership of the staging stream and publication state.
 
AtomicOutputFile & operator= (const AtomicOutputFile &)=delete
 Disallow copy replacement of a pending file publication.
 
FILE * stream () const
 Borrow the writable staging stream.
 
const std::string & error () const
 Borrow the latest stored file-operation diagnostic.
 
bool commit ()
 Flush, sync, close and attempt to rename staging over the destination.
 

Detailed Description

Own a staging stream and publish it by a checked single-file rename.

Noncopyable; destroys unpublished staging on scope exit. Caller writes synchronously through stream(), then calls commit() and inspects error() on failure. No internal thread synchronization; retain the object until serialization completes.

Constructor & Destructor Documentation

◆ AtomicOutputFile() [1/2]

openswmm::io::AtomicOutputFile::AtomicOutputFile ( const std::filesystem::path & destination,
bool binary = false )
inlineexplicit

Create an exclusive staging sibling for a single output destination.

Refuses an existing nonregular destination or one without any write permission bits, then tries up to 32 unique staging names and copies existing permissions. Filesystem/refusal diagnostics are stored rather than thrown; allocation/path-conversion exceptions may still propagate. Check stream() before serializing. Does not create missing parent directories.

Parameters
[in]destinationBorrowed native path copied into the object; existing symlinks resolve to their target, dangling symlinks are refused.
[in]binaryTrue uses binary-exclusive mode; false permits platform text newline translation.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~AtomicOutputFile()

openswmm::io::AtomicOutputFile::~AtomicOutputFile ( )
inline

Close any open staging stream and best-effort discard unpublished output.

Does not commit. Remove/close errors are ignored; a failed cleanup may leave the staging file. Published destination is retained.

◆ AtomicOutputFile() [2/2]

openswmm::io::AtomicOutputFile::AtomicOutputFile ( const AtomicOutputFile & )
delete

Disallow copying ownership of the staging stream and publication state.

Here is the call graph for this function:

Member Function Documentation

◆ commit()

bool openswmm::io::AtomicOutputFile::commit ( )
inline

Flush, sync, close and attempt to rename staging over the destination.

Checks ferror, fflush, platform file sync and fclose in order, closes even on failure, then uses filesystem::rename. On failure error() describes the first relevant stage and unpublished staging remains for destructor cleanup. After any attempt the stream is unavailable; a second commit returns false. This is one-file rename publication, not a multi-file transaction or parent-directory durability guarantee.

Returns
True only after successful publication; false for missing stream or an IO/rename refusal.
Here is the caller graph for this function:

◆ error()

const std::string & openswmm::io::AtomicOutputFile::error ( ) const
inline

Borrow the latest stored file-operation diagnostic.

Returns
Owned diagnostic reference, empty initially; copy before a later operation or destruction.
Here is the caller graph for this function:

◆ operator=()

AtomicOutputFile & openswmm::io::AtomicOutputFile::operator= ( const AtomicOutputFile & )
delete

Disallow copy replacement of a pending file publication.

Here is the call graph for this function:

◆ stream()

FILE * openswmm::io::AtomicOutputFile::stream ( ) const
inline

Borrow the writable staging stream.

Caller writes but must not fclose() or retain it past commit/destruction; ownership stays with this object. Caller serializes all access.

Returns
Nonowning FILE pointer, or nullptr after preparation failure/commit.
Here is the caller graph for this function:

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