Setup basics for userdata binary operations
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
3367e60ae5
commit
f7a6ff7d87
|
@ -6,10 +6,27 @@
|
|||
#include <utility>
|
||||
#include <unordered_map>
|
||||
#include "UserDataField.hpp"
|
||||
#include "UserDataOperation.hpp"
|
||||
|
||||
namespace Porygon::UserData {
|
||||
class UserData {
|
||||
std::unordered_map<uint32_t, UserDataField *> _fields;
|
||||
|
||||
// Binary operations
|
||||
UserDataBinaryOperation* _addition = nullptr;
|
||||
UserDataBinaryOperation* _subtraction = nullptr;
|
||||
UserDataBinaryOperation* _multiplication = nullptr;
|
||||
UserDataBinaryOperation* _division = nullptr;
|
||||
UserDataBinaryOperation* _equality = nullptr;
|
||||
UserDataBinaryOperation* _inequality = nullptr;
|
||||
UserDataBinaryOperation* _lessThen = nullptr;
|
||||
UserDataBinaryOperation* _lessThenEqual = nullptr;
|
||||
UserDataBinaryOperation* _greaterThen = nullptr;
|
||||
UserDataBinaryOperation* _greaterThenEqual = nullptr;
|
||||
UserDataBinaryOperation* _logicalAnd = nullptr;
|
||||
UserDataBinaryOperation* _logicalOr = nullptr;
|
||||
UserDataBinaryOperation* _concatenation = nullptr;
|
||||
|
||||
public:
|
||||
explicit UserData(std::unordered_map<uint32_t, UserDataField *> fields)
|
||||
: _fields(std::move(fields))
|
||||
|
@ -20,6 +37,19 @@ namespace Porygon::UserData {
|
|||
for (auto f: _fields){
|
||||
delete f.second;
|
||||
}
|
||||
delete _addition;
|
||||
delete _subtraction;
|
||||
delete _multiplication;
|
||||
delete _division;
|
||||
delete _equality;
|
||||
delete _inequality;
|
||||
delete _lessThen;
|
||||
delete _lessThenEqual;
|
||||
delete _greaterThen;
|
||||
delete _greaterThenEqual;
|
||||
delete _logicalAnd;
|
||||
delete _logicalOr;
|
||||
delete _concatenation;
|
||||
}
|
||||
|
||||
bool ContainsField(uint32_t fieldId) const{
|
||||
|
@ -37,6 +67,25 @@ namespace Porygon::UserData {
|
|||
int32_t GetFieldCount() const{
|
||||
return _fields.size();
|
||||
}
|
||||
|
||||
UserDataBinaryOperation* GetBinaryOperation(Binder::BoundBinaryOperation op){
|
||||
switch (op){
|
||||
|
||||
case Binder::BoundBinaryOperation::Addition: return _addition;
|
||||
case Binder::BoundBinaryOperation::Subtraction: return _subtraction;
|
||||
case Binder::BoundBinaryOperation::Multiplication: return _multiplication;
|
||||
case Binder::BoundBinaryOperation::Division: return _division;
|
||||
case Binder::BoundBinaryOperation::Equality: return _equality;
|
||||
case Binder::BoundBinaryOperation::Inequality: return _inequality;
|
||||
case Binder::BoundBinaryOperation::LessThan: return _lessThen;
|
||||
case Binder::BoundBinaryOperation::LessThanEquals: return _lessThenEqual;
|
||||
case Binder::BoundBinaryOperation::GreaterThan: return _greaterThen;
|
||||
case Binder::BoundBinaryOperation::GreaterThanEquals: return _greaterThenEqual;
|
||||
case Binder::BoundBinaryOperation::LogicalAnd: return _logicalAnd;
|
||||
case Binder::BoundBinaryOperation::LogicalOr: return _logicalOr;
|
||||
case Binder::BoundBinaryOperation::Concatenation: return _concatenation;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
#include "UserDataOperation.hpp"
|
|
@ -0,0 +1,37 @@
|
|||
|
||||
#ifndef PORYGONLANG_USERDATAOPERATION_HPP
|
||||
#define PORYGONLANG_USERDATAOPERATION_HPP
|
||||
#include <utility>
|
||||
#include "../Binder/BoundOperators.hpp"
|
||||
#include "../Evaluator/EvalValues/EvalValue.hpp"
|
||||
|
||||
namespace Porygon::UserData {
|
||||
class UserDataBinaryOperation {
|
||||
void* _parent;
|
||||
Evaluation::EvalValue *(*_func)(void *obj, Evaluation::EvalValue *b);
|
||||
const shared_ptr<ScriptType> _secondParameter;
|
||||
const shared_ptr<ScriptType> _returnType;
|
||||
public:
|
||||
UserDataBinaryOperation(void *parent,
|
||||
Evaluation::EvalValue *(*func)(void *, Evaluation::EvalValue *),
|
||||
shared_ptr<ScriptType> secondParameter,
|
||||
shared_ptr<ScriptType> returnType)
|
||||
: _parent(parent), _func(func), _secondParameter(std::move(secondParameter)),
|
||||
_returnType(std::move(returnType)) {}
|
||||
|
||||
Evaluation::EvalValue* Invoke(Evaluation::EvalValue * b) const{
|
||||
return _func(_parent, b);
|
||||
}
|
||||
|
||||
const shared_ptr<ScriptType> GetSecondParameterType() const{
|
||||
return _secondParameter;
|
||||
}
|
||||
|
||||
const shared_ptr<ScriptType> GetReturnType() const{
|
||||
return _returnType;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //PORYGONLANG_USERDATAOPERATION_HPP
|
Loading…
Reference in New Issue