Skip to content
Snippets Groups Projects
Commit 746d8959 authored by Jorrit Fahlke's avatar Jorrit Fahlke
Browse files

Allow parsing config files from a C++ stream, e.g. std::cin.

[[Imported from SVN: r5999]]
parent 724e5484
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,13 @@ void ConfigParser::parseFile(std::string file)
if (!in)
DUNE_THROW(IOError, "Could not open configuration file " << file);
parseStream(in, "file '" + file + "'");
}
void ConfigParser::parseStream(std::istream& in,
const std::string srcname)
{
string prefix;
set<string> keysInFile;
while(!in.eof())
......@@ -76,7 +83,8 @@ void ConfigParser::parseFile(std::string file)
}
if (keysInFile.count(key) != 0)
DUNE_THROW(Exception, "Key '" << key << "' appears twice in file '" << file << "' !");
DUNE_THROW(Exception, "Key '" << key <<
"' appears twice in " << srcname << " !");
else
{
(*this)[key] = value;
......@@ -87,7 +95,6 @@ void ConfigParser::parseFile(std::string file)
}
}
in.close();
return;
}
......
......@@ -4,6 +4,7 @@
#define DUNE_CONFIGPARSER_HH
#include <istream>
#include <map>
#include <vector>
#include <string>
......@@ -68,6 +69,18 @@ namespace Dune {
ConfigParser();
/** \brief parse C++ stream
*
* Parses C++ stream and build hierarchical config structure.
*
* \param in The stream to parse
* \param srcname Name of the configuration source for error
* messages, "stdin" or a filename.
*/
void parseStream(std::istream& in,
const std::string srcname = "stream");
/** \brief parse file
*
* Parses file with given name and build hierarchical config structure.
......
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