2019-05-25 14:15:20 +00:00
|
|
|
|
|
|
|
#ifndef PORYGONLANG_STRINGEVALVALUE_HPP
|
|
|
|
#define PORYGONLANG_STRINGEVALVALUE_HPP
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include "EvalValue.hpp"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
class StringEvalValue : public EvalValue{
|
|
|
|
string _value;
|
2019-06-09 18:15:09 +00:00
|
|
|
size_t _hash;
|
2019-06-01 17:20:31 +00:00
|
|
|
std::shared_ptr<ScriptType> _type;
|
2019-05-25 14:15:20 +00:00
|
|
|
public:
|
|
|
|
explicit StringEvalValue(string s){
|
|
|
|
_value = move(s);
|
2019-06-01 17:20:31 +00:00
|
|
|
_type = std::make_shared<ScriptType>(TypeClass::String);
|
2019-06-09 18:15:09 +00:00
|
|
|
_hash = std::hash<string>{}(_value);
|
2019-05-25 14:15:20 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 17:20:31 +00:00
|
|
|
std::shared_ptr<ScriptType> GetType() final{
|
2019-05-25 14:15:20 +00:00
|
|
|
return _type;
|
|
|
|
};
|
|
|
|
bool operator ==(EvalValue* b) final{
|
|
|
|
if (b->GetType()->GetClass() != TypeClass::String)
|
|
|
|
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-05 15:46:46 +00:00
|
|
|
string* EvaluateString() final{
|
|
|
|
return &_value;
|
2019-05-25 14:15:20 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 19:38:39 +00:00
|
|
|
shared_ptr<EvalValue> Clone() final{
|
|
|
|
return make_shared<StringEvalValue>(_value);
|
2019-05-30 13:23:48 +00:00
|
|
|
}
|
2019-06-06 15:35:51 +00:00
|
|
|
|
2019-06-09 18:15:09 +00:00
|
|
|
shared_ptr<EvalValue> IndexValue(EvalValue* val) 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-09 18:15:09 +00:00
|
|
|
return make_shared<StringEvalValue>(string(1, _value[l]));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t GetHashCode() final{
|
|
|
|
return _hash;
|
2019-06-06 15:35:51 +00:00
|
|
|
}
|
2019-05-25 14:15:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //PORYGONLANG_STRINGEVALVALUE_HPP
|