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;
|
|
|
|
}
|
|
|
|
|
2012-12-31 16:10:37 +00:00
|
|
|
void Context::register_function(std::string name, SenchaFunction * f)
|
2012-12-30 21:37:10 +00:00
|
|
|
{
|
2012-12-31 16:10:37 +00:00
|
|
|
registered_sfunctions[name] = f;
|
2012-12-30 21:37:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Context::add(std::string name, SenchaObject object)
|
|
|
|
{
|
2012-12-31 16:10:37 +00:00
|
|
|
object_store[name] = object;
|
2012-12-30 21:37:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SenchaObject Context::get(std::string name)
|
|
|
|
{
|
2012-12-31 16:10:37 +00:00
|
|
|
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 = "";
|
|
|
|
|
2012-12-31 16:10:37 +00:00
|
|
|
for( auto iter = this->object_store.begin(); iter != this->object_store.end(); iter++)
|
2012-12-30 21:37:10 +00:00
|
|
|
{
|
2012-12-31 16:10:37 +00:00
|
|
|
debug_note += "Context: " + (*iter).second.repr() + ": " + (*iter).first + " " + "\n";
|
2012-12-30 21:37:10 +00:00
|
|
|
}
|
|
|
|
return debug_note;
|
|
|
|
|
|
|
|
|
|
|
|
}
|