use crate::{
io::{Data, Read, UniqueIdentifier, Write},
Update,
};
use linya::{Bar, Progress};
use std::{
mem::take,
sync::{Arc, Mutex},
};
mod signals;
#[doc(inline)]
pub use signals::{OneSignal, Signal, Signals};
mod timer;
#[doc(inline)]
pub use timer::{Tick, Timer, Void};
mod logging;
#[doc(inline)]
pub use logging::Logging;
mod sampler;
#[doc(inline)]
pub use sampler::Sampler;
mod integrator;
#[doc(inline)]
pub use integrator::Integrator;
mod smooth;
#[doc(inline)]
pub use smooth::{Smooth, Weight};
mod average;
#[doc(inline)]
pub use average::Average;
#[derive(Debug)]
pub(crate) struct ProgressBar {
progress: Arc<Mutex<Progress>>,
bar: Bar,
}
pub trait TimerMarker {}
impl<T: TimerMarker> Read<Tick> for T {
fn read(&mut self, _: Arc<Data<Tick>>) {}
}
pub struct Concat<T>(Vec<T>);
impl<T: Default> Default for Concat<T> {
fn default() -> Self {
Self(Vec::new())
}
}
impl<T> Update for Concat<T> {}
impl<T: Clone + Default, U: UniqueIdentifier<DataType = T>> Read<U> for Concat<T> {
fn read(&mut self, data: Arc<Data<U>>) {
self.0.push((*data).clone());
}
}
impl<T: Clone, U: UniqueIdentifier<DataType = Vec<T>>> Write<U> for Concat<T> {
fn write(&mut self) -> Option<Arc<Data<U>>> {
Some(Arc::new(Data::new(take(&mut self.0))))
}
}
pub struct Source<T> {
n: usize,
data: Vec<T>,
}
impl<T> Source<T> {
pub fn new(data: Vec<T>, n: usize) -> Self {
Source { n, data }
}
}
impl<T> TimerMarker for Source<T> {}
impl<T> Update for Source<T> {}
impl<T, V> Write<V> for Source<T>
where
V: UniqueIdentifier<DataType = Vec<T>>,
{
fn write(&mut self) -> Option<Arc<Data<V>>> {
if self.data.is_empty() {
None
} else {
let y: Vec<T> = self.data.drain(..self.n).collect();
Some(Arc::new(Data::new(y)))
}
}
}
#[cfg(feature = "nalgebra")]
mod gain;
#[cfg(feature = "nalgebra")]
pub use gain::Gain;