#include "EvaluationScope.hpp" #include namespace Porygon::Evaluation { EvaluationScope::EvaluationScope(map> *scriptVariables, int localVariableCount) { _scriptScope = scriptVariables; _localScope = map>(); } void EvaluationScope::CreateVariable(const BoundVariableKey *key, const shared_ptr &value) { if (key->GetScopeId() == 0) { _scriptScope->at(key->GetIdentifier()) = value; } else { auto insert = _localScope.insert({key->GetHash(), value}); if (!insert.second) { _localScope[key->GetHash()] = value; } } } void EvaluationScope::SetVariable(const BoundVariableKey *key, const shared_ptr &value) { if (key->GetScopeId() == 0) { _scriptScope->at(key->GetIdentifier()) = value; } else { _localScope[key->GetHash()] = value; } } shared_ptr EvaluationScope::GetVariable(const BoundVariableKey *key) { if (key->GetScopeId() == 0) { return _scriptScope->at(key->GetIdentifier()); } else { return _localScope[key->GetHash()]; } } }