diff --git a/include/plasp/sas/Operator.h b/include/plasp/sas/Operator.h index 1b6b0fb..b6f21b6 100644 --- a/include/plasp/sas/Operator.h +++ b/include/plasp/sas/Operator.h @@ -5,6 +5,7 @@ #include #include +#include #include namespace plasp @@ -24,7 +25,7 @@ struct Operator using Conditions = std::vector; using Effects = std::vector; - std::string name; + Predicate predicate; Conditions preconditions; Effects effects; size_t costs; diff --git a/include/plasp/sas/Predicate.h b/include/plasp/sas/Predicate.h new file mode 100644 index 0000000..91b4281 --- /dev/null +++ b/include/plasp/sas/Predicate.h @@ -0,0 +1,34 @@ +#ifndef __SAS__PREDICATE_H +#define __SAS__PREDICATE_H + +#include +#include +#include + +namespace plasp +{ +namespace sas +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Predicate +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +struct Predicate +{ + std::string name; + std::vector arguments; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +std::ostream &operator <<(std::ostream &ostream, const Predicate &predicate); + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +} + +#endif diff --git a/src/plasp/sas/Description.cpp b/src/plasp/sas/Description.cpp index 30560da..56c7287 100644 --- a/src/plasp/sas/Description.cpp +++ b/src/plasp/sas/Description.cpp @@ -2,6 +2,7 @@ #include #include +#include #include @@ -29,7 +30,7 @@ Description Description::fromStream(std::istream &istream) { Description description; - setlocale(LC_NUMERIC, "C"); + std::setlocale(LC_NUMERIC, "C"); istream.exceptions(std::ifstream::failbit | std::ifstream::badbit); @@ -170,7 +171,7 @@ void Description::print(std::ostream &ostream) const std::for_each(m_operators.cbegin(), m_operators.cend(), [&](const auto &operator_) { - ostream << "\t" << operator_.name << ":" << std::endl; + ostream << "\t" << operator_.predicate << ":" << std::endl; ostream << "\t\tpreconditions: " << operator_.preconditions.size() << std::endl; std::for_each(operator_.preconditions.cbegin(), operator_.preconditions.cend(), @@ -445,10 +446,30 @@ void Description::parseOperatorSection(std::istream &istream) { parseSectionIdentifier(istream, "begin_operator"); - istream.ignore(std::numeric_limits::max(), '\n'); - auto &operator_ = m_operators[i]; - std::getline(istream, operator_.name); + + try + { + istream.ignore(std::numeric_limits::max(), '\n'); + + // TODO: Inefficient, reimplement in one pass + std::string line; + std::getline(istream, line); + + std::stringstream lineStream(line); + + operator_.predicate.name = parse(lineStream); + + while (lineStream.peek() == ' ') + lineStream.ignore(1); + + for (std::string argument; std::getline(lineStream, argument, ' ');) + operator_.predicate.arguments.push_back(std::move(argument)); + } + catch (const std::exception &e) + { + throw ParserException("Could not parse operator predicate"); + } const auto numberOfPrevailConditions = parse(istream); operator_.preconditions.reserve(numberOfPrevailConditions); diff --git a/src/plasp/sas/Predicate.cpp b/src/plasp/sas/Predicate.cpp new file mode 100644 index 0000000..e142f69 --- /dev/null +++ b/src/plasp/sas/Predicate.cpp @@ -0,0 +1,34 @@ +#include + +#include + +namespace plasp +{ +namespace sas +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Predicate +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +std::ostream &operator <<(std::ostream &ostream, const Predicate &predicate) +{ + ostream << predicate.name << "("; + + for (size_t i = 0; i < predicate.arguments.size(); i++) + { + if (i > 0) + ostream << ", "; + + ostream << predicate.arguments[i]; + } + + return (ostream << ")"); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +}