2019-05-24 17:14:30 +00:00
|
|
|
|
|
|
|
#ifndef PORYGONLANG_EVALVALUE_HPP
|
|
|
|
#define PORYGONLANG_EVALVALUE_HPP
|
|
|
|
|
|
|
|
#include "../../ScriptType.hpp"
|
|
|
|
#include "../EvaluationException.hpp"
|
|
|
|
#include <string>
|
2019-05-25 14:15:20 +00:00
|
|
|
#include <sstream>
|
2019-05-24 17:14:30 +00:00
|
|
|
|
|
|
|
class EvalValue{
|
|
|
|
public:
|
|
|
|
virtual ~EvalValue() = default;
|
|
|
|
virtual ScriptType* GetType() = 0;
|
|
|
|
|
2019-05-25 11:57:43 +00:00
|
|
|
virtual bool operator ==(EvalValue* b) = 0;
|
|
|
|
|
|
|
|
virtual bool operator !=(EvalValue*b){
|
|
|
|
return ! (this->operator==(b));
|
|
|
|
}
|
|
|
|
|
2019-05-24 17:14:30 +00:00
|
|
|
virtual long EvaluateInteger(){
|
|
|
|
throw EvaluationException("Can't evaluate this EvalValue as integer.");
|
|
|
|
}
|
|
|
|
virtual double EvaluateFloat(){
|
|
|
|
throw EvaluationException("Can't evaluate this EvalValue as float.");
|
|
|
|
}
|
|
|
|
virtual bool EvaluateBool(){
|
|
|
|
throw EvaluationException("Can't evaluate this EvalValue as bool.");
|
|
|
|
}
|
|
|
|
virtual std::string EvaluateString(){
|
|
|
|
throw EvaluationException("Can't evaluate this EvalValue as string.");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-25 11:30:20 +00:00
|
|
|
class BooleanEvalValue : public EvalValue{
|
|
|
|
bool _value;
|
|
|
|
ScriptType* _type;
|
|
|
|
public:
|
|
|
|
explicit BooleanEvalValue(bool val){
|
|
|
|
_value = val;
|
|
|
|
_type = new ScriptType(TypeClass::Bool);
|
|
|
|
}
|
|
|
|
|
|
|
|
~BooleanEvalValue() final{
|
|
|
|
delete _type;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScriptType* GetType() final{
|
|
|
|
return _type;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool EvaluateBool() final{
|
|
|
|
return _value;
|
|
|
|
}
|
2019-05-25 11:57:43 +00:00
|
|
|
|
|
|
|
bool operator ==(EvalValue* b) final{
|
|
|
|
if (b->GetType()->GetClass() != TypeClass::Bool)
|
|
|
|
return false;
|
|
|
|
return this->EvaluateBool() == b->EvaluateBool();
|
|
|
|
};
|
2019-05-25 14:15:20 +00:00
|
|
|
|
|
|
|
std::string EvaluateString() final{
|
|
|
|
std::ostringstream strs;
|
|
|
|
strs << _value;
|
|
|
|
return strs.str();
|
|
|
|
}
|
2019-05-25 11:30:20 +00:00
|
|
|
};
|
|
|
|
|
2019-05-24 17:14:30 +00:00
|
|
|
#endif //PORYGONLANG_EVALVALUE_HPP
|