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
441 {
442  o.write(os);
443  return os;
444 }
void write(std::ostream &os) const
print function, which accepts an std::stringstream as input.
Definition: File.cc:420

◆ 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
35 {
36  if (fileType == FileType::NO_FILE)
37  os << "NO_FILE";
38  else if (fileType == FileType::ONE_FILE)
39  os << "ONE_FILE";
40  else if (fileType == FileType::MULTIPLE_FILES)
41  os << "MULTIPLE_FILES";
42  else if (fileType == FileType::MULTIPLE_FILES_PADDED)
43  os << "MULTIPLE_FILES_PADDED";
44  else
45  {
46  logger(ERROR, "FileType not recognized");
47  }
48  return os;
49 }
@ 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:32

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&
452 {
453  o.read(is);
454  return (is);
455 }
void read(std::istream &is)
read function, which accepts an input stream std::istream.
Definition: File.cc:395

◆ 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)
57 {
58  std::string fileTypeString;
59  is >> fileTypeString;
60  if (!fileTypeString.compare("NO_FILE"))
61  fileType = FileType::NO_FILE;
62  else if (!fileTypeString.compare("ONE_FILE"))
63  fileType = FileType::ONE_FILE;
64  else if (!fileTypeString.compare("MULTIPLE_FILES"))
65  fileType = FileType::MULTIPLE_FILES;
66  else if (!fileTypeString.compare("MULTIPLE_FILES_PADDED"))
68  else
69  {
70  logger(ERROR, "operator>>: FileType % not recognized", fileTypeString);
71  }
72  return is;
73 }
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286

References ERROR, logger, MULTIPLE_FILES, MULTIPLE_FILES_PADDED, NO_FILE, ONE_FILE, and oomph::Global_string_for_annotation::string().

◆ 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
23 {
24  std::ostringstream out;
25  out << std::setw(4) << std::setfill('0') << value;
26  return out.str();
27 }
squared absolute value
Definition: GlobalFunctions.h:87
std::ofstream out("Result.txt")

References out(), and Eigen::value.

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