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

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

Variables

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

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 40 of file File.h.

40  : unsigned char
41 {
45  NO_FILE = 0,
49  ONE_FILE = 1,
53  MULTIPLE_FILES = 2,
58 };
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 56 of file File.cc.

References MULTIPLE_FILES, MULTIPLE_FILES_PADDED, NO_FILE, and ONE_FILE.

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  std::cerr << "FileType not recognized" << std::endl;
69  exit(-1);
70  }
71  return os;
72 }
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 79 of file File.cc.

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

80 {
81  std::string fileTypeString;
82  is >> fileTypeString;
83  if (!fileTypeString.compare("NO_FILE"))
84  fileType = FileType::NO_FILE;
85  else if (!fileTypeString.compare("ONE_FILE"))
86  fileType = FileType::ONE_FILE;
87  else if (!fileTypeString.compare("MULTIPLE_FILES"))
88  fileType = FileType::MULTIPLE_FILES;
89  else if (!fileTypeString.compare("MULTIPLE_FILES_PADDED"))
91  else
92  {
93  logger(ERROR, "operator>>: FileType % not recognized", fileTypeString);
94  }
95  return is;
96 }
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, ..
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
LL< Log::ERROR > ERROR
Error log level.
Definition: Logger.cc:53
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.

Parameters
valueThe value to modify
Returns
A padded string

Definition at line 44 of file File.cc.

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

45 {
46  std::ostringstream out;
47  out << std::setw(4) << std::setfill('0') << value;
48  return out.str();
49 }

Variable Documentation

const unsigned NEVER = static_cast<const unsigned int>(-1)
Todo:
IFCD: can we make this an int instead of unsigned int, as -1 as an unsigned is not good style?

Definition at line 35 of file File.h.

Referenced by BaseCG::BaseCG(), File::File(), CGHandler::finish(), DPMBase::forceWriteOutputFiles(), File::read(), DPMBase::resetFileCounter(), File::saveCurrentTimeStepNoFileTypeCheck(), and File::writeFirstAndLastTimeStep().