51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
|
|
||
|
#ifndef PORYGONLANG_USERDATAVALUE_HPP
|
||
|
#define PORYGONLANG_USERDATAVALUE_HPP
|
||
|
|
||
|
|
||
|
#include "../Evaluator/EvalValues/EvalValue.hpp"
|
||
|
#include "UserData.hpp"
|
||
|
#include "UserDataStorage.hpp"
|
||
|
|
||
|
class UserDataValue : public EvalValue{
|
||
|
UserData* _userData;
|
||
|
void* _obj;
|
||
|
public:
|
||
|
UserDataValue(UserData* userData, void* obj){
|
||
|
_userData = userData;
|
||
|
_obj = obj;
|
||
|
}
|
||
|
|
||
|
UserDataValue(int userDataId, void* obj){
|
||
|
_userData = UserDataStorage::GetUserDataType(userDataId);
|
||
|
_obj = obj;
|
||
|
}
|
||
|
|
||
|
const TypeClass GetTypeClass() final{
|
||
|
return TypeClass ::UserData;
|
||
|
}
|
||
|
|
||
|
bool operator ==(EvalValue* b) final {
|
||
|
if (b->GetTypeClass() != TypeClass::UserData)
|
||
|
return false;
|
||
|
return _obj == ((UserDataValue*)b)->_obj;
|
||
|
}
|
||
|
|
||
|
shared_ptr<EvalValue> Clone() final{
|
||
|
return make_shared<UserDataValue>(_userData, _obj);
|
||
|
}
|
||
|
|
||
|
std::size_t GetHashCode() final{
|
||
|
return reinterpret_cast<intptr_t>(_obj);
|
||
|
}
|
||
|
|
||
|
shared_ptr<EvalValue> IndexValue(EvalValue* val) final {
|
||
|
auto fieldId = val->GetHashCode();
|
||
|
auto field = _userData->GetField(fieldId);
|
||
|
return shared_ptr<EvalValue>(field->Get(_obj));
|
||
|
}
|
||
|
};
|
||
|
|
||
|
|
||
|
#endif //PORYGONLANG_USERDATAVALUE_HPP
|