File.h File Reference
#include <fstream>
#include "GeneralDefine.h"

Go to the source code of this file.

Classes

class  File
 

Enumerations

enum class  FileType : unsigned char { NO_FILE = 0 , ONE_FILE = 1 , MULTIPLE_FILES = 2 , MULTIPLE_FILES_PADDED = 3 }
 With FileType options, one is able to choose if data is to be read/written from/into no or single or multiple files. More...
 

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...
 

Variables

const unsigned NEVER = static_cast<const unsigned int>(-1)
 

Enumeration Type Documentation

◆ FileType

enum FileType : unsigned char
strong

With FileType options, one is able to choose if data is to be read/written from/into no or single or multiple files.

Enumerator
NO_FILE 

file will not be created/read

ONE_FILE 

all data will be written into/ read from a single file called name_

MULTIPLE_FILES 

each time-step will be written into/read from separate files numbered consecutively: name_.0, name_.1, .. so on

MULTIPLE_FILES_PADDED 

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, ..

19 {
23  NO_FILE = 0,
27  ONE_FILE = 1,
31  MULTIPLE_FILES = 2,
36 };
@ 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_

Function Documentation

◆ operator<<()

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 }
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>>()

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().

Variable Documentation

◆ NEVER