-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvalState.cpp
More file actions
41 lines (32 loc) · 970 Bytes
/
EvalState.cpp
File metadata and controls
41 lines (32 loc) · 970 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
35
36
37
38
39
40
41
#include "evalstate.h"
#include <stdexcept>
EvalState::EvalState(std::istream &input, std::ostream &output)
: m_input(&input), m_output(&output) {}
void EvalState::setValue(const std::string& name, int value) {
variables[name] = value;
}
int EvalState::getValue(const std::string& name) const {
auto it = variables.find(name);
if (it == variables.end()) {
throw std::runtime_error("Undefined variable: " + name);
}
return it->second;
}
bool EvalState::isDefined(const std::string& name) const {
return variables.find(name) != variables.end();
}
void EvalState::clear() {
variables.clear();
}
void EvalState::setInputStream(std::istream &input) {
m_input = &input;
}
void EvalState::setOutputStream(std::ostream &output) {
m_output = &output;
}
std::istream &EvalState::input() const {
return *m_input;
}
std::ostream &EvalState::output() const {
return *m_output;
}