-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDefinitionManager.hpp
executable file
·92 lines (74 loc) · 2.1 KB
/
DefinitionManager.hpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* \file DefinitionManager
*
* \brief Enables a more flexibility in adding new definitions
*/
#ifndef DEFINITIONMANAGER_HPP
#define DEFINITIONMANAGER_HPP
#include "hashtablemap.hpp"
#include <map>
#include <vector>
#include <stdexcept>
#include "Cell.hpp"
using namespace std;
/**
* \class DefinitionManager
*
* \brief Singleton Class which manages the "stack" of definition
* tables
*
* DefinitionManager implements a singleton pattern. Therefore the
* constructor is private and the instance shall be called via
* DefinitionMangager::Instance(). This approach enables the
* DefinitionManager to initialize itself only ones (and also the
* default global definition table), without the need to hook into the
* entrypoint of the programm.
*/
class DefinitionManager {
public:
/**
* \brief Should be used to get the instance of this class. Will
* instantiate itself if is is not done yet. --> Singleton
* pattern
*/
static DefinitionManager* Instance();
/**
* \brief Adds a local stack frame
*/
void add_stackframe();
/**
* \brief Pops local stack frame
*/
void pop_stackframe() throw (logic_error);
/**
* \brief Adds definition to the current stack frame
*/
void add_definition(string key, Cell* c) throw (runtime_error);
/**
* \brief Checks if definition is available. Goes from through all "stack" frames
*/
bool is_definition(string key);
/**
* \brief get the definition, will look through the whole vector "stack" in order
* to find occurence
*/
Cell* get_definition(string key) const throw (runtime_error);
private:
/// typedef aliases for readability
typedef hashtablemap<string, Cell*> DefMap;
static DefinitionManager* instance;
static vector< DefMap > defs_stack_m;
/**
* \brief Constructor is private --> Singleton Pattern
*/
DefinitionManager();
/**
* \brief Makes sure there is no copy constructor
*/
DefinitionManager(DefinitionManager const&);
/**
* \brief Makes sure no assignments are possible
*/
void operator=(DefinitionManager const&);
};
#endif