26 #ifndef MERCURYDPM_FILEIO_HELPERS_H
27 #define MERCURYDPM_FILEIO_HELPERS_H
41 bool writeToFile(std::string filename, std::string filecontent);
51 bool addToFile(std::string filename, std::string filecontent);
61 bool openFile(std::fstream& file, std::string filename, std::fstream::openmode mode);
86 const auto pos = is.tellg();
121 T
readFromFile(
const std::string fileName,
const std::string varName,
const T defaultValue)
124 std::ifstream is(fileName.c_str(), std::ios::in);
127 logger(
INFO,
"readFromFile: file % could not be opened, variable % set to default value %",
128 fileName, varName, defaultValue);
141 logger(
INFO,
"readFromFile: variable % set to % ", varName, value);
147 logger(
WARN,
"readFromFile: variable % not set in file %, using default value % ", varName, fileName, defaultValue);
const unsigned n
Definition: CG3DPackingUnitTest.cpp:32
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:55
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
LL< Log::WARN > WARN
Warning log level.
Definition: Logger.cc:54
const unsigned unsignedMax
Definition: GeneralDefine.h:46
Definition: CommandLineHelpers.h:32
bool readOptionalVariable(std::istream &is, const std::string &name, T &variable)
Reads optional variables in the restart file.
Definition: FileIOHelpers.h:82
void writeCommandLineToFile(const std::string filename, const int argc, char *const argv[])
Writes a string to a file.
Definition: FileIOHelpers.cc:76
bool openFile(std::fstream &file, std::string filename, std::fstream::openmode mode)
Provides a simple interface for opening a file.
Definition: FileIOHelpers.cc:145
bool createDirectory(std::string)
Definition: FileIOHelpers.cc:203
bool addToFile(std::string filename, std::string filecontent)
Adds a string to an existing file.
Definition: FileIOHelpers.cc:89
void more(std::string filename, unsigned nLines=constants::unsignedMax)
Definition: FileIOHelpers.cc:181
std::string getPath()
Definition: FileIOHelpers.cc:224
std::vector< double > readArrayFromFile(std::string filename, int &n, int &m)
Definition: FileIOHelpers.cc:158
T readFromFile(const std::string fileName, const std::string varName, const T defaultValue)
Definition: FileIOHelpers.h:121
bool writeToFile(std::string filename, std::string filecontent)
Writes a string to a file.
Definition: FileIOHelpers.cc:58
bool fileExists(std::string strFilename)
Function to check if a file exists, is used to check if a run has already need done.
Definition: FileIOHelpers.cc:107
std::string name
Definition: MercuryProb.h:48