Moved parsing utilities to separate namespace.
This commit is contained in:
@@ -44,8 +44,6 @@ class Description
|
||||
|
||||
void parseSectionIdentifier(std::istream &istream, const std::string &expectedSectionIdentifier) const;
|
||||
|
||||
template<class T>
|
||||
T parse(std::istream &istream) const;
|
||||
const Variable &parseVariable(std::istream &istream) const;
|
||||
const Value &parseValue(std::istream &istream, const Variable &variable) const;
|
||||
AssignedVariable parseAssignedVariable(std::istream &istream) const;
|
||||
|
@@ -1,12 +1,12 @@
|
||||
#ifndef __SAS__PARSER_EXCEPTION_H
|
||||
#define __SAS__PARSER_EXCEPTION_H
|
||||
#ifndef __UTILS__PARSER_EXCEPTION_H
|
||||
#define __UTILS__PARSER_EXCEPTION_H
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace sas
|
||||
namespace utils
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
42
include/plasp/utils/Parsing.h
Normal file
42
include/plasp/utils/Parsing.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef __UTILS__PARSING_H
|
||||
#define __UTILS__PARSING_H
|
||||
|
||||
#include <exception>
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
#include <typeinfo>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace utils
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Parsing
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class T>
|
||||
T parse(std::istream &istream)
|
||||
{
|
||||
T value;
|
||||
|
||||
try
|
||||
{
|
||||
istream >> value;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
throw ParserException(std::string("Could not parse value of type ") + typeid(T).name() + " (" + e.what() + ")");
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user