73 open(pathname, streamOpt);
111 mode_(modeType::NONE)
116 std::ios_base::openmode openmode
118 std::ios_base::out | std::ios_base::binary
123 openmode |= std::ios_base::app;
137 openmode |= std::ios_base::in;
155 const fileName pathname_gz(pathname +
".gz");
156 const fileName pathname_tmp(pathname +
"~tmp~");
168 const fileName& target = (atomic ? pathname_tmp : pathname_gz);
187 ptr_.reset(
new ogzstream(target, openmode));
195 <<
"No write support for gz compressed files (libz)"
196 <<
" : downgraded to UNCOMPRESSED" <<
nl
197 <<
"file: " << pathname_gz <<
endl;
204 const fileName& target = (atomic ? pathname_tmp : pathname);
224 auto filePtr = std::make_unique<std::ofstream>(target, openmode);
235 filePtr->seekp(0, std::ios_base::end);
251 filePtr->seekp(0, std::ios_base::end);
275 (std::ios_base::out | std::ios_base::binary)
285 mode_ = modeType::APPENDING;
291 mode_ |= modeType::ATOMIC;
298 const fileName& pathname,
307 IOstreamOption(IOstreamOption::ASCII, comp),
325 const std::ios_base::openmode openmode
327 std::ios_base::in | std::ios_base::binary
330 ptr_.reset(
new std::ifstream(pathname, openmode));
336 const fileName pathname_gz(pathname +
".gz");
342 ptr_.reset(
new igzstream(pathname_gz, openmode));
347 <<
"No read support for gz compressed files (libz)"
348 <<
" : could use 'gunzip' from the command-line" <<
nl
349 <<
"file: " << pathname_gz <<
endl
369 auto* gz =
dynamic_cast<igzstream*
>(ptr_.get());
380 (std::ios_base::in | std::ios_base::binary)
391 auto* gz =
dynamic_cast<ogzstream*
>(ptr_.get());
399 if (mode_ & modeType::ATOMIC)
404 (std::ios_base::out | std::ios_base::binary)
412 (std::ios_base::out | std::ios_base::binary)
419 auto* file =
dynamic_cast<std::ofstream*
>(ptr_.get());
431 mode_ &= ~modeType::APPENDING;
433 if (mode_ & modeType::ATOMIC)
438 (std::ios_base::out | std::ios_base::binary)
446 (std::ios_base::out | std::ios_base::binary)
457 mode_ &= ~modeType::APPENDING;
459 if (pathname.empty() || !(mode_ & modeType::ATOMIC))
465 auto* gz =
dynamic_cast<ogzstream*
>(ptr_.get());
475 (pathname +
"~tmp~").c_str(),
476 (pathname +
".gz").c_str()
482 auto* file =
dynamic_cast<std::ofstream*
>(ptr_.get());
494 (pathname +
"~tmp~").c_str(),
506 if (
dynamic_cast<const igzstream*
>(ptr_.get()))
520 if (
dynamic_cast<const ogzstream*
>(ptr_.get()))
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
A simple container for options an IOstream can normally have.
compressionType compression() const noexcept
Get the stream compression.
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED).
@ UNCOMPRESSED
compression = false
@ COMPRESSED
compression = true
appendType
File appending (NO_APPEND | APPEND_APP | APPEND_ATE).
@ NO_APPEND
no append (truncates existing)
@ APPEND_ATE
append (seek end after open)
@ APPEND_APP
append (seek end each write)
A class for handling file names.
Type
Enumerations to handle directory entry types.
@ SYMLINK
A symbolic link.
@ UNDEFINED
Undefined type.
static bool supports_gz() noexcept
True if compiled with libz support.
void open(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption())
Attempts to open the specified file for reading.
void reopen_gz(const std::string &pathname)
Special 'rewind' method for compressed stream.
IOstreamOption::compressionType whichCompression() const
Which compression type?
ifstreamPointer() noexcept=default
Default construct (empty).
Trivial output stream for calculating byte counts.
static bool supports_gz() noexcept
True if compiled with libz support.
ofstreamPointer(const ofstreamPointer &)=delete
No copy construct.
void reopen(const std::string &pathname)
Reopen for compressed/non-compressed. Discards append status.
IOstreamOption::compressionType whichCompression() const
Which compression type?
void close(const std::string &pathname)
Close stream and rename file.
ofstreamPointer() noexcept
Default construct (empty).
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
messageStream Warning
Warning stream (stdout output on master, null elsewhere), with additional 'FOAM Warning' header text.
constexpr char nl
The newline '\n' character (0x0a).
autoPtr< OFstream > filePtr