Refactored Requirement to be a proper class.
This commit is contained in:
@@ -60,7 +60,7 @@ const std::string &Domain::name() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const Requirement::Types &Domain::requirements() const
|
||||
const Requirements &Domain::requirements() const
|
||||
{
|
||||
return m_requirements;
|
||||
}
|
||||
@@ -134,7 +134,7 @@ void Domain::parseRequirementsSection(utils::Parser &parser)
|
||||
if (parser.currentCharacter() == ':')
|
||||
parser.advance();
|
||||
|
||||
m_requirements.emplace_back(Requirement::fromPDDL(parser));
|
||||
m_requirements.emplace_back(Requirement::parse(parser));
|
||||
}
|
||||
|
||||
if (m_requirements.empty())
|
||||
@@ -145,9 +145,13 @@ void Domain::parseRequirementsSection(utils::Parser &parser)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Domain::hasRequirement(Requirement::Type requirement) const
|
||||
bool Domain::hasRequirement(Requirement::Type requirementType) const
|
||||
{
|
||||
const auto match = std::find(m_requirements.cbegin(), m_requirements.cend(), requirement);
|
||||
const auto match = std::find_if(m_requirements.cbegin(), m_requirements.cend(),
|
||||
[&](const auto &requirement)
|
||||
{
|
||||
return requirement.type() == requirementType;
|
||||
});
|
||||
|
||||
return match != m_requirements.cend();
|
||||
}
|
||||
@@ -162,7 +166,7 @@ void Domain::computeDerivedRequirements()
|
||||
if (hasRequirement(requirement))
|
||||
return;
|
||||
|
||||
m_requirements.push_back(requirement);
|
||||
m_requirements.push_back(Requirement(requirement));
|
||||
};
|
||||
|
||||
// If no requirements are specified, assume STRIPS
|
||||
@@ -220,7 +224,7 @@ void Domain::checkConsistency()
|
||||
{
|
||||
throw ConsistencyException("Domain contains typing information but does not declare typing requirement");
|
||||
|
||||
m_requirements.push_back(Requirement::Type::Typing);
|
||||
m_requirements.push_back(Requirement(Requirement::Type::Typing));
|
||||
}
|
||||
|
||||
// Verify that all used types have been declared
|
||||
|
@@ -72,7 +72,14 @@ const RequirementTypeNames requirementTypesToASP = boost::assign::list_of<Requir
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Requirement::Type Requirement::fromPDDL(utils::Parser &parser)
|
||||
Requirement::Requirement(Requirement::Type type)
|
||||
: m_type{type}
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Requirement Requirement::parse(utils::Parser &parser)
|
||||
{
|
||||
const auto requirementName = parser.parseIdentifier(isIdentifier);
|
||||
|
||||
@@ -81,14 +88,21 @@ Requirement::Type Requirement::fromPDDL(utils::Parser &parser)
|
||||
if (match == requirementTypesToPDDL.right.end())
|
||||
throw utils::ParserException(parser.row(), parser.column(), "Unknown PDDL requirement \"" + requirementName + "\"");
|
||||
|
||||
return match->second;
|
||||
return Requirement(match->second);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Requirement::toPDDL(std::ostream &ostream, Requirement::Type requirementType)
|
||||
Requirement::Type Requirement::type() const
|
||||
{
|
||||
const auto match = requirementTypesToPDDL.left.find(requirementType);
|
||||
return m_type;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Requirement::printAsPDDL(std::ostream &ostream) const
|
||||
{
|
||||
const auto match = requirementTypesToPDDL.left.find(m_type);
|
||||
|
||||
BOOST_ASSERT(match != requirementTypesToPDDL.left.end());
|
||||
|
||||
@@ -97,9 +111,9 @@ void Requirement::toPDDL(std::ostream &ostream, Requirement::Type requirementTyp
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Requirement::toASP(std::ostream &ostream, Requirement::Type requirementType)
|
||||
void Requirement::printAsASP(std::ostream &ostream) const
|
||||
{
|
||||
const auto match = requirementTypesToASP.left.find(requirementType);
|
||||
const auto match = requirementTypesToASP.left.find(m_type);
|
||||
|
||||
BOOST_ASSERT(match != requirementTypesToASP.left.end());
|
||||
|
||||
|
Reference in New Issue
Block a user