63 std::ostringstream out;
64 out << std::setw(4) << std::setfill(
'0') << value;
80 os <<
"MULTIPLE_FILES";
82 os <<
"MULTIPLE_FILES_PADDED";
85 std::cerr <<
"FileType not recognized" << std::endl;
98 std::string fileTypeString;
100 if (!fileTypeString.compare(
"NO_FILE"))
102 else if (!fileTypeString.compare(
"ONE_FILE"))
104 else if (!fileTypeString.compare(
"MULTIPLE_FILES"))
106 else if (!fileTypeString.compare(
"MULTIPLE_FILES_PADDED"))
110 std::cerr <<
"FileType not recognized" << std::endl;
174 std::stringstream fullFileName(
"");
175 fullFileName <<
name_;
191 return fullFileName.str();
324 std::cerr <<
"Error: Name must be set before opening file" << std::endl;
345 std::cout <<
"open " <<
getFullName() << std::endl;
376 if (!dummy.compare(
"name"))
377 is >>
name_ >> dummy;
392 os <<
"name " <<
name_ <<
" ";
FileType fileType_
fileType_ indicates the type of the files. Whether it is No file, one file or multiple file as descri...
each time-step will be written into/read from separate files numbered consecutively, with numbers padded by zeros to a minimum of four digits: name_.0000, name_.0001, ..
FileType getFileType() const
Gets the file type e.g. NOFILE, ONEFILE and MULTIPLE FILES. File::fileType_.
std::fstream::openmode getOpenMode() const
Allows the user to know the file mode i.e. gets File::openMode_.
void read(std::istream &is)
read function, which accepts an input stream std::istream.
void setCounter(unsigned int counter)
Allows the user to set the file counter according to his need. Sets File::counter_.
const std::string getFullName() const
Also allows to access the file name, however with additional information which is the file counter...
unsigned int nextSavedTimeStep_
the time step at which the next write or read operation has to happen.
bool openNextFile()
This function should be called before a data corresponding to the new time step is written or read...
FileType
With FileType options, one is able to choose if data is to be read/written from/into no or single or ...
unsigned int counter_
counts the number of the next file to be opened; needed if multiple files are written/read ...
unsigned int getSaveCount() const
Gets File::saveCount_.
void close()
Closes the file by calling fstream_.close()
std::fstream::openmode openMode_
A variable to indicate how the file should be opened i.e. in, out, ... see http://en.cppreference.com (std::fstream::out by default)
unsigned int getCounter() const
In case of multiple files, File::getCounter() returns the the number (FILE::Counter_) of the next fil...
file will not be created/read
std::fstream & getFstream()
Allows to access the member variable File::fstream_.
void setNextSavedTimeStep(unsigned int nextSavedTimeStep)
Sets File::nextSavedTimeStep_.
all data will be written into/ read from a single file called name_
std::istream & operator>>(std::istream &is, FileType &fileType)
Reads the FileType from an input stream 'is'.
unsigned int getNextSavedTimeStep() const
Gets File::nextSavedTimeStep_.
unsigned int saveCount_
Allows one to define the number of timesteps to be skipped to make a snap shot. E.g. TMax = 100, saveCount_ = 10, timeStep = 1; It stores data at t={0,10,20,30,40...100}. And if TMax =101, it stores data at t={0,10,20,30,...100,101}.
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_.
void setFileType(FileType fileType)
Sets the type of file needed to write into or read from. File::fileType_.
std::string to_string_padded(unsigned int value)
Pads the number This function tries to pad the number to 4 digits, which is used when you create mult...
bool open()
Checks if the file stream fstream_ has any issues while opening. Alongside, it also increments the ne...
bool saveCurrentTimestep(unsigned int ntimeSteps)
bool compare(std::istream &is, std::string s)
std::string name_
name of the file.
virtual ~File()
destructor
each time-step will be written into/read from separate files numbered consecutively: name_...
std::ostream & operator<<(std::ostream &os, FileType fileType)
Writes the FileType as a human-readable string into the output stream 'os'.
void setName(const std::string &name)
Sets the file name, e.g. "Name.data".
void write(std::ostream &os) const
print function, which accepts an std::stringstream as input.
const std::string & getName() const
Allows to access the file name, e.g., "problem.data".
std::fstream fstream_
Stream object used to read/write data files.
void setOpenMode(std::fstream::openmode openMode)
Allows the user to Sets File::openMode_.