2016-05-20 15:29:24 +02:00
|
|
|
#include <plasp/sas/Value.h>
|
|
|
|
|
2016-05-21 01:17:17 +02:00
|
|
|
#include <iostream>
|
|
|
|
|
2016-05-21 16:22:40 +02:00
|
|
|
#include <plasp/utils/Parsing.h>
|
|
|
|
|
2016-05-20 15:29:24 +02:00
|
|
|
namespace plasp
|
|
|
|
{
|
|
|
|
namespace sas
|
|
|
|
{
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Value
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-05-21 16:22:40 +02:00
|
|
|
const Value Value::any()
|
|
|
|
{
|
|
|
|
Value any;
|
|
|
|
|
|
|
|
any.m_name = "(any)";
|
|
|
|
|
|
|
|
return any;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
const Value Value::Any = Value::any();
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
Value::Value()
|
|
|
|
: m_sign(Sign::Positive)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
Value Value::fromSAS(std::istream &istream)
|
|
|
|
{
|
|
|
|
Value value;
|
|
|
|
|
|
|
|
const auto sasSign = utils::parse<std::string>(istream);
|
|
|
|
|
|
|
|
if (sasSign == "Atom")
|
|
|
|
value.m_sign = Value::Sign::Positive;
|
|
|
|
else if (sasSign == "NegatedAtom")
|
|
|
|
value.m_sign = Value::Sign::Negative;
|
|
|
|
else
|
|
|
|
throw utils::ParserException("Invalid value sign \"" + sasSign + "\"");
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
istream.ignore(1);
|
|
|
|
std::getline(istream, value.m_name);
|
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
|
|
|
throw utils::ParserException(std::string("Could not parse variable value (") + e.what() + ")");
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
Value::Sign Value::sign() const
|
|
|
|
{
|
|
|
|
return m_sign;
|
|
|
|
}
|
2016-05-21 01:17:17 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-05-21 16:22:40 +02:00
|
|
|
const std::string &Value::name() const
|
2016-05-21 01:17:17 +02:00
|
|
|
{
|
2016-05-21 16:22:40 +02:00
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void Value::printAsASP(std::ostream &ostream) const
|
|
|
|
{
|
|
|
|
if (m_sign == Value::Sign::Negative)
|
2016-05-21 01:17:17 +02:00
|
|
|
ostream << "not ";
|
|
|
|
|
2016-05-21 16:22:40 +02:00
|
|
|
ostream << m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void Value::printAsSAS(std::ostream &ostream) const
|
|
|
|
{
|
|
|
|
if (m_sign == Value::Sign::Positive)
|
|
|
|
ostream << "Atom ";
|
|
|
|
else
|
|
|
|
ostream << "NegatedAtom ";
|
|
|
|
|
|
|
|
ostream << m_name;
|
2016-05-21 01:17:17 +02:00
|
|
|
}
|
2016-05-20 15:29:24 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|