Implemented common function for parsing expected values.

This commit is contained in:
2016-05-21 15:40:19 +02:00
parent aa351f0573
commit 20c2af5f7d
3 changed files with 34 additions and 28 deletions

View File

@@ -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;

View File

@@ -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());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}