2019-05-24 17:14:30 +00:00
|
|
|
|
|
|
|
#ifndef PORYGONLANG_NUMERICEVALVALUE_HPP
|
|
|
|
#define PORYGONLANG_NUMERICEVALVALUE_HPP
|
|
|
|
|
2019-05-25 14:15:20 +00:00
|
|
|
#include <sstream>
|
2019-05-24 17:14:30 +00:00
|
|
|
#include "EvalValue.hpp"
|
2019-06-23 13:58:14 +00:00
|
|
|
#include "../../Utilities/StringUtils.hpp"
|
|
|
|
|
2019-06-17 16:35:12 +00:00
|
|
|
namespace Porygon::Evaluation {
|
|
|
|
class NumericEvalValue : public EvalValue {
|
2019-05-24 17:14:30 +00:00
|
|
|
|
2019-06-17 16:35:12 +00:00
|
|
|
virtual const long GetIntegerValue() const = 0;
|
|
|
|
|
|
|
|
virtual const double GetFloatValue() const = 0;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual const bool IsFloat() const = 0;
|
|
|
|
|
2019-07-04 17:08:13 +00:00
|
|
|
inline const TypeClass GetTypeClass() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return TypeClass::Number;
|
|
|
|
}
|
|
|
|
|
|
|
|
const shared_ptr<NumericEvalValue> operator+(const shared_ptr<NumericEvalValue> &b) const;
|
|
|
|
|
|
|
|
const shared_ptr<NumericEvalValue> operator-(const shared_ptr<NumericEvalValue> &b) const;
|
|
|
|
|
|
|
|
const shared_ptr<NumericEvalValue> operator*(const shared_ptr<NumericEvalValue> &b) const;
|
|
|
|
|
|
|
|
const shared_ptr<NumericEvalValue> operator/(const shared_ptr<NumericEvalValue> &b) const;
|
|
|
|
|
|
|
|
const shared_ptr<BooleanEvalValue> operator<(const shared_ptr<NumericEvalValue> &b) const;
|
|
|
|
|
|
|
|
const shared_ptr<BooleanEvalValue> operator<=(const shared_ptr<NumericEvalValue> &b) const;
|
|
|
|
|
|
|
|
const shared_ptr<BooleanEvalValue> operator>(const shared_ptr<NumericEvalValue> &b) const;
|
|
|
|
|
|
|
|
const shared_ptr<BooleanEvalValue> operator>=(const shared_ptr<NumericEvalValue> &b) const;
|
|
|
|
|
|
|
|
const bool operator==(EvalValue *b) const final;
|
|
|
|
};
|
|
|
|
|
|
|
|
class IntegerEvalValue : public NumericEvalValue {
|
|
|
|
const long _value;
|
|
|
|
|
|
|
|
const long GetIntegerValue() const final { return _value; }
|
|
|
|
|
|
|
|
const double GetFloatValue() const final {
|
|
|
|
throw EvaluationException("Attempting to retrieve float from int eval value.");
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit IntegerEvalValue(long value) : _value(value) {
|
|
|
|
}
|
|
|
|
|
2019-07-04 17:08:13 +00:00
|
|
|
inline const bool IsFloat() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-04 17:08:13 +00:00
|
|
|
inline const long EvaluateInteger() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
|
2019-07-04 17:08:13 +00:00
|
|
|
inline const std::u16string EvaluateString() const final{
|
2019-06-23 13:58:14 +00:00
|
|
|
return Utilities::StringUtils::IntToString(_value);
|
|
|
|
}
|
|
|
|
|
2019-07-04 17:08:13 +00:00
|
|
|
inline const shared_ptr<EvalValue> Clone() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return make_shared<IntegerEvalValue>(_value);
|
|
|
|
}
|
|
|
|
|
2019-07-04 17:08:13 +00:00
|
|
|
inline const std::size_t GetHashCode() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return std::hash<long>{}(_value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class FloatEvalValue : public NumericEvalValue {
|
|
|
|
const double _value;
|
|
|
|
|
2019-07-04 17:08:13 +00:00
|
|
|
inline const long GetIntegerValue() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
throw EvaluationException("Attempting to retrieve float from int eval value.");
|
|
|
|
}
|
|
|
|
|
2019-07-04 17:08:13 +00:00
|
|
|
inline const double GetFloatValue() const final {
|
|
|
|
return _value;
|
|
|
|
}
|
2019-06-17 16:35:12 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
explicit FloatEvalValue(double value) : _value(value) {
|
|
|
|
}
|
|
|
|
|
2019-07-04 17:08:13 +00:00
|
|
|
inline const bool IsFloat() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-04 17:08:13 +00:00
|
|
|
inline const double EvaluateFloat() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
|
2019-07-04 17:08:13 +00:00
|
|
|
inline const shared_ptr<EvalValue> Clone() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return make_shared<FloatEvalValue>(_value);
|
|
|
|
}
|
|
|
|
|
2019-07-04 17:08:13 +00:00
|
|
|
inline const std::size_t GetHashCode() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return std::hash<double>{}(_value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2019-05-24 17:14:30 +00:00
|
|
|
|
|
|
|
#endif //PORYGONLANG_NUMERICEVALVALUE_HPP
|