Implemented SAS parsing directly from streams.

This commit is contained in:
Patrick Lühne 2016-05-20 18:02:52 +02:00
parent e899bd7aec
commit 2d3760b774
2 changed files with 24 additions and 17 deletions

View File

@ -1,6 +1,7 @@
#ifndef __SAS__DESCRIPTION_H #ifndef __SAS__DESCRIPTION_H
#define __SAS__DESCRIPTION_H #define __SAS__DESCRIPTION_H
#include <iosfwd>
#include <vector> #include <vector>
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
@ -24,6 +25,7 @@ namespace sas
class Description class Description
{ {
public: public:
static Description fromStream(std::istream &istream);
static Description fromFile(const boost::filesystem::path &path); static Description fromFile(const boost::filesystem::path &path);
public: public:

View File

@ -24,35 +24,40 @@ Description::Description()
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
Description Description::fromFile(const boost::filesystem::path &path) Description Description::fromStream(std::istream &istream)
{ {
Description description; Description description;
setlocale(LC_NUMERIC, "C"); setlocale(LC_NUMERIC, "C");
if (!boost::filesystem::is_regular_file(path)) istream.exceptions(std::ifstream::failbit | std::ifstream::badbit);
{
std::cerr << "Error: File does not exist: " << path.string() << std::endl;
return description;
}
std::ifstream fileStream(path.string(), std::ios::in); description.parseVersionSection(istream);
fileStream.exceptions(std::ifstream::failbit | std::ifstream::badbit); description.parseMetricSection(istream);
description.parseVariablesSection(istream);
description.parseVersionSection(fileStream); description.parseMutexSection(istream);
description.parseMetricSection(fileStream); description.parseInitialStateSection(istream);
description.parseVariablesSection(fileStream); description.parseGoalSection(istream);
description.parseMutexSection(fileStream); description.parseOperatorSection(istream);
description.parseInitialStateSection(fileStream); description.parseAxiomSection(istream);
description.parseGoalSection(fileStream);
description.parseOperatorSection(fileStream);
description.parseAxiomSection(fileStream);
return description; return description;
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
Description Description::fromFile(const boost::filesystem::path &path)
{
if (!boost::filesystem::is_regular_file(path))
throw std::runtime_error("File does not exist: \"" + path.string() + "\"");
std::ifstream fileStream(path.string(), std::ios::in);
return Description::fromStream(fileStream);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Description::print(std::ostream &ostream) const void Description::print(std::ostream &ostream) const
{ {
// Metric section // Metric section