-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnvironment.c++
81 lines (56 loc) · 1.94 KB
/
Environment.c++
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
//
// Environment.c++
// Tech1
//
// Created by Justin Hust on 12/14/13.
// Copyright (c) 2013 __MyCompanyName__. All rights reserved.
//
#include <iostream>
#include <cassert>
#include "Environment.h"
// ---------------------------------------------------
Environment::Environment(void) {
// no init yet
}
// ---------------------------------------------------
Environment::~Environment(void) {
// no cleanup yet
}
// ---------------------------------------------------
void Environment::declare(const std::string &sKey, const Variant &defaultVal) {
_vars.insert( std::make_pair(sKey, defaultVal));
}
// ---------------------------------------------------
void Environment::set(const std::string &sKey, const Variant &val) {
std::map<std::string, Variant>::iterator it = _vars.find(sKey);
assert(it != _vars.end() );
// todo: re-enable this: assert(it->second.getType() == val.getType());
it->second = val;
}
// ---------------------------------------------------
Variant Environment::get(const std::string &sKey) const {
std::map<std::string, Variant>::const_iterator it = _vars.find(sKey);
assert(it != _vars.end() );
return it->second;
}
// ---------------------------------------------------
EnvironmentMgr::EnvironmentMgr(void) {
// no init yet
}
// ---------------------------------------------------
EnvironmentMgr::~EnvironmentMgr(void) {
// no cleanup yet
}
// ---------------------------------------------------
Environment * EnvironmentMgr::create(const std::string &sKey) {
Environment * newEnv = new Environment();
_envs.insert( std::make_pair(sKey, newEnv ) );
return newEnv;
}
// ---------------------------------------------------
Environment * EnvironmentMgr::lookup(const std::string &sKey) {
std::map<std::string, Environment *>::iterator it = _envs.find(sKey);
assert( it != _envs.end() );
return dynamic_cast<Environment *>(it->second);
}
// ---------------------------------------------------