patrick
/
plasp
Archived
1
0
Fork 0
This repository has been archived on 2023-07-19. You can view files and clone it, but cannot push or open issues or pull requests.
plasp/lib/pddlparse/include/pddlparse/detail/ASTCopy.h

162 lines
5.4 KiB
C++

#ifndef __PDDL_PARSE__DETAIL__AST_COPY_H
#define __PDDL_PARSE__DETAIL__AST_COPY_H
#include <pddlparse/AST.h>
namespace pddl
{
namespace ast
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// ASTCopy
//
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
// Primitives
////////////////////////////////////////////////////////////////////////////////////////////////////
inline Constant deepCopy(Constant &other);
inline PrimitiveType deepCopy(PrimitiveType &other);
inline Variable deepCopy(Variable &other);
////////////////////////////////////////////////////////////////////////////////////////////////////
// Expressions: Base Classes
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Derived, class ArgumentLeft, class ArgumentRight = ArgumentLeft>
inline Binary<Derived, ArgumentLeft, ArgumentRight> deepCopy(Binary<Derived, ArgumentLeft, ArgumentRight> &other);
template<class Derived, class Argument>
inline NAry<Derived, Argument> deepCopy(NAry<Derived, Argument> &other);
template<class Derived, class Argument>
inline Quantified<Derived, Argument> deepCopy(Quantified<Derived, Argument> &other);
////////////////////////////////////////////////////////////////////////////////////////////////////
// Expressions
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Argument>
inline At<Argument> deepCopy(At<Argument> &other);
template<class Argument>
inline Not<Argument> deepCopy(Not<Argument> &other);
////////////////////////////////////////////////////////////////////////////////////////////////////
// Variants
////////////////////////////////////////////////////////////////////////////////////////////////////
inline ast::Term deepCopy(ast::Term &other);
////////////////////////////////////////////////////////////////////////////////////////////////////
// Primitives
////////////////////////////////////////////////////////////////////////////////////////////////////
Constant deepCopy(Constant &other)
{
return Constant(other.declaration);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
PrimitiveType deepCopy(PrimitiveType &other)
{
return PrimitiveType(other.declaration);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
Variable deepCopy(Variable &other)
{
return Variable(other.declaration);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Expressions: Base Classes
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Derived, class ArgumentLeft, class ArgumentRight>
Binary<Derived, ArgumentLeft, ArgumentRight> deepCopy(Binary<Derived, ArgumentLeft, ArgumentRight> &other)
{
auto argumentLeft = deepCopy(other.argumentLeft);
auto argumentRight = deepCopy(other.argumentRight);
return Binary<Derived, ArgumentLeft, ArgumentRight>(std::move(argumentLeft), std::move(argumentRight));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Derived, class Argument>
NAry<Derived, Argument> deepCopy(NAry<Derived, Argument> &other)
{
typename NAry<Derived, Argument>::Arguments arguments;
arguments.reserve(other.arguments.size());
for (auto &argument : other.arguments)
arguments.emplace_back(deepCopy(argument));
return NAry<Derived, Argument>(std::move(arguments));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Derived, class Argument>
Quantified<Derived, Argument> deepCopy(Quantified<Derived, Argument> &other)
{
auto argument = deepCopy(other.argument);
return Quantified<Derived, Argument>(std::move(argument));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Expressions
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Argument>
At<Argument> deepCopy(At<Argument> &other)
{
auto argument = deepCopy(other.argument);
return At<Argument>(other.timePoint, std::move(argument));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Argument>
Not<Argument> deepCopy(Not<Argument> &other)
{
auto argument = deepCopy(other.argument);
return Not<Argument>(std::move(argument));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Variants
////////////////////////////////////////////////////////////////////////////////////////////////////
struct DeepCopyVisitor
{
template<class Argument>
Argument visit(Argument &other)
{
return deepCopy(other);
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
// Unique Pointers
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class T>
std::unique_ptr<T> deepCopy(std::unique_ptr<T> &other)
{
return std::make_unique<T>(deepCopy(*other));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif