Implemented predicate parsing and refactored context storage.
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
#ifndef __PLASP__PDDL__CONTEXT_H
|
||||
#define __PLASP__PDDL__CONTEXT_H
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/pddl/Predicate.h>
|
||||
#include <plasp/pddl/Type.h>
|
||||
|
||||
@@ -18,8 +22,13 @@ namespace pddl
|
||||
class Context
|
||||
{
|
||||
public:
|
||||
TypeHashMap types;
|
||||
PredicateHashMap predicates;
|
||||
std::vector<std::unique_ptr<PrimitiveType>> primitiveTypes;
|
||||
std::unordered_map<std::string, PrimitiveType *> primitiveTypesHashMap;
|
||||
|
||||
std::vector<std::unique_ptr<EitherType>> eitherTypes;
|
||||
|
||||
std::vector<std::unique_ptr<Predicate>> predicates;
|
||||
std::unordered_map<PredicateHashMapKey, Predicate *> predicatesHashMap;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -28,8 +28,8 @@ class Domain
|
||||
public:
|
||||
const std::string &name() const;
|
||||
const Requirements &requirements() const;
|
||||
const TypeHashMap &types() const;
|
||||
const PredicateHashMap &predicates() const;
|
||||
const std::vector<std::unique_ptr<PrimitiveType>> &types() const;
|
||||
const std::vector<std::unique_ptr<Predicate>> &predicates() const;
|
||||
|
||||
private:
|
||||
Domain(Context &context);
|
||||
@@ -40,7 +40,7 @@ class Domain
|
||||
bool hasRequirement(Requirement::Type requirementType) const;
|
||||
void computeDerivedRequirements();
|
||||
|
||||
void parseTypingSection(utils::Parser &parser);
|
||||
void parseTypeSection(utils::Parser &parser);
|
||||
|
||||
void parsePredicateSection(utils::Parser &parser);
|
||||
|
||||
|
43
include/plasp/pddl/EitherType.h
Normal file
43
include/plasp/pddl/EitherType.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef __PLASP__PDDL__EITHER_TYPE_H
|
||||
#define __PLASP__PDDL__EITHER_TYPE_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/pddl/PrimitiveType.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// EitherType
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class EitherType
|
||||
{
|
||||
public:
|
||||
static EitherType &parse(utils::Parser &parser, Context &context);
|
||||
|
||||
public:
|
||||
const std::vector<const PrimitiveType *> &allowedTypes() const;
|
||||
|
||||
private:
|
||||
EitherType() = default;
|
||||
|
||||
std::vector<const PrimitiveType *> m_allowedTypes;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,7 +1,6 @@
|
||||
#ifndef __PLASP__PDDL__PREDICATE_H
|
||||
#define __PLASP__PDDL__PREDICATE_H
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
@@ -33,9 +32,6 @@ struct PredicateHashMapKey
|
||||
}
|
||||
};
|
||||
|
||||
class Predicate;
|
||||
using PredicateHashMap = std::unordered_map<PredicateHashMapKey, Predicate>;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Predicate
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#ifndef __PLASP__PDDL__TYPE_PRIMITIVE_H
|
||||
#define __PLASP__PDDL__TYPE_PRIMITIVE_H
|
||||
#ifndef __PLASP__PDDL__PRIMITIVE_TYPE_H
|
||||
#define __PLASP__PDDL__PRIMITIVE_TYPE_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -13,7 +13,7 @@ namespace pddl
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TypePrimitive
|
||||
// PrimitiveType
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -21,34 +21,34 @@ class Context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class TypePrimitive
|
||||
class PrimitiveType
|
||||
{
|
||||
public:
|
||||
static TypePrimitive &parse(utils::Parser &parser, Context &context);
|
||||
static TypePrimitive &parseDeclaration(utils::Parser &parser, Context &context);
|
||||
static PrimitiveType &parse(utils::Parser &parser, Context &context);
|
||||
static PrimitiveType &parseDeclaration(utils::Parser &parser, Context &context);
|
||||
|
||||
public:
|
||||
const std::string &name() const;
|
||||
const std::vector<const TypePrimitive *> &parentTypes() const;
|
||||
const std::vector<const PrimitiveType *> &parentTypes() const;
|
||||
|
||||
bool isDeclared() const;
|
||||
|
||||
private:
|
||||
TypePrimitive(std::string name);
|
||||
PrimitiveType(std::string name);
|
||||
|
||||
void setDirty(bool isDirty = true);
|
||||
bool isDirty() const;
|
||||
|
||||
void setDeclared();
|
||||
|
||||
void addParentType(const TypePrimitive &parentType);
|
||||
void addParentType(const PrimitiveType &parentType);
|
||||
|
||||
bool m_isDirty;
|
||||
bool m_isDeclared;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
std::vector<const TypePrimitive *> m_parentTypes;
|
||||
std::vector<const PrimitiveType *> m_parentTypes;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -1,11 +1,10 @@
|
||||
#ifndef __PLASP__PDDL__TYPE_H
|
||||
#define __PLASP__PDDL__TYPE_H
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include <boost/variant.hpp>
|
||||
|
||||
#include <plasp/pddl/TypePrimitive.h>
|
||||
#include <plasp/pddl/EitherType.h>
|
||||
#include <plasp/pddl/PrimitiveType.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -18,8 +17,7 @@ namespace pddl
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using Type = boost::variant<TypePrimitive>;
|
||||
using TypeHashMap = std::unordered_map<std::string, Type>;
|
||||
using TypePtr = boost::variant<const PrimitiveType *, const EitherType *>;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@@ -31,12 +31,12 @@ class Variable
|
||||
|
||||
public:
|
||||
const std::string &name() const;
|
||||
const Type &type() const;
|
||||
TypePtr type() const;
|
||||
|
||||
void setDirty(bool isDirty = true);
|
||||
bool isDirty() const;
|
||||
|
||||
void setType(const Type &type);
|
||||
void setType(TypePtr type);
|
||||
|
||||
private:
|
||||
Variable(std::string name);
|
||||
@@ -45,7 +45,7 @@ class Variable
|
||||
|
||||
std::string m_name;
|
||||
|
||||
const Type *m_type;
|
||||
TypePtr m_type;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
Reference in New Issue
Block a user