-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSetCommand.cpp
More file actions
49 lines (48 loc) · 1.34 KB
/
Copy pathSetCommand.cpp
File metadata and controls
49 lines (48 loc) · 1.34 KB
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
45
46
47
48
49
//
// Created by ofir8 on 12/20/18.
//
#include "SetCommand.h"
#include "MapsHandler.h"
#include "ComunicateWithSimulator.h"
/**
* constructor
*/
SetCommand::SetCommand(vector<string> vec) {
var = *vec.begin();
sign = vec.at(1);
params = vector<string>(vec.begin() + 2, vec.end());
}
/**
* the method sets the value to the var
*/
void SetCommand::doCommand() {
if (sign != "=" || !MapsHandler::isVarExist(var)) {
cout << "wrong input" << endl;
return;
}
Expression* ex;
vector<string>::iterator it = params.begin();
//It's a set
ex = ExpressionBuilder::getExpression(it, params.end());
//make sure it finished all the strings
if (it != params.end()) {
cout << "wrong input" << endl;
delete(ex);
return;
}
double value = ex->calculate();
delete(ex);
MapsHandler::addVar(var, value);
//if there is a bind - we need to inform all the vars in the bind
while (MapsHandler::isBindExist(var)) {
if(MapsHandler::isAddressExist(MapsHandler::getVarAddress(var))) {
MapsHandler::addToAddresses(MapsHandler::getVarAddress(var), value);
ComunicateWithSimulator::sendToServer(var, value);
break;
}
else {
var = MapsHandler::getVarAddress(var);
MapsHandler::addVar(var, value);
}
}
}