-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryVar.cpp
More file actions
61 lines (56 loc) · 1.18 KB
/
MemoryVar.cpp
File metadata and controls
61 lines (56 loc) · 1.18 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
57
58
59
60
61
#include "MemoryVar.h"
MemoryVar::MemoryVar(ScriptMemory * memory) : mem(memory)
{
}
MemoryVar::~MemoryVar(void)
{
}
Variable * MemoryVar::clone(void) const
{
return new MemoryVar(*this);
}
#include "StringVar.h"
#include "BooleanVar.h"
std::shared_ptr<Variable> MemoryVar::operate(const std::string& op, std::shared_ptr<Variable> rhs, bool allocate)
{
std::shared_ptr<MemoryVar> var = std::dynamic_pointer_cast<MemoryVar>(rhs);
if (var!=0)
{
switch(op.front())
{
case'!':
{
if (op.size()==2 && op.back()=='=')
return std::shared_ptr<BooleanVar>(new BooleanVar(mem!=var->mem));
}
break;
case'=':
{
if (op.size()==2 && op.back()=='=')
return std::shared_ptr<BooleanVar>(new BooleanVar(mem==var->mem));
}
break;
default:
break;
}
}
if (op.compare(".")==0)
{
std::shared_ptr<StringVar> str = std::dynamic_pointer_cast<StringVar>(rhs);
if (str!=0)
{
if (mem!=0)
{
std::shared_ptr<Variable> var = mem->getVariable(str->str);
if (var!=0)
return var;
else
return mem->setVariable(str->str, std::shared_ptr<Variable>(new Variable()));
}
}
}
if (allocate)
return Variable::operate(op, rhs);
else
return 0;
}