2019-05-25 14:15:20 +00:00
|
|
|
|
|
|
|
#ifndef PORYGONLANG_STRINGEVALVALUE_HPP
|
|
|
|
#define PORYGONLANG_STRINGEVALVALUE_HPP
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include "EvalValue.hpp"
|
2019-06-12 13:19:28 +00:00
|
|
|
#include "../../Utilities/HashedString.hpp"
|
2019-05-25 14:15:20 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2019-06-17 16:35:12 +00:00
|
|
|
namespace Porygon::Evaluation {
|
|
|
|
class StringEvalValue : public EvalValue {
|
|
|
|
u16string _value;
|
|
|
|
size_t _hash;
|
|
|
|
public:
|
2019-07-04 16:24:49 +00:00
|
|
|
explicit StringEvalValue(u16string s) : _value(move(s)){
|
2019-06-17 16:35:12 +00:00
|
|
|
_hash = Utilities::HashedString::ConstHash(_value.c_str());
|
|
|
|
}
|
|
|
|
|
2019-07-04 17:08:13 +00:00
|
|
|
inline const TypeClass GetTypeClass() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return TypeClass::String;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool operator==(EvalValue *b) const final {
|
|
|
|
if (b->GetTypeClass() != TypeClass::String)
|
|
|
|
return false;
|
|
|
|
return this->_hash == b->GetHashCode();
|
|
|
|
};
|
|
|
|
|
2019-07-04 17:08:13 +00:00
|
|
|
inline const u16string EvaluateString() const final {
|
2019-06-23 13:58:14 +00:00
|
|
|
return _value;
|
2019-06-17 16:35:12 +00:00
|
|
|
}
|
|
|
|
|
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<StringEvalValue>(_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
const shared_ptr<EvalValue> IndexValue(EvalValue *val) const final {
|
|
|
|
// Porygon is 1-indexed, so we convert to that.
|
|
|
|
auto l = val->EvaluateInteger() - 1;
|
|
|
|
return make_shared<StringEvalValue>(u16string(1, _value[l]));
|
|
|
|
}
|
|
|
|
|
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 _hash;
|
|
|
|
}
|
2019-05-25 14:15:20 +00:00
|
|
|
};
|
2019-06-17 16:35:12 +00:00
|
|
|
}
|
2019-05-25 14:15:20 +00:00
|
|
|
|
|
|
|
#endif //PORYGONLANG_STRINGEVALVALUE_HPP
|