From 2d3760b7749428fb2b376cd73bfc24a3eac34d59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Fri, 20 May 2016 18:02:52 +0200 Subject: [PATCH] Implemented SAS parsing directly from streams. --- include/plasp/sas/Description.h | 2 ++ src/plasp/sas/Description.cpp | 39 +++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/include/plasp/sas/Description.h b/include/plasp/sas/Description.h index a525b56..67e2c37 100644 --- a/include/plasp/sas/Description.h +++ b/include/plasp/sas/Description.h @@ -1,6 +1,7 @@ #ifndef __SAS__DESCRIPTION_H #define __SAS__DESCRIPTION_H +#include #include #include @@ -24,6 +25,7 @@ namespace sas class Description { public: + static Description fromStream(std::istream &istream); static Description fromFile(const boost::filesystem::path &path); public: diff --git a/src/plasp/sas/Description.cpp b/src/plasp/sas/Description.cpp index 05ab86a..1961396 100644 --- a/src/plasp/sas/Description.cpp +++ b/src/plasp/sas/Description.cpp @@ -24,35 +24,40 @@ Description::Description() //////////////////////////////////////////////////////////////////////////////////////////////////// -Description Description::fromFile(const boost::filesystem::path &path) +Description Description::fromStream(std::istream &istream) { Description description; setlocale(LC_NUMERIC, "C"); - if (!boost::filesystem::is_regular_file(path)) - { - std::cerr << "Error: File does not exist: " << path.string() << std::endl; - return description; - } + istream.exceptions(std::ifstream::failbit | std::ifstream::badbit); - std::ifstream fileStream(path.string(), std::ios::in); - fileStream.exceptions(std::ifstream::failbit | std::ifstream::badbit); - - description.parseVersionSection(fileStream); - description.parseMetricSection(fileStream); - description.parseVariablesSection(fileStream); - description.parseMutexSection(fileStream); - description.parseInitialStateSection(fileStream); - description.parseGoalSection(fileStream); - description.parseOperatorSection(fileStream); - description.parseAxiomSection(fileStream); + description.parseVersionSection(istream); + description.parseMetricSection(istream); + description.parseVariablesSection(istream); + description.parseMutexSection(istream); + description.parseInitialStateSection(istream); + description.parseGoalSection(istream); + description.parseOperatorSection(istream); + description.parseAxiomSection(istream); 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 { // Metric section