MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
File.h File Reference
#include <fstream>
#include <cstdlib>

Go to the source code of this file.

Classes

class  File
 

Enumerations

enum  FileType : unsigned char { FileType::NO_FILE = 0, FileType::ONE_FILE = 1, FileType::MULTIPLE_FILES = 2, FileType::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...
 

Enumeration Type Documentation

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

Definition at line 35 of file File.h.

35  : unsigned char
36 {
40  NO_FILE = 0,
44  ONE_FILE = 1,
48  MULTIPLE_FILES = 2,
53 };
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, ..
file will not be created/read
all data will be written into/ read from a single file called name_
each time-step will be written into/read from separate files numbered consecutively: name_...

Function Documentation

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

Definition at line 73 of file File.cc.

References MULTIPLE_FILES, MULTIPLE_FILES_PADDED, NO_FILE, and ONE_FILE.

74 {
75  if (fileType == FileType::NO_FILE)
76  os << "NO_FILE";
77  else if (fileType == FileType::ONE_FILE)
78  os << "ONE_FILE";
79  else if (fileType == FileType::MULTIPLE_FILES)
80  os << "MULTIPLE_FILES";
81  else if (fileType == FileType::MULTIPLE_FILES_PADDED)
82  os << "MULTIPLE_FILES_PADDED";
83  else
84  {
85  std::cerr << "FileType not recognized" << std::endl;
86  exit(-1);
87  }
88  return os;
89 }
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, ..
file will not be created/read
all data will be written into/ read from a single file called name_
each time-step will be written into/read from separate files numbered consecutively: name_...
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)

Definition at line 96 of file File.cc.

References MULTIPLE_FILES, MULTIPLE_FILES_PADDED, NO_FILE, and ONE_FILE.

97 {
98  std::string fileTypeString;
99  is >> fileTypeString;
100  if (!fileTypeString.compare("NO_FILE"))
101  fileType = FileType::NO_FILE;
102  else if (!fileTypeString.compare("ONE_FILE"))
103  fileType = FileType::ONE_FILE;
104  else if (!fileTypeString.compare("MULTIPLE_FILES"))
105  fileType = FileType::MULTIPLE_FILES;
106  else if (!fileTypeString.compare("MULTIPLE_FILES_PADDED"))
108  else
109  {
110  std::cerr << "FileType not recognized" << std::endl;
111  exit(-1);
112  }
113  return is;
114 }
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, ..
file will not be created/read
all data will be written into/ read from a single file called name_
each time-step will be written into/read from separate files numbered consecutively: name_...
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.

Todo:
TW: I am not able to define the operator >> for enum class type (the implementation works fine for the old enum)
Parameters
valueThe value to modify
Returns
A padded string

Definition at line 61 of file File.cc.

Referenced by DPMBase::readNextArgument().

62 {
63  std::ostringstream out;
64  out << std::setw(4) << std::setfill('0') << value;
65  return out.str();
66 }