MercuryDPM  Beta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
File.cc File Reference
#include "File.h"
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>

Go to the source code of this file.

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

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 72 of file File.cc.

References MULTIPLE_FILES, MULTIPLE_FILES_PADDED, NO_FILE, and ONE_FILE.

73 {
74  if (fileType == FileType::NO_FILE)
75  os << "NO_FILE";
76  else if (fileType == FileType::ONE_FILE)
77  os << "ONE_FILE";
78  else if (fileType == FileType::MULTIPLE_FILES)
79  os << "MULTIPLE_FILES";
80  else if (fileType == FileType::MULTIPLE_FILES_PADDED)
81  os << "MULTIPLE_FILES_PADDED";
82  else
83  {
84  std::cerr << "FileType not recognized" << std::endl;
85  exit(-1);
86  }
87  return os;
88 }
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::ostream& operator<< ( std::ostream &  os,
const File o 
)
Parameters
[in,out]os
[in]o
Returns
std::ostream& os

Definition at line 402 of file File.cc.

References File::write().

403 {
404  o.write(os);
405  return os;
406 }
void write(std::ostream &os) const
print function, which accepts an std::stringstream as input.
Definition: File.cc:386
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 95 of file File.cc.

References MULTIPLE_FILES, MULTIPLE_FILES_PADDED, NO_FILE, and ONE_FILE.

96 {
97  std::string fileTypeString;
98  is >> fileTypeString;
99  if (!fileTypeString.compare("NO_FILE"))
100  fileType = FileType::NO_FILE;
101  else if (!fileTypeString.compare("ONE_FILE"))
102  fileType = FileType::ONE_FILE;
103  else if (!fileTypeString.compare("MULTIPLE_FILES"))
104  fileType = FileType::MULTIPLE_FILES;
105  else if (!fileTypeString.compare("MULTIPLE_FILES_PADDED"))
107  else
108  {
109  std::cerr << "FileType not recognized" << std::endl;
110  exit(-1);
111  }
112  return is;
113 }
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,
File o 
)
Parameters
[in,out]is
[in]o
Returns
std::istream&

Definition at line 412 of file File.cc.

References File::read().

413 {
414  o.read(is);
415  return (is);
416 }
void read(std::istream &is)
read function, which accepts an input stream std::istream.
Definition: File.cc:370
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 60 of file File.cc.

Referenced by DPMBase::readNextArgument().

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