-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptMemory.cpp
More file actions
85 lines (73 loc) · 1.96 KB
/
ScriptMemory.cpp
File metadata and controls
85 lines (73 loc) · 1.96 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "ScriptMemory.h"
#include "Script.h"
ScriptMemory::ScriptMemory(void)
{
push(std::shared_ptr<MemoryLayer>(new MemoryLayer()));
}
ScriptMemory::~ScriptMemory(void)
{
}
#include <iostream>
std::shared_ptr<Variable> ScriptMemory::getVariable(const std::string& name, bool top)
{
//std::cout << "getting variable " << name << std::endl;
if (top)
{
return *(*var.front())[name];
}
for (auto i=var.rbegin();i!=var.rend();++i) {
if ((**i)[name]!=0) {
return *(**i)[name];
}
}
return 0;
}
std::shared_ptr<Variable> ScriptMemory::setVariable(const std::string& name, std::shared_ptr<Variable> variable, bool local, bool top)
{
//std::cout << "setting variable " << name << std::endl;
if (top)
{
(*var.front())[name] = std::shared_ptr<std::shared_ptr<Variable>>(new std::shared_ptr<Variable>(variable));
variable->address = (*var.front())[name];
return variable;
}
if (!local)
{
for (auto i=var.rbegin();i!=var.rend();++i)
if ((**i).find(name)!=(**i).end())
{
(**i)[name] = std::shared_ptr<std::shared_ptr<Variable>>(new std::shared_ptr<Variable>(variable));
variable->address = (**i)[name];
return variable;
}
}
(*var.back())[name] = std::shared_ptr<std::shared_ptr<Variable>>(new std::shared_ptr<Variable>(variable));
variable->address = (*var.back())[name];
return variable;
}
void ScriptMemory::pop(void)
{
var.pop_back();
}
void ScriptMemory::push(void)
{
var.push_back(std::shared_ptr<MemoryLayer>(new MemoryLayer()));
}
void ScriptMemory::push(const std::shared_ptr<MemoryLayer>& layer)
{
var.push_back(layer);
}
#include "FloatVar.h"
void ScriptMemory::get(const std::string& name, float& f)
{
std::shared_ptr<FloatVar> var = std::dynamic_pointer_cast<FloatVar>(getVariable(name));
if (var!=0)
f = var->f;
}
#include "StringVar.h"
void ScriptMemory::get(const std::string& name, std::string& str)
{
std::shared_ptr<StringVar> var = std::dynamic_pointer_cast<StringVar>(getVariable(name));
if (var!=0)
str = var->str;
}