-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathenv.h
More file actions
34 lines (27 loc) · 956 Bytes
/
env.h
File metadata and controls
34 lines (27 loc) · 956 Bytes
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
#ifndef TINYJS_ENV
#define TINYJS_ENV
#include <string>
#include <vector>
#include <unordered_map>
namespace Env
{
template <typename T>
class EnvImpl
{
private:
std::unordered_map<std::string, T> Symbol;
public:
std::string Name;
std::shared_ptr<EnvImpl<T>> Parent; // Parent Scope
EnvImpl() : Name("") { }
EnvImpl(const std::string& Name) : Name(Name) { }
EnvImpl(std::shared_ptr<EnvImpl<T>> Parent) : Name(""), Parent(Parent) { }
EnvImpl(const std::string& Name, std::shared_ptr<EnvImpl<T>> Parent) : Name(Name), Parent(Parent) { }
virtual ~EnvImpl() = default;
T get(const std::string& key) { return Symbol.find(key) != Symbol.end() ? Symbol[key] : nullptr; }
void set(const std::string& key, T value) { Symbol[key] = value; }
void set(const std::string& key) { Symbol[key] = 0; }
void reset() { Symbol.clear(); }
};
}
#endif