2019-06-14 12:59:38 +00:00
|
|
|
|
|
|
|
#ifndef PORYGONLANG_USERDATAVALUE_HPP
|
|
|
|
#define PORYGONLANG_USERDATAVALUE_HPP
|
|
|
|
|
2019-06-14 15:35:05 +00:00
|
|
|
#include <utility>
|
2019-06-14 12:59:38 +00:00
|
|
|
#include "../Evaluator/EvalValues/EvalValue.hpp"
|
|
|
|
#include "UserData.hpp"
|
|
|
|
#include "UserDataStorage.hpp"
|
|
|
|
|
|
|
|
class UserDataValue : public EvalValue{
|
2019-06-17 15:43:54 +00:00
|
|
|
const shared_ptr<UserData> _userData;
|
2019-06-14 12:59:38 +00:00
|
|
|
void* _obj;
|
|
|
|
public:
|
2019-06-17 15:43:54 +00:00
|
|
|
UserDataValue(shared_ptr<UserData> userData, void* obj)
|
|
|
|
: _userData(std::move(userData))
|
|
|
|
{
|
2019-06-14 12:59:38 +00:00
|
|
|
_obj = obj;
|
|
|
|
}
|
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
UserDataValue(uint32_t userDataId, void* obj)
|
|
|
|
: _userData(UserDataStorage::GetUserDataType(userDataId))
|
|
|
|
{
|
2019-06-14 12:59:38 +00:00
|
|
|
_obj = obj;
|
|
|
|
}
|
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
const TypeClass GetTypeClass() const final{
|
2019-06-14 12:59:38 +00:00
|
|
|
return TypeClass ::UserData;
|
|
|
|
}
|
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
const bool operator ==(EvalValue* b) const final {
|
2019-06-14 12:59:38 +00:00
|
|
|
if (b->GetTypeClass() != TypeClass::UserData)
|
|
|
|
return false;
|
|
|
|
return _obj == ((UserDataValue*)b)->_obj;
|
|
|
|
}
|
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
const shared_ptr<EvalValue> Clone() const final{
|
2019-06-14 12:59:38 +00:00
|
|
|
return make_shared<UserDataValue>(_userData, _obj);
|
|
|
|
}
|
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
const std::size_t GetHashCode() const final{
|
2019-06-14 12:59:38 +00:00
|
|
|
return reinterpret_cast<intptr_t>(_obj);
|
|
|
|
}
|
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
const shared_ptr<EvalValue> IndexValue(EvalValue* val) const final {
|
2019-06-14 12:59:38 +00:00
|
|
|
auto fieldId = val->GetHashCode();
|
|
|
|
auto field = _userData->GetField(fieldId);
|
|
|
|
return shared_ptr<EvalValue>(field->Get(_obj));
|
|
|
|
}
|
2019-06-14 15:12:27 +00:00
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
const shared_ptr<EvalValue> IndexValue(uint32_t hash) const final{
|
2019-06-17 13:45:33 +00:00
|
|
|
auto field = _userData->GetField(hash);
|
|
|
|
return shared_ptr<EvalValue>(field->Get(_obj));
|
|
|
|
}
|
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
void SetIndexValue(EvalValue *key, const shared_ptr<EvalValue>& value) const final{
|
2019-06-14 15:12:27 +00:00
|
|
|
auto fieldId = key->GetHashCode();
|
|
|
|
auto field = _userData->GetField(fieldId);
|
|
|
|
field -> Set(_obj, value.get());
|
|
|
|
}
|
2019-06-14 12:59:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //PORYGONLANG_USERDATAVALUE_HPP
|