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;
|
|
|
|
|
|
|
|
class StringEvalValue : public EvalValue{
|
2019-06-15 15:20:27 +00:00
|
|
|
u16string _value;
|
2019-06-09 18:15:09 +00:00
|
|
|
size_t _hash;
|
2019-05-25 14:15:20 +00:00
|
|
|
public:
|
2019-06-15 15:20:27 +00:00
|
|
|
explicit StringEvalValue(u16string s){
|
2019-05-25 14:15:20 +00:00
|
|
|
_value = move(s);
|
2019-06-12 13:19:28 +00:00
|
|
|
_hash = HashedString::ConstHash (_value.c_str());
|
2019-05-25 14:15:20 +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 ::String;
|
|
|
|
}
|
|
|
|
|
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::String)
|
2019-05-25 14:15:20 +00:00
|
|
|
return false;
|
2019-06-09 18:15:09 +00:00
|
|
|
return this->_hash == b->GetHashCode();
|
2019-05-25 14:15:20 +00:00
|
|
|
};
|
|
|
|
|
2019-06-15 15:20:27 +00:00
|
|
|
const u16string* EvaluateString() const final{
|
2019-06-05 15:46:46 +00:00
|
|
|
return &_value;
|
2019-05-25 14:15: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<StringEvalValue>(_value);
|
2019-05-30 13:23:48 +00:00
|
|
|
}
|
2019-06-06 15:35:51 +00:00
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
const shared_ptr<EvalValue> IndexValue(EvalValue* val) const final{
|
2019-06-06 15:35:51 +00:00
|
|
|
// Porygon is 1-indexed, so we convert to that.
|
|
|
|
auto l = val->EvaluateInteger() - 1;
|
2019-06-15 15:20:27 +00:00
|
|
|
return make_shared<StringEvalValue>(u16string(1, _value[l]));
|
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 _hash;
|
2019-06-06 15:35:51 +00:00
|
|
|
}
|
2019-05-25 14:15:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //PORYGONLANG_STRINGEVALVALUE_HPP
|