-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVarChanger.cpp
45 lines (37 loc) · 1.07 KB
/
VarChanger.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// Created by matan on 12/19/19.
//
#include <iostream>
#include "VarChanger.h"
#include "helpFromEx1.h"
#include "GeneralResources.h"
//a command that changes a variable
//and swnd a messege to the simulator if needE:
int VarChanger::execute() {
protectSymbolTable.lock();
protectSymbolTable.unlock();
//calculating the var:
Interpreter* i = new Interpreter();
string vals = tableToString();
i->setVariables(vals);
Expression* expToCalc = i->interpret(VarChanger::exp);
double val = expToCalc->calculate();
//changing the symbol table if needed:
protectSymbolTable.lock();
if(val != symbolTable[VarChanger::varName]->getVal())
{
symbolTable[VarChanger::varName]->changeVal(val);
}
protectSymbolTable.unlock();
protectSymbolTable.lock();
//sending a command:
client->addCommand("set " + symbolTable[VarChanger::varName]->getPath() + " " + to_string(val) + "\r\n");
protectSymbolTable.unlock();
delete i;
return 2;
}
//constructor:
VarChanger::VarChanger(string name1, string exp1) {
VarChanger::varName = name1;
VarChanger::exp = exp1;
}