| 123456789101112131415161718192021222324252627282930313233343536373839 |
- use std::collections::HashMap;
-
- use log::error;
-
- use protocol::{Location, Value, ValueType};
-
- pub struct CurrentValues {
- map: HashMap<Key, i64>,
- }
-
- impl CurrentValues {
- pub fn new() -> CurrentValues {
- CurrentValues {
- map: HashMap::new(),
- }
- }
-
- pub fn set(&mut self, location: Location, value: Value) {
- let (type_, value) = match value.split() {
- Some(x) => x,
- None => {
- error!("Invalid value passed to CurrentValues::set().");
- return;
- }
- };
- self.map.insert(Key { location, type_ }, value);
- }
-
- pub fn get(&self, location: Location, type_: ValueType) -> Option<Value> {
- let entry = self.map.get(&Key { location, type_ })?.clone();
- Some(Value::combine(type_, entry))
- }
- }
-
- #[derive(Copy, Clone, PartialEq, Eq, Hash)]
- struct Key {
- location: Location,
- type_: ValueType,
- }
|