sencha-lang/Sencha-lang/Context.cpp

70 lines
1.3 KiB
C++
Raw Normal View History

2012-12-30 21:37:10 +00:00
/*
* 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
}
2013-01-04 12:24:14 +00:00
bool Context::contains_function(std::string name)
{
return contains_sfunction(name) || contains_nfunction(name);
}
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);
}
2012-12-30 21:37:10 +00:00
void Context::register_function(std::string name, PointerToNativeFunction f)
{
registered_functions[name] = f;
}
void Context::register_function(std::string name, SenchaFunction * f)
2012-12-30 21:37:10 +00:00
{
registered_sfunctions[name] = f;
2012-12-30 21:37:10 +00:00
}
void Context::add(std::string name, SenchaObject object)
{
object_store[name] = object;
2012-12-30 21:37:10 +00:00
}
SenchaObject Context::get(std::string name)
{
if(object_store.count(name) != 0)
return object_store[name];
else return SenchaObject();
2012-12-30 21:37:10 +00:00
}
std::string Context::debug() {
std::string debug_note = "";
for( auto iter = this->object_store.begin(); iter != this->object_store.end(); iter++)
2012-12-30 21:37:10 +00:00
{
debug_note += "Context: " + (*iter).second.repr() + ": " + (*iter).first + " " + "\n";
2012-12-30 21:37:10 +00:00
}
return debug_note;
}