45 lines
1.1 KiB
C++
45 lines
1.1 KiB
C++
|
|
#ifndef PORYGONLANG_USERDATAFIELD_HPP
|
|
#define PORYGONLANG_USERDATAFIELD_HPP
|
|
|
|
|
|
#include "../Evaluator/EvalValues/EvalValue.hpp"
|
|
#include "../Evaluator/EvalValues/NumericEvalValue.hpp"
|
|
|
|
namespace Porygon::UserData{
|
|
class UserDataField {
|
|
shared_ptr<ScriptType> _type;
|
|
Evaluation::EvalValue* (*_get)(void* obj);
|
|
void (*_set)(void* obj, Evaluation::EvalValue* val);
|
|
public:
|
|
UserDataField(ScriptType* type, Evaluation::EvalValue* (*getter)(void* obj), void (*setter)(void* obj, Evaluation::EvalValue* val)){
|
|
_type = shared_ptr<ScriptType>(type);
|
|
_get = getter;
|
|
_set = setter;
|
|
}
|
|
|
|
shared_ptr<ScriptType> GetType(){
|
|
return _type;
|
|
}
|
|
|
|
bool HasGetter(){
|
|
return _get != nullptr;
|
|
}
|
|
|
|
Evaluation::EvalValue* Get(void* obj){
|
|
return this ->_get(obj);
|
|
}
|
|
|
|
bool HasSetter(){
|
|
return _set != nullptr;
|
|
}
|
|
|
|
void Set(void* obj, Evaluation::EvalValue* val){
|
|
this->_set(obj, val);
|
|
}
|
|
};
|
|
}
|
|
|
|
|
|
#endif //PORYGONLANG_USERDATAFIELD_HPP
|