|
|
@@ -1,20 +1,39 @@
|
|
|
1
|
+use std::collections::HashMap;
|
|
|
2
|
+
|
|
|
3
|
+use log::error;
|
|
|
4
|
+
|
|
1
|
5
|
use protocol::{Location, Value, ValueType};
|
|
2
|
6
|
|
|
3
|
7
|
pub struct CurrentValues {
|
|
4
|
|
- // TODO
|
|
|
8
|
+ map: HashMap<Key, i64>,
|
|
5
|
9
|
}
|
|
6
|
10
|
|
|
7
|
11
|
impl CurrentValues {
|
|
8
|
12
|
pub fn new() -> CurrentValues {
|
|
9
|
|
- CurrentValues {}
|
|
|
13
|
+ CurrentValues {
|
|
|
14
|
+ map: HashMap::new(),
|
|
|
15
|
+ }
|
|
10
|
16
|
}
|
|
11
|
17
|
|
|
12
|
|
- pub fn set(&mut self, location: Location, _value: Value) {
|
|
13
|
|
- // TODO
|
|
|
18
|
+ pub fn set(&mut self, location: Location, value: Value) {
|
|
|
19
|
+ let (type_, value) = match value.split() {
|
|
|
20
|
+ Some(x) => x,
|
|
|
21
|
+ None => {
|
|
|
22
|
+ error!("Invalid value passed to CurrentValues::set().");
|
|
|
23
|
+ return;
|
|
|
24
|
+ }
|
|
|
25
|
+ };
|
|
|
26
|
+ self.map.insert(Key { location, type_ }, value);
|
|
14
|
27
|
}
|
|
15
|
28
|
|
|
16
|
|
- pub fn get(&self, location: Location, _value: ValueType) -> Option<Value> {
|
|
17
|
|
- // TODO
|
|
18
|
|
- None
|
|
|
29
|
+ pub fn get(&self, location: Location, type_: ValueType) -> Option<Value> {
|
|
|
30
|
+ let entry = self.map.get(&Key { location, type_ })?.clone();
|
|
|
31
|
+ Some(Value::combine(type_, entry))
|
|
19
|
32
|
}
|
|
20
|
33
|
}
|
|
|
34
|
+
|
|
|
35
|
+#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
|
|
36
|
+struct Key {
|
|
|
37
|
+ location: Location,
|
|
|
38
|
+ type_: ValueType,
|
|
|
39
|
+}
|