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-06-01 17:20:31 +00:00
|
|
|
#include <memory>
|
2019-05-24 17:14:30 +00:00
|
|
|
|
|
|
|
class EvalValue{
|
|
|
|
public:
|
2019-05-30 13:23:48 +00:00
|
|
|
EvalValue() = default;
|
2019-05-24 17:14:30 +00:00
|
|
|
virtual ~EvalValue() = default;
|
2019-06-17 15:43:54 +00:00
|
|
|
virtual const TypeClass GetTypeClass() const = 0;
|
2019-05-24 17:14:30 +00:00
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
virtual const bool operator ==(EvalValue* b) const = 0;
|
2019-05-25 11:57:43 +00:00
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
virtual const bool operator !=(EvalValue*b) const{
|
2019-05-25 11:57:43 +00:00
|
|
|
return ! (this->operator==(b));
|
|
|
|
}
|
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
virtual const shared_ptr<EvalValue> Clone() const = 0;
|
2019-05-30 13:23:48 +00:00
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
virtual const long EvaluateInteger() const{
|
2019-05-24 17:14:30 +00:00
|
|
|
throw EvaluationException("Can't evaluate this EvalValue as integer.");
|
|
|
|
}
|
2019-06-17 15:43:54 +00:00
|
|
|
virtual const double EvaluateFloat() const{
|
2019-05-24 17:14:30 +00:00
|
|
|
throw EvaluationException("Can't evaluate this EvalValue as float.");
|
|
|
|
}
|
2019-06-17 15:43:54 +00:00
|
|
|
virtual const bool EvaluateBool() const{
|
2019-05-24 17:14:30 +00:00
|
|
|
throw EvaluationException("Can't evaluate this EvalValue as bool.");
|
|
|
|
}
|
2019-06-15 15:20:27 +00:00
|
|
|
virtual const std::u16string* EvaluateString() const {
|
2019-05-24 17:14:30 +00:00
|
|
|
throw EvaluationException("Can't evaluate this EvalValue as string.");
|
|
|
|
}
|
2019-06-06 15:35:51 +00:00
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
virtual const std::size_t GetHashCode() const = 0;
|
2019-06-09 18:15:09 +00:00
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
virtual const shared_ptr<EvalValue> IndexValue(EvalValue* val) const{
|
2019-06-06 15:35:51 +00:00
|
|
|
throw EvaluationException("Can't index this EvalValue");
|
|
|
|
}
|
2019-06-14 15:12:27 +00:00
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
virtual const shared_ptr<EvalValue> IndexValue(uint32_t hash) const{
|
2019-06-17 13:45:33 +00:00
|
|
|
throw EvaluationException("Can't index this EvalValue");
|
|
|
|
}
|
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
virtual void SetIndexValue(EvalValue *key, const shared_ptr<EvalValue>& value) const{
|
2019-06-14 15:12:27 +00:00
|
|
|
throw EvaluationException("Can't index this EvalValue");
|
|
|
|
}
|
2019-05-24 17:14:30 +00:00
|
|
|
};
|
|
|
|
|
2019-05-25 11:30:20 +00:00
|
|
|
class BooleanEvalValue : public EvalValue{
|
2019-06-13 14:26:10 +00:00
|
|
|
const bool _value;
|
2019-05-25 11:30:20 +00:00
|
|
|
public:
|
2019-06-13 14:26:10 +00:00
|
|
|
explicit BooleanEvalValue(bool val)
|
|
|
|
: _value(val)
|
|
|
|
{
|
2019-05-25 11:30:20 +00:00
|
|
|
}
|
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
const shared_ptr<EvalValue> Clone() const final{
|
2019-06-01 19:38:39 +00:00
|
|
|
return make_shared<BooleanEvalValue>(_value);
|
2019-05-30 13:23:48 +00:00
|
|
|
}
|
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
const TypeClass GetTypeClass() const final{
|
2019-06-13 14:26:10 +00:00
|
|
|
return TypeClass ::Bool;
|
|
|
|
}
|
2019-05-25 11:30:20 +00:00
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
const bool EvaluateBool() const final{
|
2019-05-25 11:30:20 +00:00
|
|
|
return _value;
|
|
|
|
}
|
2019-05-25 11:57:43 +00:00
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
const bool operator ==(EvalValue* b) const final{
|
2019-06-13 14:26:10 +00:00
|
|
|
if (b->GetTypeClass() != TypeClass::Bool)
|
2019-05-25 11:57:43 +00:00
|
|
|
return false;
|
|
|
|
return this->EvaluateBool() == b->EvaluateBool();
|
|
|
|
};
|
2019-06-09 18:15:09 +00:00
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
const std::size_t GetHashCode() const final{
|
2019-06-09 18:15:09 +00:00
|
|
|
return _value;
|
|
|
|
}
|
2019-05-25 11:30:20 +00:00
|
|
|
};
|
|
|
|
|
2019-05-24 17:14:30 +00:00
|
|
|
#endif //PORYGONLANG_EVALVALUE_HPP
|