-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPrintCommand.cpp
More file actions
56 lines (48 loc) · 1.52 KB
/
Copy pathPrintCommand.cpp
File metadata and controls
56 lines (48 loc) · 1.52 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
50
51
52
53
54
55
56
//
// Created by yuvalshechter on 02/01/2020.
//
#include "PrintCommand.h"
#include "thread"
//
// Created by adam on 02/01/2020.
//
#include <iostream>
#include <mutex>
using namespace std;
PrintCommand::PrintCommand(symbolTables* sT){
st = sT;
}
int PrintCommand::execute(int index) {
mutex m;
bool lock = m.try_lock();
if (!lock) {
cout << "unable to lock mutex in defineVarCommand" <<endl;
}
// toPrint is a print command that we should print
string toPrint = vec[index+2];
//if there is quotation marks we should print without it
if(toPrint[0] == '"') {
//cut the quotation marks
toPrint = toPrint.substr(1, toPrint.length() - 2);
if (toPrint == "done") {
flag = false;
}
this_thread::sleep_for(chrono::seconds(1));
//print the command
cout << toPrint << endl;
//it's not a print command and we need to print the value of the variable
} else {
//check if the variable is exist in the rightSignToSimulator map and print the value
if(st->rightSignToSimulator[toPrint]){
cout << st->rightSignToSimulator[toPrint]->getValue();
//the variable is exist in the leftSignFromSimulator map and print the value
} else if (st->leftSignFromSimulator[toPrint]){
//cout << "***CHECKKKK****";
cout << st->leftSignFromSimulator[toPrint]->getValue() << endl;
}
//cout << "check";
}
m.unlock();
return 5;
}
PrintCommand::~PrintCommand(){}