-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariable.cpp
More file actions
45 lines (34 loc) · 875 Bytes
/
Variable.cpp
File metadata and controls
45 lines (34 loc) · 875 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
42
43
//
// Created by Vinayak Agarwal on 12/4/21.
//
#include "Variable.h"
#include <utility>
#include "../Clock/GlobalClock.h"
pair<int, string> Variable::getLatestValue() {
if (value.empty()) return {};
return value.back();
}
pair<int, string> Variable::getLatestValue(int time) {
for (auto it = value.rbegin(); it != value.rend(); it++) {
if (it->first <= time) return *it;
}
return {};
}
void Variable::stageValue(string newValue) {
stagedValue = std::move(newValue);
stagingTime = GlobalClock::getTime();
}
void Variable::commitStagedValue() {
value.emplace_back(GlobalClock::getTime(), stagedValue);
isStale = false;
}
Variable::Variable(string var, string data) : var(std::move(var)) {
value.emplace_back(0, std::move(data));
isStale = false;
}
void Variable::markStale() {
isStale = true;
}
bool Variable::isDataStale() const {
return isStale;
}