Started refactoring Types with variants.

This commit is contained in:
2016-06-01 01:29:46 +02:00
parent 2654a6ff23
commit ced1fd0038
6 changed files with 113 additions and 83 deletions

View File

@@ -1,12 +1,9 @@
#ifndef __PLASP__PDDL__TYPE_H
#define __PLASP__PDDL__TYPE_H
#include <functional>
#include <string>
#include <unordered_map>
#include <vector>
#include <boost/variant.hpp>
#include <plasp/utils/Parser.h>
#include <plasp/pddl/TypePrimitive.h>
namespace plasp
{
@@ -19,45 +16,11 @@ namespace pddl
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Context;
class Type;
using Type = boost::variant<TypePrimitive>;
using TypeHashMap = std::unordered_map<std::string, Type>;
////////////////////////////////////////////////////////////////////////////////////////////////////
class Type
{
public:
static Type &parse(utils::Parser &parser, Context &context);
static Type &parseDeclaration(utils::Parser &parser, Context &context);
public:
const std::string &name() const;
const std::vector<const Type *> &parentTypes() const;
bool isDeclared() const;
private:
Type(std::string name);
void setDirty(bool isDirty = true);
bool isDirty() const;
void setDeclared();
void addParentType(const Type &parentType);
bool m_isDirty;
bool m_isDeclared;
std::string m_name;
std::vector<const Type *> m_parentTypes;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}

View File

@@ -0,0 +1,61 @@
#ifndef __PLASP__PDDL__TYPE_PRIMITIVE_H
#define __PLASP__PDDL__TYPE_PRIMITIVE_H
#include <functional>
#include <string>
#include <unordered_map>
#include <vector>
#include <plasp/utils/Parser.h>
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// TypePrimitive
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Context;
////////////////////////////////////////////////////////////////////////////////////////////////////
class TypePrimitive
{
public:
static TypePrimitive &parse(utils::Parser &parser, Context &context);
static TypePrimitive &parseDeclaration(utils::Parser &parser, Context &context);
public:
const std::string &name() const;
const std::vector<const TypePrimitive *> &parentTypes() const;
bool isDeclared() const;
private:
TypePrimitive(std::string name);
void setDirty(bool isDirty = true);
bool isDirty() const;
void setDeclared();
void addParentType(const TypePrimitive &parentType);
bool m_isDirty;
bool m_isDeclared;
std::string m_name;
std::vector<const TypePrimitive *> m_parentTypes;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif