patrick
/
plasp
Archived
1
0
Fork 0

Removed obsolete Variable class.

This commit is contained in:
Patrick Lühne 2016-06-03 13:37:23 +02:00
parent 133aa051eb
commit 5abf1f8a84
7 changed files with 16 additions and 181 deletions

View File

@ -5,7 +5,6 @@
#include <boost/variant.hpp>
#include <plasp/pddl/Variable.h>
#include <plasp/utils/Parser.h>
namespace plasp

View File

@ -3,7 +3,7 @@
#include <boost/functional/hash.hpp>
#include <plasp/pddl/Variable.h>
#include <plasp/pddl/expressions/Variable.h>
#include <plasp/utils/Parser.h>
namespace plasp
@ -39,7 +39,7 @@ class Predicate
public:
const std::string &name() const;
const Variables &arguments() const;
const expressions::Variables &arguments() const;
bool isDeclared() const;
@ -51,7 +51,7 @@ class Predicate
bool m_isDeclared;
std::string m_name;
Variables m_arguments;
expressions::Variables m_arguments;
};
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -1,57 +0,0 @@
#ifndef __PLASP__PDDL__VARIABLE_H
#define __PLASP__PDDL__VARIABLE_H
#include <vector>
#include <plasp/pddl/Type.h>
#include <plasp/utils/Parser.h>
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Variable
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Context;
class Variable;
using Variables = std::vector<Variable>;
////////////////////////////////////////////////////////////////////////////////////////////////////
class Variable
{
public:
static Variable parse(utils::Parser &parser);
static void parseTyped(utils::Parser &parser, Context &context, std::vector<Variable> &variables);
public:
const std::string &name() const;
TypePtr type() const;
void setDirty(bool isDirty = true);
bool isDirty() const;
void setType(TypePtr type);
private:
Variable(std::string name);
bool m_isDirty;
std::string m_name;
TypePtr m_type;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@ -2,6 +2,7 @@
#define __PLASP__PDDL__EXPRESSION__VARIABLE_H
#include <plasp/pddl/Expression.h>
#include <plasp/pddl/Type.h>
namespace plasp
{

View File

@ -40,7 +40,7 @@ Predicate &Predicate::parseDeclaration(utils::Parser &parser, Context &context)
// Parse arguments
while (parser.currentCharacter() != ')')
{
Variable::parseTyped(parser, context, predicate->m_arguments);
expressions::Variable::parseTypedDeclaration(parser, context, predicate->m_arguments);
parser.skipWhiteSpace();
}
@ -82,7 +82,7 @@ const std::string &Predicate::name() const
////////////////////////////////////////////////////////////////////////////////////////////////////
const Variables &Predicate::arguments() const
const expressions::Variables &Predicate::arguments() const
{
return m_arguments;
}

View File

@ -1,108 +0,0 @@
#include <plasp/pddl/Variable.h>
#include <boost/assert.hpp>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Identifier.h>
#include <plasp/pddl/Type.h>
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Variable
//
////////////////////////////////////////////////////////////////////////////////////////////////////
Variable::Variable(std::string name)
: m_isDirty{false},
m_name(name)
{
}
////////////////////////////////////////////////////////////////////////////////////////////////////
Variable Variable::parse(utils::Parser &parser)
{
parser.skipWhiteSpace();
parser.expect<std::string>("?");
const auto variableName = parser.parseIdentifier(isIdentifier);
Variable variable(variableName);
variable.setDirty();
return variable;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Variable::parseTyped(utils::Parser &parser, Context &context, std::vector<Variable> &variables)
{
// Parse and store variable itself
variables.emplace_back(parse(parser));
parser.skipWhiteSpace();
// Check if the variable has a type declaration
if (!parser.advanceIf('-'))
return;
// Parse argument type
const auto type = parseType(parser, context);
// Set the argument type for all previously flagged arguments
std::for_each(variables.begin(), variables.end(),
[&](auto &variable)
{
if (!variable.isDirty())
return;
variable.setType(type);
variable.setDirty(false);
});
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Variable::setDirty(bool isDirty)
{
m_isDirty = isDirty;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
bool Variable::isDirty() const
{
return m_isDirty;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
const std::string &Variable::name() const
{
return m_name;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Variable::setType(TypePtr type)
{
m_type = type;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
TypePtr Variable::type() const
{
return m_type;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}

View File

@ -75,11 +75,11 @@ TEST_F(PDDLParserTests, ParseBlocksWorldDomain)
ASSERT_EQ(on.name(), "on");
ASSERT_EQ(on.arguments().size(), 2u);
ASSERT_EQ(on.arguments()[0].name(), "x");
const auto onArgument0Type = boost::get<const plasp::pddl::PrimitiveType *>(on.arguments()[0].type());
ASSERT_EQ(on.arguments()[0]->name(), "x");
const auto onArgument0Type = boost::get<const plasp::pddl::PrimitiveType *>(on.arguments()[0]->type());
ASSERT_EQ(onArgument0Type, &block);
ASSERT_EQ(on.arguments()[1].name(), "y");
const auto onArgument1Type = boost::get<const plasp::pddl::PrimitiveType *>(on.arguments()[1].type());
ASSERT_EQ(on.arguments()[1]->name(), "y");
const auto onArgument1Type = boost::get<const plasp::pddl::PrimitiveType *>(on.arguments()[1]->type());
ASSERT_EQ(onArgument1Type, &block);
const auto &handempty = *domain.predicates()[3];
@ -138,18 +138,18 @@ TEST_F(PDDLParserTests, ParseStorageDomain)
ASSERT_EQ(on.name(), "on");
ASSERT_EQ(on.arguments().size(), 2u);
ASSERT_EQ(on.arguments()[0].name(), "c");
const auto onArgument0Type = boost::get<const plasp::pddl::PrimitiveType *>(on.arguments()[0].type());
ASSERT_EQ(on.arguments()[0]->name(), "c");
const auto onArgument0Type = boost::get<const plasp::pddl::PrimitiveType *>(on.arguments()[0]->type());
ASSERT_EQ(onArgument0Type, &crate);
ASSERT_EQ(on.arguments()[1].name(), "s");
const auto onArgument1Type = boost::get<const plasp::pddl::PrimitiveType *>(on.arguments()[1].type());
ASSERT_EQ(on.arguments()[1]->name(), "s");
const auto onArgument1Type = boost::get<const plasp::pddl::PrimitiveType *>(on.arguments()[1]->type());
ASSERT_EQ(onArgument1Type, &storearea);
const auto &in = *domain.predicates()[1];
ASSERT_EQ(in.name(), "in");
ASSERT_EQ(in.arguments().size(), 2u);
ASSERT_EQ(in.arguments()[0].name(), "x");
const auto inArgument0Type = boost::get<const plasp::pddl::EitherType *>(in.arguments()[0].type());
ASSERT_EQ(in.arguments()[0]->name(), "x");
const auto inArgument0Type = boost::get<const plasp::pddl::EitherType *>(in.arguments()[0]->type());
ASSERT_EQ(inArgument0Type->allowedTypes().size(), 2u);
ASSERT_EQ(inArgument0Type->allowedTypes()[0], &storearea);
ASSERT_EQ(inArgument0Type->allowedTypes()[1], &crate);