summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/Context.cpp
blob: 172cc47a8fd99fb5570e8a88ac1276c31bf12c6f (plain)
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
86
87
/*
 * Context.cpp
 *
 *  Created on: Dec 30, 2012
 *      Author: att
 */

#include "Context.h"

Context::Context(std::string name) {
	// TODO Auto-generated constructor stub
	this->index = 0;
	this->name = name;
}

Context::~Context() {
	// TODO Auto-generated destructor stub
}

bool Context::contains_function(std::string name)
{
	 return contains_sfunction(name) || contains_nfunction(name);
}

SenchaObject Context::get_updated_string(std::string name)
{
	SenchaObject result = get(name);
	if(result.type == SenchaObject::string_literal)
	{
		for(unsigned int i = 0; i < result.text.size(); i++)
		{
			std::string indexed_name = "_" + name + "_" + to_string(i);
			if(object_store.count(indexed_name) != 0)
			{
				result.text[i] = object_store[indexed_name].text[0];
			}
		}
	}
	add(name, result);
	return result;
}

bool Context::contains_sfunction(std::string name)
{
	return this->registered_sfunctions.count(name) == 1;
}

bool Context::contains_nfunction(std::string name)
{
	return this->registered_functions.count(name);
}

void Context::register_function(std::string name, PointerToNativeFunction f)
{
	registered_functions[name] = f;
}

void Context::register_function(std::string name, SenchaFunction * f)
{
	registered_sfunctions[name] = f;
}


void Context::add(std::string name, SenchaObject object)
{
	object_store[name] = object;
}


SenchaObject Context::get(std::string name)
{
	if(object_store.count(name) != 0)
		return object_store[name];
	else return SenchaObject();
}

std::string Context::debug() {
	std::string debug_note = "";

	for( auto iter = this->object_store.begin(); iter != this->object_store.end(); iter++)
	{
		debug_note += "Context: " + (*iter).second.repr() + ": "  + (*iter).first +  " "  + "\n";
	}
	return debug_note;


}