Refactored type parsing.

This commit is contained in:
2016-05-31 01:06:57 +02:00
parent a989f5f86e
commit 85da5024ea
7 changed files with 128 additions and 57 deletions

View File

@@ -0,0 +1,27 @@
#ifndef __PLASP__PDDL__CONTEXT_H
#define __PLASP__PDDL__CONTEXT_H
#include <plasp/pddl/Type.h>
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Context
//
////////////////////////////////////////////////////////////////////////////////////////////////////
struct Context
{
TypeHashMap types;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@@ -32,6 +32,7 @@ class Description
void parseContent(utils::Parser &parser);
void parseSection(utils::Parser &parser);
Context m_context;
std::unique_ptr<Domain> m_domain;
//std::unique_ptr<Problem> m_problem;
};

View File

@@ -3,6 +3,7 @@
#include <unordered_map>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Requirement.h>
#include <plasp/pddl/Type.h>
#include <plasp/utils/Parser.h>
@@ -21,17 +22,15 @@ namespace pddl
class Domain
{
public:
static Domain fromPDDL(utils::Parser &parser);
using TypesHashMap = std::unordered_map<std::string, Type>;
static Domain fromPDDL(utils::Parser &parser, Context &context);
public:
const std::string &name() const;
const Requirement::Types &requirements() const;
const TypesHashMap &types() const;
const TypeHashMap &types() const;
private:
Domain() = default;
Domain(Context &context);
void parseSection(utils::Parser &parser);
@@ -43,9 +42,10 @@ class Domain
void checkConsistency();
Context &m_context;
std::string m_name;
Requirement::Types m_requirements;
TypesHashMap m_types;
};
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -3,6 +3,7 @@
#include <functional>
#include <string>
#include <unordered_map>
#include <vector>
#include <plasp/utils/Parser.h>
@@ -18,21 +19,30 @@ namespace pddl
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Context;
class Type;
using TypeHashMap = std::unordered_map<std::string, Type>;
////////////////////////////////////////////////////////////////////////////////////////////////////
class Type
{
public:
Type(std::string name);
static void parsePDDL(utils::Parser &parser, Context &context);
public:
void setDirty(bool isDirty = true);
bool isDirty() const;
const std::string &name() const;
void addParentType(const Type &parentType);
const std::vector<const Type *> &parentTypes() const;
private:
Type(std::string name);
void setDirty(bool isDirty = true);
bool isDirty() const;
void addParentType(const Type &parentType);
bool m_isDirty;
std::string m_name;