Skip to content
Snippets Groups Projects
Commit 0ca47c40 authored by williamfgc's avatar williamfgc Committed by GitHub
Browse files

Merge pull request #168 from williamfgc/xmlpermissive

Makes missing xml file permissive
parents 045c384b 52141202
No related branches found
No related tags found
1 merge request!170Release
...@@ -20,15 +20,13 @@ ...@@ -20,15 +20,13 @@
namespace adios2 namespace adios2
{ {
std::string FileToString(const std::string &fileName) std::string FileToString(const std::string &fileName) noexcept
{ {
std::ifstream fileStream(fileName); std::ifstream fileStream(fileName);
if (!fileStream) if (!fileStream)
{ {
throw std::invalid_argument( return std::string(); // empty string
"ERROR: file " + fileName +
" could not be opened. Check permissions or existence\n");
} }
std::ostringstream fileSS; std::ostringstream fileSS;
......
...@@ -27,7 +27,7 @@ namespace adios2 ...@@ -27,7 +27,7 @@ namespace adios2
* @param fileName of text file * @param fileName of text file
* @return file contents in a string * @return file contents in a string
*/ */
std::string FileToString(const std::string &fileName); std::string FileToString(const std::string &fileName) noexcept;
/** /**
* Transforms a vector to a map of parameters * Transforms a vector to a map of parameters
......
...@@ -196,11 +196,13 @@ Params GetTagAttributesXML(const std::string &tagHeader) ...@@ -196,11 +196,13 @@ Params GetTagAttributesXML(const std::string &tagHeader)
auto lf_GetAttributes = [&](const std::string &tag) -> Params { auto lf_GetAttributes = [&](const std::string &tag) -> Params {
Params attributes; Params attributes;
std::string currentTag(tag.substr(tag.find_first_of(" \t\n"))); std::string currentTag(tag.substr(tag.find_first_of(" \t\n")));
std::string::size_type currentPosition(0);
while (currentTag.find('=') != currentTag.npos) // equalPosition while (currentTag.find('=', currentPosition) !=
currentTag.npos) // equalPosition
{ {
currentTag = currentTag = currentTag.substr(
currentTag.substr(currentTag.find_first_not_of(" \t\n")); currentTag.find_first_not_of(" \t\n", currentPosition));
auto equalPosition = currentTag.find('='); auto equalPosition = currentTag.find('=');
if (currentTag.size() <= equalPosition + 1) if (currentTag.size() <= equalPosition + 1)
{ {
...@@ -210,20 +212,28 @@ Params GetTagAttributesXML(const std::string &tagHeader) ...@@ -210,20 +212,28 @@ Params GetTagAttributesXML(const std::string &tagHeader)
"in call to ADIOS constructor\n"); "in call to ADIOS constructor\n");
} }
const std::string key(currentTag.substr(0, equalPosition)); std::string key(currentTag.substr(0, equalPosition));
key.erase(key.find_last_not_of(" \t\n") + 1);
std::string value; std::string value;
const char quote = currentTag[equalPosition + 1]; auto quotePosition =
currentTag.find_first_not_of(" \t\n", equalPosition + 1);
const char quote = currentTag.at(quotePosition);
if (quote == '\'' || quote == '"') if (quote == '\'' || quote == '"')
{ {
value = lf_GetQuotedValue(quote, equalPosition + 1, currentTag); value = lf_GetQuotedValue(quote, quotePosition, currentTag);
} }
else else
{ {
// throw exception here? throw std::invalid_argument(
"ERROR: quote must be \" or ' in XML config tag " + tag +
", in call to ADIOS constructor");
} }
attributes.emplace(key, value); attributes.emplace(key, value);
currentPosition = quotePosition + value.size() + 1;
} }
return attributes; return attributes;
}; };
...@@ -262,6 +272,12 @@ void InitXML(const std::string configXML, const MPI_Comm mpiComm, ...@@ -262,6 +272,12 @@ void InitXML(const std::string configXML, const MPI_Comm mpiComm,
{ {
// independent IO // independent IO
std::string fileContents(FileToString(configXML)); std::string fileContents(FileToString(configXML));
if (fileContents.empty())
{
// issue a warning?
return;
}
RemoveCommentsXML(fileContents); RemoveCommentsXML(fileContents);
// adios-config // adios-config
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment