/*
 * Context.h
 *
 *  Created on: Dec 30, 2012
 *      Author: att
 */

#ifndef CONTEXT_H_
#define CONTEXT_H_
#include <map>
#include <string>
#include "Utils/to_string.h"
#include "Elements/SenchaObject.h"
#include "Elements/SenchaFunction.h"
#include "AST/ASTExpression.h"



/**
 * Context is object used to store variables for some execution context.
 * It's most useful in function calls. Every function has to have its own execution contexts,
 * for its variables. Arguments are passed to functions by predefining them in new Context, assigned to
 * function.
 */
class Context {
public:
	Context(std::string name);
	std::string name;
	typedef SenchaObject (*PointerToNativeFunction)(std::vector<ASTExpression *>);
	void register_function(std::string name, PointerToNativeFunction f);
	void register_function(std::string name, SenchaFunction * f);
	SenchaObject execute_native_function(std::string name, std::vector<ASTExpression *> arguments);
	SenchaObject get_updated_string(std::string name);
	std::string debug() ;
	void add(std::string name, SenchaObject object);
	void set(std::string name, SenchaObject object);
	SenchaObject get(std::string name);
	bool contains_function(std::string name);
	bool contains_sfunction(std::string name);
	bool contains_nfunction(std::string name);
	std::map<std::string, PointerToNativeFunction> registered_functions;
	std::map<std::string, SenchaFunction *> registered_sfunctions;
	virtual ~Context();

private:
	unsigned int index;



	std::map<std::string, SenchaObject> object_store;
};

#endif /* CONTEXT_H_ */
