-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLevel.cpp
More file actions
42 lines (35 loc) · 1.25 KB
/
Level.cpp
File metadata and controls
42 lines (35 loc) · 1.25 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
#include "Level.h"
#include <iostream>
namespace cmd_calc {
static uint64_t gs_levels = 0;
Level::Level(const double in_val, const char in_op, const int in_prior, Level* in_prev)
: m_val(in_val), m_op(in_op), m_prior(in_prior), m_level_id(++gs_levels), prev(in_prev), next(nullptr) {
std::cout << " Created level #:" << m_level_id << ": " << m_val << " " << m_op << " : " << m_prior << std::endl;
}
void Level::exec() {
if (next) {
double rv = next->GetValue();
switch (m_op) {
case '+':
m_val += rv;
break;
case '-':
m_val -= rv;
break;
case '*':
m_val *= rv;
break;
case '/':
m_val /= rv;
break;
default: break;
}
m_op = next->get_oper();
m_prior = next->GetPriority();
std::cout << "Executed level #:" << m_level_id << ": " << m_val << " " << m_op << " : " << m_prior << std::endl;
delete next;
--gs_levels;
next = nullptr;
}
}
};