Implemented common function for parsing expected values.
This commit is contained in:
@@ -42,8 +42,6 @@ class Description
|
||||
private:
|
||||
Description();
|
||||
|
||||
void parseSectionIdentifier(std::istream &istream, const std::string &expectedSectionIdentifier) const;
|
||||
|
||||
const Variable &parseVariable(std::istream &istream) const;
|
||||
const Value &parseValue(std::istream &istream, const Variable &variable) const;
|
||||
AssignedVariable parseAssignedVariable(std::istream &istream) const;
|
||||
|
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <exception>
|
||||
#include <iosfwd>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <typeinfo>
|
||||
|
||||
@@ -38,6 +39,23 @@ T parse(std::istream &istream)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class T>
|
||||
void parseExpected(std::istream &istream, const T &expectedValue)
|
||||
{
|
||||
const auto value = parse<T>(istream);
|
||||
|
||||
if (value == expectedValue)
|
||||
return;
|
||||
|
||||
std::stringstream errorStream;
|
||||
|
||||
errorStream << "Invalid format, expected " << expectedValue << ", got " + value;
|
||||
|
||||
throw utils::ParserException(errorStream.str());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user