-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariables.cpp
More file actions
111 lines (97 loc) · 3.29 KB
/
variables.cpp
File metadata and controls
111 lines (97 loc) · 3.29 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "variables.h"
void VariablesContainer::Add(const std::string& variable_name,
const std::string& type) {
if (type == "int") {
int_container_[variable_name] = int();
} else if (type == "double") {
double_container_[variable_name] = double();
} else if (type == "bool") {
bool_container_[variable_name] = bool();
} else if (type == "string") {
string_container_[variable_name] = std::string();
} else {
std::cerr << "unknown type" << std::endl;
exit(RUNTIME_ERROR);
}
}
void VariablesContainer::ChangeInt(const std::string& variable_name,
int value) {
if (ExistsInt(variable_name)) {
int_container_[variable_name] = value;
} else {
std::cerr << variable_name
<< " isn't declared in this scope or has incompatible type"
<< std::endl;
exit(USAGE_ERROR);
}
}
void VariablesContainer::ChangeDouble(const std::string& variable_name,
double value) {
if (ExistsDouble(variable_name)) {
double_container_[variable_name] = value;
} else {
std::cerr << variable_name
<< " isn't declared in this scope or has incompatible type"
<< std::endl;
exit(USAGE_ERROR);
}
}
void VariablesContainer::ChangeBool(const std::string& variable_name,
bool value) {
if (ExistsBool(variable_name)) {
bool_container_[variable_name] = value;
} else {
std::cerr << variable_name
<< " isn't declared in this scope or has incompatible type"
<< std::endl;
exit(USAGE_ERROR);
}
}
void VariablesContainer::ChangeString(const std::string& variable_name,
const std::string& value) {
if (ExistsString(variable_name)) {
string_container_[variable_name] = value;
} else {
std::cerr << variable_name
<< " isn't declared in this scope or has incompatible type"
<< std::endl;
exit(USAGE_ERROR);
}
}
int VariablesContainer::GetInt(const std::string& variable_name) {
if (ExistsInt(variable_name)) {
return int_container_[variable_name];
}
exit(NOT_DECLARED_VARIABLE);
}
double VariablesContainer::GetDouble(const std::string& variable_name) {
if (ExistsDouble(variable_name)) {
return double_container_[variable_name];
}
exit(NOT_DECLARED_VARIABLE);
}
std::string VariablesContainer::GetString(const std::string& variable_name) {
if (ExistsString(variable_name)) {
return string_container_[variable_name];
}
exit(NOT_DECLARED_VARIABLE);
}
bool VariablesContainer::GetBool(const std::string& variable_name) {
if (ExistsBool(variable_name)) {
return bool_container_[variable_name];
}
exit(NOT_DECLARED_VARIABLE);
}
bool VariablesContainer::ExistsInt(const std::string& variable_name) {
return int_container_.count(variable_name) > 0;
}
bool VariablesContainer::ExistsDouble(const std::string& variable_name) {
return double_container_.count(variable_name) > 0;
}
bool VariablesContainer::ExistsString(const std::string& variable_name) {
return string_container_.count(variable_name) > 0;
}
bool VariablesContainer::ExistsBool(const std::string& variable_name) {
return bool_container_.count(variable_name) > 0;
}
VariablesContainer variables_container;