-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathoperational_point_cache.rs
73 lines (63 loc) · 1.95 KB
/
operational_point_cache.rs
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use derivative::Derivative;
use editoast_common::Identifier;
use editoast_schemas::primitives::OSRDIdentified;
use editoast_schemas::primitives::OSRDTyped;
use editoast_schemas::primitives::ObjectType;
use serde::Deserialize;
use serde::Serialize;
use crate::infra_cache::Cache;
use crate::infra_cache::ObjectCache;
use editoast_schemas::infra::OperationalPoint;
use editoast_schemas::infra::OperationalPointPart;
#[derive(Debug, Clone, Derivative)]
#[derivative(Hash, PartialEq)]
pub struct OperationalPointCache {
pub obj_id: String,
#[derivative(Hash = "ignore", PartialEq = "ignore")]
pub parts: Vec<OperationalPointPartCache>,
}
impl OperationalPointCache {
pub fn new(obj_id: String, parts: Vec<OperationalPointPartCache>) -> Self {
Self { obj_id, parts }
}
}
impl From<OperationalPoint> for OperationalPointCache {
fn from(op: OperationalPoint) -> Self {
let parts = op.parts.into_iter().map(|p| p.into()).collect();
Self::new(op.id.0, parts)
}
}
impl OSRDTyped for OperationalPointCache {
fn get_type() -> ObjectType {
ObjectType::OperationalPoint
}
}
impl OSRDIdentified for OperationalPointCache {
fn get_id(&self) -> &String {
&self.obj_id
}
}
impl Cache for OperationalPointCache {
fn get_track_referenced_id(&self) -> Vec<&String> {
self.parts.iter().map(|tr| &*tr.track).collect()
}
fn get_object_cache(&self) -> ObjectCache {
ObjectCache::OperationalPoint(self.clone())
}
}
#[derive(Debug, Derivative, Clone, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
#[derivative(Default, PartialEq)]
pub struct OperationalPointPartCache {
#[derivative(Default(value = r#""InvalidRef".into()"#))]
pub track: Identifier,
pub position: f64,
}
impl From<OperationalPointPart> for OperationalPointPartCache {
fn from(op: OperationalPointPart) -> Self {
Self {
track: op.track,
position: op.position,
}
}
}