diff --git a/include/plasp/pddl/Domain.h b/include/plasp/pddl/Domain.h index 7f4eb46..d9261ca 100644 --- a/include/plasp/pddl/Domain.h +++ b/include/plasp/pddl/Domain.h @@ -33,6 +33,7 @@ class Domain const Requirements &requirements() const; bool hasRequirement(Requirement::Type requirementType) const; + void checkRequirement(Requirement::Type requirementType) const; expressions::PrimitiveTypes &types(); const expressions::PrimitiveTypes &types() const; diff --git a/include/plasp/pddl/Problem.h b/include/plasp/pddl/Problem.h index 4ffb2ce..c360b5b 100644 --- a/include/plasp/pddl/Problem.h +++ b/include/plasp/pddl/Problem.h @@ -32,6 +32,7 @@ class Problem const Requirements &requirements() const; bool hasRequirement(Requirement::Type requirementType) const; + void checkRequirement(Requirement::Type requirementType) const; expressions::Constants &objects(); const expressions::Constants &objects() const; diff --git a/include/plasp/pddl/Requirement.h b/include/plasp/pddl/Requirement.h index 45106ab..266b5ba 100644 --- a/include/plasp/pddl/Requirement.h +++ b/include/plasp/pddl/Requirement.h @@ -56,8 +56,8 @@ class Requirement Type type() const; - void printAsPDDL(std::ostream &ostream) const; - void printAsASP(std::ostream &ostream) const; + std::string toPDDL() const; + std::string toASP() const; private: Type m_type; diff --git a/src/plasp/pddl/Domain.cpp b/src/plasp/pddl/Domain.cpp index d6e1e7e..d351e39 100644 --- a/src/plasp/pddl/Domain.cpp +++ b/src/plasp/pddl/Domain.cpp @@ -206,6 +206,16 @@ bool Domain::hasRequirement(Requirement::Type requirementType) const //////////////////////////////////////////////////////////////////////////////////////////////////// +void Domain::checkRequirement(Requirement::Type requirementType) const +{ + if (hasRequirement(requirementType)) + return; + + throw ConsistencyException("Requirement \"" + Requirement(requirementType).toPDDL() + "\" used but never declared"); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + void Domain::computeDerivedRequirements() { const auto addRequirementUnique = diff --git a/src/plasp/pddl/Problem.cpp b/src/plasp/pddl/Problem.cpp index c0b0d65..632c099 100644 --- a/src/plasp/pddl/Problem.cpp +++ b/src/plasp/pddl/Problem.cpp @@ -190,6 +190,18 @@ bool Problem::hasRequirement(Requirement::Type requirementType) const //////////////////////////////////////////////////////////////////////////////////////////////////// +void Problem::checkRequirement(Requirement::Type requirementType) const +{ + m_domain.checkRequirement(requirementType); + + if (hasRequirement(requirementType)) + return; + + throw ConsistencyException("Requirement \"" + Requirement(requirementType).toPDDL() + "\" used but never declared"); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + void Problem::computeDerivedRequirements() { const auto addRequirementUnique = diff --git a/src/plasp/pddl/Requirement.cpp b/src/plasp/pddl/Requirement.cpp index 451ee0f..38f94c9 100644 --- a/src/plasp/pddl/Requirement.cpp +++ b/src/plasp/pddl/Requirement.cpp @@ -101,24 +101,24 @@ Requirement::Type Requirement::type() const //////////////////////////////////////////////////////////////////////////////////////////////////// -void Requirement::printAsPDDL(std::ostream &ostream) const +std::string Requirement::toPDDL() const { const auto match = requirementTypesToPDDL.left.find(m_type); BOOST_ASSERT(match != requirementTypesToPDDL.left.end()); - ostream << match->second; + return match->second; } //////////////////////////////////////////////////////////////////////////////////////////////////// -void Requirement::printAsASP(std::ostream &ostream) const +std::string Requirement::toASP() const { const auto match = requirementTypesToASP.left.find(m_type); BOOST_ASSERT(match != requirementTypesToASP.left.end()); - ostream << match->second; + return match->second; } ////////////////////////////////////////////////////////////////////////////////////////////////////