start.hh: move check for nonexistent parameter file into parseParameterFile

now we don't have to pull in <fstream> in start.hh
This commit is contained in:
Arne Morten Kvarving
2024-09-05 13:30:54 +02:00
parent e56fc10b4c
commit 7726924cb1
3 changed files with 9 additions and 9 deletions

View File

@@ -559,10 +559,14 @@ void printUsage(const std::string& helpPreamble,
}
}
void parseParameterFile(const std::string& fileName, bool overwrite)
bool parseParameterFile(const std::string& fileName, bool overwrite)
{
std::set<std::string> seenKeys;
std::ifstream ifs(fileName);
if (!ifs.is_open()) {
return false;
}
unsigned curLineNum = 0;
while (ifs) {
// string and file processing in c++ is quite blunt!
@@ -624,6 +628,8 @@ void parseParameterFile(const std::string& fileName, bool overwrite)
MetaData::tree()[canonicalKey] = value;
}
}
return true;
}
std::string parseCommandLineOptions(int argc,

View File

@@ -146,7 +146,7 @@ parseCommandLineOptions(int argc,
*
* This function does some basic syntax checks.
*/
void parseParameterFile(const std::string& fileName, bool overwrite = true);
bool parseParameterFile(const std::string& fileName, bool overwrite = true);
/*!
* \ingroup Parameter

View File

@@ -44,7 +44,6 @@
#include <dune/fem/misc/mpimanager.hh>
#endif
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
@@ -145,9 +144,7 @@ static inline int setupParameters_(int argc,
////////////////////////////////////////////////////////////
// check whether the parameter file is readable.
std::ifstream tmp;
tmp.open(paramFileName.c_str());
if (!tmp.is_open()) {
if (!Parameters::parseParameterFile(paramFileName, /*overwrite=*/false)) {
std::ostringstream oss;
if (myRank == 0) {
oss << "Parameter file \"" << paramFileName
@@ -156,9 +153,6 @@ static inline int setupParameters_(int argc,
}
return /*status=*/1;
}
// read the parameter file.
Parameters::parseParameterFile(paramFileName, /*overwrite=*/false);
}
// make sure that no unknown parameters are encountered