sencha-lang/Sencha-lang/ContextManager.h

48 lines
1014 B
C++

/*
* Context.h
*
* Created on: Dec 7, 2012
* Author: attero
*/
#ifndef CONTEXT_MANAGER_H_
#define CONTEXT_MANAGER_H_
#include <map>
#include <string>
#include <iostream>
#include <stack>
#include "Context.h"
/**
* ContextManager manages contexts.
*/
class ContextManager {
public:
ContextManager();
/**
* execute_function(name, arguments) executes function giving her its own execution context.
*/
SenchaObject execute_function(std::string name, std::vector<ASTExpression *> arguments);
//creation, destruction and basic access to contexts
Context * create_new_context();
void destroy_context(std::string name);
Context * context(std::string name);
//access to contexts using stack
Context * get_top();
void pop_context();
virtual ~ContextManager();
private:
/**
* Contexts are stored both in a stack (FILO) and in a map (indexed by names).
*/
std::stack<Context *> stack;
std::map<std::string, Context *> contexts;
unsigned int index;
};
#endif /* CONTEXT_MANAGER_H_ */