File.cc File Reference
#include "File.h"
#include <string>
#include <sstream>
#include <iostream>
#include <cmath>
#include <iomanip>
#include "Logger.h"

Functions

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 multiple files with padded numbers. Any numbers larger than 4 digits return unmodified. More...
 
std::ostream & operator<< (std::ostream &os, FileType fileType)
 Writes the FileType as a human-readable string into the output stream 'os'. More...
 
std::istream & operator>> (std::istream &is, FileType &fileType)
 Reads the FileType from an input stream 'is'. More...
 
std::ostream & operator<< (std::ostream &os, const File &o)
 
std::istream & operator>> (std::istream &is, File &o)
 

Function Documentation

◆ operator<<() [1/2]

std::ostream& operator<< ( std::ostream &  os,
const File o 
)
Parameters
[in,out]os
[in]o
Returns
std::ostream& os
463 {
464  o.write(os);
465  return os;
466 }
void write(std::ostream &os) const
print function, which accepts an std::stringstream as input.
Definition: File.cc:442

◆ operator<<() [2/2]

std::ostream& operator<< ( std::ostream &  os,
FileType  fileType 
)

Writes the FileType as a human-readable string into the output stream 'os'.

Parameters
[in,out]osoutput stream to which the fileType is written
[in]fileTypethe fileType that has to be written to the output stream
Returns
the output stream "os" that is returned after adding the fileType string
57 {
58  if (fileType == FileType::NO_FILE)
59  os << "NO_FILE";
60  else if (fileType == FileType::ONE_FILE)
61  os << "ONE_FILE";
62  else if (fileType == FileType::MULTIPLE_FILES)
63  os << "MULTIPLE_FILES";
64  else if (fileType == FileType::MULTIPLE_FILES_PADDED)
65  os << "MULTIPLE_FILES_PADDED";
66  else
67  {
68  logger(ERROR, "FileType not recognized");
69  }
70  return os;
71 }
@ MULTIPLE_FILES
each time-step will be written into/read from separate files numbered consecutively: name_....
@ MULTIPLE_FILES_PADDED
each time-step will be written into/read from separate files numbered consecutively,...
@ NO_FILE
file will not be created/read
@ ONE_FILE
all data will be written into/ read from a single file called name_
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
LL< Log::ERROR > ERROR
Error log level.
Definition: Logger.cc:53

References ERROR, logger, MULTIPLE_FILES, MULTIPLE_FILES_PADDED, NO_FILE, and ONE_FILE.

◆ operator>>() [1/2]

std::istream& operator>> ( std::istream &  is,
File o 
)
Parameters
[in,out]is
[in]o
Returns
std::istream&
474 {
475  o.read(is);
476  return (is);
477 }
void read(std::istream &is)
read function, which accepts an input stream std::istream.
Definition: File.cc:417

◆ operator>>() [2/2]

std::istream& operator>> ( std::istream &  is,
FileType fileType 
)

Reads the FileType from an input stream 'is'.

Parameters
[in,out]isThe input stream from which the fileType is read
[in]fileTypeThe fileType that has to be read from the input stream
Returns
the input stream "is" (that is returned after the fileType string is read out)
79 {
80  std::string fileTypeString;
81  is >> fileTypeString;
82  if (!fileTypeString.compare("NO_FILE"))
83  fileType = FileType::NO_FILE;
84  else if (!fileTypeString.compare("ONE_FILE"))
85  fileType = FileType::ONE_FILE;
86  else if (!fileTypeString.compare("MULTIPLE_FILES"))
87  fileType = FileType::MULTIPLE_FILES;
88  else if (!fileTypeString.compare("MULTIPLE_FILES_PADDED"))
90  else
91  {
92  logger(ERROR, "operator>>: FileType % not recognized", fileTypeString);
93  }
94  return is;
95 }

References ERROR, logger, MULTIPLE_FILES, MULTIPLE_FILES_PADDED, NO_FILE, and ONE_FILE.

◆ to_string_padded()

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 multiple files with padded numbers. Any numbers larger than 4 digits return unmodified.

Parameters
valueThe value to modify
Returns
A padded string
45 {
46  std::ostringstream out;
47  out << std::setw(4) << std::setfill('0') << value;
48  return out.str();
49 }

Referenced by File::getFullName(), and DPMBase::removeOldFiles().