![]() |
fpmas 1.6
|
#include <output.h>
Public Member Functions | |
FileOutput () | |
FileOutput (std::string filename, std::ios::openmode mode=std::ios::out) | |
FileOutput (std::string file_format, int rank, std::ios::openmode mode=std::ios::out) | |
FileOutput (std::string file_format, api::scheduler::TimeStep step, std::ios::openmode mode=std::ios::out) | |
FileOutput (std::string file_format, int rank, api::scheduler::TimeStep step, std::ios::openmode mode=std::ios::out) | |
std::ofstream & | get () override |
![]() | |
virtual std::ostream & | get ()=0 |
std::ostream & | operator<< (std::ostream &(*func)(std::ostream &)) |
An helper class that can be used to initialize a file output stream.
This class is notably useful to extend output classes that take an output stream as constructor parameter, such as CsvOutput.
For example, the following code is wrong and will produce a segmentation fault:
Indeed, the CsvOutput constructor uses the specified output stream (to automatically write CSV headers), BUT CsvOutput, as a base class of MyOutput
, is initialized before MyOutput
, so before file
, what produces a segmentation fault.
This FileOutput class can be used to easily solve the issue:
In this case, FileOutput is properly initialized before CsvOutput so no error occurs.
|
inline |
Default constructor.
The underlying file is left in an undefined state.
fpmas::io::FileOutput::FileOutput | ( | std::string | filename, |
std::ios::openmode | mode = std::ios::out |
||
) |
FileOutput constructor.
The underlying file is opened only when get() is called.
filename | file name |
mode | standard open mode |
fpmas::io::FileOutput::FileOutput | ( | std::string | file_format, |
int | rank, | ||
std::ios::openmode | mode = std::ios::out |
||
) |
FileOutput constructor.
file_format
is formatted using fpmas::utils::format(std::string, int) to produce a file name.
The underlying file is opened only when get() is called.
file_format | file name to format |
rank | rank of the current process |
mode | standard open mode |
fpmas::io::FileOutput::FileOutput | ( | std::string | file_format, |
api::scheduler::TimeStep | step, | ||
std::ios::openmode | mode = std::ios::out |
||
) |
FileOutput constructor.
file_format
is formatted using fpmas::utils::format(std::string, fpmas::api::scheduler::TimeStep) to produce a file name.
The underlying file is opened only when get() is called.
file_format | file name to format |
step | current time step |
mode | standard open mode |
fpmas::io::FileOutput::FileOutput | ( | std::string | file_format, |
int | rank, | ||
api::scheduler::TimeStep | step, | ||
std::ios::openmode | mode = std::ios::out |
||
) |
FileOutput constructor.
file_format
is formatted using fpmas::utils::format(std::string, int, fpmas::api::scheduler::TimeStep) to produce a file name.
The underlying file is opened only when get() is called.
file_format | file name to format |
rank | rank of the current process |
step | current time step |
mode | standard open mode |
|
overridevirtual |
Returns a reference to the internal file output stream, that can be used to output data using the classical C++ <<
operator.
The file is open once, the first time this get() method is called.
This allows the FileOutput object to be declared on all processes, while being opened only on one process, assuming only one process is writing to the file, preventing other processes to delete the file content when it is opened if the current openmode is out
.
Implements fpmas::api::io::OutputStream.