use super::super::ControlledGateBatch;
use crate::structures::{GateActuatorSnapshotData, OperatingControlSnapshotData, StructureError};
use numr::dtype::DType;
use numr::runtime::Runtime;
pub const CONTROLLED_GATE_SNAPSHOT_SCHEMA: &str = "hydr-controlled-gate-checkpoint-1";
pub const CONTROLLED_GATE_CONTRACT_VERSION: &str = "hydr-controlled-gate-numr-cpu-1";
#[derive(Clone, Debug, PartialEq)]
pub struct ControlledGateSnapshotData {
pub schema: String,
pub contract: String,
pub controls: OperatingControlSnapshotData,
pub actuators: GateActuatorSnapshotData,
}
#[derive(Clone, Debug)]
pub struct ControlledGateSnapshot<R: Runtime<DType = DType>> {
pub(super) batch: ControlledGateBatch<R>,
}
impl<R: Runtime<DType = DType>> ControlledGateSnapshot<R> {
pub fn time(&self) -> f64 {
self.batch.time()
}
pub fn data(&self) -> Result<ControlledGateSnapshotData, StructureError> {
self.batch.snapshot_data()
}
}
impl<R: Runtime<DType = DType>> ControlledGateBatch<R> {
pub fn snapshot(&self) -> ControlledGateSnapshot<R> {
ControlledGateSnapshot {
batch: self.clone(),
}
}
pub fn snapshot_data(&self) -> Result<ControlledGateSnapshotData, StructureError> {
Ok(ControlledGateSnapshotData {
schema: CONTROLLED_GATE_SNAPSHOT_SCHEMA.into(),
contract: CONTROLLED_GATE_CONTRACT_VERSION.into(),
controls: self.controls.snapshot_data()?,
actuators: self.actuators.snapshot_data()?,
})
}
}