summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/ContextManager.h
blob: be4ccc9f0cc711e827885cea007582d89210d3d7 (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
/*
 * 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_ */